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.
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.
25 26 27 28 |
# File 'lib/metanorma/plugin/glossarist/non_verbal_renderer.rb', line 25 def initialize(collections:, lang: "eng") @collections = collections @lang = lang 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.
49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/metanorma/plugin/glossarist/non_verbal_renderer.rb', line 49 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.
34 35 36 37 38 39 40 |
# File 'lib/metanorma/plugin/glossarist/non_verbal_renderer.rb', line 34 def render_kind(kind) collection = @collections[kind] return "" if collection.nil? || collection.entries.empty? entries = collection.entries "#{entries.map { |e| format_one(kind, e) }.join("\n\n")}\n" end |