metanorma-plugin-lutaml 0.7.36 → 0.7.38
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/rake.yml +1 -1
- data/README.adoc +5 -5
- data/docs/usages/enterprise_architect.adoc +18 -1
- data/docs/usages/express.adoc +1 -1
- data/docs/usages/json_yaml.adoc +1 -1
- data/docs/usages/lutaml-gml.adoc +1 -1
- data/docs/usages/lutaml-uml.adoc +1 -1
- data/docs/usages/xmi_to_uml.adoc +213 -0
- data/lib/metanorma/plugin/lutaml/base_structured_text_preprocessor.rb +1 -1
- data/lib/metanorma/plugin/lutaml/config/root.rb +2 -0
- data/lib/metanorma/plugin/lutaml/express_remarks_decorator.rb +1 -1
- data/lib/metanorma/plugin/lutaml/lutaml_ea_xmi_base.rb +48 -3
- data/lib/metanorma/plugin/lutaml/lutaml_enum_table_block_macro.rb +7 -39
- data/lib/metanorma/plugin/lutaml/lutaml_klass_table_block_macro.rb +7 -39
- data/lib/metanorma/plugin/lutaml/lutaml_preprocessor.rb +4 -1
- data/lib/metanorma/plugin/lutaml/lutaml_xmi_uml_preprocessor.rb +71 -0
- data/lib/metanorma/plugin/lutaml/utils.rb +2 -2
- data/lib/metanorma/plugin/lutaml/version.rb +1 -1
- data/lib/metanorma-plugin-lutaml.rb +1 -0
- metadata +4 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: cb242e5ff7bfcfa7b4baec472a6fc0ecf0be94558913c8bb39bcf19655640e12
|
|
4
|
+
data.tar.gz: 81455de9a154af7534d43830562613fbee00bd8ce2c252ce13be79fc790efaec
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c84b7143c72c6bbb6334bc9c27faea196a516edd34c67607579f61b0a371be648c9087e5b297159f98d60654f43ffc9a2c736a5e5c546196f7251917cc042d28
|
|
7
|
+
data.tar.gz: b68b53795e9576abc2e1beb3746219ae2ca0ab8e888ab15f0c79430f94eedb870a568fe425e9a3ae503ba34e03d603436cc2dcb0cd64068500d30db421e079e5
|
data/.github/workflows/rake.yml
CHANGED
data/README.adoc
CHANGED
|
@@ -24,15 +24,15 @@ $ gem install metanorma-plugin-lutaml
|
|
|
24
24
|
|
|
25
25
|
== Usages
|
|
26
26
|
|
|
27
|
-
link:docs/usages/express.adoc[Usage with EXPRESS]
|
|
27
|
+
link:docs/usages/express.adoc[Usage with EXPRESS files by lutaml_express]
|
|
28
28
|
|
|
29
|
-
link:docs/usages/lutaml-uml.adoc[Usage with LutaML
|
|
29
|
+
link:docs/usages/lutaml-uml.adoc[Usage with LutaML files by lutaml_diagram]
|
|
30
30
|
|
|
31
|
-
link:docs/usages/enterprise_architect.adoc[Usage with Enterprise Architect
|
|
31
|
+
link:docs/usages/enterprise_architect.adoc[Usage with Enterprise Architect XMI files by lutaml_ea_xmi, lutaml_ea_diagram, lutaml_klass_table or lutaml_enum_table]
|
|
32
32
|
|
|
33
|
-
link:docs/usages/lutaml-gml.adoc[Usage with LutaML GML Dictionary]
|
|
33
|
+
link:docs/usages/lutaml-gml.adoc[Usage with LutaML GML Dictionary by lutaml_gml_dictionary]
|
|
34
34
|
|
|
35
|
-
link:docs/usages/json_yaml.adoc[Usage with JSON or YAML files]
|
|
35
|
+
link:docs/usages/json_yaml.adoc[Usage with JSON or YAML files by data2text, yaml2text or json2text]
|
|
36
36
|
|
|
37
37
|
== Documentation
|
|
38
38
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
== Usage with Enterprise Architect
|
|
2
|
+
== Usage with Enterprise Architect XMI files by lutaml_ea_xmi, lutaml_ea_diagram, lutaml_klass_table or lutaml_enum_table
|
|
3
3
|
|
|
4
4
|
=== General
|
|
5
5
|
|
|
@@ -184,6 +184,15 @@ The command accepts the options listed below:
|
|
|
184
184
|
`lib/metanorma/plugin/lutaml/templates`. This template can be customized by
|
|
185
185
|
changing the template path in the `template` option.
|
|
186
186
|
|
|
187
|
+
* `external_data="context_name:/path/to/my_data.yml"` specifies the path of
|
|
188
|
+
the YAML/JSON file of the external data to be used in the liquid template.
|
|
189
|
+
(Optional)
|
|
190
|
+
You can specify multiple external data by separating them with `;`.
|
|
191
|
+
(e.g. `external_data="my_data:/path/to/my_data.yml;second_data:/path/to/my_second_data.yml"`)
|
|
192
|
+
In the liquid template, you can access the data by using `context_name`.
|
|
193
|
+
(e.g. `my_data` or `second_data` in the above example)
|
|
194
|
+
The external data file should be in YAML/JSON format.
|
|
195
|
+
|
|
187
196
|
* `guidance="/path/to/my_guidance.yml"` specifies the path of
|
|
188
197
|
the yaml file of the guidance. (Optional)
|
|
189
198
|
|
|
@@ -240,6 +249,14 @@ The command accepts the options listed below:
|
|
|
240
249
|
`lib/metanorma/plugin/lutaml/templates`. This template can be customized by
|
|
241
250
|
changing the template path in the `template` option.
|
|
242
251
|
|
|
252
|
+
* `external_data="context_name:/path/to/my_data.yml"` specifies the path of
|
|
253
|
+
the YAML/JSON file of the external data to be used in the liquid template.
|
|
254
|
+
(Optional)
|
|
255
|
+
You can specify multiple external data by separating them with `;`.
|
|
256
|
+
(e.g. `external_data="my_data:/path/to/my_data.yml;second_data:/path/to/my_second_data.yml"`)
|
|
257
|
+
In the liquid template, you can access the data by using `context_name`.
|
|
258
|
+
(e.g. `my_data` or `second_data` in the above example)
|
|
259
|
+
The external data file should be in YAML/JSON format.
|
|
243
260
|
|
|
244
261
|
=== Usage of `lutaml_ea_xmi` command
|
|
245
262
|
|
data/docs/usages/express.adoc
CHANGED
data/docs/usages/json_yaml.adoc
CHANGED
data/docs/usages/lutaml-gml.adoc
CHANGED
data/docs/usages/lutaml-uml.adoc
CHANGED
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
|
|
2
|
+
== Usage with Enterprise Architect XMI files by lutaml_xmi_uml
|
|
3
|
+
|
|
4
|
+
=== General
|
|
5
|
+
|
|
6
|
+
The LutaML plugin supports working with Enterprise Architect exported XMI files
|
|
7
|
+
to render them as LutaML UML documents.
|
|
8
|
+
|
|
9
|
+
The command is prefixed as `lutaml_xmi_uml` to denote their specific use.
|
|
10
|
+
|
|
11
|
+
=== Usage of `lutaml_xmi_uml` command
|
|
12
|
+
|
|
13
|
+
The `lutaml_xmi_uml` command renders Lutaml UML document and its dependent
|
|
14
|
+
objects for the supplied XMI file.
|
|
15
|
+
|
|
16
|
+
[example]
|
|
17
|
+
.Specify the path of a XMI file by `lutaml_xmi_uml` command
|
|
18
|
+
====
|
|
19
|
+
[source,adoc]
|
|
20
|
+
----
|
|
21
|
+
[lutaml_xmi_uml,/path/to/first.xmi]
|
|
22
|
+
--
|
|
23
|
+
Name of the Lutaml UML Document: {{ context.name }}
|
|
24
|
+
|
|
25
|
+
Number of packages: {{ context.packages | size }}
|
|
26
|
+
--
|
|
27
|
+
----
|
|
28
|
+
|
|
29
|
+
By default, the command will parse the XMI file and render it as a
|
|
30
|
+
Lutaml::Uml::Document via `context`.
|
|
31
|
+
====
|
|
32
|
+
|
|
33
|
+
=== Usage of `lutaml_xmi_uml` command with configuration file
|
|
34
|
+
|
|
35
|
+
You can use the `lutaml_xmi_uml` command with a configuration file.
|
|
36
|
+
The configuration file is a YAML file that looks like:
|
|
37
|
+
|
|
38
|
+
[example]
|
|
39
|
+
.Configuration file for `lutaml_xmi_uml` command
|
|
40
|
+
====
|
|
41
|
+
[source,yaml]
|
|
42
|
+
----
|
|
43
|
+
ea_extension:
|
|
44
|
+
- "ISO19103MDG v1.0.0-beta.xml"
|
|
45
|
+
- "CityGML_MDG_Technology.xml"
|
|
46
|
+
context_name: my_uml_document
|
|
47
|
+
template_path: "path/to/liquid_templates"
|
|
48
|
+
----
|
|
49
|
+
|
|
50
|
+
where:
|
|
51
|
+
|
|
52
|
+
`ea_extension`:: optional, list of EA extensions to load. Some XMI files may
|
|
53
|
+
contain elements that cannot be resolved by default, for example CityGML
|
|
54
|
+
elements. You can use `ea_extension` to load the definition of these elements
|
|
55
|
+
in XML format (`CityGML_MDG_Technology.xml`) in order to resolve them. The
|
|
56
|
+
location of the xml files is relative to the config YAML file.
|
|
57
|
+
|
|
58
|
+
`context_name`:: optional, name of the context for the rendered output.
|
|
59
|
+
This can be used to customize the output further by providing a specific
|
|
60
|
+
context name.
|
|
61
|
+
|
|
62
|
+
`template_path`:: optional, path to custom Liquid templates directory for
|
|
63
|
+
rendering the output. When specified, the processor will use custom templates
|
|
64
|
+
from this directory. This allows for complete customization of the rendered
|
|
65
|
+
output format and structure.
|
|
66
|
+
|
|
67
|
+
To use the configuration file, you can specify it in the command:
|
|
68
|
+
|
|
69
|
+
[source,adoc]
|
|
70
|
+
----
|
|
71
|
+
[lutaml_xmi_uml,/path/to/first.xmi,path/to/config.yml]
|
|
72
|
+
--
|
|
73
|
+
Name of the Lutaml UML Document: {{ context.name }}
|
|
74
|
+
|
|
75
|
+
Number of packages: {{ context.packages | size }}
|
|
76
|
+
--
|
|
77
|
+
----
|
|
78
|
+
====
|
|
79
|
+
|
|
80
|
+
=== Document attribute `:lutaml-xmi-index:`
|
|
81
|
+
|
|
82
|
+
This attribute allows specifying one or more XMI files to define names
|
|
83
|
+
for later use with `lutaml_xmi_uml` commands.
|
|
84
|
+
|
|
85
|
+
Syntax:
|
|
86
|
+
|
|
87
|
+
[source,adoc]
|
|
88
|
+
----
|
|
89
|
+
:lutaml-xmi-index: index_name; index_path[; config=config_path]
|
|
90
|
+
----
|
|
91
|
+
|
|
92
|
+
where:
|
|
93
|
+
|
|
94
|
+
`index_name`:: name of index
|
|
95
|
+
`index_path`:: path to XMI file for the later use with `lutaml_xmi_uml` command
|
|
96
|
+
`config_path`:: optional, location of YAML configuration file that specifies
|
|
97
|
+
what packages to include in the render, what render style is desired and
|
|
98
|
+
location of the root package.
|
|
99
|
+
|
|
100
|
+
[example]
|
|
101
|
+
.Define an index in the document and use it in the `lutaml_xmi_uml` command
|
|
102
|
+
====
|
|
103
|
+
[source,adoc]
|
|
104
|
+
----
|
|
105
|
+
:lutaml-xmi-index: first-xmi-index; /path/to/first.xmi
|
|
106
|
+
|
|
107
|
+
[lutaml_xmi_uml,index=first-xmi-index]
|
|
108
|
+
--
|
|
109
|
+
...
|
|
110
|
+
--
|
|
111
|
+
----
|
|
112
|
+
|
|
113
|
+
The command `lutaml_xmi_uml` will load the XMI file from the path
|
|
114
|
+
`/path/to/first.xmi` which is specified by the `index`: `first-xmi-index`.
|
|
115
|
+
====
|
|
116
|
+
|
|
117
|
+
=== Advanced example usage of `lutaml_xmi_uml` command
|
|
118
|
+
|
|
119
|
+
The following is an advanced example of using the `lutaml_xmi_uml` command
|
|
120
|
+
with a configuration file and custom Liquid templates to render a UML class
|
|
121
|
+
table.
|
|
122
|
+
|
|
123
|
+
[example]
|
|
124
|
+
.Advanced example usage of `lutaml_xmi_uml` command
|
|
125
|
+
====
|
|
126
|
+
|
|
127
|
+
Assume you have the following configuration file `config.yml`:
|
|
128
|
+
|
|
129
|
+
[source,yaml]
|
|
130
|
+
----
|
|
131
|
+
ea_extension:
|
|
132
|
+
- "ISO19103MDG v1.0.0-beta.xml"
|
|
133
|
+
- "CityGML_MDG_Technology.xml"
|
|
134
|
+
context_name: my_uml_document
|
|
135
|
+
template_path: "path/to/my_liquid_templates"
|
|
136
|
+
----
|
|
137
|
+
|
|
138
|
+
And the following Liquid template `_klass.liquid` in the directory
|
|
139
|
+
`path/to/my_liquid_templates`:
|
|
140
|
+
|
|
141
|
+
[source,liquid]
|
|
142
|
+
----
|
|
143
|
+
[cols="1a,1a,1a,2a"]
|
|
144
|
+
|===
|
|
145
|
+
| Name of Class 3+| {{ klass.name }}
|
|
146
|
+
| Definition 3+| {{ klass.definition }}
|
|
147
|
+
|===
|
|
148
|
+
|
|
149
|
+
{% render "attributes", attributes: klass.attributes %}
|
|
150
|
+
----
|
|
151
|
+
|
|
152
|
+
And the following Liquid template `_attributes.liquid` in the directory
|
|
153
|
+
`path/to/my_liquid_templates`:
|
|
154
|
+
|
|
155
|
+
[source,liquid]
|
|
156
|
+
----
|
|
157
|
+
[cols="1a,1a,1a,2a"]
|
|
158
|
+
|===
|
|
159
|
+
4+| Attributes
|
|
160
|
+
| Name | Type | Multiplicity | Definition
|
|
161
|
+
{% for attr in attributes %}
|
|
162
|
+
| {{ attr.name }}
|
|
163
|
+
| {{ attr.type }}
|
|
164
|
+
| {{ attr.cardinality.min }}..{{ attr.cardinality.max }}
|
|
165
|
+
| {{ attr.definition }}
|
|
166
|
+
{% endfor %}
|
|
167
|
+
|===
|
|
168
|
+
----
|
|
169
|
+
|
|
170
|
+
You can use the command to render a specific class
|
|
171
|
+
`RootPackage::MySubPackage::MyClass` by liquid filters:
|
|
172
|
+
|
|
173
|
+
[source,adoc]
|
|
174
|
+
----
|
|
175
|
+
[lutaml_xmi_uml,example.xmi,config.yml]
|
|
176
|
+
--
|
|
177
|
+
Name of the Lutaml UML Document: {{ my_uml_document.name }}
|
|
178
|
+
|
|
179
|
+
{% assign root_package = my_uml_document.packages.first %}
|
|
180
|
+
|
|
181
|
+
{% assign sub_package = root_package.packages | where: "name", "MySubPackage" | first %}
|
|
182
|
+
|
|
183
|
+
{% assign klass = sub_package.classes | where: "name", "MyClass" | first %}
|
|
184
|
+
|
|
185
|
+
{% render "klass", klass: klass %}
|
|
186
|
+
----
|
|
187
|
+
|
|
188
|
+
The output will be a formatted table of the class `MyClass` with its attributes
|
|
189
|
+
looks like:
|
|
190
|
+
|
|
191
|
+
[source]
|
|
192
|
+
----
|
|
193
|
+
Name of the Lutaml UML Document: `My document`
|
|
194
|
+
|
|
195
|
+
--------------------------------------------------
|
|
196
|
+
| Name of Class | MyClass |
|
|
197
|
+
--------------------------------------------------
|
|
198
|
+
| Definition | My class definition |
|
|
199
|
+
--------------------------------------------------
|
|
200
|
+
|
|
201
|
+
--------------------------------------------------
|
|
202
|
+
| Attributes |
|
|
203
|
+
--------------------------------------------------
|
|
204
|
+
| Name | Type | Multiplicity | Definition |
|
|
205
|
+
--------------------------------------------------
|
|
206
|
+
| Attribute1 | Type1 | 0..* | Def1 |
|
|
207
|
+
--------------------------------------------------
|
|
208
|
+
| Attribute2 | Type2 | 0..1 | Def2 |
|
|
209
|
+
--------------------------------------------------
|
|
210
|
+
| Attribute3 | Type3 | 1..* | Def3 |
|
|
211
|
+
--------------------------------------------------
|
|
212
|
+
----
|
|
213
|
+
====
|
|
@@ -153,7 +153,7 @@ module Metanorma
|
|
|
153
153
|
end
|
|
154
154
|
line
|
|
155
155
|
.gsub(/(?<!{){(?!%)([^{}]{1,900})(?<!%)}(?!})/, '{{\1}}')
|
|
156
|
-
.gsub(/[a-z
|
|
156
|
+
.gsub(/[a-z.]{1,900}\#/, "index")
|
|
157
157
|
.gsub(/{{([^}]{1,900})\s+\+\s+(\d+)\s*?}}/, '{{ \1 | plus: \2 }}')
|
|
158
158
|
.gsub(/{{([^}]{1,900})\s+-\s+(\d+)\s*?}}/, '{{ \1 | minus: \2 }}')
|
|
159
159
|
.gsub(/{{([^}]{1,500})\.values([^}]{0,500})}}/,
|
|
@@ -17,6 +17,7 @@ module Metanorma
|
|
|
17
17
|
attribute :render_nested_packages, :boolean
|
|
18
18
|
attribute :external_classes, :hash
|
|
19
19
|
attribute :skip_unrecognized_connector, :boolean
|
|
20
|
+
attribute :context_name, :string
|
|
20
21
|
|
|
21
22
|
yaml do
|
|
22
23
|
map "packages", to: :packages,
|
|
@@ -34,6 +35,7 @@ module Metanorma
|
|
|
34
35
|
map "render_nested_packages", to: :render_nested_packages
|
|
35
36
|
map "external_classes", to: :external_classes
|
|
36
37
|
map "skip_unrecognized_connector", to: :skip_unrecognized_connector
|
|
38
|
+
map "context_name", to: :context_name
|
|
37
39
|
end
|
|
38
40
|
|
|
39
41
|
def packages_from_yaml(model, values) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
|
|
@@ -9,7 +9,7 @@ module Metanorma
|
|
|
9
9
|
(link|image|video|audio|include) # Capture group 1: content type
|
|
10
10
|
(:+)? # Capture group 2: optional colons
|
|
11
11
|
(?! # Negative lookahead
|
|
12
|
-
[
|
|
12
|
+
[^/:]+://| # Don't match URLs (http://, etc.)
|
|
13
13
|
[A-Z]:/| # Don't match Windows paths
|
|
14
14
|
/ # Don't match absolute paths
|
|
15
15
|
) # End negative lookahead
|
|
@@ -244,15 +244,21 @@ module Metanorma
|
|
|
244
244
|
.merge(children_pks_diags)
|
|
245
245
|
end
|
|
246
246
|
|
|
247
|
-
def
|
|
248
|
-
additional_context = Hash.new { |hash, key| hash[key] = [] }
|
|
249
|
-
additional_context["all_macros"] = []
|
|
247
|
+
def collect_block_lines(input_lines, end_mark)
|
|
250
248
|
block_lines = []
|
|
251
249
|
|
|
252
250
|
while (block_line = input_lines.next) != end_mark
|
|
253
251
|
block_lines.push(block_line)
|
|
254
252
|
end
|
|
255
253
|
|
|
254
|
+
block_lines
|
|
255
|
+
end
|
|
256
|
+
|
|
257
|
+
def collect_additional_context(document, input_lines, end_mark) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
|
|
258
|
+
additional_context = Hash.new { |hash, key| hash[key] = [] }
|
|
259
|
+
additional_context["all_macros"] = []
|
|
260
|
+
block_lines = collect_block_lines(input_lines, end_mark)
|
|
261
|
+
|
|
256
262
|
processed_lines = process(
|
|
257
263
|
document,
|
|
258
264
|
::Asciidoctor::PreprocessorReader.new(document, block_lines),
|
|
@@ -428,6 +434,45 @@ module Metanorma
|
|
|
428
434
|
{% include "#{include_name}", depth: #{section_depth}, package_skip_sections: context.package_skip_sections, package_entities: context.package_entities, context: context, additional_context: context.additional_context, render_nested_packages: context.render_nested_packages %}
|
|
429
435
|
LIQUID
|
|
430
436
|
end
|
|
437
|
+
|
|
438
|
+
def render_table(context, context_name, parent, attrs) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
|
|
439
|
+
table_tmpl = get_template(parent.document, attrs)
|
|
440
|
+
table_tmpl.assigns[context_name] = context
|
|
441
|
+
|
|
442
|
+
if attrs["external_data"]
|
|
443
|
+
data_array = attrs["external_data"].split(";")
|
|
444
|
+
data_array.each do |data_item|
|
|
445
|
+
context_name, external_data_path = data_item.split(":")
|
|
446
|
+
external_data = content_from_file(
|
|
447
|
+
parent.document, external_data_path.strip
|
|
448
|
+
)
|
|
449
|
+
table_tmpl.assigns[context_name.strip] = external_data
|
|
450
|
+
end
|
|
451
|
+
end
|
|
452
|
+
|
|
453
|
+
rendered_table = table_tmpl.render
|
|
454
|
+
block = create_open_block(parent, "", attrs)
|
|
455
|
+
parse_content(block, rendered_table, attrs)
|
|
456
|
+
end
|
|
457
|
+
|
|
458
|
+
def get_template(document, attrs)
|
|
459
|
+
template = get_default_template
|
|
460
|
+
template = attrs["template"] if attrs["template"]
|
|
461
|
+
|
|
462
|
+
rel_tmpl_path = Utils.relative_file_path(
|
|
463
|
+
document, template
|
|
464
|
+
)
|
|
465
|
+
|
|
466
|
+
::Liquid::Template.parse(File.read(rel_tmpl_path))
|
|
467
|
+
end
|
|
468
|
+
|
|
469
|
+
def get_name_path(attrs)
|
|
470
|
+
return attrs["path"] if attrs["path"]
|
|
471
|
+
|
|
472
|
+
return "#{attrs['package']}::#{attrs['name']}" if attrs["package"]
|
|
473
|
+
|
|
474
|
+
attrs["name"]
|
|
475
|
+
end
|
|
431
476
|
end
|
|
432
477
|
end
|
|
433
478
|
end
|
|
@@ -6,6 +6,7 @@ module Metanorma
|
|
|
6
6
|
class LutamlEnumTableBlockMacro <
|
|
7
7
|
::Asciidoctor::Extensions::BlockMacroProcessor
|
|
8
8
|
include LutamlEaXmiBase
|
|
9
|
+
include Content
|
|
9
10
|
|
|
10
11
|
DEFAULT_TEMPLATE = File.join(
|
|
11
12
|
Gem::Specification.find_by_name("metanorma-plugin-lutaml").gem_dir,
|
|
@@ -13,59 +14,26 @@ module Metanorma
|
|
|
13
14
|
"_enum_table.liquid"
|
|
14
15
|
)
|
|
15
16
|
|
|
17
|
+
CONTEXT_NAME = "enum"
|
|
18
|
+
|
|
16
19
|
use_dsl
|
|
17
20
|
named :lutaml_enum_table
|
|
18
21
|
|
|
19
22
|
def process(parent, target, attrs) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
|
|
20
23
|
xmi_path = get_xmi_path(parent, target, attrs)
|
|
21
|
-
|
|
22
|
-
if attrs["template"]
|
|
23
|
-
attrs["template"] = Utils.relative_file_path(
|
|
24
|
-
parent.document, attrs["template"]
|
|
25
|
-
)
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
path = if !attrs["path"].nil?
|
|
29
|
-
attrs["path"]
|
|
30
|
-
elsif !attrs["package"].nil? && !attrs["name"].nil?
|
|
31
|
-
"#{attrs['package']}::#{attrs['name']}"
|
|
32
|
-
else
|
|
33
|
-
attrs["name"]
|
|
34
|
-
end
|
|
24
|
+
path = get_name_path(attrs)
|
|
35
25
|
|
|
36
26
|
enum = ::Lutaml::XMI::Parsers::XML.serialize_enumeration_by_name(
|
|
37
27
|
xmi_path, path
|
|
38
28
|
)
|
|
39
29
|
|
|
40
|
-
|
|
30
|
+
render_table(enum, CONTEXT_NAME, parent, attrs)
|
|
41
31
|
end
|
|
42
32
|
|
|
43
33
|
private
|
|
44
34
|
|
|
45
|
-
def
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
block = create_open_block(parent, "", attrs)
|
|
49
|
-
parse_content(block, rendered_table, attrs)
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
def render_table(enum, parent, attrs)
|
|
53
|
-
table_tmpl = get_template(parent.document, attrs)
|
|
54
|
-
table_tmpl.assigns["enum"] = enum
|
|
55
|
-
table_tmpl.render
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
def get_template(document, attrs)
|
|
59
|
-
template = DEFAULT_TEMPLATE
|
|
60
|
-
if attrs["template"]
|
|
61
|
-
template = attrs["template"]
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
rel_tmpl_path = Utils.relative_file_path(
|
|
65
|
-
document, template
|
|
66
|
-
)
|
|
67
|
-
|
|
68
|
-
::Liquid::Template.parse(File.read(rel_tmpl_path))
|
|
35
|
+
def get_default_template
|
|
36
|
+
DEFAULT_TEMPLATE
|
|
69
37
|
end
|
|
70
38
|
end
|
|
71
39
|
end
|
|
@@ -6,6 +6,7 @@ module Metanorma
|
|
|
6
6
|
class LutamlKlassTableBlockMacro <
|
|
7
7
|
::Asciidoctor::Extensions::BlockMacroProcessor
|
|
8
8
|
include LutamlEaXmiBase
|
|
9
|
+
include Content
|
|
9
10
|
|
|
10
11
|
DEFAULT_TEMPLATE = File.join(
|
|
11
12
|
Gem::Specification.find_by_name("metanorma-plugin-lutaml").gem_dir,
|
|
@@ -13,64 +14,31 @@ module Metanorma
|
|
|
13
14
|
"_klass_table.liquid"
|
|
14
15
|
)
|
|
15
16
|
|
|
17
|
+
CONTEXT_NAME = "klass"
|
|
18
|
+
|
|
16
19
|
use_dsl
|
|
17
20
|
named :lutaml_klass_table
|
|
18
21
|
|
|
19
22
|
def process(parent, target, attrs) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
|
|
20
23
|
xmi_path = get_xmi_path(parent, target, attrs)
|
|
21
|
-
|
|
22
|
-
if attrs["template"]
|
|
23
|
-
attrs["template"] = Utils.relative_file_path(
|
|
24
|
-
parent.document, attrs["template"]
|
|
25
|
-
)
|
|
26
|
-
end
|
|
24
|
+
path = get_name_path(attrs)
|
|
27
25
|
|
|
28
26
|
guidance = nil
|
|
29
27
|
if attrs["guidance"]
|
|
30
28
|
guidance = get_guidance(parent.document, attrs["guidance"])
|
|
31
29
|
end
|
|
32
30
|
|
|
33
|
-
path = if !attrs["path"].nil?
|
|
34
|
-
attrs["path"]
|
|
35
|
-
elsif !attrs["package"].nil? && !attrs["name"].nil?
|
|
36
|
-
"#{attrs['package']}::#{attrs['name']}"
|
|
37
|
-
else
|
|
38
|
-
attrs["name"]
|
|
39
|
-
end
|
|
40
|
-
|
|
41
31
|
klass = ::Lutaml::XMI::Parsers::XML.serialize_generalization_by_name(
|
|
42
32
|
xmi_path, path, guidance
|
|
43
33
|
)
|
|
44
34
|
|
|
45
|
-
|
|
35
|
+
render_table(klass, CONTEXT_NAME, parent, attrs)
|
|
46
36
|
end
|
|
47
37
|
|
|
48
38
|
private
|
|
49
39
|
|
|
50
|
-
def
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
block = create_open_block(parent, "", attrs)
|
|
54
|
-
parse_content(block, rendered_table, attrs)
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
def render_table(klass, parent, attrs)
|
|
58
|
-
table_tmpl = get_template(parent.document, attrs)
|
|
59
|
-
table_tmpl.assigns["klass"] = klass
|
|
60
|
-
table_tmpl.render
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
def get_template(document, attrs)
|
|
64
|
-
template = DEFAULT_TEMPLATE
|
|
65
|
-
if attrs["template"]
|
|
66
|
-
template = attrs["template"]
|
|
67
|
-
end
|
|
68
|
-
|
|
69
|
-
rel_tmpl_path = Utils.relative_file_path(
|
|
70
|
-
document, template
|
|
71
|
-
)
|
|
72
|
-
|
|
73
|
-
::Liquid::Template.parse(File.read(rel_tmpl_path))
|
|
40
|
+
def get_default_template
|
|
41
|
+
DEFAULT_TEMPLATE
|
|
74
42
|
end
|
|
75
43
|
end
|
|
76
44
|
end
|
|
@@ -13,6 +13,8 @@ module Metanorma
|
|
|
13
13
|
module Lutaml
|
|
14
14
|
# Class for processing Lutaml files
|
|
15
15
|
class LutamlPreprocessor < ::Asciidoctor::Extensions::Preprocessor
|
|
16
|
+
include Utils
|
|
17
|
+
|
|
16
18
|
REMARKS_ATTRIBUTE = "remarks"
|
|
17
19
|
EXPRESS_PREPROCESSOR_REGEX = %r{
|
|
18
20
|
^ # Start of line
|
|
@@ -225,7 +227,8 @@ module Metanorma
|
|
|
225
227
|
.new(include_paths, ["%s.liquid", "_%s.liquid", "_%s.adoc"])
|
|
226
228
|
|
|
227
229
|
# Parse template once outside the loop
|
|
228
|
-
template = ::Liquid::Template
|
|
230
|
+
template = ::Liquid::Template
|
|
231
|
+
.parse(lines.join("\n"), environment: create_liquid_environment)
|
|
229
232
|
template.registers[:file_system] = file_system
|
|
230
233
|
|
|
231
234
|
# Render for each item
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "liquid"
|
|
4
|
+
require "asciidoctor"
|
|
5
|
+
require "asciidoctor/reader"
|
|
6
|
+
require "lutaml"
|
|
7
|
+
require_relative "utils"
|
|
8
|
+
require "metanorma/plugin/lutaml/asciidoctor/preprocessor"
|
|
9
|
+
require "metanorma/plugin/lutaml/lutaml_ea_xmi_base"
|
|
10
|
+
|
|
11
|
+
module Metanorma
|
|
12
|
+
module Plugin
|
|
13
|
+
module Lutaml
|
|
14
|
+
# Macro for rendering Lutaml::Uml models which are parsing from XMI file
|
|
15
|
+
class LutamlXmiUmlPreprocessor < ::Asciidoctor::Extensions::Preprocessor
|
|
16
|
+
include LutamlEaXmiBase
|
|
17
|
+
|
|
18
|
+
MACRO_REGEXP = /\[lutaml_xmi_uml,([^,]+),?(.+)?\]/.freeze
|
|
19
|
+
|
|
20
|
+
private
|
|
21
|
+
|
|
22
|
+
def parse_result_document(full_path, _guidance)
|
|
23
|
+
::Lutaml::XMI::Parsers::XML.parse(
|
|
24
|
+
File.new(full_path, encoding: "UTF-8"),
|
|
25
|
+
)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def process_text_blocks(document, input_lines) # rubocop:disable Metrics/MethodLength,Metrics/AbcSize
|
|
29
|
+
line = input_lines.next
|
|
30
|
+
process_xmi_index_lines(document, line)
|
|
31
|
+
block_match = line.match(get_macro_regexp)
|
|
32
|
+
|
|
33
|
+
return [line] if block_match.nil?
|
|
34
|
+
|
|
35
|
+
config_yaml_path = block_match[2]&.strip
|
|
36
|
+
xmi_or_index = block_match[1]&.strip
|
|
37
|
+
|
|
38
|
+
lutaml_document, yaml_config = load_lutaml_doc_and_config(
|
|
39
|
+
document,
|
|
40
|
+
xmi_or_index,
|
|
41
|
+
config_yaml_path,
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
block_lines = collect_block_lines(input_lines, input_lines.next)
|
|
45
|
+
|
|
46
|
+
render_result, errors = Utils.render_liquid_string(
|
|
47
|
+
template_string: block_lines.join("\n"),
|
|
48
|
+
contexts: create_default_context_object(
|
|
49
|
+
lutaml_document, yaml_config
|
|
50
|
+
),
|
|
51
|
+
document: document,
|
|
52
|
+
include_path: template_path(document, yaml_config.template_path),
|
|
53
|
+
)
|
|
54
|
+
Utils.notify_render_errors(document, errors)
|
|
55
|
+
|
|
56
|
+
render_result.split("\n")
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def create_default_context_object(uml_document, options)
|
|
60
|
+
context_name = "context"
|
|
61
|
+
if options.context_name
|
|
62
|
+
context_name = options.context_name
|
|
63
|
+
end
|
|
64
|
+
contexts = {}
|
|
65
|
+
contexts[context_name] = uml_document.to_liquid
|
|
66
|
+
contexts
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
end
|
|
@@ -39,8 +39,8 @@ module Metanorma
|
|
|
39
39
|
end
|
|
40
40
|
|
|
41
41
|
def render_liquid_string( # rubocop:disable Metrics/MethodLength,Metrics/AbcSize
|
|
42
|
-
|
|
43
|
-
include_path: nil, template_path: nil
|
|
42
|
+
contexts:, document:,
|
|
43
|
+
template_string: nil, include_path: nil, template_path: nil
|
|
44
44
|
)
|
|
45
45
|
# Allow includes for the template
|
|
46
46
|
include_paths = [
|
|
@@ -6,6 +6,7 @@ require "metanorma/plugin/lutaml/data2_text_preprocessor"
|
|
|
6
6
|
require "metanorma/plugin/lutaml/lutaml_preprocessor"
|
|
7
7
|
require "metanorma/plugin/lutaml/lutaml_uml_datamodel_description_preprocessor"
|
|
8
8
|
require "metanorma/plugin/lutaml/lutaml_ea_xmi_preprocessor"
|
|
9
|
+
require "metanorma/plugin/lutaml/lutaml_xmi_uml_preprocessor"
|
|
9
10
|
require "metanorma/plugin/lutaml/lutaml_diagram_block"
|
|
10
11
|
require "metanorma/plugin/lutaml/lutaml_diagram_block_macro"
|
|
11
12
|
require "metanorma/plugin/lutaml/lutaml_figure_inline_macro"
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: metanorma-plugin-lutaml
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.7.
|
|
4
|
+
version: 0.7.38
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Ribose Inc.
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2025-
|
|
11
|
+
date: 2025-10-28 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: asciidoctor
|
|
@@ -146,6 +146,7 @@ files:
|
|
|
146
146
|
- docs/usages/json_yaml.adoc
|
|
147
147
|
- docs/usages/lutaml-gml.adoc
|
|
148
148
|
- docs/usages/lutaml-uml.adoc
|
|
149
|
+
- docs/usages/xmi_to_uml.adoc
|
|
149
150
|
- lib/metanorma-plugin-lutaml.rb
|
|
150
151
|
- lib/metanorma/plugin/lutaml/asciidoctor/preprocessor.rb
|
|
151
152
|
- lib/metanorma/plugin/lutaml/base_structured_text_preprocessor.rb
|
|
@@ -197,6 +198,7 @@ files:
|
|
|
197
198
|
- lib/metanorma/plugin/lutaml/lutaml_preprocessor.rb
|
|
198
199
|
- lib/metanorma/plugin/lutaml/lutaml_table_inline_macro.rb
|
|
199
200
|
- lib/metanorma/plugin/lutaml/lutaml_uml_datamodel_description_preprocessor.rb
|
|
201
|
+
- lib/metanorma/plugin/lutaml/lutaml_xmi_uml_preprocessor.rb
|
|
200
202
|
- lib/metanorma/plugin/lutaml/parse_error.rb
|
|
201
203
|
- lib/metanorma/plugin/lutaml/source_extractor.rb
|
|
202
204
|
- lib/metanorma/plugin/lutaml/utils.rb
|