metanorma-plugin-lutaml 0.7.20 → 0.7.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8c70ed413914e29f4c181d02bfd50681434437361fe26f10dc1ca94f7e85058e
4
- data.tar.gz: addb2f7403c0ffebe85e26cd918440e140d43349c57055be8366b4d35cf794a9
3
+ metadata.gz: 2141a34ad005450e66a18defc983c59a7178b83260713cd2565dcb4ed1e8cc2a
4
+ data.tar.gz: 004eecc5e8640fe07f06344a7a60163d875e6da502dffdf8824f478c1a57780f
5
5
  SHA512:
6
- metadata.gz: c5a5b0e871111297d907041d087a24acc58caf7f4c54db1f5213f6be08afdc5d26baceb50a34d9b0d806acd61d9316e72c0b051b7b5da5edfc0aad54ecc995f7
7
- data.tar.gz: 61b0e6159c1444ea0faf3f3e693e3e2ef228aca57d2129a98450207dec0158e72459049462483a436ddc68e119624298c78d66ac161c2bc34a736b70ab765a96
6
+ metadata.gz: d1fedd8cf68d1bdbbbdee4ad12e892d8986f8f9d12f9135651e65460b6c7101a59ed76c70cef55ec28293a61445375381813b28d11ad7cd68dc735bdb63a68d7
7
+ data.tar.gz: '092a888203f0e03f77fa73dbd33fdd20e411a77d110cf1cae99e9bf89df3b16fca27c6070c014a1918a5b4cdac2079dea15be706e98a38f573e0d527da2f2cac'
data/README.adoc CHANGED
@@ -295,7 +295,7 @@ via Liquid:
295
295
  {% assign selected = repo.schemas | where: "selected" %}
296
296
  ... do things with `selected` ...
297
297
  ---
298
- -----
298
+ ----
299
299
 
300
300
  NOTE: This functionality is used in the ISO 10303 SRL to load the full schema
301
301
  set at once but only render the selected schemas in individual documents.
@@ -374,155 +374,6 @@ diagram MyView {
374
374
  ....
375
375
  ----
376
376
 
377
- === Generating a UML class and attributes clause: `lutaml_uml_class`
378
-
379
- This command allows rendering a definition clause for a UML class.
380
-
381
- Given `example.lutaml` with this content:
382
-
383
- [source,java]
384
- ----
385
- class Register {
386
- definition {
387
- A register of information.
388
- }
389
-
390
- identifier: String[1] {
391
- definition {
392
- Unique identifier of the register.
393
- }
394
- }
395
-
396
- concepts: Concept[0..*] {
397
- definition {
398
- Concepts.
399
- }
400
- }
401
- }
402
- ----
403
-
404
- The command:
405
-
406
- [source,adoc]
407
- ----
408
- [lutaml_uml_class,views/Register_Register.lutaml,Register]
409
- ----
410
-
411
- Will produce this output:
412
-
413
- ____
414
- == Register
415
-
416
- A register of information.
417
-
418
- === Attributes
419
-
420
- ==== identifier
421
-
422
- Unique identifier of the register.
423
-
424
- .Specification of `Register.identifier`
425
- |===
426
- h|Value type and multiplicity | `String [1]`
427
- |===
428
-
429
- ==== concepts
430
-
431
- Concepts.
432
-
433
- .Specification of `Register.concepts`
434
- |===
435
- h|Value type and multiplicity | `Concepts [0..*]`
436
- |===
437
-
438
- ____
439
-
440
- The command accepts two options:
441
-
442
- `skip_headers=true`:: (or just `skip_headers`) The initial heading (the UML class name)
443
- will not be generated. This is useful if additional content is to be supplied
444
- to the clause, such as diagrams that are defined outside the UML model.
445
-
446
- `depth={n}`:: (default: `2`) This determines the depth of the generated headings.
447
- A depth of `2` means the initial heading will have 2 equal signs, and so forth.
448
- The heading depth of the attributes are in relation to the initial depth, so
449
- a depth of `2` will have the "Attributes" section at depth `3`.
450
-
451
-
452
- === Generating a UML attributes table: `lutaml_uml_attributes_table`
453
-
454
- This command allows rendering definition tables for a UML model.
455
-
456
- Given `example.lutaml` file with the content:
457
-
458
- [source,java]
459
- ----
460
- diagram MyView {
461
- title "my diagram"
462
-
463
- enum AddressClassProfile {
464
- imlicistAttributeProfile: CharacterString [0..1] {
465
- definition
466
- this is multiline with `ascidoc`
467
- end definition
468
- }
469
- }
470
-
471
- class AttributeProfile {
472
- +addressClassProfile: CharacterString [0..1]
473
- imlicistAttributeProfile: CharacterString [0..1] {
474
- definition this is attribute definition
475
- }
476
- }
477
- }
478
- ----
479
-
480
- And the `lutaml_uml_attributes_table` command:
481
-
482
- [source,adoc]
483
- ----
484
- [lutaml_uml_attributes_table, example.lutaml, AttributeProfile]
485
- ----
486
-
487
- Will produce this output:
488
-
489
- ____
490
- === AttributeProfile
491
-
492
- .AttributeProfile attributes
493
- |===
494
- |Name |Definition |Mandatory/ Optional/ Conditional |Max Occur |Data Type
495
-
496
- |addressClassProfile |TODO: enum's definition |M |1 | `CharacterString`
497
-
498
- |imlicistAttributeProfile |this is attribute definition with multiply lines |M |1 | `CharacterString`
499
-
500
- |===
501
- ____
502
-
503
-
504
- In case of "enumeration" (AddressClassProfile) entity:
505
-
506
- [source,adoc]
507
- ----
508
- [lutaml_uml_attributes_table, example.lutaml, AddressClassProfile]
509
- ----
510
-
511
- Will produce this output:
512
-
513
- ____
514
- === AddressClassProfile
515
-
516
- .AddressClassProfile values
517
- |===
518
- |Name |Definition
519
-
520
- |imlicistAttributeProfile |this is multiline with `asciidoc`
521
-
522
- |===
523
- ____
524
-
525
-
526
377
  == Usage with Enterprise Architect (UML in XMI)
527
378
 
528
379
  === General
@@ -42,9 +42,7 @@ module Metanorma
42
42
  end
43
43
 
44
44
  doc ||= parent.document.attributes["lutaml_xmi_cache"].values.first
45
- return doc if doc.instance_of?(::Lutaml::XMI::RootDrop)
46
-
47
- doc.original_document
45
+ doc
48
46
  end
49
47
 
50
48
  def get_path_from_index(parent, index_name) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
@@ -162,16 +162,8 @@ module Metanorma
162
162
  [lutaml_document, yaml_config]
163
163
  end
164
164
 
165
- def get_original_document(wrapper)
166
- doc = wrapper
167
- return doc if doc.instance_of?(::Lutaml::XMI::RootDrop)
168
-
169
- doc.original_document
170
- end
171
-
172
165
  def fill_in_entities_refs_attributes(document, # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength
173
166
  lutaml_document, _options)
174
- lutaml_document = get_original_document(lutaml_document)
175
167
  # render_style = options.fetch(RENDER_STYLE_ATTRIBUTE, "default")
176
168
  all_children_packages = lutaml_document.packages
177
169
  .map(&:children_packages).flatten
@@ -201,7 +193,6 @@ module Metanorma
201
193
  end
202
194
 
203
195
  def fill_in_diagrams_attributes(document, lutaml_document) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
204
- lutaml_document = get_original_document(lutaml_document)
205
196
  package_flat_diagrams = lambda do |pks|
206
197
  pks.each_with_object({}) do |package, res|
207
198
  package.diagrams.map do |diag|
@@ -49,7 +49,7 @@ module Metanorma
49
49
  line.match(/^\[(?:\blutaml\b|\blutaml_express\b|\blutaml_express_liquid\b),(?<index_names>[^,]+)?,?(?<context_name>[^,]+)?(?<options>,.*)?\]/) # rubocop:disable Layout/LineLength
50
50
  end
51
51
 
52
- def load_lutaml_file(document, file_path)
52
+ def load_express_lutaml_file(document, file_path)
53
53
  ::Lutaml::Parser.parse(
54
54
  File.new(
55
55
  Utils.relative_file_path(document, file_path),
@@ -108,9 +108,7 @@ module Metanorma
108
108
  index_names.map do |path|
109
109
  if indexes[path]
110
110
  indexes[path][:liquid_drop] ||=
111
- indexes[path][:wrapper].original_document.to_liquid(
112
- options: options,
113
- )
111
+ indexes[path][:model].to_liquid(options: options)
114
112
  else
115
113
  full_path = Utils.relative_file_path(document, path)
116
114
  unless File.file?(full_path)
@@ -120,11 +118,9 @@ module Metanorma
120
118
  "the full path.",
121
119
  )
122
120
  end
123
- wrapper = load_lutaml_file(document, path)
121
+ express_model = load_express_lutaml_file(document, path)
124
122
  indexes[path] = {
125
- liquid_drop: wrapper.original_document.to_liquid(
126
- options: options,
127
- ),
123
+ liquid_drop: express_model.to_liquid(options: options),
128
124
  }
129
125
  end
130
126
 
@@ -155,13 +151,6 @@ module Metanorma
155
151
  options
156
152
  end
157
153
 
158
- def get_original_document(wrapper)
159
- doc = wrapper
160
- return doc if doc.instance_of?(::Lutaml::XMI::RootDrop)
161
-
162
- doc.original_document
163
- end
164
-
165
154
  def render_liquid_template(document:, lines:, context_name:, # rubocop:disable Metrics/AbcSize,Metrics/MethodLength,Metrics/ParameterLists
166
155
  index_names:, options:, indexes:)
167
156
  config_yaml_path = options.delete("config_yaml")
@@ -14,7 +14,7 @@ module Metanorma
14
14
  module Plugin
15
15
  module Lutaml
16
16
  # Macro for quick rendering of datamodel attributes/values table
17
- # @example [lutaml_uml_attributes_table,path/to/lutaml,EntityName]
17
+ # TODO: merge with lutaml_ea_xmi
18
18
  class LutamlUmlDatamodelDescriptionPreprocessor <
19
19
  ::Asciidoctor::Extensions::Preprocessor
20
20
  include LutamlEaXmiBase
@@ -24,8 +24,11 @@ module Metanorma
24
24
 
25
25
  private
26
26
 
27
- def parse_result_document(full_path, _guidance = nil)
28
- ::Lutaml::Parser.parse(File.new(full_path, encoding: "UTF-8")).first
27
+ def parse_result_document(full_path, guidance)
28
+ ::Lutaml::XMI::Parsers::XML.serialize_xmi_to_liquid(
29
+ File.new(full_path, encoding: "UTF-8"),
30
+ guidance,
31
+ )
29
32
  end
30
33
  end
31
34
  end
@@ -61,13 +61,6 @@ module Metanorma
61
61
  end
62
62
  end
63
63
 
64
- def get_original_document(wrapper)
65
- doc = wrapper
66
- return doc if doc.instance_of?(::Lutaml::XMI::RootDrop)
67
-
68
- doc.original_document
69
- end
70
-
71
64
  def load_express_repositories(path:, cache_path:, document:,
72
65
  force_read: false)
73
66
  cache_full_path = cache_path &&
@@ -80,17 +73,17 @@ force_read: false)
80
73
 
81
74
  # If there is no cache or "force read" is set.
82
75
  full_path = Utils.relative_file_path(document, path)
83
- lutaml_wrapper = load_express_repo_from_path(document, full_path)
76
+ lutaml_doc = load_express_repo_from_path(document, full_path)
84
77
 
85
78
  if cache_full_path && !File.file?(cache_full_path)
86
79
  save_express_repo_to_cache(
87
80
  cache_full_path,
88
- get_original_document(lutaml_wrapper),
81
+ lutaml_doc,
89
82
  document,
90
83
  )
91
84
  end
92
85
 
93
- lutaml_wrapper
86
+ lutaml_doc
94
87
  rescue Expressir::Error
95
88
  FileUtils.rm_rf(cache_full_path)
96
89
 
@@ -179,16 +172,15 @@ force_read: false)
179
172
  raise StandardError.new("No name and path set in `:lutaml-express-index:` attribute.")
180
173
  end
181
174
 
182
- lutaml_expressir_wrapper = load_express_repositories(
175
+ lutaml_expressir_model = load_express_repositories(
183
176
  path: path,
184
177
  cache_path: cache,
185
178
  document: document,
186
179
  )
187
180
 
188
- if lutaml_expressir_wrapper
181
+ if lutaml_expressir_model
189
182
  express_indexes[name] = {
190
- wrapper: lutaml_expressir_wrapper,
191
- serialized_hash: nil,
183
+ model: lutaml_expressir_model,
192
184
  }
193
185
  end
194
186
  end
@@ -1,7 +1,7 @@
1
1
  module Metanorma
2
2
  module Plugin
3
3
  module Lutaml
4
- VERSION = "0.7.20".freeze
4
+ VERSION = "0.7.22".freeze
5
5
  end
6
6
  end
7
7
  end
@@ -1,7 +1,5 @@
1
1
  require "metanorma/plugin/lutaml/version"
2
2
  require "metanorma/plugin/lutaml/lutaml_preprocessor"
3
- require "metanorma/plugin/lutaml/lutaml_uml_class_preprocessor"
4
- require "metanorma/plugin/lutaml/lutaml_uml_attributes_table_preprocessor"
5
3
  require "metanorma/plugin/lutaml/lutaml_uml_datamodel_description_preprocessor"
6
4
  require "metanorma/plugin/lutaml/lutaml_ea_xmi_preprocessor"
7
5
  require "metanorma/plugin/lutaml/lutaml_diagram_block"
@@ -35,7 +35,7 @@ Gem::Specification.new do |spec|
35
35
 
36
36
  spec.add_development_dependency "debug"
37
37
  spec.add_development_dependency "equivalent-xml"
38
- spec.add_development_dependency "metanorma-standoc"
38
+ spec.add_development_dependency "metanorma-standoc", "~> 3.0"
39
39
  spec.add_development_dependency "rake", "~> 13"
40
40
  spec.add_development_dependency "rspec", "~> 3.6"
41
41
  spec.add_development_dependency "rspec-html-matchers"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: metanorma-plugin-lutaml
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.20
4
+ version: 0.7.22
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2025-02-13 00:00:00.000000000 Z
11
+ date: 2025-02-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: asciidoctor
@@ -140,16 +140,16 @@ dependencies:
140
140
  name: metanorma-standoc
141
141
  requirement: !ruby/object:Gem::Requirement
142
142
  requirements:
143
- - - ">="
143
+ - - "~>"
144
144
  - !ruby/object:Gem::Version
145
- version: '0'
145
+ version: '3.0'
146
146
  type: :development
147
147
  prerelease: false
148
148
  version_requirements: !ruby/object:Gem::Requirement
149
149
  requirements:
150
- - - ">="
150
+ - - "~>"
151
151
  - !ruby/object:Gem::Version
152
- version: '0'
152
+ version: '3.0'
153
153
  - !ruby/object:Gem::Dependency
154
154
  name: rake
155
155
  requirement: !ruby/object:Gem::Requirement
@@ -343,8 +343,6 @@ files:
343
343
  - lib/metanorma/plugin/lutaml/lutaml_klass_table_block_macro.rb
344
344
  - lib/metanorma/plugin/lutaml/lutaml_preprocessor.rb
345
345
  - lib/metanorma/plugin/lutaml/lutaml_table_inline_macro.rb
346
- - lib/metanorma/plugin/lutaml/lutaml_uml_attributes_table_preprocessor.rb
347
- - lib/metanorma/plugin/lutaml/lutaml_uml_class_preprocessor.rb
348
346
  - lib/metanorma/plugin/lutaml/lutaml_uml_datamodel_description_preprocessor.rb
349
347
  - lib/metanorma/plugin/lutaml/utils.rb
350
348
  - lib/metanorma/plugin/lutaml/version.rb
@@ -1,50 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "metanorma/plugin/lutaml/asciidoctor/preprocessor"
4
-
5
- module Metanorma
6
- module Plugin
7
- module Lutaml
8
- # Macro for quick rendering of datamodel attributes/values table
9
- # @example [lutaml_uml_attributes_table,path/to/lutaml,EntityName]
10
- class LutamlUmlAttributesTablePreprocessor < LutamlUmlClassPreprocessor
11
- MACRO_REGEXP =
12
- /\[lutaml_uml_attributes_table,([^,]+),?([^,]+),?(.+?)?\]/.freeze
13
-
14
- # rubocop:disable Layout/IndentHeredoc
15
- def template(options)
16
- skip_headers = options[:skip_headers]
17
-
18
- <<~TEMPLATE
19
- #{'=== {{ definition.name }}' unless skip_headers}
20
- {{ definition.definition }}
21
-
22
- {% if definition.attributes %}
23
- {% if definition.keyword == 'enumeration' %}
24
- .{{ definition.name }} values
25
- |===
26
- |Name |Definition
27
-
28
- {% for item in definition.attributes %}
29
- |{{ item.name }} |{{ item.definition }}
30
- {% endfor %}
31
- |===
32
- {% else %}
33
- .{{ definition.name }} attributes
34
- |===
35
- |Name |Definition |Mandatory / Optional / Conditional |Max Occur |Data Type
36
-
37
- {% for item in definition.attributes %}
38
- |{{ item.name }} |{% if item.definition %}{{ item.definition }}{% endif %} |{% if item.cardinality.min == "0" %}O{% else %}M{% endif %} |{% if item.cardinality.max == "*" %}N{% else %}1{% endif %} |{% if item.origin %}<<{{ item.origin }}>>{% endif %} `{{ item.type }}`
39
- {% endfor %}
40
- |===
41
- {% endif %}
42
- {% endif %}
43
-
44
- TEMPLATE
45
- end
46
- # rubocop:enable Layout/IndentHeredoc
47
- end
48
- end
49
- end
50
- end
@@ -1,168 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "liquid"
4
- require "asciidoctor"
5
- require "asciidoctor/reader"
6
- require "lutaml"
7
- require "lutaml/uml"
8
- require "metanorma/plugin/lutaml/utils"
9
- require "metanorma/plugin/lutaml/asciidoctor/preprocessor"
10
-
11
- module Metanorma
12
- module Plugin
13
- module Lutaml
14
- # Macro for quick rendering of datamodel attributes/values table
15
- # @example [lutaml_uml_class,path/to/lutaml,EntityName]
16
- class LutamlUmlClassPreprocessor < ::Asciidoctor::Extensions::Preprocessor
17
- MACRO_REGEXP =
18
- /\[lutaml_uml_class,([^,]+),?([^,]+),?(.+?)?\]/.freeze
19
-
20
- def get_macro_regexp
21
- self.class.const_get(:MACRO_REGEXP)
22
- end
23
-
24
- # search document for block `datamodel_attributes_table`
25
- # read include derectives that goes after that in block and transform
26
- # into yaml2text blocks
27
- def process(document, reader)
28
- r = Asciidoctor::PreprocessorNoIfdefsReader.new document, reader.lines
29
- input_lines = r.readlines.to_enum
30
- Asciidoctor::PreprocessorNoIfdefsReader
31
- .new(document, processed_lines(document, input_lines))
32
- end
33
-
34
- private
35
-
36
- def lutaml_document_from_file(document, file_path)
37
- ::Lutaml::Parser.parse(
38
- File.new(
39
- Utils.relative_file_path(document, file_path),
40
- encoding: "UTF-8",
41
- ),
42
- ).first
43
- end
44
-
45
- DEFAULT_OPTIONS = { depth: 2 }.freeze
46
-
47
- def parse_options_to_hash(options_string)
48
- return DEFAULT_OPTIONS.dup if options_string.nil? ||
49
- options_string.empty?
50
-
51
- opts = options_string.split(",").inject({}) do |acc, pair|
52
- key, value = pair.split("=")
53
- key = key.to_sym
54
- value = true if value.nil?
55
- value = value.to_i if key == :depth
56
- acc[key] = value if key
57
- acc
58
- end
59
-
60
- DEFAULT_OPTIONS.dup.merge(opts)
61
- end
62
-
63
- def processed_lines(document, input_lines)
64
- input_lines.each_with_object([]) do |line, result|
65
- if match = line.match(get_macro_regexp)
66
- lutaml_path = match[1]
67
- entity_name = match[2]
68
- options = parse_options_to_hash(match[3])
69
-
70
- result.push(*parse_macro(lutaml_path, entity_name, document,
71
- options))
72
- else
73
- result.push(line)
74
- end
75
- end
76
- end
77
-
78
- def parse_macro(lutaml_path, entity_name, document, options)
79
- lutaml_document = lutaml_document_from_file(document, lutaml_path)
80
- .serialized_document
81
- entities = [lutaml_document["classes"], lutaml_document["enums"]]
82
- .compact
83
- .flatten
84
- entity_definition = entities.detect do |klass|
85
- klass["name"] == entity_name.strip
86
- end
87
- model_representation(entity_definition, document, options)
88
- end
89
-
90
- def model_representation(entity_definition, document, options)
91
- render_result, errors = Utils.render_liquid_string(
92
- template_string: template(options),
93
- context_items: entity_definition,
94
- context_name: "definition",
95
- document: document,
96
- )
97
- Utils.notify_render_errors(document, errors)
98
- render_result.split("\n")
99
- end
100
-
101
- def equalsigns(depth)
102
- "=" * depth
103
- end
104
-
105
- # rubocop:disable Layout/IndentHeredoc
106
- def template(options)
107
- skip_headers = options[:skip_headers]
108
- depth = options[:depth]
109
-
110
- <<~TEMPLATE
111
- {% if definition.keyword == 'enumeration' %}
112
- #{"#{equalsigns(depth)} Enumeration: {{ definition.name }}" unless skip_headers}
113
- {% else %}
114
- #{"#{equalsigns(depth)} Class: {{ definition.name }}" unless skip_headers}
115
- {% endif %}
116
-
117
- #{equalsigns(depth + 1)} Description
118
-
119
- {{ definition.definition }}
120
-
121
- {% if definition.attributes %}
122
- {% if definition.keyword == 'enumeration' %}
123
- {% for item in definition.attributes %}
124
- #{equalsigns(depth + 1)} Enumeration value: {{item.name}}
125
-
126
- {% if item.definition %}
127
- {{ item.definition }}
128
- {% endif %}
129
-
130
- {% endfor %}
131
-
132
- {% else %}
133
-
134
- {% for item in definition.attributes %}
135
- #{equalsigns(depth + 1)} Attribute: {{item.name}}
136
-
137
- {% if item.definition %}
138
- {{ item.definition }}
139
- {% endif %}
140
-
141
- Value type and multiplicity:
142
- {% if item.type -%}{{ item.type }}{% else -%}(no type specified){% endif %}
143
- {% if item.cardinality.min -%}
144
- {% if item.cardinality.max -%}
145
- {blank}[{{item.cardinality.min}}..{{item.cardinality.max}}]
146
- {% else -%}
147
- {blank}[{{item.cardinality.min}}]
148
- {% endif -%}
149
- {% else -%}
150
- (multiplicity unspecified)
151
- {% endif %}
152
-
153
- {% if item.origin %}
154
- Origin: <<{{ item.origin }}>>
155
- {% endif %}
156
-
157
- {% endfor %}
158
-
159
- {% endif %}
160
- {% endif %}
161
-
162
- TEMPLATE
163
- end
164
- # rubocop:enable Layout/IndentHeredoc
165
- end
166
- end
167
- end
168
- end