Class: Metanorma::Plugin::Glossarist::DatasetPreprocessor

Inherits:
Asciidoctor::Extensions::Preprocessor
  • Object
show all
Defined in:
lib/metanorma/plugin/glossarist/dataset_preprocessor.rb

Constant Summary collapse

GLOSSARIST_DATASET_REGEX =
/^:glossarist-dataset:\s*(.*?)$/m.freeze
GLOSSARIST_IMPORT_REGEX =
/^glossarist::import\[(.*?)\]$/m.freeze
GLOSSARIST_RENDER_REGEX =
/^glossarist::render\[(.*?)\]$/m.freeze
GLOSSARIST_BLOCK_REGEX =
/^\[glossarist,(.+?),(.+?)\]/
GLOSSARIST_FILTER_BLOCK_REGEX =
/^\[glossarist,(.+?),(filter=.+?),(.+?)\]/
GLOSSARIST_BIBLIOGRAPHY_REGEX =
/^glossarist::render_bibliography\[(.*?)\]$/m.freeze
GLOSSARIST_BIBLIOGRAPHY_ENTRY_REGEX =
/^glossarist::render_bibliography_entry\[(.*?)\]$/m.freeze

Instance Method Summary collapse

Constructor Details

#initialize(config = {}) ⇒ DatasetPreprocessor

Search document for the following blocks

- :glossarist-dataset: dataset1:./dataset1;dataset2:./dataset2
  This will load `glossarist` concepts from `./dataset1` path into
  `dataset1` and concepts from `./dataset2` path into `dataset2`,
  These can then be used anywhere in the document like
  {{dataset1.concept_name.en.definition.content}}

- glossarist:render[dataset1, concept_name]
  this will render the `concept_name` using the below format

  ==== concept term
  alt:[if additional terms]

  definition text

  NOTE: if there is a note.

  [example]
  If there is an example.

  [.source]
  <<If there is some source>>

- glossarist:import[dataset1]
  this will render all concepts in the `dataset1` using the above
  format


60
61
62
63
64
65
# File 'lib/metanorma/plugin/glossarist/dataset_preprocessor.rb', line 60

def initialize(config = {})
  super
  @config = config
  @datasets = {}
  @rendered_bibliographies = {}
end

Instance Method Details

#process(document, reader) ⇒ Object



67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/metanorma/plugin/glossarist/dataset_preprocessor.rb', line 67

def process(document, reader)
  input_lines = reader.readlines.to_enum

  file_system = ::Liquid::LocalFileSystem.new(
    relative_file_path(document, ""),
  )

  @config[:file_system] = file_system

  processed_doc = prepare_document(document, input_lines)
  Asciidoctor::Reader.new(
    processed_doc.to_s.split("\n"),
  )
end