From c4915ea9afdfcdb91dbccdfcde2bbf3ec37f074e Mon Sep 17 00:00:00 2001 From: Rene Saarsoo Date: Fri, 4 Jan 2013 11:57:54 +0200 Subject: [PATCH] Extract TagLoader class from TagRegistry. --- lib/jsduck/tag_loader.rb | 29 +++++++++++++++++++++++++++++ lib/jsduck/tag_registry.rb | 18 +++--------------- 2 files changed, 32 insertions(+), 15 deletions(-) create mode 100644 lib/jsduck/tag_loader.rb diff --git a/lib/jsduck/tag_loader.rb b/lib/jsduck/tag_loader.rb new file mode 100644 index 00000000..3c1d4098 --- /dev/null +++ b/lib/jsduck/tag_loader.rb @@ -0,0 +1,29 @@ +require "jsduck/tag/tag" + +module JsDuck + + class TagLoader + # Loads builtin tags from /tag dir. + # Returns array of Tag classes. + def load_builtins + load_tag_classes(File.dirname(__FILE__) + "/tag") + tag_classes + end + + private + + # Loads tags from given dir. + def load_tag_classes(dirname) + Dir[dirname+"/**/*.rb"].each {|file| require(file) } + end + + # Returns all available Tag classes sorted alphabetically. This + # ensures attributes in member signatures are always rendered in + # the same order. + def tag_classes + JsDuck::Tag::Tag.descendants.sort {|a, b| a.to_s <=> b.to_s } + end + + end + +end diff --git a/lib/jsduck/tag_registry.rb b/lib/jsduck/tag_registry.rb index 83791769..9d0512d1 100644 --- a/lib/jsduck/tag_registry.rb +++ b/lib/jsduck/tag_registry.rb @@ -1,4 +1,4 @@ -require "jsduck/tag/tag" +require "jsduck/tag_loader" require "jsduck/util/singleton" module JsDuck @@ -15,17 +15,12 @@ module JsDuck @keys = {} @signatures = [] @html_renderers = {:top => [], :bottom => []} - load_tag_classes(File.dirname(__FILE__) + "/tag") - instantiate_tags - end - # Loads tags from given dir. - def load_tag_classes(dirname) - Dir[dirname+"/**/*.rb"].each {|file| require(file) } + instantiate_tags(TagLoader.new.load_builtins) end # Instantiates all descendants of JsDuck::Tag::Tag - def instantiate_tags + def instantiate_tags(tag_classes) tag_classes.each do |cls| tag = cls.new() Array(tag.pattern).each do |pattern| @@ -53,13 +48,6 @@ module JsDuck end end - # Returns all available Tag classes sorted alphabetically. This - # ensures attributes in member signatures are always rendered in - # the same order. - def tag_classes - JsDuck::Tag::Tag.descendants.sort {|a, b| a.to_s <=> b.to_s } - end - # # Accessors for lists of tags # -- GitLab