Class: Metanorma::Plugin::Glossarist::Document
- Inherits:
-
Object
- Object
- Metanorma::Plugin::Glossarist::Document
- Defined in:
- lib/metanorma/plugin/glossarist/document.rb
Instance Attribute Summary collapse
-
#bibliographies ⇒ Object
Returns the value of attribute bibliographies.
-
#content ⇒ Object
Returns the value of attribute content.
-
#file_system ⇒ Object
Returns the value of attribute file_system.
Instance Method Summary collapse
- #add_content(content, options = {}) ⇒ Object
- #create_liquid_environment ⇒ Object
-
#initialize ⇒ Document
constructor
A new instance of Document.
-
#render_liquid(file_content, options = {}) ⇒ Object
rubocop:disable Metrics/AbcSize.
- #to_s ⇒ Object
Constructor Details
#initialize ⇒ Document
Returns a new instance of Document.
13 14 15 16 |
# File 'lib/metanorma/plugin/glossarist/document.rb', line 13 def initialize @content = [] @bibliographies = [] end |
Instance Attribute Details
#bibliographies ⇒ Object
Returns the value of attribute bibliographies.
11 12 13 |
# File 'lib/metanorma/plugin/glossarist/document.rb', line 11 def bibliographies @bibliographies end |
#content ⇒ Object
Returns the value of attribute content.
11 12 13 |
# File 'lib/metanorma/plugin/glossarist/document.rb', line 11 def content @content end |
#file_system ⇒ Object
Returns the value of attribute file_system.
11 12 13 |
# File 'lib/metanorma/plugin/glossarist/document.rb', line 11 def file_system @file_system end |
Instance Method Details
#add_content(content, options = {}) ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/metanorma/plugin/glossarist/document.rb', line 18 def add_content(content, = {}) @content << if [:render] render_liquid(content, ) else content end end |
#create_liquid_environment ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/metanorma/plugin/glossarist/document.rb', line 45 def create_liquid_environment ::Liquid::Environment.new.tap do |liquid_env| liquid_env.register_tag( "with_glossarist_context", ::Metanorma::Plugin::Glossarist::Liquid::CustomBlocks:: WithGlossaristContext, ) liquid_env.register_filter( ::Metanorma::Plugin::Glossarist::Liquid::CustomFilters::Filters, ) end end |
#render_liquid(file_content, options = {}) ⇒ Object
rubocop:disable Metrics/AbcSize
30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/metanorma/plugin/glossarist/document.rb', line 30 def render_liquid(file_content, = {}) # rubocop:disable Metrics/AbcSize include_paths = [file_system, [:template]].compact template = ::Liquid::Template .parse(file_content, environment: create_liquid_environment) template.registers[:file_system] = ::Metanorma::Plugin::Glossarist::Liquid::LocalFileSystem.new( include_paths, ["%s.liquid", "_%s.liquid", "_%s.adoc"] ) rendered_template = template.render(strict_variables: false, error_mode: :warn) return rendered_template unless template.errors.any? raise template.errors.first.cause end |
#to_s ⇒ Object
26 27 28 |
# File 'lib/metanorma/plugin/glossarist/document.rb', line 26 def to_s @content.compact.join("\n") end |