Class: Metanorma::Html::FlavorRegistry
- Inherits:
-
Object
- Object
- Metanorma::Html::FlavorRegistry
- Includes:
- Enumerable
- Defined in:
- lib/metanorma/html/flavor_registry.rb
Overview
Registry of known flavors. Queried by:
- Generator — to pick the renderer for a document
- BaseRenderer — to resolve flavor_name for theme loading
- PubidRenderer — to resolve the Pubid module
Single source of truth for flavor identity. Adding a flavor is one Flavor entry via #register.
Instance Method Summary collapse
- #each ⇒ Object
-
#find_for(document_class) ⇒ Object
Returns the most-specific Flavor whose model_class matches the given document class (by ancestry).
-
#initialize ⇒ FlavorRegistry
constructor
A new instance of FlavorRegistry.
- #name_for(document_class) ⇒ Object
- #pubid_module_for(document_class) ⇒ Object
- #register(flavor) ⇒ Object
- #renderer_for(document_class) ⇒ Object
Constructor Details
#initialize ⇒ FlavorRegistry
Returns a new instance of FlavorRegistry.
15 16 17 |
# File 'lib/metanorma/html/flavor_registry.rb', line 15 def initialize @flavors = [] end |
Instance Method Details
#each ⇒ Object
24 25 26 |
# File 'lib/metanorma/html/flavor_registry.rb', line 24 def each(&) @flavors.each(&) end |
#find_for(document_class) ⇒ Object
Returns the most-specific Flavor whose model_class matches the given document class (by ancestry). Most-specific = registered last. We scan in reverse so general flavors (registered first) only match if no more specific flavor does.
32 33 34 |
# File 'lib/metanorma/html/flavor_registry.rb', line 32 def find_for(document_class) @flavors.reverse_each.find { |f| f.matches?(document_class) } end |
#name_for(document_class) ⇒ Object
36 37 38 |
# File 'lib/metanorma/html/flavor_registry.rb', line 36 def name_for(document_class) find_for(document_class)&.name end |
#pubid_module_for(document_class) ⇒ Object
44 45 46 |
# File 'lib/metanorma/html/flavor_registry.rb', line 44 def pubid_module_for(document_class) find_for(document_class)&.pubid_module_const end |
#register(flavor) ⇒ Object
19 20 21 22 |
# File 'lib/metanorma/html/flavor_registry.rb', line 19 def register(flavor) @flavors << flavor self end |
#renderer_for(document_class) ⇒ Object
40 41 42 |
# File 'lib/metanorma/html/flavor_registry.rb', line 40 def renderer_for(document_class) find_for(document_class)&.renderer_class end |