class Metanorma::Plugin::Lutaml::LutamlUmlAttributesTablePreprocessor
Macro for quick rendering of datamodel attributes/values table @example [lutaml_uml_attributes_table,path/to/lutaml,EntityName]
Constants
- MARCO_REGEXP
Public Instance Methods
process(document, reader)
click to toggle source
search document for block `datamodel_attributes_table`
read include derectives that goes after that in block and transform into yaml2text blocks
# File lib/metanorma/plugin/lutaml/lutaml_uml_attributes_table_preprocessor.rb, line 21 def process(document, reader) input_lines = reader.readlines.to_enum Asciidoctor::Reader.new(processed_lines(document, input_lines)) end
Private Instance Methods
lutaml_document_from_file(document, file_path)
click to toggle source
# File lib/metanorma/plugin/lutaml/lutaml_uml_attributes_table_preprocessor.rb, line 28 def lutaml_document_from_file(document, file_path) ::Lutaml::Parser .parse(File.new(Utils.relative_file_path(document, file_path), encoding: "UTF-8")) .first end
model_representation(entity_definition, document, skip_headers)
click to toggle source
# File lib/metanorma/plugin/lutaml/lutaml_uml_attributes_table_preprocessor.rb, line 60 def model_representation(entity_definition, document, skip_headers) render_result, errors = Utils.render_liquid_string( template_string: table_template(skip_headers), context_items: entity_definition, context_name: "definition", document: document ) Utils.notify_render_errors(document, errors) render_result.split("\n") end
parse_marco(lutaml_path, entity_name, document, skip_headers)
click to toggle source
# File lib/metanorma/plugin/lutaml/lutaml_uml_attributes_table_preprocessor.rb, line 48 def parse_marco(lutaml_path, entity_name, document, skip_headers) lutaml_document = lutaml_document_from_file(document, lutaml_path) .serialized_document entities = [lutaml_document["classes"], lutaml_document["enums"]] .compact .flatten entity_definition = entities.detect do |klass| klass["name"] == entity_name.strip end model_representation(entity_definition, document, skip_headers) end
processed_lines(document, input_lines)
click to toggle source
# File lib/metanorma/plugin/lutaml/lutaml_uml_attributes_table_preprocessor.rb, line 35 def processed_lines(document, input_lines) input_lines.each_with_object([]) do |line, result| if match = line.match(MARCO_REGEXP) lutaml_path = match[1] entity_name = match[2] skip_headers = match[3] result.push(*parse_marco(lutaml_path, entity_name, document, skip_headers)) else result.push(line) end end end
table_template(skip_headers)
click to toggle source
rubocop:disable Layout/IndentHeredoc
# File lib/metanorma/plugin/lutaml/lutaml_uml_attributes_table_preprocessor.rb, line 72 def table_template(skip_headers) <<~TEMPLATE #{"=== {{ definition.name }}" unless skip_headers} {{ definition.definition }} {% if definition.attributes %} {% if definition.keyword == 'enumeration' %} .{{ definition.name }} values |=== |Name |Definition {% for item in definition.attributes %} |{{ item.name }} |{{ item.definition }} {% endfor %} |=== {% else %} .{{ definition.name }} attributes |=== |Name |Definition |Mandatory/ Optional/ Conditional |Max Occur |Data Type {% for item in definition.attributes %} |{{ item.name }} |{% if item.definition %}{{ item.definition }}{% endif %} |{% if item.cardinality.min == "0" %}O{% else %}M{% endif %} |{% if item.cardinality.max == "*" %}N{% else %}1{% endif %} |{% if item.origin %}<<{{ item.origin }}>>{% endif %} `{{ item.type }}` {% endfor %} |=== {% endif %} {% endif %} TEMPLATE end