metanorma-plugin-lutaml 0.7.36 → 0.7.37

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: d43aaa8c6ecdc67372b3aad6b2f7544132233255012209cb0ed58fbd47385959
4
- data.tar.gz: 3b2a90461dcd3d1790bbfc7742102c6f5c337eeb7f03dcdfd24a6308f6ffb408
3
+ metadata.gz: 2322a39b5dc29e981cf64a1c383c7d53aee9e1b132412ea79fc91dfac88485aa
4
+ data.tar.gz: b1199f54f2e895a3938b1711c1b36184fbb0bc68fd79e56a6bc9acac12979c2e
5
5
  SHA512:
6
- metadata.gz: b89e3f6357f35059bb73ff892e113b371ed362deda4317259be50c0ced969e9b90dafbed4eda435180c4b85ed58a4b12ea031211e53c4766f825d8acf61f53ee
7
- data.tar.gz: 1182223b096793ab132ac4bfb6c55bf419086a4958eba4a46b1b0ee70f314f4cf883708c40fa437ee06e87f079a4c6ef52bf6eb5767a0dbc07b22cdbc3915488
6
+ metadata.gz: a11578fe6890dbf07994ba86d55ae9eee7d7eac605907b0dde761570c48d1871de497418ca1adff80091fdd931b520dcedf68ff1fc20f0cedac1f26bc78062a0
7
+ data.tar.gz: a7f983789b4b1afd9d4b1b01b1b2546218d1530e9c6ff4cdb8f0ffab0d7f6af83d1f2611fdda609d038c0616dfe1ea50e91b0a61b053000602d3f1685f61a5e1
@@ -10,6 +10,6 @@ on:
10
10
 
11
11
  jobs:
12
12
  rake:
13
- uses: metanorma/ci/.github/workflows/plantuml-rake.yml@main
13
+ uses: metanorma/ci/.github/workflows/graphviz-rake.yml@main
14
14
  secrets:
15
15
  pat_token: ${{ secrets.METANORMA_CI_PAT_TOKEN }}
data/README.adoc CHANGED
@@ -24,15 +24,15 @@ $ gem install metanorma-plugin-lutaml
24
24
 
25
25
  == Usages
26
26
 
27
- link:docs/usages/express.adoc[Usage with EXPRESS]
27
+ link:docs/usages/express.adoc[Usage with EXPRESS files by lutaml_express]
28
28
 
29
- link:docs/usages/lutaml-uml.adoc[Usage with LutaML-UML]
29
+ link:docs/usages/lutaml-uml.adoc[Usage with LutaML files by lutaml_diagram]
30
30
 
31
- link:docs/usages/enterprise_architect.adoc[Usage with Enterprise Architect (UML in XMI)]
31
+ link:docs/usages/enterprise_architect.adoc[Usage with Enterprise Architect XMI files by lutaml_ea_xmi, lutaml_ea_diagram, lutaml_klass_table or lutaml_enum_table]
32
32
 
33
- link:docs/usages/lutaml-gml.adoc[Usage with LutaML GML Dictionary]
33
+ link:docs/usages/lutaml-gml.adoc[Usage with LutaML GML Dictionary by lutaml_gml_dictionary]
34
34
 
35
- link:docs/usages/json_yaml.adoc[Usage with JSON or YAML files]
35
+ link:docs/usages/json_yaml.adoc[Usage with JSON or YAML files by data2text, yaml2text or json2text]
36
36
 
37
37
  == Documentation
38
38
 
@@ -1,5 +1,5 @@
1
1
 
2
- == Usage with Enterprise Architect (UML in XMI)
2
+ == Usage with Enterprise Architect XMI files by lutaml_ea_xmi, lutaml_ea_diagram, lutaml_klass_table or lutaml_enum_table
3
3
 
4
4
  === General
5
5
 
@@ -1,5 +1,5 @@
1
1
 
2
- == Usage with EXPRESS
2
+ == Usage with EXPRESS files by lutaml_express
3
3
 
4
4
  === General
5
5
 
@@ -1,5 +1,5 @@
1
1
 
2
- == Usage with JSON or YAML files
2
+ == Usage with JSON or YAML files by data2text, yaml2text or json2text
3
3
 
4
4
  === General
5
5
 
@@ -1,5 +1,5 @@
1
1
 
2
- == Usage with LutaML GML Dictionary
2
+ == Usage with LutaML GML Dictionary by lutaml_gml_dictionary
3
3
 
4
4
  === Rendering a LutaML GML Dictionary: `lutaml_gml_dictionary`
5
5
 
@@ -1,5 +1,5 @@
1
1
 
2
- == Usage with Lutaml-UML
2
+ == Usage with LutaML files by lutaml_diagram
3
3
 
4
4
  === General
5
5
 
@@ -0,0 +1,213 @@
1
+
2
+ == Usage with Enterprise Architect XMI files by lutaml_xmi_uml
3
+
4
+ === General
5
+
6
+ The LutaML plugin supports working with Enterprise Architect exported XMI files
7
+ to render them as LutaML UML documents.
8
+
9
+ The command is prefixed as `lutaml_xmi_uml` to denote their specific use.
10
+
11
+ === Usage of `lutaml_xmi_uml` command
12
+
13
+ The `lutaml_xmi_uml` command renders Lutaml UML document and its dependent
14
+ objects for the supplied XMI file.
15
+
16
+ [example]
17
+ .Specify the path of a XMI file by `lutaml_xmi_uml` command
18
+ ====
19
+ [source,adoc]
20
+ ----
21
+ [lutaml_xmi_uml,/path/to/first.xmi]
22
+ --
23
+ Name of the Lutaml UML Document: {{ context.name }}
24
+
25
+ Number of packages: {{ context.packages | size }}
26
+ --
27
+ ----
28
+
29
+ By default, the command will parse the XMI file and render it as a
30
+ Lutaml::Uml::Document via `context`.
31
+ ====
32
+
33
+ === Usage of `lutaml_xmi_uml` command with configuration file
34
+
35
+ You can use the `lutaml_xmi_uml` command with a configuration file.
36
+ The configuration file is a YAML file that looks like:
37
+
38
+ [example]
39
+ .Configuration file for `lutaml_xmi_uml` command
40
+ ====
41
+ [source,yaml]
42
+ ----
43
+ ea_extension:
44
+ - "ISO19103MDG v1.0.0-beta.xml"
45
+ - "CityGML_MDG_Technology.xml"
46
+ context_name: my_uml_document
47
+ template_path: "path/to/liquid_templates"
48
+ ----
49
+
50
+ where:
51
+
52
+ `ea_extension`:: optional, list of EA extensions to load. Some XMI files may
53
+ contain elements that cannot be resolved by default, for example CityGML
54
+ elements. You can use `ea_extension` to load the definition of these elements
55
+ in XML format (`CityGML_MDG_Technology.xml`) in order to resolve them. The
56
+ location of the xml files is relative to the config YAML file.
57
+
58
+ `context_name`:: optional, name of the context for the rendered output.
59
+ This can be used to customize the output further by providing a specific
60
+ context name.
61
+
62
+ `template_path`:: optional, path to custom Liquid templates directory for
63
+ rendering the output. When specified, the processor will use custom templates
64
+ from this directory. This allows for complete customization of the rendered
65
+ output format and structure.
66
+
67
+ To use the configuration file, you can specify it in the command:
68
+
69
+ [source,adoc]
70
+ ----
71
+ [lutaml_xmi_uml,/path/to/first.xmi,path/to/config.yml]
72
+ --
73
+ Name of the Lutaml UML Document: {{ context.name }}
74
+
75
+ Number of packages: {{ context.packages | size }}
76
+ --
77
+ ----
78
+ ====
79
+
80
+ === Document attribute `:lutaml-xmi-index:`
81
+
82
+ This attribute allows specifying one or more XMI files to define names
83
+ for later use with `lutaml_xmi_uml` commands.
84
+
85
+ Syntax:
86
+
87
+ [source,adoc]
88
+ ----
89
+ :lutaml-xmi-index: index_name; index_path[; config=config_path]
90
+ ----
91
+
92
+ where:
93
+
94
+ `index_name`:: name of index
95
+ `index_path`:: path to XMI file for the later use with `lutaml_xmi_uml` command
96
+ `config_path`:: optional, location of YAML configuration file that specifies
97
+ what packages to include in the render, what render style is desired and
98
+ location of the root package.
99
+
100
+ [example]
101
+ .Define an index in the document and use it in the `lutaml_xmi_uml` command
102
+ ====
103
+ [source,adoc]
104
+ ----
105
+ :lutaml-xmi-index: first-xmi-index; /path/to/first.xmi
106
+
107
+ [lutaml_xmi_uml,index=first-xmi-index]
108
+ --
109
+ ...
110
+ --
111
+ ----
112
+
113
+ The command `lutaml_xmi_uml` will load the XMI file from the path
114
+ `/path/to/first.xmi` which is specified by the `index`: `first-xmi-index`.
115
+ ====
116
+
117
+ === Advanced example usage of `lutaml_xmi_uml` command
118
+
119
+ The following is an advanced example of using the `lutaml_xmi_uml` command
120
+ with a configuration file and custom Liquid templates to render a UML class
121
+ table.
122
+
123
+ [example]
124
+ .Advanced example usage of `lutaml_xmi_uml` command
125
+ ====
126
+
127
+ Assume you have the following configuration file `config.yml`:
128
+
129
+ [source,yaml]
130
+ ----
131
+ ea_extension:
132
+ - "ISO19103MDG v1.0.0-beta.xml"
133
+ - "CityGML_MDG_Technology.xml"
134
+ context_name: my_uml_document
135
+ template_path: "path/to/my_liquid_templates"
136
+ ----
137
+
138
+ And the following Liquid template `_klass.liquid` in the directory
139
+ `path/to/my_liquid_templates`:
140
+
141
+ [source,liquid]
142
+ ----
143
+ [cols="1a,1a,1a,2a"]
144
+ |===
145
+ | Name of Class 3+| {{ klass.name }}
146
+ | Definition 3+| {{ klass.definition }}
147
+ |===
148
+
149
+ {% render "attributes", attributes: klass.attributes %}
150
+ ----
151
+
152
+ And the following Liquid template `_attributes.liquid` in the directory
153
+ `path/to/my_liquid_templates`:
154
+
155
+ [source,liquid]
156
+ ----
157
+ [cols="1a,1a,1a,2a"]
158
+ |===
159
+ 4+| Attributes
160
+ | Name | Type | Multiplicity | Definition
161
+ {% for attr in attributes %}
162
+ | {{ attr.name }}
163
+ | {{ attr.type }}
164
+ | {{ attr.cardinality.min }}..{{ attr.cardinality.max }}
165
+ | {{ attr.definition }}
166
+ {% endfor %}
167
+ |===
168
+ ----
169
+
170
+ You can use the command to render a specific class
171
+ `RootPackage::MySubPackage::MyClass` by liquid filters:
172
+
173
+ [source,adoc]
174
+ ----
175
+ [lutaml_xmi_uml,example.xmi,config.yml]
176
+ --
177
+ Name of the Lutaml UML Document: {{ my_uml_document.name }}
178
+
179
+ {% assign root_package = my_uml_document.packages.first %}
180
+
181
+ {% assign sub_package = root_package.packages | where: "name", "MySubPackage" | first %}
182
+
183
+ {% assign klass = sub_package.classes | where: "name", "MyClass" | first %}
184
+
185
+ {% render "klass", klass: klass %}
186
+ ----
187
+
188
+ The output will be a formatted table of the class `MyClass` with its attributes
189
+ looks like:
190
+
191
+ [source]
192
+ ----
193
+ Name of the Lutaml UML Document: `My document`
194
+
195
+ --------------------------------------------------
196
+ | Name of Class | MyClass |
197
+ --------------------------------------------------
198
+ | Definition | My class definition |
199
+ --------------------------------------------------
200
+
201
+ --------------------------------------------------
202
+ | Attributes |
203
+ --------------------------------------------------
204
+ | Name | Type | Multiplicity | Definition |
205
+ --------------------------------------------------
206
+ | Attribute1 | Type1 | 0..* | Def1 |
207
+ --------------------------------------------------
208
+ | Attribute2 | Type2 | 0..1 | Def2 |
209
+ --------------------------------------------------
210
+ | Attribute3 | Type3 | 1..* | Def3 |
211
+ --------------------------------------------------
212
+ ----
213
+ ====
@@ -17,6 +17,7 @@ module Metanorma
17
17
  attribute :render_nested_packages, :boolean
18
18
  attribute :external_classes, :hash
19
19
  attribute :skip_unrecognized_connector, :boolean
20
+ attribute :context_name, :string
20
21
 
21
22
  yaml do
22
23
  map "packages", to: :packages,
@@ -34,6 +35,7 @@ module Metanorma
34
35
  map "render_nested_packages", to: :render_nested_packages
35
36
  map "external_classes", to: :external_classes
36
37
  map "skip_unrecognized_connector", to: :skip_unrecognized_connector
38
+ map "context_name", to: :context_name
37
39
  end
38
40
 
39
41
  def packages_from_yaml(model, values) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
@@ -244,15 +244,21 @@ module Metanorma
244
244
  .merge(children_pks_diags)
245
245
  end
246
246
 
247
- def collect_additional_context(document, input_lines, end_mark) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
248
- additional_context = Hash.new { |hash, key| hash[key] = [] }
249
- additional_context["all_macros"] = []
247
+ def collect_block_lines(input_lines, end_mark)
250
248
  block_lines = []
251
249
 
252
250
  while (block_line = input_lines.next) != end_mark
253
251
  block_lines.push(block_line)
254
252
  end
255
253
 
254
+ block_lines
255
+ end
256
+
257
+ def collect_additional_context(document, input_lines, end_mark) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
258
+ additional_context = Hash.new { |hash, key| hash[key] = [] }
259
+ additional_context["all_macros"] = []
260
+ block_lines = collect_block_lines(input_lines, end_mark)
261
+
256
262
  processed_lines = process(
257
263
  document,
258
264
  ::Asciidoctor::PreprocessorReader.new(document, block_lines),
@@ -0,0 +1,71 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "liquid"
4
+ require "asciidoctor"
5
+ require "asciidoctor/reader"
6
+ require "lutaml"
7
+ require_relative "utils"
8
+ require "metanorma/plugin/lutaml/asciidoctor/preprocessor"
9
+ require "metanorma/plugin/lutaml/lutaml_ea_xmi_base"
10
+
11
+ module Metanorma
12
+ module Plugin
13
+ module Lutaml
14
+ # Macro for rendering Lutaml::Uml models which are parsing from XMI file
15
+ class LutamlXmiUmlPreprocessor < ::Asciidoctor::Extensions::Preprocessor
16
+ include LutamlEaXmiBase
17
+
18
+ MACRO_REGEXP = /\[lutaml_xmi_uml,([^,]+),?(.+)?\]/.freeze
19
+
20
+ private
21
+
22
+ def parse_result_document(full_path, _guidance)
23
+ ::Lutaml::XMI::Parsers::XML.parse(
24
+ File.new(full_path, encoding: "UTF-8"),
25
+ )
26
+ end
27
+
28
+ def process_text_blocks(document, input_lines) # rubocop:disable Metrics/MethodLength,Metrics/AbcSize
29
+ line = input_lines.next
30
+ process_xmi_index_lines(document, line)
31
+ block_match = line.match(get_macro_regexp)
32
+
33
+ return [line] if block_match.nil?
34
+
35
+ config_yaml_path = block_match[2]&.strip
36
+ xmi_or_index = block_match[1]&.strip
37
+
38
+ lutaml_document, yaml_config = load_lutaml_doc_and_config(
39
+ document,
40
+ xmi_or_index,
41
+ config_yaml_path,
42
+ )
43
+
44
+ block_lines = collect_block_lines(input_lines, input_lines.next)
45
+
46
+ render_result, errors = Utils.render_liquid_string(
47
+ template_string: block_lines.join("\n"),
48
+ contexts: create_default_context_object(
49
+ lutaml_document, yaml_config
50
+ ),
51
+ document: document,
52
+ include_path: template_path(document, yaml_config.template_path),
53
+ )
54
+ Utils.notify_render_errors(document, errors)
55
+
56
+ render_result.split("\n")
57
+ end
58
+
59
+ def create_default_context_object(uml_document, options)
60
+ context_name = "context"
61
+ if options.context_name
62
+ context_name = options.context_name
63
+ end
64
+ contexts = {}
65
+ contexts[context_name] = uml_document.to_liquid
66
+ contexts
67
+ end
68
+ end
69
+ end
70
+ end
71
+ end
@@ -39,8 +39,8 @@ module Metanorma
39
39
  end
40
40
 
41
41
  def render_liquid_string( # rubocop:disable Metrics/MethodLength,Metrics/AbcSize
42
- template_string:, contexts:, document:,
43
- include_path: nil, template_path: nil
42
+ contexts:, document:,
43
+ template_string: nil, include_path: nil, template_path: nil
44
44
  )
45
45
  # Allow includes for the template
46
46
  include_paths = [
@@ -1,7 +1,7 @@
1
1
  module Metanorma
2
2
  module Plugin
3
3
  module Lutaml
4
- VERSION = "0.7.36".freeze
4
+ VERSION = "0.7.37".freeze
5
5
  end
6
6
  end
7
7
  end
@@ -6,6 +6,7 @@ require "metanorma/plugin/lutaml/data2_text_preprocessor"
6
6
  require "metanorma/plugin/lutaml/lutaml_preprocessor"
7
7
  require "metanorma/plugin/lutaml/lutaml_uml_datamodel_description_preprocessor"
8
8
  require "metanorma/plugin/lutaml/lutaml_ea_xmi_preprocessor"
9
+ require "metanorma/plugin/lutaml/lutaml_xmi_uml_preprocessor"
9
10
  require "metanorma/plugin/lutaml/lutaml_diagram_block"
10
11
  require "metanorma/plugin/lutaml/lutaml_diagram_block_macro"
11
12
  require "metanorma/plugin/lutaml/lutaml_figure_inline_macro"
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.36
4
+ version: 0.7.37
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-08-15 00:00:00.000000000 Z
11
+ date: 2025-10-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: asciidoctor
@@ -146,6 +146,7 @@ files:
146
146
  - docs/usages/json_yaml.adoc
147
147
  - docs/usages/lutaml-gml.adoc
148
148
  - docs/usages/lutaml-uml.adoc
149
+ - docs/usages/xmi_to_uml.adoc
149
150
  - lib/metanorma-plugin-lutaml.rb
150
151
  - lib/metanorma/plugin/lutaml/asciidoctor/preprocessor.rb
151
152
  - lib/metanorma/plugin/lutaml/base_structured_text_preprocessor.rb
@@ -197,6 +198,7 @@ files:
197
198
  - lib/metanorma/plugin/lutaml/lutaml_preprocessor.rb
198
199
  - lib/metanorma/plugin/lutaml/lutaml_table_inline_macro.rb
199
200
  - lib/metanorma/plugin/lutaml/lutaml_uml_datamodel_description_preprocessor.rb
201
+ - lib/metanorma/plugin/lutaml/lutaml_xmi_uml_preprocessor.rb
200
202
  - lib/metanorma/plugin/lutaml/parse_error.rb
201
203
  - lib/metanorma/plugin/lutaml/source_extractor.rb
202
204
  - lib/metanorma/plugin/lutaml/utils.rb