metanorma-plugin-lutaml 0.4.3 → 0.4.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.adoc +109 -76
- data/lib/metanorma-plugin-lutaml.rb +1 -0
- data/lib/metanorma/plugin/lutaml/liquid/multiply_local_file_system.rb +53 -0
- data/lib/metanorma/plugin/lutaml/liquid_templates/_diagrams_block.liquid +11 -0
- data/lib/metanorma/plugin/lutaml/liquid_templates/_packages.liquid +57 -32
- data/lib/metanorma/plugin/lutaml/liquid_templates/_packages_data_dictionary.liquid +177 -0
- data/lib/metanorma/plugin/lutaml/liquid_templates/_packages_data_dictionary_classes.liquid +43 -0
- data/lib/metanorma/plugin/lutaml/liquid_templates/_packages_entity_list.liquid +113 -0
- data/lib/metanorma/plugin/lutaml/lutaml_diagram_base.rb +2 -1
- data/lib/metanorma/plugin/lutaml/lutaml_figure_inline_macro.rb +23 -0
- data/lib/metanorma/plugin/lutaml/lutaml_uml_attributes_table_preprocessor.rb +10 -9
- data/lib/metanorma/plugin/lutaml/lutaml_uml_datamodel_description_preprocessor.rb +56 -20
- data/lib/metanorma/plugin/lutaml/utils.rb +3 -2
- data/lib/metanorma/plugin/lutaml/version.rb +1 -1
- metadata +8 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6975d55ed93f086ff54367a880fe6cd997da1040dd5266d3c5c2f5c984370801
|
4
|
+
data.tar.gz: fa336cbe86550862521a4fe051a69dfdd8e809cc3ba652c07482ab6f9d5bb7ac
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bf4817cf9ec3c41195ae30425bf4462f58dffce5773f4f07e146915a13fc7c1f9e46be8285c5f4814a673a7558aacb937b7e0dfb3939c644ad9b8cb438c1a580
|
7
|
+
data.tar.gz: e987082dd620fcf4b455204e86607df45632c5ce9bdca7dfd30815c1c720a6facab339a436d90cc8b78809c608c2271a8f7cb3e32dbad66205a25e3f11c525a7
|
data/README.adoc
CHANGED
@@ -285,31 +285,45 @@ The `lutaml_uml_datamodel_description` macro can be used:
|
|
285
285
|
-----
|
286
286
|
[lutaml_uml_datamodel_description, path/to/example.xmi]
|
287
287
|
--
|
288
|
-
--
|
289
288
|
[.before]
|
290
|
-
|
289
|
+
....
|
291
290
|
my text
|
292
|
-
|
291
|
+
....
|
292
|
+
|
293
|
+
[.diagram_include_block, base_path="requirements/", format="emf"]
|
294
|
+
....
|
295
|
+
Diagram text
|
296
|
+
....
|
297
|
+
|
298
|
+
[.include_block, package="Another", base_path="spec/fixtures"]
|
299
|
+
....
|
300
|
+
my text
|
301
|
+
....
|
302
|
+
|
303
|
+
[.include_block, base_path="spec/fixtures"]
|
304
|
+
....
|
305
|
+
my text
|
306
|
+
....
|
293
307
|
|
294
308
|
[.before, package="Another"]
|
295
|
-
|
309
|
+
....
|
296
310
|
text before Another package
|
297
|
-
|
311
|
+
....
|
298
312
|
|
299
313
|
[.after, package="Another"]
|
300
|
-
|
314
|
+
....
|
301
315
|
text after Another package
|
302
|
-
|
316
|
+
....
|
303
317
|
|
304
318
|
[.after, package="CityGML"]
|
305
|
-
|
319
|
+
....
|
306
320
|
text after CityGML package
|
307
|
-
|
321
|
+
....
|
308
322
|
|
309
323
|
[.after]
|
310
|
-
|
324
|
+
....
|
311
325
|
footer text
|
312
|
-
|
326
|
+
....
|
313
327
|
--
|
314
328
|
--
|
315
329
|
-----
|
@@ -318,102 +332,118 @@ Where:
|
|
318
332
|
|
319
333
|
* `path/to/example.xmi` - required, path to the XMI file to render
|
320
334
|
|
321
|
-
* `[.before]` - macro to add additional text before the rendered output, can be used only once, additional occurrences of macro will overwrite text
|
335
|
+
* `[.before]` - macro to add additional text before the rendered output, can be used only once, additional occurrences of macro will overwrite text, not that `literal` block style must be used in there(eg `....`)
|
322
336
|
|
323
337
|
* `[.after]` - macro to add additional text after the rendered output, can be used only once, additional occurrences of macro will overwrite text
|
324
338
|
|
325
339
|
* `[.after, package="Another"]` - macro with text to be inserted before(after in case of `.before` name) the package
|
326
340
|
|
327
|
-
|
328
|
-
Will produce this output:
|
329
|
-
|
341
|
+
* `[.diagram_include_block]` - macro to automatically include diagram images. Attribute `base_path` is a required attribute to supply path prefix where to look for a digram image. `format` is an optional attribute that tells what file extention to use when including diagram file. The logic is as follows:
|
330
342
|
[source,adoc]
|
331
343
|
-----
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
344
|
+
{% for diagram in package.diagrams %}
|
345
|
+
[[figure-{{ diagram.xmi_id }}]]
|
346
|
+
.{{ diagram.name }}
|
347
|
+
image::{{ image_base_path }}/{{ diagram.xmi_id }}.{{ format | default: 'png' }}[]
|
348
|
+
|
349
|
+
{% if diagram.definition %}
|
350
|
+
{{ diagram.definition | html2adoc }}
|
351
|
+
{% endif %}
|
352
|
+
{% endfor %}
|
353
|
+
-----
|
354
|
+
Eg: script will take package diagrams supplied in xmi file and will try to include `image` with the name equal to diagram' xmi_id attribute plus `.png`. Also one can add any text to the macro text, it will be added as paragraph before each image include.
|
338
355
|
|
339
|
-
[
|
340
|
-
==== Another
|
356
|
+
* `[.diagram_include_block, package="Another"]` - same as above, but diagram will be included only for supplied package name
|
341
357
|
|
342
|
-
|
358
|
+
* `[.include_block, base_path="spec/fixtures"]` - macro to inlude files(adoc/liquid) for each package name. Attribute `base_path` is a required attribute to supply path prefix where to look for file to include. Macro will look for a file called `base_path` + `/` `_package_name`(downcase, replace : -> '', ' ' -> '_') + `.adoc`[`.liquid`], eg for package 'My Package name' and `base_path` eq to `my/path`, macro will look for the following file path: `my/path/_my_package_name.adoc`.
|
343
359
|
|
344
|
-
|
360
|
+
* `[.include_block, package="Another", base_path="spec/fixtures"]` - same as above, but include block will be included only for supplied package name
|
345
361
|
|
346
|
-
|
347
|
-
[cols="2a,6a",options="header"]
|
348
|
-
|===
|
349
|
-
|Class |Description
|
362
|
+
In addition to macroses 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:
|
350
363
|
|
364
|
+
[source,adoc]
|
365
|
+
-----
|
366
|
+
This is lutaml_figure::[package="Wrapper root package", name="Fig B1 Full model"] figure
|
367
|
+
-----
|
351
368
|
|
352
|
-
|
353
|
-
«»
|
354
|
-
|
|
369
|
+
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 refernce package diagram.
|
355
370
|
|
371
|
+
Will produce this output:
|
356
372
|
|
357
|
-
|
358
|
-
|
359
|
-
|
373
|
+
[source,adoc]
|
374
|
+
-----
|
375
|
+
my text
|
376
|
+
== CityGML package
|
377
|
+
=== CityGML overview
|
360
378
|
|
361
|
-
|
362
|
-
|===
|
379
|
+
Diagram text
|
363
380
|
|
381
|
+
[[figure-EAID_ACBB5EE3_3428_40f5_9C7C_E41923419F29]]
|
382
|
+
.CityGML Package Diagram
|
383
|
+
image::requirements//EAID_ACBB5EE3_3428_40f5_9C7C_E41923419F29.png[]
|
364
384
|
|
385
|
+
BuildingFurnitureFunctionValue is a code list that enumerates the different purposes of a BuildingFurniture.
|
365
386
|
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|Name |Description
|
387
|
+
[[figure-EAID_938AE961_1C57_4052_B964_997D1894A58D]]
|
388
|
+
.Use of ISO and OASIS standards in CityGML
|
389
|
+
image::requirements//EAID_938AE961_1C57_4052_B964_997D1894A58D.png[]
|
370
390
|
|
391
|
+
The CityGML package is organized into
|
392
|
+
2 packages with 1 modules:
|
371
393
|
|
372
|
-
|
373
|
-
|
394
|
+
[arabic]
|
395
|
+
. Another package
|
396
|
+
. CityTML package
|
374
397
|
|
398
|
+
my text
|
375
399
|
|
376
|
-
|
377
|
-
|
|
400
|
+
Content for CityGML package
|
378
401
|
|
379
|
-
|
380
|
-
|===
|
402
|
+
==== Defining tables
|
381
403
|
|
404
|
+
[arabic]
|
405
|
+
.<<tab-P-another-C-abstractatomictimeseries>> -- Elements of Another::AbstractAtomicTimeseries
|
382
406
|
|
383
|
-
|
384
|
-
.
|
385
|
-
[
|
407
|
+
[[tab-P-another-C-abstractatomictimeseries]]
|
408
|
+
.Elements of Another::AbstractAtomicTimeseries
|
409
|
+
[width="100%",cols="a,a,a,a,a,a,a,a"]
|
386
410
|
|===
|
387
|
-
|Name
|
388
|
-
|
389
|
-
|
411
|
+
h|Name: 7+| AbstractAtomicTimeseries
|
412
|
+
h|Definition: 7+|
|
413
|
+
h|Stereotype: 7+| interface
|
414
|
+
h|Abstract: 7+|
|
415
|
+
.1+h|Associations: 7+| (none)
|
416
|
+
.4+h|Public attributes:
|
417
|
+
| _Name_
|
418
|
+
2+| _Definition_
|
419
|
+
| _Derived_
|
420
|
+
| _Obligation_
|
421
|
+
| _Maximum occurrence_
|
422
|
+
| _Data type_
|
423
|
+
| adeOfAbstractAtomicTimeseries
|
424
|
+
2+|
|
390
425
|
|
|
391
|
-
|
426
|
+
| C
|
427
|
+
| *
|
428
|
+
| ADEOfAbstractAtomicTimeseries
|
429
|
+
| observationProperty
|
430
|
+
2+|
|
431
|
+
|
|
432
|
+
| M
|
433
|
+
| 1
|
434
|
+
| CharacterString
|
435
|
+
| uom
|
436
|
+
2+|
|
437
|
+
|
|
438
|
+
| C
|
439
|
+
| 1
|
440
|
+
| CharacterString
|
441
|
+
h|Constraints: 7+| (none)
|
392
442
|
|===
|
393
443
|
|
394
|
-
|
395
|
-
==== Additional Information
|
396
|
-
|
397
|
-
text after Another package
|
398
|
-
|
399
|
-
|
400
|
-
=== CityGML
|
401
|
-
|
402
|
-
[[rc_citygml-model_section]]
|
403
|
-
==== CityGML
|
404
|
-
|
405
|
-
==== Requirements
|
406
|
-
|
407
|
-
==== Class Definitions
|
408
|
-
|
409
|
-
==== Additional Information
|
444
|
+
=== Additional Information
|
410
445
|
|
411
446
|
text after CityGML package
|
412
|
-
|
413
|
-
|
414
|
-
= footer
|
415
|
-
footer text
|
416
|
-
|
417
447
|
-----
|
418
448
|
|
419
449
|
In addition to just supplying XMI file, this macro also supports YAML
|
@@ -431,18 +461,21 @@ packages:
|
|
431
461
|
- three
|
432
462
|
# skips these packages
|
433
463
|
- skip: four
|
464
|
+
render_style: entity_list|data_dictionary|default
|
465
|
+
section_depth: 2
|
434
466
|
-----
|
435
467
|
|
436
468
|
Where:
|
437
469
|
|
438
470
|
* `packages` - required, root element with the list of strings or objects
|
439
|
-
|
440
471
|
* `Package *` - pattern matching, specifies lookup condition for packages to
|
441
472
|
render.
|
442
473
|
+
|
443
474
|
NOTE: In this example, it is equal to the following regular expression: `/^Package.*$/`
|
444
475
|
|
445
476
|
* `skip: four` - object with package name to skip
|
477
|
+
* `render_style` - what template to use to render packages, can be: entity_list, data_dictionary or default
|
478
|
+
* `section_depth` - what package to use as root package for render, eg `section_depth` equal to 2 tells processor to use first nested package of the first root packages in xmi file. Example: if xmi file has this package structure: [{ name: 'One', packages: [{ name: 'one-1' }, { name: 'one-2' }] }, { name: 'Two', packages: [{ name: 'two-1' }, { name: 'two-2' }] }] and we have `section_depth` equal to 2, root package will be `one-1`
|
446
479
|
|
447
480
|
Usage with macro:
|
448
481
|
|
@@ -4,6 +4,7 @@ require "metanorma/plugin/lutaml/lutaml_uml_attributes_table_preprocessor"
|
|
4
4
|
require "metanorma/plugin/lutaml/lutaml_uml_datamodel_description_preprocessor"
|
5
5
|
require "metanorma/plugin/lutaml/lutaml_diagram_block"
|
6
6
|
require "metanorma/plugin/lutaml/lutaml_diagram_block_macro"
|
7
|
+
require "metanorma/plugin/lutaml/lutaml_figure_inline_macro"
|
7
8
|
|
8
9
|
module Metanorma
|
9
10
|
module Plugin
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module Metanorma
|
2
|
+
module Plugin
|
3
|
+
module Lutaml
|
4
|
+
module Liquid
|
5
|
+
class LocalFileSystem
|
6
|
+
attr_accessor :roots, :patterns
|
7
|
+
|
8
|
+
def initialize(roots, patterns = ["_%s.liquid"])
|
9
|
+
@roots = roots
|
10
|
+
@patterns = patterns
|
11
|
+
end
|
12
|
+
|
13
|
+
def read_template_file(template_path)
|
14
|
+
full_path = full_path(template_path)
|
15
|
+
raise FileSystemError, "No such template '#{template_path}'" unless File.exist?(full_path)
|
16
|
+
|
17
|
+
File.read(full_path)
|
18
|
+
end
|
19
|
+
|
20
|
+
def full_path(template_path)
|
21
|
+
raise ::Liquid::FileSystemError, "Illegal template name '#{template_path}'" unless %r{\A[^./][a-zA-Z0-9_/]+\z}.match?(template_path)
|
22
|
+
|
23
|
+
result_path = if template_path.include?('/')
|
24
|
+
roots
|
25
|
+
.map do |root|
|
26
|
+
patterns.map do |pattern|
|
27
|
+
File.join(root, File.dirname(template_path), pattern % File.basename(template_path))
|
28
|
+
end
|
29
|
+
end
|
30
|
+
.flatten
|
31
|
+
.find { |path| File.file?(path) }
|
32
|
+
else
|
33
|
+
roots
|
34
|
+
.map do |root|
|
35
|
+
patterns.map do |pattern|
|
36
|
+
File.join(root, pattern % template_path)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
.flatten
|
40
|
+
.find { |path| File.file?(path) }
|
41
|
+
end
|
42
|
+
|
43
|
+
unless roots.any? { |root| File.expand_path(result_path).start_with?(File.expand_path(root)) }
|
44
|
+
raise ::Liquid::FileSystemError, "Illegal template path '#{File.expand_path(result_path)}'"
|
45
|
+
end
|
46
|
+
|
47
|
+
result_path
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
{{ text }}
|
2
|
+
|
3
|
+
{% for diagram in package.diagrams %}
|
4
|
+
[[figure-{{ diagram.xmi_id }}]]
|
5
|
+
.{{ diagram.name }}
|
6
|
+
image::{{ image_base_path }}/{{ diagram.xmi_id }}.{{ format | default: 'png' }}[]
|
7
|
+
|
8
|
+
{% if diagram.definition %}
|
9
|
+
{{ diagram.definition | html2adoc }}
|
10
|
+
{% endif %}
|
11
|
+
{% endfor %}
|
@@ -1,27 +1,29 @@
|
|
1
1
|
{% for package in context.packages %}
|
2
|
-
{% assign
|
3
|
-
{% if additional_context
|
4
|
-
{
|
2
|
+
{% assign package_name = package.name | downcase | replace: ":", "" | replace: " ", "_" %}
|
3
|
+
{% if additional_context.before and additional_context.before.size > 0 %}
|
4
|
+
{% for before in additional_context.before %}
|
5
|
+
{{ before.text }}
|
6
|
+
{% endfor %}
|
5
7
|
{% endif %}
|
6
8
|
{% assign is_package_spare = package.name | slice: 0,5 %}
|
7
9
|
{% if is_package_spare == 'old: ' %}{% continue %}
|
8
10
|
{% elsif is_package_spare == 'Spare' %}{% continue %}
|
9
11
|
{% endif %}
|
10
|
-
{% assign package_name = package.name | downcase | replace: ":", "" | replace: " ", "_" %}
|
11
12
|
|
12
13
|
{% capture equalsigns %}{% for count in (1..depth) %}={% endfor %}{% endcapture %}{{equalsigns}} {{ package.name }} package
|
13
14
|
{{equalsigns}}= {{ package.name }} overview
|
14
15
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
16
|
+
{% assign before_package_key = 'before;' | append: package.name %}
|
17
|
+
{% if additional_context[before_package_key] and additional_context[before_package_key].size > 0 %}
|
18
|
+
{% for before in additional_context[before_package_key] %}
|
19
|
+
{{ before.text }}
|
20
|
+
{% endfor %}
|
21
|
+
{% endif %}
|
22
|
+
{% if additional_context.diagram_include_block %}
|
23
|
+
{% for diagram_include_block in additional_context.diagram_include_block %}
|
24
|
+
{% include "diagrams_block", package_name: package_name, image_base_path: diagram_include_block.base_path, text: diagram_include_block.text, format: diagram_include_block.format %}
|
25
|
+
{% endfor %}
|
26
|
+
{% endif %}
|
25
27
|
|
26
28
|
{% if package.packages.size > 0 %}The {{ package.name }} package is organized into
|
27
29
|
{{ package.packages.size }} packages{% assign modules_nested_size = 0 %}{% for module in package.packages %}{% assign modules_nested_size = modules_nested_size | plus: module.packages.size %}{% endfor %}{% if modules_nested_size > 0 %} with {{modules_nested_size}} modules{% endif %}:
|
@@ -38,7 +40,7 @@
|
|
38
40
|
{% endif %}
|
39
41
|
{% endfor %}
|
40
42
|
|
41
|
-
{% if package.classes.size > 0 %}
|
43
|
+
{% if package.classes.size > 0 or package.enums.size > 0 or package.data_types.size > 0 %}
|
42
44
|
|
43
45
|
{{equalsigns}}= Defining tables
|
44
46
|
|
@@ -83,26 +85,49 @@
|
|
83
85
|
{% include "packages_data_type" %}
|
84
86
|
{% endfor %}
|
85
87
|
|
86
|
-
|
87
|
-
// {% capture requirement_filename %}requirements/REQ_{{ package_name }}{% endcapture %}
|
88
|
-
// {% capture requirement_content %}{% include requirement_filename %}{% endcapture %}
|
89
|
-
// {% unless requirement_content contains "Liquid error" %}
|
90
|
-
// The following requirements apply:
|
91
|
-
// {{ requirement_content }}
|
92
|
-
//
|
93
|
-
// {% for num in (1..5) %}
|
94
|
-
// {% capture nested_requirement_filename %}requirements/REQ_{{ package_name }}_{{num}}{% endcapture %}
|
95
|
-
// {% capture nested_requirement_content %}{% include nested_requirement_filename %}{% endcapture %}
|
96
|
-
// {% unless nested_requirement_content contains "Liquid error" %}
|
97
|
-
// {{ nested_requirement_content }}
|
98
|
-
// {% endunless %}
|
99
|
-
// {% endfor %}
|
100
|
-
// {% endunless %}
|
88
|
+
{% endif %}
|
101
89
|
|
90
|
+
{% if additional_context.include_block and additional_context.include_block.size > 0 %}
|
91
|
+
{% for block in additional_context.include_block %}
|
92
|
+
{% capture block_filename %}{{ block.base_path }}{{ package_name }}{% endcapture %}
|
93
|
+
{% capture block_content %}{% include block_filename %}{% endcapture %}
|
94
|
+
{% unless block_content contains "Liquid error" %}
|
95
|
+
{% if block.text %}
|
96
|
+
{{ block.text }}
|
97
|
+
{% endif %}
|
98
|
+
{{ block_content }}
|
99
|
+
{% endunless %}
|
100
|
+
{% endfor %}
|
102
101
|
{% endif %}
|
102
|
+
|
103
|
+
{% assign include_block_package_key = 'include_block;' | append: package.name %}
|
104
|
+
{% if additional_context[include_block_package_key] and additional_context[include_block_package_key].size > 0 %}
|
105
|
+
{% for block in additional_context[include_block_package_key] %}
|
106
|
+
{% capture block_filename %}{{ block.base_path }}{{ package_name }}{% endcapture %}
|
107
|
+
{% capture block_content %}{% include block_filename %}{% endcapture %}
|
108
|
+
{% unless block_content contains "Liquid error" %}
|
109
|
+
{% if block.text %}
|
110
|
+
{{ block.text }}
|
111
|
+
{% endif %}
|
112
|
+
{{ block_content }}
|
113
|
+
{% endunless %}
|
114
|
+
{% endfor %}
|
115
|
+
{% endif %}
|
116
|
+
|
103
117
|
{% assign after_package_key = 'after;' | append: package.name %}
|
104
|
-
{{equalsigns}}= Additional Information
|
105
118
|
{% if additional_context[after_package_key] %}
|
106
|
-
{{
|
119
|
+
{{equalsigns}}= Additional Information
|
120
|
+
{% for after in additional_context[after_package_key] %}
|
121
|
+
{{ after.text }}
|
122
|
+
{% endfor %}
|
123
|
+
{% endif %}
|
124
|
+
{% if package.packages.size > 0 and render_nested_packages %}
|
125
|
+
{% assign nested_depth = depth | plus: 1 %}{% include "packages", depth: nested_depth, context: package %}
|
107
126
|
{% endif %}
|
108
127
|
{% endfor %}
|
128
|
+
|
129
|
+
{% if additional_context.after and additional_context.after.size > 0 %}
|
130
|
+
{% for after in additional_context.after %}
|
131
|
+
{{ after.text }}
|
132
|
+
{% endfor %}
|
133
|
+
{% endif %}
|
@@ -0,0 +1,177 @@
|
|
1
|
+
{% for package in context.packages %}
|
2
|
+
{% assign package_name = package.name | downcase | replace: ":", "" | replace: " ", "_" %}
|
3
|
+
{% if additional_context.before and additional_context.before.size > 0 %}
|
4
|
+
{% for before in additional_context.before %}
|
5
|
+
{{ before.text }}
|
6
|
+
{% endfor %}
|
7
|
+
{% endif %}
|
8
|
+
{% capture equalsigns %}{% for count in (1..depth) %}={% endfor %}{% endcapture %}{{equalsigns}} {{ package.name }}
|
9
|
+
{{equalsigns}}= {{ package.name }}
|
10
|
+
|
11
|
+
{% assign before_package_key = 'before;' | append: package.name %}
|
12
|
+
{% if additional_context[before_package_key] and additional_context[before_package_key].size > 0 %}
|
13
|
+
{% for before in additional_context[before_package_key] %}
|
14
|
+
{{ before.text }}
|
15
|
+
{% endfor %}
|
16
|
+
{% endif %}
|
17
|
+
|
18
|
+
[cols="1a,4a"]
|
19
|
+
|===
|
20
|
+
|
21
|
+
h|Description: | {{ package.definition }}
|
22
|
+
h|Parent Package: | {{ context.name }}
|
23
|
+
h|Stereotype: | «{{ package.stereotype }}»
|
24
|
+
|
25
|
+
|===
|
26
|
+
|
27
|
+
{% assign feature_types = package.classes | where: "stereotype", "FeatureType" %}
|
28
|
+
{% assign object_types = package.classes | where: "stereotype", "ObjectType" %}
|
29
|
+
{% assign basic_types = package.classes | where: "stereotype", "BasicType" %}
|
30
|
+
{% assign unions = package.classes | where: "stereotype", "Union" %}
|
31
|
+
{% assign code_lists = package.classes | where: "stereotype", "CodeList" %}
|
32
|
+
{% if feature_types.size > 0 or object_types.size > 0 %}
|
33
|
+
{{equalsigns}}= Classes
|
34
|
+
|
35
|
+
{% include "packages_data_dictionary_classes", classes: feature_types %}
|
36
|
+
{% include "packages_data_dictionary_classes", classes: object_types %}
|
37
|
+
{% endif %}
|
38
|
+
|
39
|
+
{% if basic_types.size > 0 %}
|
40
|
+
{{equalsigns}}= Basic Types
|
41
|
+
|
42
|
+
{% include "packages_data_dictionary_classes", classes: basic_types %}
|
43
|
+
{% endif %}
|
44
|
+
|
45
|
+
{% if unions.size > 0 %}
|
46
|
+
{{equalsigns}}= Unions
|
47
|
+
|
48
|
+
{% include "packages_data_dictionary_classes", classes: unions %}
|
49
|
+
{% endif %}
|
50
|
+
|
51
|
+
{% if code_lists.size > 0 %}
|
52
|
+
{{equalsigns}}= Code Lists
|
53
|
+
|
54
|
+
{% include "packages_data_dictionary_classes", classes: code_lists %}
|
55
|
+
{% endif %}
|
56
|
+
|
57
|
+
{% if package.data_types.size > 0 %}
|
58
|
+
{{equalsigns}}= Data Types
|
59
|
+
|
60
|
+
{% for data_type in package.data_types %}
|
61
|
+
{% capture generalizations %}{% for assoc in data_type.associations | where: "member_end_type", "generalization" %}{{ assoc.member_end }} {% endfor %}{% endcapture %}
|
62
|
+
[[{{ data_type.name }}-section]]
|
63
|
+
[cols="1a"]
|
64
|
+
|===
|
65
|
+
|*{{ data_type.name }}*
|
66
|
+
|[cols="1,4",frame=none,grid=none]
|
67
|
+
!===
|
68
|
+
!{nbsp}{nbsp}{nbsp}{nbsp}Definition: ! {{ data_type.definition }}
|
69
|
+
!{nbsp}{nbsp}{nbsp}{nbsp}Subclass of: ! {{ generalizations }}
|
70
|
+
!{nbsp}{nbsp}{nbsp}{nbsp}Stereotype: ! «DataType»
|
71
|
+
!===
|
72
|
+
{% if data_type.associations.size > 0 %}
|
73
|
+
{% capture rendered_associations %}
|
74
|
+
{% for assoc in data_type.associations %}
|
75
|
+
{% if assoc.member_end_attribute_name.size > 0 %}
|
76
|
+
{% capture cardinality %}{% if assoc.member_end_cardinality.min == 'C' %}[0..{{ assoc.member_end_cardinality.max }}]{% elsif assoc.member_end_cardinality.min == 'M' and assoc.member_end_cardinality.max == '1' %}[1..1]{% else %}[{{ assoc.member_end_cardinality.max }}]{% endif %}{% endcapture %}
|
77
|
+
!{set:cellbgcolor:#FFFFFF} {{ assoc.member_end_attribute_name }} !<<{{assoc.member_end}}-section,{{assoc.member_end}}>> {{ cardinality }} ! {{ assoc.definition }}
|
78
|
+
{% endif %}
|
79
|
+
{% endfor %}
|
80
|
+
{% endcapture %}
|
81
|
+
{% if rendered_associations.size > 0 %}
|
82
|
+
|[cols="15,20,60",frame=none,grid=none,options="header"]
|
83
|
+
!===
|
84
|
+
!{set:cellbgcolor:#DDDDDD} *Role name* !*Target class and multiplicity* !*Definition*
|
85
|
+
{{ rendered_associations }}
|
86
|
+
!===
|
87
|
+
{% endif %}
|
88
|
+
{% endif %}
|
89
|
+
{% if data_type.attributes.size > 0 %}
|
90
|
+
|[cols="15,20,60",frame=none,grid=none,options="header"]
|
91
|
+
!===
|
92
|
+
!{set:cellbgcolor:#DDDDDD} *Attribute* !*Value type and multiplicity* !*Definition*
|
93
|
+
{% for attr in data_type.attributes %}
|
94
|
+
{% capture cardinality %}{% if attr.cardinality.min == 'C' %}[0..{{ attr.cardinality.max }}]{% elsif assoc.member_end_cardinality.min == 'M' and assoc.member_end_cardinality.max == '1' %}[1..1]{% else %}[{{ attr.cardinality.max }}]{% endif %}{% endcapture %}
|
95
|
+
!{set:cellbgcolor:#FFFFFF} {{ attr.name }} !<<{{ attr.type }}-section,{{ attr.name }}>> {{ cardinality }} !{{ attr.definition }}
|
96
|
+
{% endfor %}
|
97
|
+
!===
|
98
|
+
|{set:cellbgcolor:#FFFFFF} Note: Unless otherwise specified, all attributes and role names have the stereotype «Property».
|
99
|
+
{% endif %}
|
100
|
+
|===
|
101
|
+
|
102
|
+
{% endfor %}
|
103
|
+
{% endif %}
|
104
|
+
|
105
|
+
{% if package.enums.size > 0 %}
|
106
|
+
{{equalsigns}}= Enumerations
|
107
|
+
|
108
|
+
{% for enum in package.enums %}
|
109
|
+
{% capture generalizations %}{% for assoc in enum.associations | where: "member_end_type", "generalization" %}{{ assoc.member_end }} {% endfor %}{% endcapture %}
|
110
|
+
[[{{ enum.name }}-section]]
|
111
|
+
[cols="1a"]
|
112
|
+
|===
|
113
|
+
|*{{ enum.name }}*
|
114
|
+
|[cols="1,4",frame=none,grid=none]
|
115
|
+
!===
|
116
|
+
!{nbsp}{nbsp}{nbsp}{nbsp}Definition: ! {{ enum.definition }}
|
117
|
+
!{nbsp}{nbsp}{nbsp}{nbsp}Stereotype: ! «Enumeration»
|
118
|
+
!===
|
119
|
+
{% if enum.values.size > 0 %}
|
120
|
+
|[cols="1,4",frame=none,grid=none,options="header"]
|
121
|
+
!===
|
122
|
+
^!{set:cellbgcolor:#DDDDDD} *Literal value* !*Definition*
|
123
|
+
|
124
|
+
{% for val in enum.values %}
|
125
|
+
^!{set:cellbgcolor:#FFFFFF} {{ val.name }} !{{ val.definition }}
|
126
|
+
{% endfor %}
|
127
|
+
!===
|
128
|
+
{% endif %}
|
129
|
+
|===
|
130
|
+
|
131
|
+
{% endfor %}
|
132
|
+
{% endif %}
|
133
|
+
|
134
|
+
{% if additional_context.include_block and additional_context.include_block.size > 0 %}
|
135
|
+
{% for block in additional_context.include_block %}
|
136
|
+
{% capture block_filename %}{{ block.base_path }}{{ package_name }}{% endcapture %}
|
137
|
+
{% capture block_content %}{% include block_filename %}{% endcapture %}
|
138
|
+
{% unless block_content contains "Liquid error" %}
|
139
|
+
{% if block.text %}
|
140
|
+
{{ block.text }}
|
141
|
+
{% endif %}
|
142
|
+
{{ block_content }}
|
143
|
+
{% endunless %}
|
144
|
+
{% endfor %}
|
145
|
+
{% endif %}
|
146
|
+
|
147
|
+
{% assign include_block_package_key = 'include_block;' | append: package.name %}
|
148
|
+
{% if additional_context[include_block_package_key] and additional_context[include_block_package_key].size > 0 %}
|
149
|
+
{% for block in additional_context[include_block_package_key] %}
|
150
|
+
{% capture block_filename %}{{ block.base_path }}{{ package_name }}{% endcapture %}
|
151
|
+
{% capture block_content %}{% include block_filename %}{% endcapture %}
|
152
|
+
{% unless block_content contains "Liquid error" %}
|
153
|
+
{% if block.text %}
|
154
|
+
{{ block.text }}
|
155
|
+
{% endif %}
|
156
|
+
{{ block_content }}
|
157
|
+
{% endunless %}
|
158
|
+
{% endfor %}
|
159
|
+
{% endif %}
|
160
|
+
|
161
|
+
{% assign after_package_key = 'after;' | append: package.name %}
|
162
|
+
{% if additional_context[after_package_key] %}
|
163
|
+
{{equalsigns}}= Additional Information
|
164
|
+
{% for after in additional_context[after_package_key] %}
|
165
|
+
{{ after.text }}
|
166
|
+
{% endfor %}
|
167
|
+
{% endif %}
|
168
|
+
{% if package.packages.size > 0 and render_nested_packages %}
|
169
|
+
{% assign nested_depth = depth | plus: 1 %}{% include "packages_data_dictionary", depth: nested_depth, context: package %}
|
170
|
+
{% endif %}
|
171
|
+
{% endfor %}
|
172
|
+
|
173
|
+
{% if additional_context.after and additional_context.after.size > 0 %}
|
174
|
+
{% for after in additional_context.after %}
|
175
|
+
{{ after.text }}
|
176
|
+
{% endfor %}
|
177
|
+
{% endif %}
|
@@ -0,0 +1,43 @@
|
|
1
|
+
{% for klass in classes %}
|
2
|
+
{% capture generalizations %}{% for assoc in klass.associations | where: "member_end_type", "generalization" %}{{ assoc.member_end }} {% endfor %}{% endcapture %}
|
3
|
+
[[{{ klass.name }}-section]]
|
4
|
+
[cols="1a"]
|
5
|
+
|===
|
6
|
+
|*{{ klass.name }}*
|
7
|
+
|[cols="1,4",frame=none,grid=none]
|
8
|
+
!===
|
9
|
+
!{nbsp}{nbsp}{nbsp}{nbsp}Definition: ! {{ klass.definition }}
|
10
|
+
!{nbsp}{nbsp}{nbsp}{nbsp}Subclass of: ! {{ generalizations }}
|
11
|
+
!{nbsp}{nbsp}{nbsp}{nbsp}Stereotype: ! «{{ klass.stereotype }}»
|
12
|
+
!===
|
13
|
+
{% if klass.associations.size > 0 %}
|
14
|
+
{% capture rendered_associations %}
|
15
|
+
{% for assoc in klass.associations %}
|
16
|
+
{% if assoc.member_end_attribute_name.size > 0 %}
|
17
|
+
{% capture cardinality %}{% if assoc.member_end_cardinality.min == 'C' %}[0..{{ assoc.member_end_cardinality.max }}]{% elsif assoc.member_end_cardinality.min == 'M' and assoc.member_end_cardinality.max == '1' %}[1..1]{% else %}[{{ assoc.member_end_cardinality.max }}]{% endif %}{% endcapture %}
|
18
|
+
!{set:cellbgcolor:#FFFFFF} {{ assoc.member_end_attribute_name }} !<<{{assoc.member_end}}-section,{{assoc.member_end}}>> {{ cardinality }} ! {{ assoc.definition }}
|
19
|
+
{% endif %}
|
20
|
+
{% endfor %}
|
21
|
+
{% endcapture %}
|
22
|
+
{% if rendered_associations.size > 0 %}
|
23
|
+
|[cols="15,20,60",frame=none,grid=none,options="header"]
|
24
|
+
!===
|
25
|
+
!{set:cellbgcolor:#DDDDDD} *Role name* !*Target class and multiplicity* !*Definition*
|
26
|
+
{{ rendered_associations }}
|
27
|
+
!===
|
28
|
+
{% endif %}
|
29
|
+
{% endif %}
|
30
|
+
{% if klass.attributes.size > 0 %}
|
31
|
+
|[cols="15,20,60",frame=none,grid=none,options="header"]
|
32
|
+
!===
|
33
|
+
!{set:cellbgcolor:#DDDDDD} *Attribute* !*Value type and multiplicity* !*Definition*
|
34
|
+
{% for attr in klass.attributes %}
|
35
|
+
{% capture cardinality %}{% if attr.cardinality.min == 'C' %}[0..{{ attr.cardinality.max }}]{% elsif assoc.member_end_cardinality.min == 'M' and assoc.member_end_cardinality.max == '1' %}[1..1]{% else %}[{{ attr.cardinality.max }}]{% endif %}{% endcapture %}
|
36
|
+
!{set:cellbgcolor:#FFFFFF} {{ attr.name }} !<<{{ attr.type }}-section,{{ attr.name }}>> {{ cardinality }} !{{ attr.definition }}
|
37
|
+
{% endfor %}
|
38
|
+
!===
|
39
|
+
|{set:cellbgcolor:#FFFFFF} Note: Unless otherwise specified, all attributes and role names have the stereotype «Property».
|
40
|
+
{% endif %}
|
41
|
+
|===
|
42
|
+
|
43
|
+
{% endfor %}
|
@@ -0,0 +1,113 @@
|
|
1
|
+
{% for package in context.packages %}
|
2
|
+
{% assign package_name = package.name | downcase | replace: ":", "" | replace: " ", "_" %}
|
3
|
+
{% if additional_context.before and additional_context.before.size > 0 %}
|
4
|
+
{% for before in additional_context.before %}
|
5
|
+
{{ before.text }}
|
6
|
+
{% endfor %}
|
7
|
+
{% endif %}
|
8
|
+
{% capture equalsigns %}{% for count in (1..depth) %}={% endfor %}{% endcapture %}{{equalsigns}} {{ package.name }}
|
9
|
+
[[rc_{{ package_name }}-model_section]]
|
10
|
+
{{equalsigns}}= {{ package.name }}
|
11
|
+
|
12
|
+
{% assign before_package_key = 'before;' | append: package.name %}
|
13
|
+
{% if additional_context[before_package_key] and additional_context[before_package_key].size > 0 %}
|
14
|
+
{% for before in additional_context[before_package_key] %}
|
15
|
+
{{ before.text }}
|
16
|
+
{% endfor %}
|
17
|
+
{% endif %}
|
18
|
+
{% if additional_context.diagram_include_block %}
|
19
|
+
{% for diagram_include_block in additional_context.diagram_include_block %}
|
20
|
+
{% include "diagrams_block", package_name: package_name, image_base_path: diagram_include_block.base_path, text: diagram_include_block.text %}
|
21
|
+
{% endfor %}
|
22
|
+
{% endif %}
|
23
|
+
|
24
|
+
{% if additional_context.include_block and additional_context.include_block.size > 0 %}
|
25
|
+
{% for block in additional_context.include_block %}
|
26
|
+
{% capture block_filename %}{{ block.base_path }}{{ package_name }}{% endcapture %}
|
27
|
+
{% capture block_content %}{% include block_filename %}{% endcapture %}
|
28
|
+
{% unless block_content contains "Liquid error" %}
|
29
|
+
{% if block.text %}
|
30
|
+
{{ block.text }}
|
31
|
+
{% endif %}
|
32
|
+
{{ block_content }}
|
33
|
+
{% endunless %}
|
34
|
+
{% endfor %}
|
35
|
+
{% endif %}
|
36
|
+
|
37
|
+
{% assign include_block_package_key = 'include_block;' | append: package.name %}
|
38
|
+
{% if additional_context[include_block_package_key] and additional_context[include_block_package_key].size > 0 %}
|
39
|
+
{% for block in additional_context[include_block_package_key] %}
|
40
|
+
{% capture block_filename %}{{ block.base_path }}{{ package_name }}{% endcapture %}
|
41
|
+
{% capture block_content %}{% include block_filename %}{% endcapture %}
|
42
|
+
{% unless block_content contains "Liquid error" %}
|
43
|
+
{% if block.text %}
|
44
|
+
{{ block.text }}
|
45
|
+
{% endif %}
|
46
|
+
{{ block_content }}
|
47
|
+
{% endunless %}
|
48
|
+
{% endfor %}
|
49
|
+
{% endif %}
|
50
|
+
|
51
|
+
{{equalsigns}}= Class Definitions
|
52
|
+
{% if package.classes.size > 0 %}
|
53
|
+
.Classes used in {{ package.name }}
|
54
|
+
[cols="2a,6a",options="header"]
|
55
|
+
|===
|
56
|
+
|Class |Description
|
57
|
+
|
58
|
+
{% for klass in package.classes %}
|
59
|
+
|<<{{ klass.name }}-section,{{ klass.name }}>>
|
60
|
+
«{{ klass.stereotype }}»
|
61
|
+
|{{ klass.definition }}
|
62
|
+
|
63
|
+
{% endfor %}
|
64
|
+
|===
|
65
|
+
{% endif %}
|
66
|
+
|
67
|
+
{% if package.data_types.size > 0 %}
|
68
|
+
.Data Types used in {{ package.name }}
|
69
|
+
[cols="2,6",options="header"]
|
70
|
+
|===
|
71
|
+
|Name |Description
|
72
|
+
|
73
|
+
{% for klass in package.data_types %}
|
74
|
+
|<<{{ klass.name }}-section,{{ klass.name }}>>
|
75
|
+
|{{ klass.definition }}
|
76
|
+
|
77
|
+
{% endfor %}
|
78
|
+
|
79
|
+
|===
|
80
|
+
{% endif %}
|
81
|
+
|
82
|
+
{% if package.enums.size > 0 %}
|
83
|
+
.Enumerated Classes used in {{ package.name }}
|
84
|
+
[cols="2a,6a",options="header"]
|
85
|
+
|===
|
86
|
+
|Name |Description
|
87
|
+
|
88
|
+
{% for klass in package.enums %}
|
89
|
+
|<<{{ klass.name }}-section,{{ klass.name }}>>
|
90
|
+
|{{ klass.definition }}
|
91
|
+
|
92
|
+
{% endfor %}
|
93
|
+
|
94
|
+
|===
|
95
|
+
{% endif %}
|
96
|
+
|
97
|
+
{% assign after_package_key = 'after;' | append: package.name %}
|
98
|
+
{% if additional_context[after_package_key] %}
|
99
|
+
{{equalsigns}}= Additional Information
|
100
|
+
{% for after in additional_context[after_package_key] %}
|
101
|
+
{{ after.text }}
|
102
|
+
{% endfor %}
|
103
|
+
{% endif %}
|
104
|
+
{% if package.packages.size > 0 and render_nested_packages %}
|
105
|
+
{% assign nested_depth = depth | plus: 1 %}{% include "packages_entity_list", depth: nested_depth, context: package %}
|
106
|
+
{% endif %}
|
107
|
+
{% endfor %}
|
108
|
+
|
109
|
+
{% if additional_context.after and additional_context.after.size > 0 %}
|
110
|
+
{% for after in additional_context.after %}
|
111
|
+
{{ after.text }}
|
112
|
+
{% endfor %}
|
113
|
+
{% endif %}
|
@@ -5,6 +5,7 @@ require "asciidoctor"
|
|
5
5
|
require "asciidoctor/reader"
|
6
6
|
require "lutaml"
|
7
7
|
require "lutaml/uml"
|
8
|
+
require "lutaml/formatter"
|
8
9
|
require "metanorma/plugin/lutaml/utils"
|
9
10
|
|
10
11
|
module Metanorma
|
@@ -41,7 +42,7 @@ module Metanorma
|
|
41
42
|
|
42
43
|
# if no :imagesdir: leave image file in lutaml
|
43
44
|
def generate_file(parent, _reader, uml_document)
|
44
|
-
formatter = ::Lutaml::
|
45
|
+
formatter = ::Lutaml::Formatter::Graphviz.new
|
45
46
|
formatter.type = :png
|
46
47
|
|
47
48
|
imagesdir = if parent.document.attr("imagesdir")
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Metanorma
|
4
|
+
module Plugin
|
5
|
+
module Lutaml
|
6
|
+
class LutamlFigureInlineMacro < Asciidoctor::Extensions::InlineMacroProcessor
|
7
|
+
include LutamlDiagramBase
|
8
|
+
|
9
|
+
use_dsl
|
10
|
+
named :lutaml_figure
|
11
|
+
|
12
|
+
def process(parent, _target, attrs)
|
13
|
+
diagram_key = [attrs["package"], attrs["name"]].compact.join(":")
|
14
|
+
return if parent.document.attributes['lutaml_figure_id'].nil?
|
15
|
+
xmi_id = parent.document.attributes['lutaml_figure_id'][diagram_key]
|
16
|
+
return unless xmi_id
|
17
|
+
|
18
|
+
%Q(<xref target="figure-#{xmi_id}"></xref>)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -14,7 +14,7 @@ module Metanorma
|
|
14
14
|
# @example [lutaml_uml_attributes_table,path/to/lutaml,EntityName]
|
15
15
|
class LutamlUmlAttributesTablePreprocessor < Asciidoctor::Extensions::Preprocessor
|
16
16
|
MARCO_REGEXP =
|
17
|
-
/\[lutaml_uml_attributes_table,([^,]+),?(
|
17
|
+
/\[lutaml_uml_attributes_table,([^,]+),?([^,]+),?(.+?)?\]/
|
18
18
|
# search document for block `datamodel_attributes_table`
|
19
19
|
# read include derectives that goes after that in block and transform
|
20
20
|
# into yaml2text blocks
|
@@ -36,15 +36,16 @@ module Metanorma
|
|
36
36
|
input_lines.each_with_object([]) do |line, result|
|
37
37
|
if match = line.match(MARCO_REGEXP)
|
38
38
|
lutaml_path = match[1]
|
39
|
-
entity_name = match[
|
40
|
-
|
39
|
+
entity_name = match[2]
|
40
|
+
skip_headers = match[3]
|
41
|
+
result.push(*parse_marco(lutaml_path, entity_name, document, skip_headers))
|
41
42
|
else
|
42
43
|
result.push(line)
|
43
44
|
end
|
44
45
|
end
|
45
46
|
end
|
46
47
|
|
47
|
-
def parse_marco(lutaml_path, entity_name, document)
|
48
|
+
def parse_marco(lutaml_path, entity_name, document, skip_headers)
|
48
49
|
lutaml_document = lutaml_document_from_file(document, lutaml_path)
|
49
50
|
.serialized_document
|
50
51
|
entities = [lutaml_document["classes"], lutaml_document["enums"]]
|
@@ -53,12 +54,12 @@ module Metanorma
|
|
53
54
|
entity_definition = entities.detect do |klass|
|
54
55
|
klass["name"] == entity_name.strip
|
55
56
|
end
|
56
|
-
model_representation(entity_definition, document)
|
57
|
+
model_representation(entity_definition, document, skip_headers)
|
57
58
|
end
|
58
59
|
|
59
|
-
def model_representation(entity_definition, document)
|
60
|
+
def model_representation(entity_definition, document, skip_headers)
|
60
61
|
render_result, errors = Utils.render_liquid_string(
|
61
|
-
template_string: table_template,
|
62
|
+
template_string: table_template(skip_headers),
|
62
63
|
context_items: entity_definition,
|
63
64
|
context_name: "definition",
|
64
65
|
document: document
|
@@ -68,9 +69,9 @@ module Metanorma
|
|
68
69
|
end
|
69
70
|
|
70
71
|
# rubocop:disable Layout/IndentHeredoc
|
71
|
-
def table_template
|
72
|
+
def table_template(skip_headers)
|
72
73
|
<<~TEMPLATE
|
73
|
-
=== {{ definition.name }}
|
74
|
+
#{"=== {{ definition.name }}" unless skip_headers}
|
74
75
|
{{ definition.definition }}
|
75
76
|
|
76
77
|
{% if definition.attributes %}
|
@@ -16,11 +16,18 @@ module Metanorma
|
|
16
16
|
Asciidoctor::Extensions::Preprocessor
|
17
17
|
MARCO_REGEXP =
|
18
18
|
/\[lutaml_uml_datamodel_description,([^,]+),?(.+)?\]/
|
19
|
-
SUPPORTED_NESTED_MACROSES = %w[before after].freeze
|
20
19
|
LIQUID_INCLUDE_PATH = File.join(
|
21
20
|
Gem.loaded_specs["metanorma-plugin-lutaml"].full_gem_path,
|
22
21
|
"lib", "metanorma", "plugin", "lutaml", "liquid_templates"
|
23
22
|
)
|
23
|
+
DEFAULT_RENDER_INCLUDE = 'packages'.freeze
|
24
|
+
RENDER_STYLES_INCLUDES = {
|
25
|
+
'default' => 'packages',
|
26
|
+
'entity_list' => 'packages_entity_list',
|
27
|
+
'data_dictionary' => 'packages_data_dictionary'
|
28
|
+
}.freeze
|
29
|
+
SUPPORTED_NESTED_MACRO = %w[
|
30
|
+
before diagram_include_block after include_block].freeze
|
24
31
|
# search document for block `lutaml_uml_datamodel_description`
|
25
32
|
# read include derectives that goes after that in block and transform
|
26
33
|
# into yaml2text blocks
|
@@ -58,35 +65,63 @@ module Metanorma
|
|
58
65
|
block_match = line.match(MARCO_REGEXP)
|
59
66
|
return [line] if block_match.nil?
|
60
67
|
|
68
|
+
lutaml_document = lutaml_document_from_file(document, block_match[1])
|
69
|
+
fill_in_diagrams_attributes(document, lutaml_document)
|
61
70
|
model_representation(
|
62
|
-
|
71
|
+
lutaml_document,
|
63
72
|
document,
|
64
73
|
collect_additional_context(input_lines, input_lines.next),
|
65
74
|
parse_yaml_config_file(document, block_match[2]))
|
66
75
|
end
|
67
76
|
|
77
|
+
def fill_in_diagrams_attributes(document, lutaml_document_wrapper)
|
78
|
+
lutaml_document = lutaml_document_wrapper.original_document
|
79
|
+
package_flat_diagrams = lambda do |pks|
|
80
|
+
pks.each_with_object({}) do |package, res|
|
81
|
+
package.diagrams.map { |diag| res["#{package.name}:#{diag.name}"] = diag.xmi_id }
|
82
|
+
end
|
83
|
+
end
|
84
|
+
children_pks_daigs = package_flat_diagrams.call(lutaml_document.packages.map(&:children_packages).flatten)
|
85
|
+
document.attributes['lutaml_figure_id'] = package_flat_diagrams.call(lutaml_document.packages)
|
86
|
+
.merge(children_pks_daigs)
|
87
|
+
end
|
88
|
+
|
68
89
|
def collect_additional_context(input_lines, end_mark)
|
69
|
-
additional_context = {}
|
90
|
+
additional_context = Hash.new { |hash, key| hash[key] = [] }
|
91
|
+
block_lines = []
|
70
92
|
while (block_line = input_lines.next) != end_mark
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
end
|
93
|
+
block_lines.push(block_line)
|
94
|
+
end
|
95
|
+
block_document = (Asciidoctor::Document.new(block_lines, {})).parse
|
96
|
+
block_document.blocks.each do |block|
|
97
|
+
next unless SUPPORTED_NESTED_MACRO.include?(block.attributes['role'])
|
98
|
+
|
99
|
+
attrs = block.attributes
|
100
|
+
name = attrs.delete('role')
|
101
|
+
package = attrs.delete('package')
|
102
|
+
macro_keyword = [name, package].compact.join(";")
|
103
|
+
block_text = block.lines.length > 0 ? block.lines[1..-2].join("\n") : ''
|
104
|
+
additional_context[macro_keyword].push({ 'text' => block_text }.merge(attrs))
|
84
105
|
end
|
85
106
|
additional_context
|
86
107
|
end
|
87
108
|
|
109
|
+
def package_level(lutaml_document, level)
|
110
|
+
return lutaml_document if level <= 0
|
111
|
+
|
112
|
+
package_level(lutaml_document['packages'].first, level - 1)
|
113
|
+
end
|
114
|
+
|
88
115
|
def create_context_object(lutaml_document, additional_context, options)
|
89
|
-
root_package = lutaml_document.to_liquid['
|
116
|
+
root_package = package_level(lutaml_document.to_liquid, options['package_root_level'] || 1)
|
117
|
+
if options.length.zero? || options['packages'].nil?
|
118
|
+
return {
|
119
|
+
'render_nested_packages' => true,
|
120
|
+
"packages" => root_package['packages'],
|
121
|
+
"additional_context" => additional_context
|
122
|
+
}
|
123
|
+
end
|
124
|
+
|
90
125
|
all_packages = [root_package, *root_package['children_packages']]
|
91
126
|
{
|
92
127
|
"packages" => sort_and_filter_out_packages(all_packages, options),
|
@@ -129,7 +164,7 @@ module Metanorma
|
|
129
164
|
|
130
165
|
def model_representation(lutaml_document, document, additional_context, options)
|
131
166
|
render_result, errors = Utils.render_liquid_string(
|
132
|
-
template_string: table_template,
|
167
|
+
template_string: table_template(options['section_depth'] || 2, options['render_style']),
|
133
168
|
context_items: create_context_object(lutaml_document,
|
134
169
|
additional_context,
|
135
170
|
options),
|
@@ -141,9 +176,10 @@ module Metanorma
|
|
141
176
|
render_result.split("\n")
|
142
177
|
end
|
143
178
|
|
144
|
-
def table_template
|
179
|
+
def table_template(section_depth, render_style)
|
180
|
+
include_name = RENDER_STYLES_INCLUDES.fetch(render_style, DEFAULT_RENDER_INCLUDE)
|
145
181
|
<<~LIQUID
|
146
|
-
{% include "
|
182
|
+
{% include "#{include_name}", depth: #{section_depth}, context: context, additional_context: context.additional_context, render_nested_packages: context.render_nested_packages %}
|
147
183
|
LIQUID
|
148
184
|
end
|
149
185
|
end
|
@@ -1,5 +1,6 @@
|
|
1
1
|
require "expressir/express/cache"
|
2
2
|
require "metanorma/plugin/lutaml/liquid/custom_filters"
|
3
|
+
require "metanorma/plugin/lutaml/liquid/multiply_local_file_system"
|
3
4
|
|
4
5
|
::Liquid::Template.register_filter(Metanorma::Plugin::Lutaml::Liquid::CustomFilters)
|
5
6
|
|
@@ -25,8 +26,8 @@ module Metanorma
|
|
25
26
|
context_name:, document:, include_path: nil)
|
26
27
|
liquid_template = ::Liquid::Template.parse(template_string)
|
27
28
|
# Allow includes for the template
|
28
|
-
|
29
|
-
liquid_template.registers[:file_system] = ::Liquid::LocalFileSystem.new(
|
29
|
+
include_paths = [Utils.relative_file_path(document, ""), include_path].compact
|
30
|
+
liquid_template.registers[:file_system] = ::Metanorma::Plugin::Lutaml::Liquid::LocalFileSystem.new(include_paths, ["_%s.liquid", "_%s.adoc"])
|
30
31
|
rendered_string = liquid_template
|
31
32
|
.render(context_name => context_items,
|
32
33
|
strict_variables: true,
|
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.4.
|
4
|
+
version: 0.4.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ribose Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-08-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: liquid
|
@@ -257,13 +257,19 @@ files:
|
|
257
257
|
- lib/metanorma-plugin-lutaml.rb
|
258
258
|
- lib/metanorma/plugin/lutaml/express_remarks_decorator.rb
|
259
259
|
- lib/metanorma/plugin/lutaml/liquid/custom_filters.rb
|
260
|
+
- lib/metanorma/plugin/lutaml/liquid/multiply_local_file_system.rb
|
261
|
+
- lib/metanorma/plugin/lutaml/liquid_templates/_diagrams_block.liquid
|
260
262
|
- lib/metanorma/plugin/lutaml/liquid_templates/_packages.liquid
|
261
263
|
- lib/metanorma/plugin/lutaml/liquid_templates/_packages_class.liquid
|
264
|
+
- lib/metanorma/plugin/lutaml/liquid_templates/_packages_data_dictionary.liquid
|
265
|
+
- lib/metanorma/plugin/lutaml/liquid_templates/_packages_data_dictionary_classes.liquid
|
262
266
|
- lib/metanorma/plugin/lutaml/liquid_templates/_packages_data_type.liquid
|
267
|
+
- lib/metanorma/plugin/lutaml/liquid_templates/_packages_entity_list.liquid
|
263
268
|
- lib/metanorma/plugin/lutaml/liquid_templates/_packages_enum.liquid
|
264
269
|
- lib/metanorma/plugin/lutaml/lutaml_diagram_base.rb
|
265
270
|
- lib/metanorma/plugin/lutaml/lutaml_diagram_block.rb
|
266
271
|
- lib/metanorma/plugin/lutaml/lutaml_diagram_block_macro.rb
|
272
|
+
- lib/metanorma/plugin/lutaml/lutaml_figure_inline_macro.rb
|
267
273
|
- lib/metanorma/plugin/lutaml/lutaml_preprocessor.rb
|
268
274
|
- lib/metanorma/plugin/lutaml/lutaml_uml_attributes_table_preprocessor.rb
|
269
275
|
- lib/metanorma/plugin/lutaml/lutaml_uml_datamodel_description_preprocessor.rb
|