metanorma-plugin-lutaml 0.4.3 → 0.4.4

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: a594ac058de2a8fc661fa9354e32c3e53cbba9ba831eb2241866c3fe50fef39e
4
- data.tar.gz: c9ccd2ad0f3d8bcb39da897b733f0c84a8aebf2b434f0c05e4229700e96b1042
3
+ metadata.gz: 213cd8b2ecaa1b45360480fc2de787f6708b625f5370b7e7617317d77b703ee6
4
+ data.tar.gz: 396fd04d0ac3f979a6a9ee3b425988fc17af5a267b8e140438a92b73ac41dd5f
5
5
  SHA512:
6
- metadata.gz: 2761bf514acf0b0861a18c7d9182834868d3061e8720373e2e57bf5f31216e7a5c66e08fee6069f93c59074c352b8f4fb6f416cbd5a1644df0d55dc6db59860e
7
- data.tar.gz: 86489b0e1915b61997af3f55388ea4b788fe505188caca2efd40589b67c1ba4e9a0acba591d111c0af7c4943dbad1a3bd69dc0c0dd737663e93b1ada5436d046
6
+ metadata.gz: 37ad00c2a5bed4ddd9314ad99883545b526ed461e92d99de045072e900592c09798d82dc6119017a5e7656d891c1ea0cc331c844801ec2c0b4d2aae8784775aa
7
+ data.tar.gz: b8b6cb960be27fc5612c7a987250cd607ea0ae3f07dec61e44334765a64f7d5c22d245a108f2bbfdd4ec6fdc34e3b822b87fb801f70a3406611639d887ea00a9
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/"]
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
  -----
@@ -324,96 +338,104 @@ Where:
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. The logic is as follows:
330
342
  [source,adoc]
331
343
  -----
332
- = preface
333
- my text
334
-
335
- text before Another package
336
-
337
- === Another
338
-
339
- [[rc_another-model_section]]
340
- ==== Another
341
-
342
- ==== Requirements
343
-
344
- ==== Class Definitions
344
+ {% for diagram in package.diagrams %}
345
+ [[figure-{{ diagram.xmi_id }}]]
346
+ .{{ diagram.name }}
347
+ image::{{ image_base_path }}/{{ diagram.xmi_id }}.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.
345
355
 
346
- .Classes used in Another
347
- [cols="2a,6a",options="header"]
348
- |===
349
- |Class |Description
356
+ * `[.diagram_include_block, package="Another"]` - same as above, but diagram will be included only for supplied package name
350
357
 
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`.
351
359
 
352
- |<<AbstractAtomicTimeseries-section,AbstractAtomicTimeseries>>
353
- «»
354
- |
360
+ * `[.include_block, package="Another", base_path="spec/fixtures"]` - same as above, but include block will be included only for supplied package name
355
361
 
356
362
 
357
- |<<AbstractTimeseries-section,AbstractTimeseries>>
358
- «»
359
- |
363
+ Will produce this output:
360
364
 
361
- ....
362
- |===
365
+ [source,adoc]
366
+ -----
367
+ my text
368
+ == CityGML package
369
+ === CityGML overview
363
370
 
371
+ Diagram text
364
372
 
373
+ [[figure-EAID_ACBB5EE3_3428_40f5_9C7C_E41923419F29]]
374
+ .CityGML Package Diagram
375
+ image::requirements//EAID_ACBB5EE3_3428_40f5_9C7C_E41923419F29.png[]
365
376
 
366
- .Data Types used in Another
367
- [cols="2,6",options="header"]
368
- |===
369
- |Name |Description
377
+ BuildingFurnitureFunctionValue is a code list that enumerates the different purposes of a BuildingFurniture.
370
378
 
379
+ [[figure-EAID_938AE961_1C57_4052_B964_997D1894A58D]]
380
+ .Use of ISO and OASIS standards in CityGML
381
+ image::requirements//EAID_938AE961_1C57_4052_B964_997D1894A58D.png[]
371
382
 
372
- |<<ADEOfAbstractAtomicTimeseries-section,ADEOfAbstractAtomicTimeseries>>
373
- |
383
+ The CityGML package is organized into
384
+ 2 packages with 1 modules:
374
385
 
386
+ [arabic]
387
+ . Another package
388
+ . CityTML package
375
389
 
376
- |<<ADEOfAbstractTimeseries-section,ADEOfAbstractTimeseries>>
377
- |
390
+ my text
378
391
 
379
- ....
380
- |===
392
+ Content for CityGML package
381
393
 
394
+ ==== Defining tables
382
395
 
396
+ [arabic]
397
+ .<<tab-P-another-C-abstractatomictimeseries>> -- Elements of Another::AbstractAtomicTimeseries
383
398
 
384
- .Enumerated Classes used in Another
385
- [cols="2a,6a",options="header"]
399
+ [[tab-P-another-C-abstractatomictimeseries]]
400
+ .Elements of Another::AbstractAtomicTimeseries
401
+ [width="100%",cols="a,a,a,a,a,a,a,a"]
386
402
  |===
387
- |Name |Description
388
-
389
- |<<TimeseriesTypeValue-section,TimeseriesTypeValue>>
403
+ h|Name: 7+| AbstractAtomicTimeseries
404
+ h|Definition: 7+|
405
+ h|Stereotype: 7+| interface
406
+ h|Abstract: 7+|
407
+ .1+h|Associations: 7+| (none)
408
+ .4+h|Public attributes:
409
+ | _Name_
410
+ 2+| _Definition_
411
+ | _Derived_
412
+ | _Obligation_
413
+ | _Maximum occurrence_
414
+ | _Data type_
415
+ | adeOfAbstractAtomicTimeseries
416
+ 2+|
390
417
  |
391
-
418
+ | C
419
+ | *
420
+ | ADEOfAbstractAtomicTimeseries
421
+ | observationProperty
422
+ 2+|
423
+ |
424
+ | M
425
+ | 1
426
+ | CharacterString
427
+ | uom
428
+ 2+|
429
+ |
430
+ | C
431
+ | 1
432
+ | CharacterString
433
+ h|Constraints: 7+| (none)
392
434
  |===
393
435
 
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
436
+ === Additional Information
410
437
 
411
438
  text after CityGML package
412
-
413
-
414
- = footer
415
- footer text
416
-
417
439
  -----
418
440
 
419
441
  In addition to just supplying XMI file, this macro also supports YAML
@@ -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 }}.png[]
7
+
8
+ {% if diagram.definition %}
9
+ {{ diagram.definition | html2adoc }}
10
+ {% endif %}
11
+ {% endfor %}
@@ -1,27 +1,23 @@
1
1
  {% for package in context.packages %}
2
+ {% assign package_name = package.name | downcase | replace: ":", "" | replace: " ", "_" %}
3
+ {% if additional_context.before %}
4
+ {{ additional_context.before.text }}
5
+ {% endif %}
2
6
  {% assign before_package_key = 'before;' | append: package.name %}
3
7
  {% if additional_context[before_package_key] %}
4
- {{ additional_context[before_package_key] }}
8
+ {{ additional_context[before_package_key].text }}
5
9
  {% endif %}
6
10
  {% assign is_package_spare = package.name | slice: 0,5 %}
7
11
  {% if is_package_spare == 'old: ' %}{% continue %}
8
12
  {% elsif is_package_spare == 'Spare' %}{% continue %}
9
13
  {% endif %}
10
- {% assign package_name = package.name | downcase | replace: ":", "" | replace: " ", "_" %}
11
14
 
12
15
  {% capture equalsigns %}{% for count in (1..depth) %}={% endfor %}{% endcapture %}{{equalsigns}} {{ package.name }} package
13
16
  {{equalsigns}}= {{ package.name }} overview
14
17
 
15
- // TODO: include blocks by base path
16
- //{% for diagram in package.diagrams %}
17
- //[[figure-{{ diagram.xmi_id }}]]
18
- //.{{ diagram.name }}
19
- //image::../../xmi-19170-only/Images/{{ diagram.xmi_id }}.png[]
20
- //
21
- //{% if diagram.definition %}
22
- //{{ diagram.definition | html2adoc }}
23
- //{% endif %}
24
- //{% endfor %}
18
+ {% if additional_context.diagram_include_block %}
19
+ {% include "diagrams_block", package_name: package_name, image_base_path: additional_context.diagram_include_block.base_path, text: additional_context.diagram_include_block.text %}
20
+ {% endif %}
25
21
 
26
22
  {% if package.packages.size > 0 %}The {{ package.name }} package is organized into
27
23
  {{ 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 +34,7 @@
38
34
  {% endif %}
39
35
  {% endfor %}
40
36
 
41
- {% if package.classes.size > 0 %}
37
+ {% if package.classes.size > 0 or package.enums.size > 0 or package.data_types.size > 0 %}
42
38
 
43
39
  {{equalsigns}}= Defining tables
44
40
 
@@ -83,26 +79,41 @@
83
79
  {% include "packages_data_type" %}
84
80
  {% endfor %}
85
81
 
86
- // TODO: include blocks by base path
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 %}
82
+ {% endif %}
101
83
 
84
+ {% if additional_context.include_block %}
85
+ {% assign block = additional_context.include_block %}
86
+ {% capture block_filename %}{{ block.base_path }}/{{ package_name }}{% endcapture %}
87
+ {% capture block_content %}{% include block_filename %}{% endcapture %}
88
+ {% unless block_content contains "Liquid error" %}
89
+ {% if block.text %}
90
+ {{ block.text }}
91
+ {% endif %}
92
+ {{ block_content }}
93
+ {% endunless %}
102
94
  {% endif %}
95
+
96
+ {% assign include_block_package_key = 'include_block;' | append: package.name %}
97
+ {% assign block = additional_context[include_block_package_key] %}
98
+ {% if block %}
99
+ {% capture block_filename %}{{ block.base_path }}/{{ package_name }}{% endcapture %}
100
+ {% capture block_content %}{% include block_filename %}{% endcapture %}
101
+ {% unless block_content contains "Liquid error" %}
102
+ {% if block.text %}
103
+ {{ block.text }}
104
+ {% endif %}
105
+ {{ block_content }}
106
+ {% endunless %}
107
+ {% endif %}
108
+
103
109
  {% assign after_package_key = 'after;' | append: package.name %}
104
110
  {{equalsigns}}= Additional Information
105
111
  {% if additional_context[after_package_key] %}
106
- {{ additional_context[after_package_key] }}
112
+ {{ additional_context[after_package_key].text }}
107
113
  {% endif %}
114
+ {% if package.packages.size > 0 and render_nested_packages %}{% assign nested_depth = depth | plus: 1 %}{% include "packages", depth: nested_depth, context: package %}{% endif %}
108
115
  {% endfor %}
116
+
117
+ {% if additional_context.after %}
118
+ {{ additional_context.after.text }}
119
+ {% 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::Uml::Formatter::Graphviz.new
45
+ formatter = ::Lutaml::Formatter::Graphviz.new
45
46
  formatter.type = :png
46
47
 
47
48
  imagesdir = if parent.document.attr("imagesdir")
@@ -16,7 +16,6 @@ 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"
@@ -67,25 +66,30 @@ module Metanorma
67
66
 
68
67
  def collect_additional_context(input_lines, end_mark)
69
68
  additional_context = {}
69
+ block_lines = []
70
70
  while (block_line = input_lines.next) != end_mark
71
- nested_match = SUPPORTED_NESTED_MACROSES
72
- .map { |macro| [macro, block_line.match(/\[.#{macro}(,\s*package=("|')(?<package>.+?)("|'))?\]/)] }
73
- .detect { |n| !n.last.nil? }
74
- nested_context_value = []
75
- if nested_match
76
- macro_keyword = [nested_match.first, nested_match.last['package']].compact.join(";")
77
- nested_end_mark = input_lines.next
78
- while (block_line = input_lines.next) != nested_end_mark
79
- nested_context_value.push(block_line)
80
- end
81
- additional_context[macro_keyword] = nested_context_value
82
- .join("\n")
83
- end
71
+ block_lines.push(block_line)
72
+ end
73
+ block_document = (Asciidoctor::Document.new(block_lines, {})).parse
74
+ block_document.blocks.each do |block|
75
+ attrs = block.attributes
76
+ name = attrs.delete('role')
77
+ package = attrs.delete('package')
78
+ macro_keyword = [name, package].compact.join(";")
79
+ additional_context[macro_keyword] = { 'text' => block.lines[1..-2].join("\n") }.merge(attrs)
84
80
  end
85
81
  additional_context
86
82
  end
87
83
 
88
84
  def create_context_object(lutaml_document, additional_context, options)
85
+ if options.length.zero?
86
+ return {
87
+ 'render_nested_packages' => true,
88
+ "packages" => lutaml_document.to_liquid['packages'].first['packages'].first['packages'],
89
+ "additional_context" => additional_context
90
+ }
91
+ end
92
+
89
93
  root_package = lutaml_document.to_liquid['packages'].first
90
94
  all_packages = [root_package, *root_package['children_packages']]
91
95
  {
@@ -143,7 +147,7 @@ module Metanorma
143
147
 
144
148
  def table_template
145
149
  <<~LIQUID
146
- {% include "packages", depth: 2, context: context, additional_context: context.additional_context %}
150
+ {% include "packages", depth: 2, context: context, additional_context: context.additional_context, render_nested_packages: context.render_nested_packages %}
147
151
  LIQUID
148
152
  end
149
153
  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
- include_path ||= Utils.relative_file_path(document, "")
29
- liquid_template.registers[:file_system] = ::Liquid::LocalFileSystem.new(include_path)
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,
@@ -1,7 +1,7 @@
1
1
  module Metanorma
2
2
  module Plugin
3
3
  module Lutaml
4
- VERSION = "0.4.3".freeze
4
+ VERSION = "0.4.4".freeze
5
5
  end
6
6
  end
7
7
  end
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.3
4
+ version: 0.4.4
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-07-28 00:00:00.000000000 Z
11
+ date: 2021-08-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: liquid
@@ -257,6 +257,8 @@ 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
262
264
  - lib/metanorma/plugin/lutaml/liquid_templates/_packages_data_type.liquid