Skip to content

Commit

Permalink
#41 new collection of macroses: lutaml_table_package, `lutaml_table…
Browse files Browse the repository at this point in the history
…_class`, `lutaml_table_enum`, `lutaml_table_data_type`, lookup xmi entities in the document by their name
  • Loading branch information
tretiakov-work authored and ronaldtse committed Sep 1, 2021
1 parent ba23df1 commit 8873ce9
Show file tree
Hide file tree
Showing 25 changed files with 1,458 additions and 1,137 deletions.
11 changes: 8 additions & 3 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,10 @@ In addition to the macros listed above that can be used only inside `lutaml_uml_
[source,adoc]
-----
This is lutaml_figure::[package="Wrapper root package", name="Fig B1 Full model"] figure
This is lutaml_table_package::[package="Wrapper root package"] package
This is lutaml_table_class::[package="Wrapper root package", name="my name"] class
This is lutaml_table_enum::[package="Wrapper root package", name="my name"] enum
This is lutaml_table_data_type::[package="Wrapper root package", name="my name"] data_type
-----

This code will be transformed into `<<figure-{diagram.xmi_id}>>` and will point to diagram figure. One can only use this macro when document rendered `lutaml_uml_datamodel_description` macro as it needs diagram lookup table in order to reference package diagram.
Expand Down Expand Up @@ -418,10 +422,11 @@ Content for CityGML package
==== Defining tables
.<<tab-P-another-C-{XMI_ID}>> -- Elements of &#8220;Another::AbstractAtomicTimeseries&#8221; (class)
[arabic]
.<<section-EAPK_9C96A88B_E98B_490b_8A9C_24AEDAC64293>> -- Elements of Another::AbstractAtomicTimeseries
[[tab-P-another-C-{XMI_ID}]]
.Elements of &#8220;Another::AbstractAtomicTimeseries&#8221; (class)
[[section-EAPK_9C96A88B_E98B_490b_8A9C_24AEDAC64293]]
.Elements of Another::AbstractAtomicTimeseries
[width="100%",cols="a,a,a,a,a,a,a,a"]
|===
h|Name: 7+| AbstractAtomicTimeseries
Expand Down
4 changes: 4 additions & 0 deletions lib/metanorma-plugin-lutaml.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
require "metanorma/plugin/lutaml/lutaml_diagram_block"
require "metanorma/plugin/lutaml/lutaml_diagram_block_macro"
require "metanorma/plugin/lutaml/lutaml_figure_inline_macro"
require "metanorma/plugin/lutaml/lutaml_table_package_inline_macro"
require "metanorma/plugin/lutaml/lutaml_table_class_inline_macro"
require "metanorma/plugin/lutaml/lutaml_table_enum_inline_macro"
require "metanorma/plugin/lutaml/lutaml_table_data_type_inline_macro"

module Metanorma
module Plugin
Expand Down
16 changes: 5 additions & 11 deletions lib/metanorma/plugin/lutaml/liquid_templates/_packages.liquid
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,8 @@
{% elsif is_package_spare == 'Spare' %}{% continue %}
{% endif %}

{% capture equalsigns %}{% for count in (1..depth) %}={% endfor %}{% endcapture %}

[[lutaml-section-{{ package_name }}]]
{{equalsigns}} {{ package.name }} package

{% capture equalsigns %}{% for count in (1..depth) %}={% endfor %}{% endcapture %}{{equalsigns}} {{ package.name }} package
[[section-{{ package.xmi_id }}]]
{{equalsigns}}= {{ package.name }} overview

{% assign before_package_key = 'before;' | append: package.name %}
Expand Down Expand Up @@ -54,8 +51,7 @@
{% elsif is_klass_spare == 'Spare' %}{% continue %}
{% endif %}
{% assign klass_name = klass.name | downcase | replace: ':', '' | replace: ' ', '_' %}
{% assign klass_xid = klass.xmi_id %}
.<<tab-P-{{ package_name }}-C-{{ klass_xid }}>> -- Elements of "{{ package.name }}::{{ klass.name }}"
.<<section-{{ klass.xmi_id }}>> -- Elements of {{ package.name }}::{{ klass.name }}

{% endfor %}
{% for enum in package.enums %}
Expand All @@ -64,8 +60,7 @@
{% elsif is_enum_spare == 'Spare' %}{% continue %}
{% endif %}
{% assign enum_name = enum.name | downcase | replace: ':', '' | replace: ' ', '_' %}
{% assign enum_xid = enum.xmi_id %}
.<<tab-P-{{ package_name }}-E-{{ enum_xid }}>> -- Elements of "{{ package.name }}::{{ enum.name }}"
.<<section-{{ enum.xmi_id }}>> -- Elements of {{ package.name }}::{{ enum.name }}

{% endfor %}
{% for data_type in package.data_types %}
Expand All @@ -74,8 +69,7 @@
{% elsif is_data_type_spare == 'Spare' %}{% continue %}
{% endif %}
{% assign data_type_name = data_type.name | downcase | replace: ':', '' | replace: ' ', '_' %}
{% assign data_type_xid = data_type.xmi_id %}
.<<tab-P-{{ package_name }}-DT-{{ data_type_xid }}>> -- Elements of "{{ package.name }}::{{ data_type.name }}"
.<<section-{{ data_type.xmi_id }}>> -- Elements of {{ package.name }}::{{ data_type.name }}

{% endfor %}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
{% elsif is_klass_spare == 'Spare' %}{% continue %}
{% endif %}
{% assign klass_name = klass.name | downcase | replace: ':', '' | replace: ' ', '_' %}
{% assign klass_xid = klass.xmi_id %}
[[tab-P-{{ package_name }}-C-{{ klass_xid }}]]
.Elements of "{{ package.name }}::{{ klass.name }}" (class)
[[section-{{ klass.xmi_id }}]]
.Elements of {{ package.name }}::{{ klass.name }}
[width="100%",cols="a,a,a,a,a,a,a,a"]
|===

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ h|Stereotype: | «{{ package.stereotype }}»

{% for data_type in package.data_types %}
{% capture generalizations %}{% for assoc in data_type.associations | where: "member_end_type", "generalization" %}{{ assoc.member_end }} {% endfor %}{% endcapture %}
[[{{ data_type.name }}-section]]
[[section-{{ data_type.xmi_id }}]]
[cols="1a"]
|===
|*{{ data_type.name }}*
Expand Down Expand Up @@ -109,7 +109,7 @@ h|Stereotype: | «{{ package.stereotype }}»

{% for enum in package.enums %}
{% capture generalizations %}{% for assoc in enum.associations | where: "member_end_type", "generalization" %}{{ assoc.member_end }} {% endfor %}{% endcapture %}
[[{{ enum.name }}-section]]
[[section-{{ enum.xmi_id }}]]
[cols="1a"]
|===
|*{{ enum.name }}*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
{% elsif is_klass_spare == 'Spare' %}{% continue %}
{% endif %}
{% assign klass_name = klass.name | downcase | replace: ':', '' | replace: ' ', '_' %}
{% assign klass_xid = klass.xmi_id %}
[[tab-P-{{ package_name }}-DT-{{ klass_xid }}]]
.Elements of "{{ package.name }}::{{ klass.name }}" (data type)
[[section-{{ klass.xmi_id }}]]
.Elements of {{ package.name }}::{{ klass.name }}
[width="100%",cols="a,a,a,a,a,a,a,a"]
|===

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
{% endif %}
{% capture equalsigns %}{% for count in (1..depth) %}={% endfor %}{% endcapture %}{{equalsigns}} {{ package.name }}

[[rc_{{ package_name }}-model_section]]
[[section-{{ package.xmi_id }}]]
{{equalsigns}}= {{ package.name }}

{% assign before_package_key = 'before;' | append: package.name %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
{% elsif is_klass_spare == 'Spare' %}{% continue %}
{% endif %}
{% assign klass_name = klass.name | downcase | replace: ':', '' | replace: ' ', '_' %}
{% assign klass_xid = klass.xmi_id %}
[[tab-P-{{ package_name }}-E-{{ klass_xid }}]]
.Elements of "{{ package.name }}::{{ klass.name }}" (enumeration)

[[section-{{ klass.xmi_id }}]]
.Elements of {{ package.name }}::{{ klass.name }}
[width="100%",cols="a,a,a,a,a,a,a,a"]
|===

Expand Down
23 changes: 23 additions & 0 deletions lib/metanorma/plugin/lutaml/lutaml_table_class_inline_macro.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# frozen_string_literal: true

module Metanorma
module Plugin
module Lutaml
class LutamlTableClassInlineMacro < Asciidoctor::Extensions::InlineMacroProcessor
include LutamlDiagramBase

use_dsl
named :lutaml_table_class

def process(parent, _target, attrs)
entity_key = ['class', attrs["package"], attrs["name"]].compact.join(":")
return if parent.document.attributes['lutaml_entity_id'].nil?
xmi_id = parent.document.attributes['lutaml_entity_id'][entity_key]
return unless xmi_id

%Q(<xref target="section-#{xmi_id}"></xref>)
end
end
end
end
end
23 changes: 23 additions & 0 deletions lib/metanorma/plugin/lutaml/lutaml_table_data_type_inline_macro.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# frozen_string_literal: true

module Metanorma
module Plugin
module Lutaml
class LutamlTableDataTypeInlineMacro < Asciidoctor::Extensions::InlineMacroProcessor
include LutamlDiagramBase

use_dsl
named :lutaml_table_data_type

def process(parent, _target, attrs)
entity_key = ['data_type', attrs["package"], attrs["name"]].compact.join(":")
return if parent.document.attributes['lutaml_entity_id'].nil?
xmi_id = parent.document.attributes['lutaml_entity_id'][entity_key]
return unless xmi_id

%Q(<xref target="section-#{xmi_id}"></xref>)
end
end
end
end
end
23 changes: 23 additions & 0 deletions lib/metanorma/plugin/lutaml/lutaml_table_enum_inline_macro.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# frozen_string_literal: true

module Metanorma
module Plugin
module Lutaml
class LutamlTableEnumInlineMacro < Asciidoctor::Extensions::InlineMacroProcessor
include LutamlDiagramBase

use_dsl
named :lutaml_table_enum

def process(parent, _target, attrs)
entity_key = ['enum', attrs["package"], attrs["name"]].compact.join(":")
return if parent.document.attributes['lutaml_entity_id'].nil?
xmi_id = parent.document.attributes['lutaml_entity_id'][entity_key]
return unless xmi_id

%Q(<xref target="section-#{xmi_id}"></xref>)
end
end
end
end
end
22 changes: 22 additions & 0 deletions lib/metanorma/plugin/lutaml/lutaml_table_package_inline_macro.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# frozen_string_literal: true

module Metanorma
module Plugin
module Lutaml
class LutamlTablePackageInlineMacro < Asciidoctor::Extensions::InlineMacroProcessor
include LutamlDiagramBase

use_dsl
named :lutaml_table_package

def process(parent, _target, attrs)
return if parent.document.attributes['lutaml_entity_id'].nil?
xmi_id = parent.document.attributes['lutaml_entity_id'][attrs["package"]]
return unless xmi_id

%Q(<xref target="section-#{xmi_id}"></xref>)
end
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class LutamlUmlDatamodelDescriptionPreprocessor <
'entity_list' => 'packages_entity_list',
'data_dictionary' => 'packages_data_dictionary'
}.freeze
RENDER_STYLE_ATTRIBUTE = 'render_style'.freeze
SUPPORTED_NESTED_MACRO = %w[
before diagram_include_block after include_block].freeze
# search document for block `lutaml_uml_datamodel_description`
Expand Down Expand Up @@ -74,6 +75,35 @@ def process_text_blocks(document, input_lines)
parse_yaml_config_file(document, block_match[2]))
end

def fill_in_entities_refs_attributes(document, lutaml_document_wrapper, options)
lutaml_document = lutaml_document_wrapper.original_document
render_style = options.fetch(RENDER_STYLE_ATTRIBUTE, 'default')
all_children_packages = lutaml_document.packages.map(&:children_packages).flatten
package_flat_packages = lambda do |pks|
pks.each_with_object({}) do |package, res|
res[package.name] = package.xmi_id
end
end
children_pks = package_flat_packages.call(all_children_packages)
ref_dictionary = package_flat_packages.call(lutaml_document.packages)
.merge(children_pks)
%w[class enum data_type].each do |type|
package_flat = lambda do |pks|
pks.each_with_object({}) do |package, res|
plural = type == "class" ? "classes" : "#{type}s"
package.send(plural).map do |entity|
res["#{type}:#{package.name}:#{entity.name}"] = entity.xmi_id
end
end
end
children_pks_daigs = package_flat.call(all_children_packages)
ref_dictionary = ref_dictionary
.merge(package_flat.call(lutaml_document.packages)
.merge(children_pks_daigs))
end
document.attributes['lutaml_entity_id'] = ref_dictionary
end

def fill_in_diagrams_attributes(document, lutaml_document_wrapper)
lutaml_document = lutaml_document_wrapper.original_document
package_flat_diagrams = lambda do |pks|
Expand Down Expand Up @@ -163,8 +193,9 @@ def config_entity_regexp(entity)
end

def model_representation(lutaml_document, document, additional_context, options)
fill_in_entities_refs_attributes(document, lutaml_document, options)
render_result, errors = Utils.render_liquid_string(
template_string: table_template(options['section_depth'] || 2, options['render_style']),
template_string: table_template(options['section_depth'] || 2, options[RENDER_STYLE_ATTRIBUTE]),
context_items: create_context_object(lutaml_document,
additional_context,
options),
Expand Down
Loading

0 comments on commit 8873ce9

Please sign in to comment.