Class: Metanorma::Plugin::Glossarist::Document

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeDocument

Returns a new instance of Document.



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

def initialize
  @content = []
  @bibliographies = []
end

Instance Attribute Details

#bibliographiesObject

Returns the value of attribute bibliographies.



7
8
9
# File 'lib/metanorma/plugin/glossarist/document.rb', line 7

def bibliographies
  @bibliographies
end

#contentObject

Returns the value of attribute content.



7
8
9
# File 'lib/metanorma/plugin/glossarist/document.rb', line 7

def content
  @content
end

#file_systemObject

Returns the value of attribute file_system.



7
8
9
# File 'lib/metanorma/plugin/glossarist/document.rb', line 7

def file_system
  @file_system
end

Instance Method Details

#add_content(content, options = {}) ⇒ Object



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

def add_content(content, options = {})
  @content << if options[:render]
                render_liquid(content)
              else
                content
              end
end

#render_liquid(file_content) ⇒ Object



26
27
28
29
30
31
32
33
34
# File 'lib/metanorma/plugin/glossarist/document.rb', line 26

def render_liquid(file_content)
  template = Liquid::Template.parse(file_content)
  template.registers[:file_system] = file_system
  rendered_template = template.render(strict_variables: false, error_mode: :warn)

  return rendered_template unless template.errors.any?

  raise template.errors.first.cause
end

#to_sObject



22
23
24
# File 'lib/metanorma/plugin/glossarist/document.rb', line 22

def to_s
  @content.compact.join("\n")
end