class Metanorma::Plugin::Datastruct::Yaml2TextPreprocessor

Public Class Methods

new(config = {}) click to toggle source

search document for block `yaml2text`

after that take template from block and read file into this template
example:
  [yaml2text,foobar.yaml]
  ----
  === {item.name}
  {item.desc}

  {item.symbol}:: {item.symbol_def}
  ----

with content of `foobar.yaml` file equal to:
  - name: spaghetti
    desc: wheat noodles of 9mm diameter
    symbol: SPAG
    symbol_def: the situation is message like spaghetti at a kid's

will produce:
  === spaghetti
  wheat noodles of 9mm diameter

  SPAG:: the situation is message like spaghetti at a kid's meal
Calls superclass method
# File lib/metanorma/plugin/datastruct/yaml2_text_preprocessor.rb, line 33
def initialize(config = {})
  super
  @config[:block_name] = "yaml2text"
end

Protected Instance Methods

content_from_file(document, file_path) click to toggle source

ruby-doc.org/stdlib-2.5.1/libdoc/psych/rdoc/Psych.html#method-c-safe_load

# File lib/metanorma/plugin/datastruct/yaml2_text_preprocessor.rb, line 41
def content_from_file(document, file_path)
  YAML.safe_load(
    File.read(relative_file_path(document, file_path), encoding: "UTF-8"),
    [Date, Time],
    [],
    true
  )
end