Class: Metanorma::Plugin::Glossarist::NonVerbalRenderer
- Inherits:
-
Object
- Object
- Metanorma::Plugin::Glossarist::NonVerbalRenderer
- Defined in:
- lib/metanorma/plugin/glossarist/non_verbal_renderer.rb
Overview
Renders dataset-level non-verbal entities (Figure, Table, Formula) as AsciiDoc blocks. MECE sibling to BibliographyRenderer: where BibliographyRenderer owns citation provenance, NonVerbalRenderer owns the rendering of authored figures/tables/formulas.
Per-kind formatting is delegated to a formatter class registered
in FORMATTERS. Adding a new kind = adding one formatter class
and one entry here; the dispatcher itself never changes shape.
Collections are Array<Figure|Table|Formula> as returned by
GlossaryStore#figures/#tables/#formulas. Lookups by id
(for concept→entity refs) use a lazily-built index that includes
Figure subfigures, preserving the recursive Figure#find_by_id
semantics of the previous Collection-based path.
Constant Summary collapse
- FORMATTERS =
{ figures: NonVerbalFormatters::Figure, tables: NonVerbalFormatters::Table, formulas: NonVerbalFormatters::Formula, }.freeze
Instance Method Summary collapse
-
#initialize(collections:, lang: "eng") ⇒ NonVerbalRenderer
constructor
A new instance of NonVerbalRenderer.
-
#render_concept_refs(concept) ⇒ String
Render the non-verbal entities referenced by a concept's figures/tables/formulas ref collections, in deterministic order (figures, tables, formulas).
-
#render_kind(kind) ⇒ String
Render every entity in the named collection.
Constructor Details
#initialize(collections:, lang: "eng") ⇒ NonVerbalRenderer
Returns a new instance of NonVerbalRenderer.
31 32 33 34 35 |
# File 'lib/metanorma/plugin/glossarist/non_verbal_renderer.rb', line 31 def initialize(collections:, lang: "eng") @collections = collections @lang = lang @indices = {} end |
Instance Method Details
#render_concept_refs(concept) ⇒ String
Render the non-verbal entities referenced by a concept's figures/tables/formulas ref collections, in deterministic order (figures, tables, formulas). Unknown refs are skipped silently — they will surface as missing anchors during Metanorma rendering.
55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/metanorma/plugin/glossarist/non_verbal_renderer.rb', line 55 def render_concept_refs(concept) FORMATTERS.keys.filter_map do |kind| refs = concept_refs(concept, kind) next if refs.empty? blocks = refs.filter_map { |ref| render_ref(kind, ref) } next if blocks.empty? "#{blocks.join("\n\n")}\n" end.join("\n") end |
#render_kind(kind) ⇒ String
Render every entity in the named collection.
41 42 43 44 45 46 |
# File 'lib/metanorma/plugin/glossarist/non_verbal_renderer.rb', line 41 def render_kind(kind) entities = @collections[kind] return "" if entities.nil? || entities.empty? "#{entities.map { |e| format_one(kind, e) }.join("\n\n")}\n" end |