Class: Metanorma::Plugin::Glossarist::TemplateRenderer

Inherits:
Object
  • Object
show all
Defined in:
lib/metanorma/plugin/glossarist/template_renderer.rb

Constant Summary collapse

DEFAULT_TEMPLATE =
File.join(TEMPLATES_DIR, "_concept.liquid")

Instance Method Summary collapse

Constructor Details

#initialize(file_system:, lang: "eng") ⇒ TemplateRenderer

Returns a new instance of TemplateRenderer.



9
10
11
12
13
# File 'lib/metanorma/plugin/glossarist/template_renderer.rb', line 9

def initialize(file_system:, lang: "eng")
  @file_system = file_system
  @lang = lang
  @template_cache = {}
end

Instance Method Details

#render_concept(concept, depth:, anchor_prefix: nil) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/metanorma/plugin/glossarist/template_renderer.rb', line 21

def render_concept(concept, depth:, anchor_prefix: nil)
  l10n = concept.localization(@lang)
  context = {
    "concept" => concept.to_liquid,
    "l10n" => l10n&.to_liquid,
    "depth_marker" => "=" * (depth + 1),
    "anchor" => build_anchor(concept.data.id.to_s, anchor_prefix),
  }
  template_content = cached_template(concept)
  rendered = render_template(template_content, context)
  normalize_whitespace(rendered)
end

#render_concepts(concepts, depth:, anchor_prefix: nil) ⇒ Object



15
16
17
18
19
# File 'lib/metanorma/plugin/glossarist/template_renderer.rb', line 15

def render_concepts(concepts, depth:, anchor_prefix: nil)
  tree = build_concept_tree(concepts)
  parts = tree.map { |c| render_tree_node(c, depth, anchor_prefix) }
  normalize_whitespace(parts.join("\n\n"))
end