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

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

Constant Summary collapse

TEMPLATES_DIR =
File.join(File.dirname(__FILE__), "liquid_templates")
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.



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

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



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

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



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

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