Class: JsDuck::MetaTagRegistry
- Inherits:
-
Object
- Object
- JsDuck::MetaTagRegistry
- Defined in:
- lib/jsduck/meta_tag_registry.rb
Overview
Access to meta-tags
Constant Summary collapse
- @@instance =
nil
Class Method Summary collapse
-
.instance ⇒ Object
Returns singleton instance of MetaTagRegistry.
-
.instance=(instance) ⇒ Object
Allows injecting another MetaTagRegistry to be used as a global instance.
Instance Method Summary collapse
-
#[](name) ⇒ Object
Accesses tag by key or name.
-
#assets=(assets) ⇒ Object
Gives access to assets for all tags.
-
#formatter ⇒ Object
Returns the formatter assigned to tags.
-
#formatter=(doc_formatter) ⇒ Object
Sets the doc-formatter for all tags.
-
#initialize ⇒ MetaTagRegistry
constructor
A new instance of MetaTagRegistry.
-
#load(paths) ⇒ Object
Loads meta-tags from the given paths.
-
#register(tags) ⇒ Object
Registers MetaTag instances.
-
#signatures ⇒ Object
Returns array of attributes to be shown in member signatures (and in order they should be shown in).
-
#tags(position = nil) ⇒ Object
Returns array of all available tag instances.
Constructor Details
#initialize ⇒ MetaTagRegistry
Returns a new instance of MetaTagRegistry.
26 27 28 29 |
# File 'lib/jsduck/meta_tag_registry.rb', line 26 def initialize @tags = [] @map = {} end |
Class Method Details
.instance ⇒ Object
Returns singleton instance of MetaTagRegistry. By default this will be auto-loaded with builtin tags.
12 13 14 15 16 17 18 |
# File 'lib/jsduck/meta_tag_registry.rb', line 12 def self.instance if !@@instance @@instance = MetaTagRegistry.new @@instance.load([:builtins]) end @@instance end |
.instance=(instance) ⇒ Object
Allows injecting another MetaTagRegistry to be used as a global instance.
21 22 23 |
# File 'lib/jsduck/meta_tag_registry.rb', line 21 def self.instance=(instance) @@instance = instance end |
Instance Method Details
#[](name) ⇒ Object
Accesses tag by key or name
67 68 69 |
# File 'lib/jsduck/meta_tag_registry.rb', line 67 def [](name) @map[name] end |
#assets=(assets) ⇒ Object
Gives access to assets for all tags
83 84 85 |
# File 'lib/jsduck/meta_tag_registry.rb', line 83 def assets=(assets) @tags.each {|tag| tag.assets = assets } end |
#formatter ⇒ Object
Returns the formatter assigned to tags
72 73 74 |
# File 'lib/jsduck/meta_tag_registry.rb', line 72 def formatter @formatter end |
#formatter=(doc_formatter) ⇒ Object
Sets the doc-formatter for all tags
77 78 79 80 |
# File 'lib/jsduck/meta_tag_registry.rb', line 77 def formatter=(doc_formatter) @formatter = doc_formatter @tags.each {|tag| tag.formatter = doc_formatter } end |
#load(paths) ⇒ Object
Loads meta-tags from the given paths. See MetaTagLoader#load for details.
This should only be called once. Calling it twice will override the previously loaded tags.
36 37 38 39 40 |
# File 'lib/jsduck/meta_tag_registry.rb', line 36 def load(paths) loader = MetaTagLoader.new paths.each {|p| loader.load(p) } register(loader.) end |
#register(tags) ⇒ Object
Registers MetaTag instances.
NB! This is for testing purposes only, elsewhere always use #load.
45 46 47 48 |
# File 'lib/jsduck/meta_tag_registry.rb', line 45 def register() @tags = register_keys end |
#signatures ⇒ Object
Returns array of attributes to be shown in member signatures (and in order they should be shown in).
89 90 91 92 93 94 95 96 97 98 |
# File 'lib/jsduck/meta_tag_registry.rb', line 89 def signatures if !@signatures @signatures = @tags.find_all(&:signature).map do |tag| s = tag.signature s[:key] = tag.key s end end @signatures end |
#tags(position = nil) ⇒ Object
Returns array of all available tag instances. When position provided, returns only tags in that position
52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/jsduck/meta_tag_registry.rb', line 52 def (position=nil) return @tags unless position unless @position_map @position_map = {} @tags.each do |t| @position_map[t.position] = [] unless @position_map[t.position] @position_map[t.position] << t end end @position_map[position] || [] end |