Class: JsDuck::TagRegistry
- Inherits:
-
Object
- Object
- JsDuck::TagRegistry
- Defined in:
- lib/jsduck/tag_registry.rb
Overview
Access to builtin @tags
Instance Attribute Summary collapse
-
#ext_define_defaults ⇒ Object
readonly
Default values for class config when Ext.define is encountered.
-
#signatures ⇒ Object
readonly
Array of attributes to be shown in member signatures (and in order they should be shown in).
Class Method Summary collapse
-
.instance ⇒ Object
Access to the singleton instance (only used internally).
-
.method_missing(meth, *args, &block) ⇒ Object
Redirect calls from TagRegistry.method to TagRegistry.instance.method, making it behave like other Singleton classes.
-
.reconfigure(load_paths) ⇒ Object
Reconfigures the registry with additional load paths.
Instance Method Summary collapse
-
#css ⇒ Object
Returns all the CSS gathered from @css attributes of tags.
-
#get_by_ext_define_pattern(name) ⇒ Object
Accesses tag by Ext.define pattern.
-
#get_by_name(name) ⇒ Object
Accesses tag by name - the symbol under which the tag data is stored in final hash.
-
#get_by_pattern(name) ⇒ Object
Accesses tag by @name pattern.
-
#html_renderers ⇒ Object
Returns tags for rendering HTML, sorted in the order they should appear in final output.
-
#initialize(load_paths = []) ⇒ TagRegistry
constructor
A new instance of TagRegistry.
-
#instantiate_tags(tag_classes) ⇒ Object
Instantiates all descendants of JsDuck::Tag::Tag.
-
#member_type_names ⇒ Object
Same as #member_types, but returns just the names of member types.
-
#member_type_regex ⇒ Object
Regex for matching member type name in member reference.
-
#member_types ⇒ Object
Returns array of available member types.
Constructor Details
#initialize(load_paths = []) ⇒ TagRegistry
Returns a new instance of TagRegistry.
25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/jsduck/tag_registry.rb', line 25 def initialize(load_paths=[]) @patterns = {} @ext_define_patterns = {} @ext_define_defaults = {} @tagnames = {} @signatures = [] @html_renderers = [] @html_renderers_sorted = false @member_types = [] @css = [] (TagLoader.new(load_paths).load_all) end |
Instance Attribute Details
#ext_define_defaults ⇒ Object (readonly)
Default values for class config when Ext.define is encountered.
85 86 87 |
# File 'lib/jsduck/tag_registry.rb', line 85 def ext_define_defaults @ext_define_defaults end |
#signatures ⇒ Object (readonly)
Array of attributes to be shown in member signatures (and in order they should be shown in).
89 90 91 |
# File 'lib/jsduck/tag_registry.rb', line 89 def signatures @signatures end |
Class Method Details
.instance ⇒ Object
Access to the singleton instance (only used internally)
8 9 10 11 |
# File 'lib/jsduck/tag_registry.rb', line 8 def self.instance @instance = TagRegistry.new unless @instance @instance end |
.method_missing(meth, *args, &block) ⇒ Object
Redirect calls from TagRegistry.method to TagRegistry.instance.method, making it behave like other Singleton classes.
21 22 23 |
# File 'lib/jsduck/tag_registry.rb', line 21 def self.method_missing(meth, *args, &block) self.instance.send(meth, *args, &block) end |
.reconfigure(load_paths) ⇒ Object
Reconfigures the registry with additional load paths. Used in Options class.
15 16 17 |
# File 'lib/jsduck/tag_registry.rb', line 15 def self.reconfigure(load_paths) @instance = TagRegistry.new(load_paths) end |
Instance Method Details
#css ⇒ Object
Returns all the CSS gathered from @css attributes of tags.
130 131 132 |
# File 'lib/jsduck/tag_registry.rb', line 130 def css @css.join("\n") end |
#get_by_ext_define_pattern(name) ⇒ Object
Accesses tag by Ext.define pattern
144 145 146 |
# File 'lib/jsduck/tag_registry.rb', line 144 def get_by_ext_define_pattern(name) @ext_define_patterns[name] end |
#get_by_name(name) ⇒ Object
Accesses tag by name - the symbol under which the tag data is stored in final hash.
150 151 152 |
# File 'lib/jsduck/tag_registry.rb', line 150 def get_by_name(name) @tagnames[name] end |
#get_by_pattern(name) ⇒ Object
Accesses tag by @name pattern
139 140 141 |
# File 'lib/jsduck/tag_registry.rb', line 139 def get_by_pattern(name) @patterns[name] end |
#html_renderers ⇒ Object
Returns tags for rendering HTML, sorted in the order they should appear in final output. Sorting order is determined by the numeric :html_position field.
120 121 122 123 124 125 126 127 |
# File 'lib/jsduck/tag_registry.rb', line 120 def html_renderers if !@html_renderers_sorted @html_renderers.sort! {|a, b| a.html_position <=> b.html_position } @html_renderers_sorted = true end @html_renderers end |
#instantiate_tags(tag_classes) ⇒ Object
Instantiates all descendants of JsDuck::Tag::Tag
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/jsduck/tag_registry.rb', line 40 def (tag_classes) tag_classes.each do |cls| tag = cls.new() Array(tag.pattern).each do |pattern| @patterns[pattern] = tag end Array(tag.ext_define_pattern).each do |pattern| @ext_define_patterns[pattern] = tag end if tag.ext_define_default @ext_define_defaults.merge!(tag.ext_define_default) end if tag.tagname @tagnames[tag.tagname] = tag end if tag.respond_to?(:member_type) && tag.member_type tag.member_type[:name] = tag.tagname @member_types << tag.member_type end if tag.signature tag.signature[:tagname] = tag.tagname @signatures << tag.signature end if tag.html_position @html_renderers << tag end if tag.css @css << tag.css end end end |
#member_type_names ⇒ Object
Same as #member_types, but returns just the names of member types.
92 93 94 |
# File 'lib/jsduck/tag_registry.rb', line 92 def member_type_names member_types.map {|mt| mt[:name] } end |
#member_type_regex ⇒ Object
Regex for matching member type name in member reference.
The regex matches strings like: “method-” or “event-”. It contains a capture group to capture the actual name of the member, leaving out the dash “-”.
112 113 114 115 |
# File 'lib/jsduck/tag_registry.rb', line 112 def member_type_regex @member_type_regex if @member_type_regex @member_type_regex = Regexp.new("(?:(" + member_type_names.join("|") + ")-)") end |
#member_types ⇒ Object
Returns array of available member types. Sorted in the order defined by :position.
98 99 100 101 102 103 104 105 |
# File 'lib/jsduck/tag_registry.rb', line 98 def member_types if !@member_types_sorted @member_types.sort! {|a, b| a[:position] <=> b[:position] } @member_types_sorted = true end @member_types end |