Class: Metanorma::Plugin::Glossarist::SectionRenderer

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

Overview

Renders concepts grouped by section, with cascading membership and configurable sort order.

Extracted from DatasetPreprocessor to keep section rendering as a single MECE concern: it owns section → concepts resolution, heading depth, and per-section rendering. Callers retain ownership of the rendered-concept accumulator (passed via the block) so the preprocessor’s global state stays in one place.

Constant Summary collapse

DEFAULT_SORT_BY =
"term"

Instance Method Summary collapse

Constructor Details

#initialize(dataset:, register:, renderer:, depth:, **options) ⇒ SectionRenderer

Returns a new instance of SectionRenderer.

Parameters:

  • dataset (Enumerable<ManagedConcept>)

    the full dataset

  • register (Glossarist::DatasetRegister, nil)

    for cascading

  • renderer (TemplateRenderer)

    concept renderer

  • depth (Integer)

    base heading depth for sections

  • options (Hash)

    :sort_by, :anchor_prefix



22
23
24
25
26
27
28
29
# File 'lib/metanorma/plugin/glossarist/section_renderer.rb', line 22

def initialize(dataset:, register:, renderer:, depth:, **options)
  @dataset = dataset
  @register = register
  @renderer = renderer
  @depth = depth
  @sort_by = options[:sort_by] || DEFAULT_SORT_BY
  @anchor_prefix = options[:anchor_prefix]
end

Instance Method Details

#render(sections) {|Array<ManagedConcept>| ... } ⇒ Array<String>

Returns one rendered block per non-empty section.

Parameters:

  • sections (Array<Glossarist::Section>)

Yields:

  • (Array<ManagedConcept>)

    concepts matched for each section

Returns:

  • (Array<String>)

    one rendered block per non-empty section



34
35
36
37
38
39
40
41
42
43
# File 'lib/metanorma/plugin/glossarist/section_renderer.rb', line 34

def render(sections)
  sections.filter_map do |section|
    concepts = concepts_for(section)
    next if concepts.empty?

    yield concepts if block_given?

    block_for(section, concepts)
  end
end