metanorma-plugin-lutaml 0.7.1 → 0.7.2

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: 6e0301e71943b66bb50f4fee26b345b9146762beab3c65603a9c05f9a42cbcac
4
- data.tar.gz: 34158f6f955d044c1ff8a01f1d4ab8844b39b870bc6439a1bfbc0af4be0c9321
3
+ metadata.gz: d134d7bb5546dc1d21dabdd8a0611fce32830f4d7942b00f1f8aaf63e40b9eb9
4
+ data.tar.gz: bb71ead1f2a50bb83908a380cea9f1fb080a57a2205d97271bb902479c093cae
5
5
  SHA512:
6
- metadata.gz: f27aceca1cd9b9136afd7ba7e5dca7e862b9ae88312bf2ae8f450783128194fd16d8e7358649023531e42d9982938a33f52ebd3dd699274a95b9b0d15d7057df
7
- data.tar.gz: fc3a3a2e78f283a4803b5af7485885e3e14d9c4769b05257e4cc2804cb62a05ddccceeaec275eec2338a9d990c712587853274cdb9149e211a47a8eb3a2e9aa2
6
+ metadata.gz: 2a38a30e6d4c2ef401f224a0f295f43755ed0192d6bd6871ca27e6de3ea67ca0495f054bf8376f558ed0bd22463cdae2c5701f1b169221b49b54374aacec6d77
7
+ data.tar.gz: a8d3633c7bc481a3063dc2a31fc3d39c783380eea51089b9675487efb7de718b77837f3402b9dea545195d4fe96c5b1806ecae5978fc65a5905ab6ba27fc8500
data/Gemfile CHANGED
@@ -6,4 +6,10 @@ git_source(:github) { |repo| "https://github.com/#{repo}" }
6
6
 
7
7
  gemspec
8
8
 
9
- eval_gemfile("Gemfile.devel") rescue nil
9
+ begin
10
+ eval_gemfile("Gemfile.devel")
11
+ rescue StandardError
12
+ nil
13
+ end
14
+
15
+ gem "ogc-gml", github: "lutaml/ogc-gml"
data/README.adoc CHANGED
@@ -273,6 +273,97 @@ diagram MyView {
273
273
  ....
274
274
  ----
275
275
 
276
+ === Rendering a LutaML Enterprise Architect diagram from XMI: `lutaml_ea_diagram`
277
+
278
+ This command allows to quickly render a LutaML diagram as an image file by
279
+ specifying the name of diagram.
280
+
281
+ [source,adoc]
282
+ -----
283
+ lutaml_ea_diagram::[name="name_of_diagram",base_path="/path/to/xmi-images",format="png"]
284
+ -----
285
+
286
+ The code will search the diagram with name `name_of_diagram` and then
287
+ render it as:
288
+
289
+ [source,adoc]
290
+ -----
291
+ [[figure-{{ diagram.xmi_id }}]]
292
+ .{{ diagram.name }}
293
+ image::{{ image_base_path }}/{{ diagram.xmi_id }}.{{ format | default: 'png' }}[]
294
+ -----
295
+
296
+ === Rendering a LutaML GML Dictionary: `lutaml_gml_dictionary`
297
+
298
+ This command allows to render a LutaML GML Dictionary by using Liquid Drop.
299
+
300
+ GmlDictionaryDrop has the following attributes:
301
+
302
+ * name
303
+ * file_name
304
+ * dictionary_entry
305
+
306
+ Each `dictionary_entry` has the following attributes:
307
+
308
+ * name
309
+ * description
310
+
311
+ [source,adoc]
312
+ -----
313
+ lutaml_gml_dictionary::/path/to/dictionary.xml[template="/path/to/template.liquid",context=dict]
314
+ -----
315
+
316
+ The command accepts the options listed below:
317
+
318
+ * `"/path/to/dictionary.xml` specifies the path of xml file of the
319
+ GML Dictionary.
320
+
321
+ * `template="/path/to/template.liquid"` specifies the liquid template.
322
+ For example, you can create a liquid template and link it by `template`.
323
+
324
+ * `context=dict` define the context in the template.
325
+
326
+ [source,adoc]
327
+ -----
328
+ [cols="3a,22a"]
329
+ |===
330
+ | Name | {{ dict.file_name }}
331
+
332
+ h| Code h| Description
333
+ {% for entry in dict.dictionary_entry %}
334
+ | {{ entry.name }} | {{ entry.description }}
335
+ {% endfor %}
336
+ |===
337
+
338
+ [.source]
339
+ <<source_link>>
340
+ -----
341
+
342
+ In spite of specifying the path of the template, you can also define an inline
343
+ template within a block by
344
+ `[lutaml_gml_dictionary,"/path/to/dictionary.xml",context=dict]`.
345
+
346
+ [source,adoc]
347
+ -----
348
+ [lutaml_gml_dictionary,"/path/to/dictionary.xml",context=dict]
349
+ --
350
+ {% capture link %}https://www.test.com/{{ dict.file_name }}{% endcapture %}
351
+
352
+ [cols="3a,22a"]
353
+ |===
354
+ | File Name | {{ dict.file_name }}
355
+ h| URL | {{ link }}
356
+ h| Help | Description
357
+ {% for entry in dict.dictionary_entry %}
358
+ | {{ entry.name }} | {{ entry.description }}
359
+ {% endfor %}
360
+ |===
361
+
362
+ [.source]
363
+ <<source_link>>
364
+ --
365
+ -----
366
+
276
367
  === Generating UML class and attributes: `lutaml_uml_class`
277
368
 
278
369
  This command allows rendering a definition clause for a UML class.
@@ -490,7 +581,7 @@ Where:
490
581
 
491
582
  * `[.after, package="Another"]` - block text to be inserted before(after in case of `.before` name) the package
492
583
 
493
- * `[.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.
584
+ * `[.package_text, position="after", package="Another"]` - include custom adoc code into package rendered body, `position` is a a required attribute which tells where to insert the code.
494
585
 
495
586
  * `[.package_text, package="Another"]` - same as above, but include block will be included only for supplied package name
496
587
 
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "ogc/gml/dictionary"
4
+
5
+ class GmlDictionaryDrop < Liquid::Drop
6
+ def initialize(dict) # rubocop:disable Lint/MissingSuper
7
+ @dict = dict
8
+ end
9
+
10
+ def name
11
+ @dict.name.join("")
12
+ end
13
+
14
+ def file_name
15
+ "#{name}.xml"
16
+ end
17
+
18
+ def dictionary_entry
19
+ @dict.dictionary_entry.map do |entry|
20
+ GmlDictionaryEntryDrop.new(entry)
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "ogc/gml/dictionary"
4
+
5
+ class GmlDictionaryEntryDrop < Liquid::Drop
6
+ def initialize(dict_entry) # rubocop:disable Lint/MissingSuper
7
+ @dict_entry = dict_entry
8
+ end
9
+
10
+ def name
11
+ @dict_entry.definition.name.first.content
12
+ end
13
+
14
+ def description
15
+ @dict_entry.definition.description
16
+ end
17
+ end
@@ -3,7 +3,7 @@
3
3
  {% elsif is_klass_spare == 'Spare' %}{% continue %}
4
4
  {% endif %}
5
5
  {% assign klass_name = klass.name | downcase | replace: ':', '' | replace: ' ', '_' %}
6
- [[section-{{ klass.xmi_id }}]]
6
+ [[section-{{ klass.type }}-{{ klass.xmi_id }}]]
7
7
  .Elements of &#8220;{{ package.name }}::{{ klass.name }}&#8221; ({{ klass.stereotype }})
8
8
  [width="100%",cols="a,a,a,a,a,a,a,a"]
9
9
  |===
@@ -0,0 +1,56 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "metanorma/plugin/lutaml/lutaml_diagram_base"
4
+
5
+ module Metanorma
6
+ module Plugin
7
+ module Lutaml
8
+ class LutamlEaDiagramBlockMacro < ::Asciidoctor::Extensions::BlockMacroProcessor
9
+ include LutamlDiagramBase
10
+
11
+ use_dsl
12
+ named :lutaml_ea_diagram
13
+
14
+ def process(parent, _target, attrs)
15
+ orig_doc = parent.document.attributes["lutaml_xmi_cache"]
16
+ .values.first.original_document
17
+ diagram = fetch_diagram_by_name(orig_doc, attrs["name"])
18
+ return if diagram.nil?
19
+
20
+ through_attrs = generate_attrs(attrs)
21
+ through_attrs["target"] =
22
+ img_src_path(parent.document, attrs, diagram)
23
+ through_attrs["title"] = diagram.name
24
+
25
+ create_image_block(parent, through_attrs)
26
+ end
27
+
28
+ private
29
+
30
+ def img_src_path(document, attrs, diagram)
31
+ base_path = attrs["base_path"]
32
+ format = attrs["format"] || "png"
33
+ img_path = Utils.relative_file_path(document, base_path)
34
+
35
+ "#{img_path}/#{diagram.xmi_id}.#{format}"
36
+ end
37
+
38
+ def fetch_diagram_by_name(orig_doc, name)
39
+ found_diagrams = []
40
+ loop_sub_packages(orig_doc.packages.first, name, found_diagrams)
41
+ found_diagrams.first
42
+ end
43
+
44
+ def loop_sub_packages(package, name, found_diagrams)
45
+ found_diagram = package.diagrams.find { |diag| diag.name == name }
46
+
47
+ found_diagrams << found_diagram if found_diagram
48
+
49
+ package.packages.each do |sub_package|
50
+ loop_sub_packages(sub_package, name, found_diagrams)
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "ogc/gml/dictionary"
4
+ require "liquid"
5
+ require_relative "liquid_drops/gml_dictionary_drop"
6
+ require_relative "liquid_drops/gml_dictionary_entry_drop"
7
+
8
+ module Metanorma
9
+ module Plugin
10
+ module Lutaml
11
+ module LutamlGmlDictionaryBase
12
+ private
13
+
14
+ def render(tmpl, parent, attrs, orig_gml_path)
15
+ dict = get_gml_dictionary(parent, orig_gml_path)
16
+ tmpl.assigns[attrs["context"]] = GmlDictionaryDrop.new(dict)
17
+ rendered_tmpl = tmpl.render
18
+ block = create_open_block(parent, "", attrs)
19
+ parse_content(block, rendered_tmpl, attrs)
20
+ end
21
+
22
+ def get_gml_dictionary(parent, orig_gml_path)
23
+ gml_path = Utils.relative_file_path(
24
+ parent.document, orig_gml_path
25
+ )
26
+ Ogc::Gml::Dictionary.from_xml(xml_content(gml_path))
27
+ end
28
+
29
+ def xml_content(filepath)
30
+ File.read(filepath).gsub(
31
+ 'xmlns:gml="http://www.opengis.net/gml"',
32
+ 'xmlns:gml="http://www.opengis.net/gml/3.2"',
33
+ )
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Metanorma
4
+ module Plugin
5
+ module Lutaml
6
+ class LutamlGmlDictionaryBlock < ::Asciidoctor::Extensions::BlockProcessor
7
+ include LutamlGmlDictionaryBase
8
+ use_dsl
9
+ named :lutaml_gml_dictionary
10
+ on_context :open
11
+ parse_content_as :raw
12
+
13
+ def process(parent, reader, attrs)
14
+ lines = reader.lines
15
+ tmpl = ::Liquid::Template.parse(lines.join("\n"))
16
+ render(tmpl, parent, attrs, attrs[2])
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Metanorma
4
+ module Plugin
5
+ module Lutaml
6
+ class LutamlGmlDictionaryBlockMacro < ::Asciidoctor::Extensions::BlockMacroProcessor
7
+ include LutamlGmlDictionaryBase
8
+ use_dsl
9
+ named :lutaml_gml_dictionary
10
+
11
+ def process(parent, target, attrs)
12
+ tmpl = gml_dictionary_template(
13
+ parent.document,
14
+ attrs["template"],
15
+ )
16
+
17
+ render(tmpl, parent, attrs, target)
18
+ end
19
+
20
+ private
21
+
22
+ def gml_dictionary_template(document, template_path)
23
+ if template_path.nil?
24
+ document.logger.warn("Template not found!")
25
+ end
26
+
27
+ rel_tmpl_path = Utils.relative_file_path(
28
+ document, template_path
29
+ )
30
+
31
+ ::Liquid::Template.parse(File.read(rel_tmpl_path))
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -52,10 +52,11 @@ module Metanorma
52
52
  return document.attributes["lutaml_xmi_cache"][full_path]
53
53
  end
54
54
 
55
- if yaml_config["ea_extension"] && !yaml_config["ea_extension"].empty?
56
- ea_extension_path = yaml_config["ea_extension"].first
57
- ea_extension_full_path = Utils.relative_file_path(document, ea_extension_path)
58
- Xmi::EaRoot.load_mdg_extension(ea_extension_full_path)
55
+ yaml_config["ea_extension"]&.each do |ea_extension_path|
56
+ ea_extension_full_path = File.expand_path(
57
+ ea_extension_path, File.dirname(file_path)
58
+ )
59
+ Xmi::EaRoot.load_extension(ea_extension_full_path)
59
60
  end
60
61
 
61
62
  result_document = ::Lutaml::Parser
@@ -204,6 +205,8 @@ options)
204
205
  "additional_context" => additional_context
205
206
  .merge("external_classes" => options["external_classes"]),
206
207
  "root_packages" => [root_package],
208
+ "render_nested_packages" => options["render_nested_packages"] ||
209
+ false,
207
210
  "name" => root_package["name"],
208
211
  }
209
212
  end
@@ -1,7 +1,7 @@
1
1
  module Metanorma
2
2
  module Plugin
3
3
  module Lutaml
4
- VERSION = "0.7.1".freeze
4
+ VERSION = "0.7.2".freeze
5
5
  end
6
6
  end
7
7
  end
@@ -7,6 +7,10 @@ require "metanorma/plugin/lutaml/lutaml_diagram_block"
7
7
  require "metanorma/plugin/lutaml/lutaml_diagram_block_macro"
8
8
  require "metanorma/plugin/lutaml/lutaml_figure_inline_macro"
9
9
  require "metanorma/plugin/lutaml/lutaml_table_inline_macro"
10
+ require "metanorma/plugin/lutaml/lutaml_ea_diagram_block_macro"
11
+ require "metanorma/plugin/lutaml/lutaml_gml_dictionary_base"
12
+ require "metanorma/plugin/lutaml/lutaml_gml_dictionary_block_macro"
13
+ require "metanorma/plugin/lutaml/lutaml_gml_dictionary_block"
10
14
 
11
15
  module Metanorma
12
16
  module Plugin
@@ -29,7 +29,7 @@ Gem::Specification.new do |spec|
29
29
  spec.add_dependency "coradoc"
30
30
  spec.add_dependency "expressir", "~> 1.4.0"
31
31
  spec.add_dependency "liquid"
32
- spec.add_dependency "lutaml"
32
+ spec.add_dependency "lutaml", ">= 0.9.4"
33
33
  spec.add_dependency "relaton-cli"
34
34
 
35
35
  spec.add_development_dependency "debug"
@@ -37,7 +37,9 @@ Gem::Specification.new do |spec|
37
37
  spec.add_development_dependency "metanorma-standoc"
38
38
  spec.add_development_dependency "rake", "~> 13"
39
39
  spec.add_development_dependency "rspec", "~> 3.6"
40
- spec.add_development_dependency "rubocop", "= 0.54.0"
40
+ spec.add_development_dependency "rspec-html-matchers"
41
+ spec.add_development_dependency "rubocop", "~> 1.58"
42
+ spec.add_development_dependency "rubocop-performance", "~> 1.19"
41
43
  spec.add_development_dependency "simplecov", "~> 0.15"
42
44
  spec.add_development_dependency "timecop", "~> 0.9"
43
45
  spec.add_development_dependency "vcr", "~> 5.0.0"
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.1
4
+ version: 0.7.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-07-23 00:00:00.000000000 Z
11
+ date: 2024-08-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: asciidoctor
@@ -72,14 +72,14 @@ dependencies:
72
72
  requirements:
73
73
  - - ">="
74
74
  - !ruby/object:Gem::Version
75
- version: '0'
75
+ version: 0.9.4
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
- version: '0'
82
+ version: 0.9.4
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: relaton-cli
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -164,20 +164,48 @@ dependencies:
164
164
  - - "~>"
165
165
  - !ruby/object:Gem::Version
166
166
  version: '3.6'
167
+ - !ruby/object:Gem::Dependency
168
+ name: rspec-html-matchers
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ">="
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
167
181
  - !ruby/object:Gem::Dependency
168
182
  name: rubocop
169
183
  requirement: !ruby/object:Gem::Requirement
170
184
  requirements:
171
- - - '='
185
+ - - "~>"
186
+ - !ruby/object:Gem::Version
187
+ version: '1.58'
188
+ type: :development
189
+ prerelease: false
190
+ version_requirements: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - "~>"
193
+ - !ruby/object:Gem::Version
194
+ version: '1.58'
195
+ - !ruby/object:Gem::Dependency
196
+ name: rubocop-performance
197
+ requirement: !ruby/object:Gem::Requirement
198
+ requirements:
199
+ - - "~>"
172
200
  - !ruby/object:Gem::Version
173
- version: 0.54.0
201
+ version: '1.19'
174
202
  type: :development
175
203
  prerelease: false
176
204
  version_requirements: !ruby/object:Gem::Requirement
177
205
  requirements:
178
- - - '='
206
+ - - "~>"
179
207
  - !ruby/object:Gem::Version
180
- version: 0.54.0
208
+ version: '1.19'
181
209
  - !ruby/object:Gem::Dependency
182
210
  name: simplecov
183
211
  requirement: !ruby/object:Gem::Requirement
@@ -274,6 +302,8 @@ files:
274
302
  - lib/metanorma/plugin/lutaml/express_remarks_decorator.rb
275
303
  - lib/metanorma/plugin/lutaml/liquid/custom_filters.rb
276
304
  - lib/metanorma/plugin/lutaml/liquid/multiply_local_file_system.rb
305
+ - lib/metanorma/plugin/lutaml/liquid_drops/gml_dictionary_drop.rb
306
+ - lib/metanorma/plugin/lutaml/liquid_drops/gml_dictionary_entry_drop.rb
277
307
  - lib/metanorma/plugin/lutaml/liquid_templates/_diagrams_block.liquid
278
308
  - lib/metanorma/plugin/lutaml/liquid_templates/_packages.liquid
279
309
  - lib/metanorma/plugin/lutaml/liquid_templates/_packages_class.liquid
@@ -289,7 +319,11 @@ files:
289
319
  - lib/metanorma/plugin/lutaml/lutaml_diagram_base.rb
290
320
  - lib/metanorma/plugin/lutaml/lutaml_diagram_block.rb
291
321
  - lib/metanorma/plugin/lutaml/lutaml_diagram_block_macro.rb
322
+ - lib/metanorma/plugin/lutaml/lutaml_ea_diagram_block_macro.rb
292
323
  - lib/metanorma/plugin/lutaml/lutaml_figure_inline_macro.rb
324
+ - lib/metanorma/plugin/lutaml/lutaml_gml_dictionary_base.rb
325
+ - lib/metanorma/plugin/lutaml/lutaml_gml_dictionary_block.rb
326
+ - lib/metanorma/plugin/lutaml/lutaml_gml_dictionary_block_macro.rb
293
327
  - lib/metanorma/plugin/lutaml/lutaml_preprocessor.rb
294
328
  - lib/metanorma/plugin/lutaml/lutaml_table_inline_macro.rb
295
329
  - lib/metanorma/plugin/lutaml/lutaml_uml_attributes_table_preprocessor.rb