metanorma-plugin-lutaml 0.7.30 → 0.7.31

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.
Files changed (38) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +10 -8
  3. data/README.adoc +16 -1030
  4. data/docs/usages/enterprise_architect.adoc +583 -0
  5. data/docs/usages/express.adoc +299 -0
  6. data/docs/usages/json_yaml.adoc +1034 -0
  7. data/docs/usages/lutaml-gml.adoc +73 -0
  8. data/docs/usages/lutaml-uml.adoc +73 -0
  9. data/lib/metanorma/plugin/lutaml/asciidoctor/preprocessor.rb +1 -1
  10. data/lib/metanorma/plugin/lutaml/base_structured_text_preprocessor.rb +192 -0
  11. data/lib/metanorma/plugin/lutaml/content.rb +89 -0
  12. data/lib/metanorma/plugin/lutaml/data2_text_preprocessor.rb +45 -0
  13. data/lib/metanorma/plugin/lutaml/express_remarks_decorator.rb +19 -6
  14. data/lib/metanorma/plugin/lutaml/json2_text_preprocessor.rb +43 -0
  15. data/lib/metanorma/plugin/lutaml/liquid/custom_blocks/key_iterator.rb +31 -0
  16. data/lib/metanorma/plugin/lutaml/liquid/custom_filters/loadfile.rb +18 -0
  17. data/lib/metanorma/plugin/lutaml/liquid/custom_filters/replace_regex.rb +14 -0
  18. data/lib/metanorma/plugin/lutaml/liquid/custom_filters/values.rb +13 -0
  19. data/lib/metanorma/plugin/lutaml/liquid/multiply_local_file_system.rb +29 -22
  20. data/lib/metanorma/plugin/lutaml/liquid_drops/gml_dictionary_drop.rb +1 -1
  21. data/lib/metanorma/plugin/lutaml/lutaml_diagram_base.rb +1 -1
  22. data/lib/metanorma/plugin/lutaml/lutaml_diagram_block_macro.rb +2 -1
  23. data/lib/metanorma/plugin/lutaml/lutaml_ea_diagram_block_macro.rb +2 -1
  24. data/lib/metanorma/plugin/lutaml/lutaml_ea_xmi_base.rb +48 -36
  25. data/lib/metanorma/plugin/lutaml/lutaml_figure_inline_macro.rb +2 -1
  26. data/lib/metanorma/plugin/lutaml/lutaml_gml_dictionary_block_macro.rb +3 -1
  27. data/lib/metanorma/plugin/lutaml/lutaml_klass_table_block_macro.rb +2 -1
  28. data/lib/metanorma/plugin/lutaml/lutaml_preprocessor.rb +15 -2
  29. data/lib/metanorma/plugin/lutaml/lutaml_table_inline_macro.rb +2 -1
  30. data/lib/metanorma/plugin/lutaml/source_extractor.rb +97 -0
  31. data/lib/metanorma/plugin/lutaml/utils.rb +59 -26
  32. data/lib/metanorma/plugin/lutaml/version.rb +1 -1
  33. data/lib/metanorma/plugin/lutaml/yaml2_text_preprocessor.rb +41 -0
  34. data/lib/metanorma-plugin-lutaml.rb +3 -0
  35. data/metanorma-plugin-lutaml.gemspec +7 -1
  36. metadata +35 -6
  37. data/lib/metanorma/plugin/lutaml/liquid_templates/test.rb +0 -1
  38. /data/lib/metanorma/plugin/lutaml/liquid/{custom_filters.rb → custom_filters/html2adoc.rb} +0 -0
@@ -0,0 +1,299 @@
1
+
2
+ == Usage with EXPRESS
3
+
4
+ === General
5
+
6
+ The LutaML plugin supports working with EXPRESS schema files to render EXPRESS
7
+ models and definitions.
8
+
9
+ LutaML supports accessing EXPRESS models via the
10
+ https://github.com/lutaml/expressir[Expressir] parser.
11
+
12
+
13
+ === Document attribute `:lutaml-express-index:`
14
+
15
+ This attribute allows specifying one or more EXPRESS files to defined names
16
+ for later use with `lutaml_express` command.
17
+
18
+ Syntax:
19
+
20
+ [source,adoc]
21
+ ----
22
+ :lutaml-express-index: shortname_of_index; name_of_schemas_listing_file.yml;
23
+ ----
24
+
25
+ Where:
26
+
27
+ `shortname_of_index`:: is name of the parsed EXPRESS files context for the later
28
+ use.
29
+
30
+ `name_of_schemas_listing_file.yml`:: location of the YAML index file to parse
31
+ all EXPRESS files listed within.
32
+
33
+
34
+ [example]
35
+ .Define an index in the document and use it in the `lutaml_express` command
36
+ ====
37
+ [source,adoc]
38
+ -----
39
+ :lutaml-express-index: my_custom_name; /path/to/schemas.yml
40
+
41
+ [lutaml_express,my_custom_name,context]
42
+ ----
43
+ {% for schema in context.schemas %}
44
+ == {{schema.id}}
45
+
46
+ {% for entity in schema.entities %}
47
+ === {{entity.id}}
48
+ {% endfor %}
49
+
50
+ {% endfor %}
51
+ -----
52
+
53
+ Where the `schemas.yml` file contains:
54
+
55
+ [source,yaml]
56
+ ----
57
+ ---
58
+ schemas:
59
+ action_schema:
60
+ path: "../../schemas/resources/action_schema/action_schema.exp"
61
+ application_context_schema:
62
+ path: "../../schemas/resources/application_context_schema/application_context_schema.exp"
63
+ ----
64
+ ====
65
+
66
+
67
+ === Schemas listing file
68
+
69
+ The schemas listing file is a YAML file that lists all EXPRESS files to be
70
+ parsed. The file should have the following structure:
71
+
72
+ [source,yaml]
73
+ ----
74
+ ---
75
+ schemas:
76
+ schema_name:
77
+ path: path/to/schema_file.exp
78
+ schema_name_2:
79
+ path: path/to/schema_file_2.exp
80
+ ----
81
+
82
+ Where:
83
+
84
+ `schema_name`:: is the name of the EXPRESS schema.
85
+
86
+ `path`:: (optional) path to the EXPRESS schema file. When the path is not
87
+ specified, the command will look for the schema file in the directory where the
88
+ YAML file is located using the filename pattern `{schema_name}.exp`. The path
89
+ can be relative to the YAML file or an absolute path.
90
+
91
+
92
+ === Usage of the `lutaml_express` command
93
+
94
+ Given an `example.exp` EXPRESS file with content:
95
+
96
+ [source,exp]
97
+ ----
98
+ SCHEMA test_schema 'test';
99
+
100
+ (* Need select elements for measure_value *)
101
+ REFERENCE FROM measure_schema
102
+ (measure_value);
103
+
104
+ TYPE my_type1 = EXTENSIBLE SELECT;
105
+ END_TYPE;
106
+
107
+ TYPE my_type2 = EXTENSIBLE ENUMERATION;
108
+ END_TYPE;
109
+
110
+ TYPE my_type3 = EXTENSIBLE ENUMERATION;
111
+ END_TYPE;
112
+
113
+ TYPE my_type4 = EXTENSIBLE ENUMERATION;
114
+ END_TYPE;
115
+
116
+ TYPE my_type5 = EXTENSIBLE ENUMERATION;
117
+ END_TYPE;
118
+ END_SCHEMA;
119
+ ----
120
+
121
+ And the `lutaml_express` block:
122
+
123
+ [source,adoc]
124
+ -----
125
+ [lutaml_express_liquid,example.exp,my_context]
126
+ ----
127
+ {% for schema in my_context.schemas %}
128
+ == {{schema.id}}
129
+
130
+ {% for entity in schema.entities %}
131
+ === {{entity.id}}
132
+ {% endfor %}
133
+
134
+ {% endfor %}
135
+ ----
136
+ -----
137
+
138
+ NOTE: The `lutaml` command can auto-detect the EXPRESS schema file type by the
139
+ file extension. If the file extension is `.exp`, the command will use the
140
+ `Expressir` parser to parse the file. If the file extension is `.lutaml`, the
141
+ command will use the `Lutaml` parser to parse the file.
142
+
143
+ Where:
144
+
145
+ * content within the block is called the "`template`";
146
+
147
+ * `{example.exp}` is the location of the EXPRESS schema file (`*.exp`) that
148
+ contains data to be loaded. Location of the file is computed relative to the
149
+ source directory that `[lutaml_express_liquid]` is used (e.g., if
150
+ `[lutaml_express_liquid,example.exp,my_context]` is invoked in an `.adoc` file
151
+ located at `/foo/bar/doc.adoc`, the data file is expected to be found at
152
+ `/foo/bar/example.exp`);
153
+
154
+ * `{my_context}` is the name where the EXPRESS Repository read from the `.exp`
155
+ file can be accessed with.
156
+
157
+ ** The `context` object is a serialized `Expressir::Model::Repository` object
158
+ with all variable names available. See
159
+ https://github.com/lutaml/expressir[Expressir] docs for reference.
160
+ `{my_context}` has `schemas` method to access Expressir
161
+ https://github.com/lutaml/expressir/blob/master/lib/expressir/model/schema.rb[schemas]
162
+
163
+ Will produce this output:
164
+
165
+ ____
166
+ == test_schema
167
+
168
+ === my_type1
169
+ === my_type2
170
+ === my_type3
171
+ === my_type4
172
+ === my_type5
173
+ ____
174
+
175
+
176
+ Instead of using the direct path to the file one can use `:lutaml-express-index:`
177
+ document attribute to supply directory with express files or YAML index file to
178
+ parse as well as the cache file location.
179
+
180
+ Syntax:
181
+
182
+ [source,adoc]
183
+ ----
184
+ :lutaml-express-index: my_custom_name; dir_or_index_path[; cache=cache_path]
185
+ ----
186
+
187
+ Where:
188
+
189
+ `my_custom_name`:: is name of the parsed EXPRESS files context for the later
190
+ use with lutaml command
191
+
192
+ `dir_or_index_path`:: location of directory with EXPRESS files or path to the
193
+ YAML index file to parse
194
+
195
+ `cache_path`:: (optional) location of the Expressir cache file to use
196
+
197
+ Example of usage:
198
+
199
+ [source,adoc]
200
+ -----
201
+ = Document title
202
+ Author
203
+ :lutaml-express-index: index_name; /path/to/express_files; cache=/path/to/cache_file.yaml
204
+
205
+ [lutaml_express_liquid,index_name,context]
206
+ ----
207
+ {% for schema in context.schemas %}
208
+ == {{schema.id}}
209
+ {% endfor %}
210
+ ----
211
+ -----
212
+
213
+ * The `lutaml_express_liquid` macro processes the EXPRESS files specified by
214
+ the `index_name` and makes them available in the `context` as
215
+ Liquid Drops object.
216
+
217
+ * The Liquid template inside the macro block iterates over the `schemas` in
218
+ the `context` and renders the attributes of each schema such as `id`.
219
+
220
+ === Using `config_yaml`
221
+
222
+ This functionality allows `[lutaml_express_liquid]` blocks to load a full set of
223
+ EXPRESS schemas in one index, and then provide a select ("filter") option
224
+ per-block via a separate YAML file.
225
+
226
+ [source,adoc]
227
+ -----
228
+ :lutaml-express-index: all_schemas; ../schemas_all.yaml;
229
+
230
+ [lutaml_express_liquid,all_schemas,context,config_yaml=schemas.yaml]
231
+ ---
232
+ {% assign all_schemas = repo.schemas %}
233
+ {% render "templates/resources/schema" for ordered_schemas as schema %}
234
+ ----
235
+ -----
236
+
237
+ Where `schemas_all.yml` provides all schemas:
238
+
239
+ [source,yaml]
240
+ ----
241
+ ---
242
+ schemas:
243
+ action_schema:
244
+ path: "../../schemas/resources/action_schema/action_schema.exp"
245
+ application_context_schema:
246
+ path: "../../schemas/resources/application_context_schema/application_context_schema.exp"
247
+ approval_schema:
248
+ path: "../../schemas/resources/approval_schema/approval_schema.exp"
249
+ ...
250
+ ----
251
+
252
+ And `schemas.yaml` only selects 2 schemas:
253
+
254
+ [source,yaml]
255
+ ----
256
+ ---
257
+ schemas:
258
+ action_schema:
259
+ anything: ...
260
+ application_context_schema:
261
+ anything: ...
262
+ ----
263
+
264
+ The resulting block adds the `ordered_schemas` context to allows you to filter
265
+ out the schemas you want to render according to the order in the config_yaml.
266
+
267
+ [source,liquid]
268
+ ----
269
+ [lutaml_express_liquid,schemas_1,repo,config_yaml=select.yaml]
270
+ ---
271
+ {% assign all_schemas = repo.schemas %}
272
+ {% render "templates/resources/schema" for ordered_schemas as schema %}
273
+ ...
274
+ ---
275
+ ----
276
+
277
+ NOTE: This functionality is used in the ISO 10303 SRL to load the full schema
278
+ set at once but only render the selected schemas in individual documents.
279
+
280
+ === Using `include_path`
281
+
282
+ This functionality allows `[lutaml_express_liquid]` blocks to load templates
283
+ from the paths other than the location of the document.
284
+
285
+ [source,adoc]
286
+ -----
287
+ :lutaml-express-index: all_schemas; ../schemas_all.yaml;
288
+
289
+ [lutaml_express_liquid,all_schemas,context,config_yaml=schemas.yaml,include_path=../templates]
290
+ ---
291
+ {% assign all_schemas = repo.schemas %}
292
+ {% render "templates/resources/schema" for ordered_schemas as schema %}
293
+ ...
294
+ ----
295
+ -----
296
+
297
+ The resulting block adds the `include_path` to the Liquid renderer. The path is
298
+ resolved based on the location of the document. You can add multiple paths by
299
+ separating them with commas.