Module: Metanorma::Html::Concerns::TocRegistry

Included in:
BaseRenderer
Defined in:
lib/metanorma/html/concerns/toc_registry.rb

Overview

Table-of-contents entry collection and ToC rendering, mixed into BaseRenderer. Sub-renderers register section/figure/table entries as they walk the document; assemble_document renders the collected entries through the _toc.html.liquid template.

Instance Method Summary collapse

Instance Method Details

#build_toc_html(entries) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/metanorma/html/concerns/toc_registry.rb', line 15

def build_toc_html(entries)
  entry_drops = entries.map { |e| Drops::TocEntryDrop.new(e) }
  figure_drops = @figure_entries.map { |f| Drops::FigureListEntryDrop.new(f) }
  table_drops = @table_entries.map { |t| Drops::FigureListEntryDrop.new(t) }
  has_special_lists = !@figure_entries.empty? || !@table_entries.empty?

  render_liquid("_toc.html.liquid", {
                  "entries" => entry_drops,
                  "figures" => figure_drops,
                  "tables" => table_drops,
                  "has_special_lists" => has_special_lists,
                })
end

#figure_entriesObject



37
38
39
# File 'lib/metanorma/html/concerns/toc_registry.rb', line 37

def figure_entries
  @figure_entries
end

#register_figure_entry(id:, text:) ⇒ Object



33
34
35
# File 'lib/metanorma/html/concerns/toc_registry.rb', line 33

def register_figure_entry(id:, text:)
  @figure_entries << { id: id, text: text }
end

#register_table_entry(id:, text:) ⇒ Object



41
42
43
# File 'lib/metanorma/html/concerns/toc_registry.rb', line 41

def register_table_entry(id:, text:)
  @table_entries << { id: id, text: text }
end

#register_toc_entry(id:, level:, text:) ⇒ Object



29
30
31
# File 'lib/metanorma/html/concerns/toc_registry.rb', line 29

def register_toc_entry(id:, level:, text:)
  @toc_entries << { id: id, level: level, text: text }
end

#toc_entriesObject



11
12
13
# File 'lib/metanorma/html/concerns/toc_registry.rb', line 11

def toc_entries
  @toc_entries
end