Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support reference of document elements generated by LutaML other than Figures #54

Merged
merged 2 commits into from
Sep 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -377,11 +377,15 @@ For instance, the script will take package diagrams supplied in the XMI file and

* `[.include_block, package="Another", base_path="spec/fixtures"]` - same as above, but include block will be included only for supplied package name

In addition to the macros listed above that can be used only inside `lutaml_uml_datamodel_description` macro there is another macro called `lutaml_figure`. `lutaml_figure` is used to lookup and reference xmi package diagrams. The syntax is as follows:
In addition to the macros listed above that can be used only inside `lutaml_uml_datamodel_description` macro there is another macroses called `lutaml_figure` and `lutaml_table`. `lutaml_figure` is used to lookup and reference xmi package diagrams. `lutaml_table` is used to lookup rendered xmi entries. The syntax is as follows:

[source,adoc]
-----
This is lutaml_figure::[package="Wrapper root package", name="Fig B1 Full model"] figure
This is lutaml_table::[package="Wrapper root package"] package
This is lutaml_table::[package="Wrapper root package", class="my name"] class
This is lutaml_table::[package="Wrapper root package", enum="my name"] enum
This is lutaml_table::[package="Wrapper root package", data_type="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,9 +422,9 @@ Content for CityGML package

==== Defining tables

.<<tab-P-another-C-{XMI_ID}>> -- Elements of &#8220;Another::AbstractAtomicTimeseries&#8221; (class)
.<<section-EAPK_9C96A88B_E98B_490b_8A9C_24AEDAC64293>> -- Elements of &#8220;Another::AbstractAtomicTimeseries&#8221; (class)

[[tab-P-another-C-{XMI_ID}]]
[[section-EAPK_9C96A88B_E98B_490b_8A9C_24AEDAC64293]]
.Elements of &#8220;Another::AbstractAtomicTimeseries&#8221; (class)
[width="100%",cols="a,a,a,a,a,a,a,a"]
|===
Expand Down
1 change: 1 addition & 0 deletions lib/metanorma-plugin-lutaml.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
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_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 }}>> -- &#8220;Elements of {{ package.name }}::{{ klass.name }}&#8221; (class)

{% 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 }}>> -- &#8220;Elements of {{ package.name }}::{{ enum.name }}&#8221; (enum)

{% 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 }}>> -- &#8220;Elements of {{ package.name }}::{{ data_type.name }}&#8221; (data_type)

{% 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 &#8220;{{ package.name }}::{{ klass.name }}&#8221; (class)
[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 }}&#8221; (data_type)
[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 }}&#8221; (enum)
[width="100%",cols="a,a,a,a,a,a,a,a"]
|===

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

module Metanorma
module Plugin
module Lutaml
class LutamlTableInlineMacro < Asciidoctor::Extensions::InlineMacroProcessor
include LutamlDiagramBase
SUPPORTED_OPTIONS = %w[class enum data_type]

use_dsl
named :lutaml_table_class

def process(parent, _target, attrs)
keyword = SUPPORTED_OPTIONS.find { |n| attrs[n] }
entity_key = [keyword, attrs["package"], attrs[keyword]].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
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