Class: Metanorma::Plugin::Glossarist::NonVerbalRenderer

Inherits:
Object
  • Object
show all
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

Constructor Details

#initialize(collections:, lang: "eng") ⇒ NonVerbalRenderer

Returns a new instance of NonVerbalRenderer.

Parameters:

  • collections (Hash{Symbol => NonVerbalCollection, nil})

    one entry per non-verbal kind, e.g. ‘{ figures: FigureCollection, tables: …, formulas: … }`. Missing or nil entries are silently skipped.



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.

Parameters:

  • concept (Glossarist::ManagedConcept)

Returns:

  • (String)


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.

Parameters:

  • kind (Symbol)

    key in FORMATTERS (e.g. :figures)

Returns:

  • (String)

    AsciiDoc blocks joined by blank lines, or “”



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