metanorma-plugin-lutaml 0.4.9 → 0.4.10

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7be44107e7c1d3c9a4471ead7d39630d49cdced1e3996b6bea8b3c64be4fd03f
4
- data.tar.gz: b99ff8fa3069c0fb0f983de14a984c06db12ecc595e0b876ed83e83926c6eeba
3
+ metadata.gz: 241b12b07d457ea48176e22ce2cacc4a533c2ffc5435465637d51d37d6da1e80
4
+ data.tar.gz: 2a2bd1fe63f4febdae9ce40679f525cfe476f2a773ab15c5de9622145dbdbd7f
5
5
  SHA512:
6
- metadata.gz: 2e6d79ef550cecde85e2e0d49717259f6e9016ef7e3935fdb938d13173361daf404e586a1d1319b05a1ab4a393213086625399d5d3e1090a4afd902c0bfc3f82
7
- data.tar.gz: 454fe356b82f983a2a4ed9b2a1fa81de19ea8dcb6ac0c10243f1afc8db8e2eed8b8600658c7f0e37040224401dae077a0f93e433227b31c9dd63c7119c59db5f
6
+ metadata.gz: 33ef546ecbc2929104ccda434021ef50afbd067d5f466b7d07181aea92415a15aaad67fdf3848b4bd0cf93878e032b007b437a630b1d5ea87398396b446b622f
7
+ data.tar.gz: 7373d126f78af6063dbfea6076018712f4185a6c0e75e50309befc23bf1e34beeec86ab80d8b36f9c73eb7e5ae238b0522e85ec307ee434538222790cc05d8c3
data/README.adoc CHANGED
@@ -28,7 +28,7 @@ LutaML supports accessing EXPRESS models via the
28
28
  https://github.com/lutaml/expressir[Expressir] parser.
29
29
 
30
30
 
31
- === Usage of the `lutaml_express` EXPRESS macro
31
+ === Usage of the `lutaml` macro
32
32
 
33
33
  Given an `example.exp` EXPRESS file with the content:
34
34
 
@@ -57,11 +57,11 @@ SCHEMA test_schema 'test';
57
57
  END_SCHEMA;
58
58
  ----
59
59
 
60
- And the `lutaml_express` macro block:
60
+ And the `lutaml` macro block:
61
61
 
62
62
  [source,adoc]
63
63
  -----
64
- [lutaml_express,example.exp,my_context]
64
+ [lutaml,example.exp,my_context]
65
65
  ----
66
66
 
67
67
  {% for schema in my_context.schemas %}
@@ -82,7 +82,7 @@ Where:
82
82
  * `{example.exp}` is the location of the EXPRESS schema file (`*.exp`) that
83
83
  contains data to be loaded. Location of the file is computed relative to the
84
84
  source directory that `[lutaml]` is used (e.g., if
85
- `[lutaml_express,example.exp,my_context]` is invoked in an `.adoc` file located at
85
+ `[lutaml,example.exp,my_context]` is invoked in an `.adoc` file located at
86
86
  `/foo/bar/doc.adoc`, the data file is expected to be found at
87
87
  `/foo/bar/example.exp`);
88
88
 
@@ -97,8 +97,7 @@ https://github.com/lutaml/expressir/blob/master/lib/expressir/model/schema.rb[sc
97
97
 
98
98
  Will produce this output:
99
99
 
100
- [source,adoc]
101
- -----
100
+ ____
102
101
  == test_schema
103
102
 
104
103
  === my_type1
@@ -106,9 +105,9 @@ Will produce this output:
106
105
  === my_type3
107
106
  === my_type4
108
107
  === my_type5
109
- -----
108
+ ____
110
109
 
111
- This macro also supports `.lutaml` files.
110
+ This command also supports `.lutaml` files.
112
111
 
113
112
  Instead of using the direct path to the file one can use `lutaml-express-index`
114
113
  document attribute to supply directory with express files or YAML index file to
@@ -137,19 +136,22 @@ Example of usage:
137
136
  -----
138
137
  = Document title
139
138
  Author
140
- :lutaml-express-index: my_custom_name; /path/to/express_files; cache=/path/to/cache_file.yaml
141
- [lutaml_express,my_custom_name,my_context]
139
+ :lutaml-express-index: index_name; /path/to/express_files; cache=/path/to/cache_file.yaml
140
+ [lutaml,index_name,context]
142
141
  ----
143
- {% for schema in my_context.schemas %}
142
+ {% for schema in context.schemas %}
144
143
  == {{schema.id}}
145
144
  {% endfor %}
146
145
  ----
147
146
  -----
148
147
 
149
- === Usage, `lutaml_diagram` macro
148
+ == Usage with UML
150
149
 
151
- This macro allows to quickly render lutaml file as diagram image.
152
- Given `example.lutaml` file with the content:
150
+ === Rendering a LutaML view: `lutaml_diagram`
151
+
152
+ This command allows to quickly render a LutaML view as an image file.
153
+
154
+ Given a file `example.lutaml` file with content:
153
155
 
154
156
  [source,java]
155
157
  ----
@@ -173,16 +175,17 @@ diagram MyView {
173
175
  }
174
176
  ----
175
177
 
176
- And the `lutaml_diagram` macro:
178
+ The `lutaml_diagram` command will add the image to the document.
177
179
 
178
180
  [source,adoc]
179
181
  -----
180
182
  lutaml_diagram::example.lutaml[]
181
183
  -----
182
184
 
183
- Will add diagram image to the document
185
+ The `lutaml_diagram` command can also be used to denote a block with an embedded
186
+ LutaML view.
184
187
 
185
- Also one can use `lutaml_diagram` block with embed lutaml code instead of block macro. Example:
188
+ For example:
186
189
 
187
190
  [source,java]
188
191
  ----
@@ -193,9 +196,9 @@ diagram MyView {
193
196
 
194
197
  enum AddressClassProfile {
195
198
  imlicistAttributeProfile: CharacterString [0..1] {
196
- definition
197
- this is multiline with `ascidoc`
198
- end definition
199
+ definition {
200
+ This is multiline AsciiDoc content.
201
+ }
199
202
  }
200
203
  }
201
204
 
@@ -210,9 +213,9 @@ diagram MyView {
210
213
  ----
211
214
 
212
215
 
213
- === Usage of `lutaml_uml_attributes_table` macro
216
+ === `lutaml_uml_attributes_table`
214
217
 
215
- This macro allows to quickly render data model attributes/values tables.
218
+ This command allows rendering definition tables for a UML model.
216
219
 
217
220
  Given `example.lutaml` file with the content:
218
221
 
@@ -247,21 +250,20 @@ And the `lutaml_uml_attributes_table` macro:
247
250
 
248
251
  Will produce this output:
249
252
 
250
- [source,adoc]
251
- -----
253
+ ____
252
254
  === AttributeProfile
253
255
 
254
-
255
256
  .AttributeProfile attributes
256
257
  |===
257
258
  |Name |Definition |Mandatory/ Optional/ Conditional |Max Occur |Data Type
258
259
 
259
- |addressClassProfile |TODO: enum 's definition |M |1 | `CharacterString`
260
+ |addressClassProfile |TODO: enum's definition |M |1 | `CharacterString`
260
261
 
261
262
  |imlicistAttributeProfile |this is attribute definition with multiply lines |M |1 | `CharacterString`
262
263
 
263
264
  |===
264
- -----
265
+ ____
266
+
265
267
 
266
268
  In case of "enumeration" (AddressClassProfile) entity:
267
269
 
@@ -272,11 +274,9 @@ In case of "enumeration" (AddressClassProfile) entity:
272
274
 
273
275
  Will produce this output:
274
276
 
275
- [source,adoc]
276
- -----
277
+ ____
277
278
  === AddressClassProfile
278
279
 
279
-
280
280
  .AddressClassProfile values
281
281
  |===
282
282
  |Name |Definition
@@ -284,11 +284,11 @@ Will produce this output:
284
284
  |imlicistAttributeProfile |this is multiline with `asciidoc`
285
285
 
286
286
  |===
287
- -----
287
+ ____
288
288
 
289
289
  === Usage of `lutaml_uml_datamodel_description` macro
290
290
 
291
- This macro allows to quickly render data model packages and its dependent
291
+ This command allows to quickly render data model packages and its dependent
292
292
  objects for supplied XMI file.
293
293
 
294
294
  Given an Enterprise Architect `example.xmi` file with 2 packages:
@@ -349,13 +349,19 @@ Where:
349
349
 
350
350
  * `path/to/example.xmi` - required, path to the XMI file to render
351
351
 
352
- * `[.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 `....`)
352
+ * `[.before]` - block text that adds 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 `....`)
353
353
 
354
- * `[.after]` - macro to add additional text after the rendered output, can be used only once, additional occurrences of macro will overwrite text
354
+ * `[.after]` - block text that adds additional text after the rendered output, can be used only once, additional occurrences of macro will overwrite text
355
355
 
356
- * `[.after, package="Another"]` - macro with text to be inserted before(after in case of `.before` name) the package
356
+ * `[.after, package="Another"]` - block text to be inserted before(after in case of `.before` name) the package
357
357
 
358
- * `[.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 diagram image. `format` is an optional attribute that tells what file extension to use when including diagram file. The logic is as follows:
358
+ * `[.package_text, position="after", package="Another"]` - include custom adoc code into package rendered body, `position` is a arequired attribute which tells where to insert the code.
359
+
360
+ * `[.package_text, package="Another"]` - same as above, but include block will be included only for supplied package name
361
+
362
+ * `[.diagram_include_block]` - block text to automatically include diagram images. Attribute `base_path` is a required attribute to supply path prefix where to look for a diagram image. `format` is an optional attribute that tells what file extension to use when including diagram file.
363
+ +
364
+ The logic is as follows:
359
365
  [source,adoc]
360
366
  -----
361
367
  {% for diagram in package.diagrams %}
@@ -377,15 +383,30 @@ For instance, the script will take package diagrams supplied in the XMI file and
377
383
 
378
384
  * `[.include_block, package="Another", base_path="spec/fixtures"]` - same as above, but include block will be included only for supplied package name
379
385
 
380
- 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:
386
+
387
+ NOTE: .after, .before, package_text and include_block macroses all can be used with additional option - `liquid`, if this option is supplied then the code inside block will be interpolated in liquid context
388
+
389
+
390
+ There are two other commands that are used to refer to LutaML generated document elements:
391
+
392
+ * `lutaml_figure`. Provides a reference anchor to a figure defined in the XMI
393
+ file, using its XMI ID for reference.
394
+
395
+ * `lutaml_table`. Provides a reference anchor to the definition tables of a
396
+ particular package, class, enumeration or data type object in the XMI.
397
+
398
+ The syntax is as follows:
381
399
 
382
400
  [source,adoc]
383
401
  -----
402
+ // For lutaml_figure
384
403
  This is lutaml_figure::[package="Wrapper root package", name="Fig B1 Full model"] figure
404
+
405
+ // For lutaml_table
385
406
  This is lutaml_table::[package="Wrapper root package"] package
386
407
  This is lutaml_table::[package="Wrapper root package", class="my name"] class
387
- This is lutaml_table::[package="Wrapper root package", enum="my name"] enum
388
- This is lutaml_table::[package="Wrapper root package", data_type="my name"] data_type
408
+ This is lutaml_table::[package="Wrapper root package", enum="my name"] enumeration
409
+ This is lutaml_table::[package="Wrapper root package", data_type="my name"] data type
389
410
  -----
390
411
 
391
412
  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.
@@ -466,13 +487,20 @@ h|Constraints: 7+| (none)
466
487
  text after CityGML package
467
488
  -----
468
489
 
469
- In addition to just supplying an XMI file, this macro also supports a YAML
470
- configuration file.
490
+ In addition to the XMI file, this macro also supports a YAML configuration file
491
+ that specifies:
492
+
493
+ * What packages to include in the render;
471
494
 
472
- The format for using YAML is this:
495
+ * What render style is desired;
496
+
497
+ * Location of the root package (which package should the iterative process start
498
+ at).
499
+
500
+ The format for using the YAML configuration file:
473
501
 
474
502
  [source,yaml]
475
- -----
503
+ ----
476
504
  ---
477
505
  packages:
478
506
  # includes these packages
@@ -481,21 +509,49 @@ packages:
481
509
  - three
482
510
  # skips these packages
483
511
  - skip: four
484
- render_style: entity_list|data_dictionary|default
512
+ render_style: entity_list | data_dictionary | default
485
513
  section_depth: 2
486
- -----
514
+ ----
487
515
 
488
516
  Where:
489
517
 
490
518
  * `packages` - required, root element with the list of strings or objects
519
+
491
520
  * `Package *` - pattern matching, specifies lookup condition for packages to
492
521
  render.
493
522
  +
494
523
  NOTE: In this example, it is equal to the following regular expression: `/^Package.*$/`
495
524
 
496
525
  * `skip: four` - object with package name to skip
497
- * `render_style` - what template to use to render packages, can be: entity_list, data_dictionary or default
498
- * `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`
526
+
527
+ * `render_style` - what template to use to render packages, can be one of:
528
+
529
+ ** `entity_list`
530
+
531
+ ** `data_dictionary`; or
532
+
533
+ ** `default`
534
+
535
+ * `section_depth` - what package to use as root package for render.
536
+ e.g., a `section_depth` equal to `2` tells the processor to use the first
537
+ nested package of the first root packages in XMI file.
538
+ +
539
+ EXAMPLE: If the XMI file has this package structure, and we have `section_depth`
540
+ equal to 2, root package will be `one-1`.
541
+ +
542
+ [source,json]
543
+ ----
544
+ [
545
+ {
546
+ name: 'One',
547
+ packages: [{ name: 'one-1' }, { name: 'one-2' }]
548
+ },
549
+ {
550
+ name: 'Two',
551
+ packages: [{ name: 'two-1' }, { name: 'two-2' }]
552
+ }
553
+ ]
554
+ ----
499
555
 
500
556
  Usage with macro:
501
557
 
@@ -509,10 +565,11 @@ Usage with macro:
509
565
  ----
510
566
  --
511
567
 
512
- The macro processor will read supplied YAML file and arrange packages according
513
- to the order supplied in the config file, also all packages supplied as `skip`
514
- will be skipped during render
568
+ The processor will read the supplied YAML config file (`path/to/config.yml`),
569
+ and iterate through packages according to the order supplied in the file. All
570
+ packages that matches `skip` in the YAML config file will be skipped during
571
+ render.
515
572
 
516
573
  == Documentation
517
574
 
518
- Please refer to https://www.metanorma.com.
575
+ Please refer to https://www.metanorma.oeg.
@@ -8,6 +8,15 @@ module Metanorma
8
8
  def html2adoc(input)
9
9
  ReverseAdoc.convert(input)
10
10
  end
11
+
12
+ def interpolate(input)
13
+ sub = ::Liquid::Template.parse(input)
14
+ sub.render(@context)
15
+ end
16
+
17
+ def identify(input)
18
+ input.split(/(?=[A-Z])/).map(&:downcase).join('-')
19
+ end
11
20
  end
12
21
  end
13
22
  end
@@ -2,7 +2,14 @@
2
2
  {% assign package_name = package.name | downcase | replace: ":", "" | replace: " ", "_" %}
3
3
  {% if additional_context.before and additional_context.before.size > 0 %}
4
4
  {% for before in additional_context.before %}
5
+ {% if before.text %}
6
+
7
+ {% if before.liquid %}
8
+ {{ before.text | interpolate }}
9
+ {% else %}
5
10
  {{ before.text }}
11
+ {% endif %}
12
+ {% endif %}
6
13
  {% endfor %}
7
14
  {% endif %}
8
15
  {% assign is_package_spare = package.name | slice: 0,5 %}
@@ -14,10 +21,52 @@
14
21
  [[section-{{ package.xmi_id }}]]
15
22
  {{equalsigns}}= {{ package.name }} overview
16
23
 
24
+ {% if additional_context.all_macros.size > 0 %}
25
+ {% assign sorted_all_macros = additional_context.all_macros | where: "position", "before" | sort: 'index' %}
26
+ {% for block in sorted_all_macros %}
27
+ {% case block.type %}
28
+ {% when 'include_block' %}
29
+ {% unless block.package and block.package != package.name %}
30
+ {% capture block_filename %}{{ block.base_path }}{{ package_name }}{% endcapture %}
31
+ {% capture block_content %}{% include block_filename %}{% endcapture %}
32
+ {% unless block_content contains "Liquid error" %}
33
+ {% if block.text %}
34
+
35
+ {% if block.liquid %}
36
+ {{ block.text | interpolate }}
37
+ {% else %}
38
+ {{ block.text }}
39
+ {% endif %}
40
+ {% endif %}
41
+
42
+ {{ block_content }}
43
+ {% endunless %}
44
+ {% endunless %}
45
+ {% when 'package_text' %}
46
+ {% unless block.package and block.package != package.name %}
47
+
48
+ {% if block.liquid %}
49
+ {{ block.text | interpolate }}
50
+ {% else %}
51
+ {{ block.text }}
52
+ {% endif %}
53
+ {% endunless %}
54
+ {% else %}
55
+ {% endcase %}
56
+ {% endfor %}
57
+ {% endif %}
58
+
17
59
  {% assign before_package_key = 'before;' | append: package.name %}
18
60
  {% if additional_context[before_package_key] and additional_context[before_package_key].size > 0 %}
19
61
  {% for before in additional_context[before_package_key] %}
62
+ {% if before.text %}
63
+
64
+ {% if before.liquid %}
65
+ {{ before.text | interpolate }}
66
+ {% else %}
20
67
  {{ before.text }}
68
+ {% endif %}
69
+ {% endif %}
21
70
  {% endfor %}
22
71
  {% endif %}
23
72
  {% if additional_context.diagram_include_block %}
@@ -51,7 +100,8 @@
51
100
  {% elsif is_klass_spare == 'Spare' %}{% continue %}
52
101
  {% endif %}
53
102
  {% assign klass_name = klass.name | downcase | replace: ':', '' | replace: ' ', '_' %}
54
- .<<section-{{ klass.xmi_id }}>> -- &#8220;Elements of {{ package.name }}::{{ klass.name }}&#8221; (class)
103
+ [[section-{{ klass.xmi_id }}]]
104
+ .Elements of &#8220;{{ package.name }}::{{ klass.name }}&#8221; ({{ klass.stereotype }})
55
105
 
56
106
  {% endfor %}
57
107
  {% for enum in package.enums %}
@@ -60,7 +110,8 @@
60
110
  {% elsif is_enum_spare == 'Spare' %}{% continue %}
61
111
  {% endif %}
62
112
  {% assign enum_name = enum.name | downcase | replace: ':', '' | replace: ' ', '_' %}
63
- .<<section-{{ enum.xmi_id }}>> -- &#8220;Elements of {{ package.name }}::{{ enum.name }}&#8221; (enum)
113
+ [[section-{{ enum.xmi_id }}]]
114
+ .Elements of &#8220;{{ package.name }}::{{ enum.name }}&#8221; ({{ enum.stereotype }})
64
115
 
65
116
  {% endfor %}
66
117
  {% for data_type in package.data_types %}
@@ -69,7 +120,8 @@
69
120
  {% elsif is_data_type_spare == 'Spare' %}{% continue %}
70
121
  {% endif %}
71
122
  {% assign data_type_name = data_type.name | downcase | replace: ':', '' | replace: ' ', '_' %}
72
- .<<section-{{ data_type.xmi_id }}>> -- &#8220;Elements of {{ package.name }}::{{ data_type.name }}&#8221; (data_type)
123
+ [[section-{{ data_type.xmi_id }}]]
124
+ .Elements of &#8220;{{ package.name }}::{{ data_type.name }}&#8221; ({{ data_type.stereotype }})
73
125
 
74
126
  {% endfor %}
75
127
 
@@ -107,18 +159,65 @@
107
159
  {% capture block_content %}{% include block_filename %}{% endcapture %}
108
160
  {% unless block_content contains "Liquid error" %}
109
161
  {% if block.text %}
162
+
163
+ {% if block.liquid %}
164
+ {{ block.text | interpolate }}
165
+ {% else %}
110
166
  {{ block.text }}
111
167
  {% endif %}
168
+ {% endif %}
112
169
  {{ block_content }}
113
170
  {% endunless %}
114
171
  {% endfor %}
115
172
  {% endif %}
116
173
 
174
+ {% if additional_context.all_macros.size > 0 %}
175
+ {% assign sorted_all_macros = additional_context.all_macros | where: "position", "after" | sort: 'index' %}
176
+ {% for block in sorted_all_macros %}
177
+ {% case block.type %}
178
+ {% when 'include_block' %}
179
+ {% unless block.package and block.package != package.name %}
180
+ {% capture block_filename %}{{ block.base_path }}{{ package_name }}{% endcapture %}
181
+ {% capture block_content %}{% include block_filename %}{% endcapture %}
182
+ {% unless block_content contains "Liquid error" %}
183
+ {% if block.text %}
184
+
185
+ {% if block.liquid %}
186
+ {{ block.text | interpolate }}
187
+ {% else %}
188
+ {{ block.text }}
189
+ {% endif %}
190
+ {% endif %}
191
+
192
+ {{ block_content }}
193
+ {% endunless %}
194
+ {% endunless %}
195
+ {% when 'package_text' %}
196
+ {% unless block.package and block.package != package.name %}
197
+
198
+ {% if block.liquid %}
199
+ {{ block.text | interpolate }}
200
+ {% else %}
201
+ {{ block.text }}
202
+ {% endif %}
203
+ {% endunless %}
204
+ {% else %}
205
+ {% endcase %}
206
+ {% endfor %}
207
+ {% endif %}
208
+
117
209
  {% assign after_package_key = 'after;' | append: package.name %}
118
210
  {% if additional_context[after_package_key] %}
119
211
  {{equalsigns}}= Additional information
120
212
  {% for after in additional_context[after_package_key] %}
213
+ {% if after.text %}
214
+
215
+ {% if after.liquid %}
216
+ {{ after.text | interpolate }}
217
+ {% else %}
121
218
  {{ after.text }}
219
+ {% endif %}
220
+ {% endif %}
122
221
  {% endfor %}
123
222
  {% endif %}
124
223
  {% if package.packages.size > 0 and render_nested_packages %}
@@ -128,6 +227,13 @@
128
227
 
129
228
  {% if additional_context.after and additional_context.after.size > 0 %}
130
229
  {% for after in additional_context.after %}
230
+ {% if after.text %}
231
+
232
+ {% if after.liquid %}
233
+ {{ after.text | interpolate }}
234
+ {% else %}
131
235
  {{ after.text }}
236
+ {% endif %}
237
+ {% endif %}
132
238
  {% endfor %}
133
239
  {% endif %}