Sha256: 89e193d9dfd367687234bba3b79a5f0527d8ff2bdea6799bcca25458d52b8bf6

Contents?: true

Size: 1.39 KB

Versions: 3

Compression:

Stored size: 1.39 KB

Contents

# frozen_string_literal: true

require "yaml"
require "metanorma/plugin/datastruct/base_structured_text_preprocessor"

module Metanorma
  module Plugin
    module Datastruct
      class Yaml2TextPreprocessor < BaseStructuredTextPreprocessor
        # 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

        def initialize(config = {})
          super
          @config[:block_name] = "yaml2text"
        end

        protected

        def content_from_file(document, file_path)
          YAML.safe_load(
            File.read(relative_file_path(document, file_path),
                      encoding: "UTF-8"),
            [Date, Time]
          )
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
metanorma-plugin-datastruct-0.1.2 lib/metanorma/plugin/datastruct/yaml2_text_preprocessor.rb
metanorma-plugin-datastruct-0.1.1 lib/metanorma/plugin/datastruct/yaml2_text_preprocessor.rb
metanorma-plugin-datastruct-0.1.0 lib/metanorma/plugin/datastruct/yaml2_text_preprocessor.rb