Module: Metanorma::Plugin::Lutaml::Utils

Defined in:
lib/metanorma/plugin/lutaml/utils.rb

Overview

Helpers for lutaml macroses

Class Method Summary collapse

Class Method Details

.notify_render_errors(document, errors) ⇒ Object



27
28
29
30
31
32
33
# File 'lib/metanorma/plugin/lutaml/utils.rb', line 27

def notify_render_errors(document, errors)
  errors.each do |error_obj|
    document
      .logger
      .warn("Liquid render error: #{error_obj.message}")
  end
end

.relative_file_path(document, file_path) ⇒ Object



8
9
10
11
12
13
14
15
# File 'lib/metanorma/plugin/lutaml/utils.rb', line 8

def relative_file_path(document, file_path)
  docfile_directory = File.dirname(
    document.attributes["docfile"] || "."
  )
  document
    .path_resolver
    .system_path(file_path, docfile_directory)
end

.render_liquid_string(template_string:, context_items:, context_name:) ⇒ Object



17
18
19
20
21
22
23
24
25
# File 'lib/metanorma/plugin/lutaml/utils.rb', line 17

def render_liquid_string(template_string:, context_items:,
                         context_name:)
  liquid_template = Liquid::Template.parse(template_string)
  rendered_string = liquid_template
    .render(context_name => context_items,
            strict_variables: true,
            error_mode: :warn)
  [rendered_string, liquid_template.errors]
end