Class: Metanorma::Html::Flavor
- Inherits:
-
Object
- Object
- Metanorma::Html::Flavor
- Defined in:
- lib/metanorma/html/flavor.rb
Overview
A flavor ties together the four concepts that identify a Metanorma document variant:
- a symbolic name (used for theme loading, CSS class names)
- a model class (the typed root class for the flavor)
- a renderer class (the HTML renderer that handles the flavor)
- an optional Pubid module (for parsing identifiers like ISO/IEC/etc.)
Flavor centralizes flavor identity so BaseRenderer, PubidRenderer, and Generator all read from the same source of truth. Adding a new flavor is one Flavor entry in the registry, not three coordinated edits across three files.
Instance Attribute Summary collapse
-
#model_class ⇒ Object
readonly
Returns the value of attribute model_class.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#pubid_module ⇒ Object
readonly
Returns the value of attribute pubid_module.
-
#renderer_class ⇒ Object
readonly
Returns the value of attribute renderer_class.
Instance Method Summary collapse
-
#initialize(name:, model_class:, renderer_class:, pubid_module: nil) ⇒ Flavor
constructor
A new instance of Flavor.
-
#matches?(document_class) ⇒ Boolean
Match by ancestry: a document whose class is the flavor's model class, or any descendant of it, belongs to this flavor.
- #pubid_module_const ⇒ Object
Constructor Details
#initialize(name:, model_class:, renderer_class:, pubid_module: nil) ⇒ Flavor
Returns a new instance of Flavor.
21 22 23 24 25 26 |
# File 'lib/metanorma/html/flavor.rb', line 21 def initialize(name:, model_class:, renderer_class:, pubid_module: nil) @name = name @model_class = model_class @renderer_class = renderer_class @pubid_module = pubid_module end |
Instance Attribute Details
#model_class ⇒ Object (readonly)
Returns the value of attribute model_class.
19 20 21 |
# File 'lib/metanorma/html/flavor.rb', line 19 def model_class @model_class end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
19 20 21 |
# File 'lib/metanorma/html/flavor.rb', line 19 def name @name end |
#pubid_module ⇒ Object (readonly)
Returns the value of attribute pubid_module.
19 20 21 |
# File 'lib/metanorma/html/flavor.rb', line 19 def pubid_module @pubid_module end |
#renderer_class ⇒ Object (readonly)
Returns the value of attribute renderer_class.
19 20 21 |
# File 'lib/metanorma/html/flavor.rb', line 19 def renderer_class @renderer_class end |
Instance Method Details
#matches?(document_class) ⇒ Boolean
Match by ancestry: a document whose class is the flavor's model class, or any descendant of it, belongs to this flavor. Walks parent classes via is_a? to support subclassing.
31 32 33 34 35 36 |
# File 'lib/metanorma/html/flavor.rb', line 31 def matches?(document_class) return false unless document_class.is_a?(Class) # `<=` returns nil for unrelated classes; coerce to boolean. !!(document_class <= model_class) end |
#pubid_module_const ⇒ Object
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/metanorma/html/flavor.rb', line 38 def pubid_module_const return nil unless pubid_module Object.const_get(pubid_module.to_s) rescue NameError raise ArgumentError, "Flavor #{name.inspect}: pubid module #{pubid_module} could " \ "not be resolved — fix the registration in " \ "Html::Generator.build_flavor_registry" end |