Class: Metanorma::Plugin::Glossarist::BibliographyRenderer

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

Overview

Renders iev termbank and dataset bibliography entries as AsciiDoc bibliography items for rendered concepts.

Bibliography lookups go through the typed Glossarist::BibliographyData model — entries are matched by ‘id` and read via BibliographyEntry accessors (#reference, #title, #link).

Constant Summary collapse

IEV_ENTRY =
"* [[[ievtermbank,IEV]]], _IEV: Electropedia_"
IEV_ANCHOR =
"ievtermbank"

Instance Method Summary collapse

Constructor Details

#initialize(existing_anchors: [], bibliography: nil) ⇒ BibliographyRenderer

Returns a new instance of BibliographyRenderer.



18
19
20
21
22
# File 'lib/metanorma/plugin/glossarist/bibliography_renderer.rb', line 18

def initialize(existing_anchors: [], bibliography: nil)
  @rendered = {}
  @existing_anchors = Set.new(existing_anchors)
  @bibliography = bibliography
end

Instance Method Details

#render_all(concepts, lang: "eng") ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/metanorma/plugin/glossarist/bibliography_renderer.rb', line 33

def render_all(concepts, lang: "eng")
  all_entries = concepts.filter_map do |concept|
    l10n = concept.localization(lang)
    next unless l10n

    source_entries(l10n)
  end.flatten

  xref = concepts.filter_map do |concept|
    l10n = concept.localization(lang)
    next unless l10n

    xref_entries(l10n)
  end.flatten

  all_entries.concat(xref)
  all_entries.sort.join("\n")
end

#render_entry(concept, lang: "eng") ⇒ Object



24
25
26
27
28
29
30
31
# File 'lib/metanorma/plugin/glossarist/bibliography_renderer.rb', line 24

def render_entry(concept, lang: "eng")
  l10n = concept.localization(lang)
  return nil unless l10n

  entries = source_entries(l10n)
  entries.concat(xref_entries(l10n))
  entries.empty? ? nil : entries.sort.join("\n")
end