metanorma-plugin-lutaml 0.4.15 → 0.4.17

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: ac83fb068848793194a604aa3da4a32bd1ee9cdc8a71bb1715fe2f44b230fded
4
- data.tar.gz: 4b818c299336493cd3c1134165c1dacbef645ed648cc08322974ce5fb8678ccd
3
+ metadata.gz: b9de85f722161434bc11ef77517f1e739db67b01608aead2e935b8a38ff6594d
4
+ data.tar.gz: bf10f9594b2cf84b594c1dba9012e9979f1c3b3fd0339892f7302882039f7a9e
5
5
  SHA512:
6
- metadata.gz: bc4635a30a4715c1adcc9fed82a76d7258646d435079bbb1003ce1ebc41edf980a66d77429a42111068fcfc106cb3dc9a872eaa00780dc07c13664d94dc62731
7
- data.tar.gz: 7634e9dfafe63910b9a3b0e6c29b29db6ca894d3f71612db60e1b5c97913db116c95a624cbba6181ce55cd24acf2a84766868b017be3907b9b8eef0396a297c9
6
+ metadata.gz: e6125065c5246f84dee92b5894f0ffb5353c55cc1b8fc3e5355e738096b4db1b005a9ef5913070c6d2130cff77338c0913e3d8ba8bb93ef7a619415cfe2ae6a8
7
+ data.tar.gz: a77a4b168701ea0a425fd6bdf9cff83195926c16ff1be07db7bbb775e7d43d29a74d7754e9e43aeda508a16bd0d5096aee84c1dca5e1c4fa949de617cf5781a9
data/README.adoc CHANGED
@@ -212,6 +212,80 @@ diagram MyView {
212
212
  ....
213
213
  ----
214
214
 
215
+ === Generating UML class and attributes: `lutaml_uml_class`
216
+
217
+ This command allows rendering a definition clause for a UML class.
218
+
219
+ Given `example.lutaml` with this content:
220
+
221
+ [source,java]
222
+ ----
223
+ class Register {
224
+ definition {
225
+ A register of information.
226
+ }
227
+
228
+ identifier: String[1] {
229
+ definition {
230
+ Unique identifier of the register.
231
+ }
232
+ }
233
+
234
+ concepts: Concept[0..*] {
235
+ definition {
236
+ Concepts.
237
+ }
238
+ }
239
+ }
240
+ ----
241
+
242
+ The command:
243
+
244
+ [source,adoc]
245
+ ----
246
+ [lutaml_uml_class,views/Register_Register.lutaml,Register]
247
+ ----
248
+
249
+ Will produce this output:
250
+
251
+ ____
252
+ == Register
253
+
254
+ A register of information.
255
+
256
+ === Attributes
257
+
258
+ ==== identifier
259
+
260
+ Unique identifier of the register.
261
+
262
+ .Specification of `Register.identifier`
263
+ |===
264
+ h|Value type and multiplicity | `String [1]`
265
+ |===
266
+
267
+ ==== concepts
268
+
269
+ Concepts.
270
+
271
+ .Specification of `Register.concepts`
272
+ |===
273
+ h|Value type and multiplicity | `Concepts [0..*]`
274
+ |===
275
+
276
+ ____
277
+
278
+ The command accepts two options:
279
+
280
+ * `skip_headers=true` (or just `skip_headers`). The initial heading (the UML class name)
281
+ will not be generated. This is useful if additional content is to be supplied
282
+ to the clause, such as diagrams that are defined outside the UML model.
283
+
284
+ * `depth={n}`. (default: `2`) This determines the depth of the generated headings.
285
+ A depth of `2` means the initial heading will have 2 equal signs, and so forth.
286
+ The heading depth of the attributes are in relation to the initial depth, so
287
+ a depth of `2` will have the "Attributes" section at depth `3`.
288
+
215
289
 
216
290
  === `lutaml_uml_attributes_table`
217
291
 
@@ -101,7 +101,7 @@
101
101
  |===
102
102
  {% endunless %}
103
103
 
104
- {% assign non_unions = package.data_types | where: "stereotype", "DataType" %}
104
+ {% assign non_unions = package.data_types | where: "stereotype", "DataType" %}
105
105
  {% if non_unions.size > 0 %}
106
106
  {% include "packages_entity_list_classes", classes: non_unions, type: "Data types", depth: nested_depth %}
107
107
  {% endif %}
@@ -5,7 +5,6 @@ require "asciidoctor"
5
5
  require "asciidoctor/reader"
6
6
  require "lutaml"
7
7
  require "metanorma/plugin/lutaml/utils"
8
- require "metanorma/plugin/lutaml/utils"
9
8
  require "metanorma/plugin/lutaml/express_remarks_decorator"
10
9
 
11
10
  module Metanorma
@@ -17,7 +17,7 @@ module Metanorma
17
17
  xmi_id = parent.document.attributes['lutaml_entity_id'][entity_key]
18
18
  return unless xmi_id
19
19
 
20
- %Q(<xref target="section-#{xmi_id}"></xref>)
20
+ %Q(<xref target="section-#{xmi_id}"/>)
21
21
  end
22
22
  end
23
23
  end
@@ -1,75 +1,20 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "liquid"
4
- require "asciidoctor"
5
- require "asciidoctor/reader"
6
- require "lutaml"
7
- require "lutaml/uml"
8
- require "metanorma/plugin/lutaml/utils"
3
+ require_relative "./lutaml_uml_class_preprocessor.rb"
9
4
 
10
5
  module Metanorma
11
6
  module Plugin
12
7
  module Lutaml
13
8
  # Macro for quick rendering of datamodel attributes/values table
14
9
  # @example [lutaml_uml_attributes_table,path/to/lutaml,EntityName]
15
- class LutamlUmlAttributesTablePreprocessor < Asciidoctor::Extensions::Preprocessor
16
- MARCO_REGEXP =
10
+ class LutamlUmlAttributesTablePreprocessor < LutamlUmlClassPreprocessor
11
+ MACRO_REGEXP =
17
12
  /\[lutaml_uml_attributes_table,([^,]+),?([^,]+),?(.+?)?\]/
18
- # search document for block `datamodel_attributes_table`
19
- # read include derectives that goes after that in block and transform
20
- # into yaml2text blocks
21
- def process(document, reader)
22
- input_lines = reader.readlines.to_enum
23
- Asciidoctor::Reader.new(processed_lines(document, input_lines))
24
- end
25
-
26
- private
27
-
28
- def lutaml_document_from_file(document, file_path)
29
- ::Lutaml::Parser
30
- .parse(File.new(Utils.relative_file_path(document, file_path),
31
- encoding: "UTF-8"))
32
- .first
33
- end
34
-
35
- def processed_lines(document, input_lines)
36
- input_lines.each_with_object([]) do |line, result|
37
- if match = line.match(MARCO_REGEXP)
38
- lutaml_path = match[1]
39
- entity_name = match[2]
40
- skip_headers = match[3]
41
- result.push(*parse_marco(lutaml_path, entity_name, document, skip_headers))
42
- else
43
- result.push(line)
44
- end
45
- end
46
- end
47
-
48
- def parse_marco(lutaml_path, entity_name, document, skip_headers)
49
- lutaml_document = lutaml_document_from_file(document, lutaml_path)
50
- .serialized_document
51
- entities = [lutaml_document["classes"], lutaml_document["enums"]]
52
- .compact
53
- .flatten
54
- entity_definition = entities.detect do |klass|
55
- klass["name"] == entity_name.strip
56
- end
57
- model_representation(entity_definition, document, skip_headers)
58
- end
59
-
60
- def model_representation(entity_definition, document, skip_headers)
61
- render_result, errors = Utils.render_liquid_string(
62
- template_string: table_template(skip_headers),
63
- context_items: entity_definition,
64
- context_name: "definition",
65
- document: document
66
- )
67
- Utils.notify_render_errors(document, errors)
68
- render_result.split("\n")
69
- end
70
13
 
71
14
  # rubocop:disable Layout/IndentHeredoc
72
- def table_template(skip_headers)
15
+ def template(options)
16
+ skip_headers = options[:skip_headers]
17
+
73
18
  <<~TEMPLATE
74
19
  #{"=== {{ definition.name }}" unless skip_headers}
75
20
  {{ definition.definition }}
@@ -100,6 +45,7 @@ module Metanorma
100
45
  end
101
46
  # rubocop:enable Layout/IndentHeredoc
102
47
  end
48
+
103
49
  end
104
50
  end
105
51
  end
@@ -0,0 +1,163 @@
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
+
10
+ module Metanorma
11
+ module Plugin
12
+ module Lutaml
13
+ # Macro for quick rendering of datamodel attributes/values table
14
+ # @example [lutaml_uml_class,path/to/lutaml,EntityName]
15
+ class LutamlUmlClassPreprocessor < Asciidoctor::Extensions::Preprocessor
16
+ MACRO_REGEXP =
17
+ /\[lutaml_uml_class,([^,]+),?([^,]+),?(.+?)?\]/
18
+
19
+ def get_macro_regexp
20
+ self.class.const_get(:MACRO_REGEXP)
21
+ end
22
+
23
+ # search document for block `datamodel_attributes_table`
24
+ # read include derectives that goes after that in block and transform
25
+ # into yaml2text blocks
26
+ def process(document, reader)
27
+ input_lines = reader.readlines.to_enum
28
+ Asciidoctor::Reader.new(processed_lines(document, input_lines))
29
+ end
30
+
31
+ private
32
+
33
+ def lutaml_document_from_file(document, file_path)
34
+ ::Lutaml::Parser.parse(
35
+ File.new(
36
+ Utils.relative_file_path(document, file_path),
37
+ encoding: "UTF-8")
38
+ ).first
39
+ end
40
+
41
+ DEFAULT_OPTIONS = {
42
+ depth: 2
43
+ }
44
+ def parse_options_to_hash(options_string)
45
+ return DEFAULT_OPTIONS.dup if options_string.nil? || options_string.empty?
46
+
47
+ opts = options_string.split(",").inject({}) do |acc,pair|
48
+ key, value = pair.split("=")
49
+ key = key.to_sym
50
+ value = true if value.nil?
51
+ value = value.to_i if key == :depth
52
+ acc[key] = value if key
53
+ acc
54
+ end
55
+
56
+ DEFAULT_OPTIONS.dup.merge(opts)
57
+ end
58
+
59
+ def processed_lines(document, input_lines)
60
+ input_lines.each_with_object([]) do |line, result|
61
+ if match = line.match(get_macro_regexp)
62
+ lutaml_path = match[1]
63
+ entity_name = match[2]
64
+ options = parse_options_to_hash(match[3])
65
+
66
+ result.push(*parse_marco(lutaml_path, entity_name, document, options))
67
+ else
68
+ result.push(line)
69
+ end
70
+ end
71
+ end
72
+
73
+ def parse_marco(lutaml_path, entity_name, document, options)
74
+ lutaml_document = lutaml_document_from_file(document, lutaml_path)
75
+ .serialized_document
76
+ entities = [lutaml_document["classes"], lutaml_document["enums"]]
77
+ .compact
78
+ .flatten
79
+ entity_definition = entities.detect do |klass|
80
+ klass["name"] == entity_name.strip
81
+ end
82
+ model_representation(entity_definition, document, options)
83
+ end
84
+
85
+ def model_representation(entity_definition, document, options)
86
+ render_result, errors = Utils.render_liquid_string(
87
+ template_string: template(options),
88
+ context_items: entity_definition,
89
+ context_name: "definition",
90
+ document: document
91
+ )
92
+ Utils.notify_render_errors(document, errors)
93
+ render_result.split("\n")
94
+ end
95
+
96
+ def equalsigns(depth)
97
+ "=" * depth
98
+ end
99
+
100
+ # rubocop:disable Layout/IndentHeredoc
101
+ def template(options)
102
+ skip_headers = options[:skip_headers]
103
+ depth = options[:depth]
104
+
105
+ <<~TEMPLATE
106
+ #{equalsigns(depth) + " {{ definition.name }}" unless skip_headers}
107
+ {{ definition.definition }}
108
+
109
+ {% if definition.attributes %}
110
+ {% if definition.keyword == 'enumeration' %}
111
+ .{{ definition.name }} values
112
+ |===
113
+ |Name |Definition
114
+
115
+ {% for item in definition.attributes %}
116
+ |{{ item.name }} |{{ item.definition }}
117
+ {% endfor %}
118
+ |===
119
+ {% else %}
120
+ #{equalsigns(depth+1)} Attributes
121
+
122
+ {% for item in definition.attributes %}
123
+ #{equalsigns(depth+2)} {{item.name}}
124
+
125
+ {% if item.definition %}
126
+ {{ item.definition }}
127
+ {% endif %}
128
+
129
+ .Specification of `{{ definition.name }}.{{ item.name }}`
130
+ [cols="h,a"]
131
+ |===
132
+
133
+ h|Value type and multiplicity
134
+ |
135
+ `{{ item.type }}`
136
+ {% if item.cardinality.min -%}
137
+ {% if item.cardinality.max -%}
138
+ `[{{item.cardinality.min}}..{{item.cardinality.max}}]`
139
+ {% else -%}
140
+ `[{{item.cardinality.min}}]`
141
+ {% endif -%}
142
+ {% else -%}
143
+ (multiplicity unspecified)
144
+ {% endif %}
145
+
146
+ {% if item.origin %}
147
+ h|Origin
148
+ |<<{{ item.origin }}>>
149
+ {% endif %}
150
+
151
+ |===
152
+ {% endfor %}
153
+
154
+ {% endif %}
155
+ {% endif %}
156
+
157
+ TEMPLATE
158
+ end
159
+ # rubocop:enable Layout/IndentHeredoc
160
+ end
161
+ end
162
+ end
163
+ end
@@ -14,7 +14,7 @@ module Metanorma
14
14
  # @example [lutaml_uml_attributes_table,path/to/lutaml,EntityName]
15
15
  class LutamlUmlDatamodelDescriptionPreprocessor <
16
16
  Asciidoctor::Extensions::Preprocessor
17
- MARCO_REGEXP =
17
+ MACRO_REGEXP =
18
18
  /\[lutaml_uml_datamodel_description,([^,]+),?(.+)?\]/
19
19
  LIQUID_INCLUDE_PATH = File.join(
20
20
  Gem.loaded_specs["metanorma-plugin-lutaml"].full_gem_path,
@@ -72,7 +72,7 @@ module Metanorma
72
72
 
73
73
  def process_text_blocks(document, input_lines)
74
74
  line = input_lines.next
75
- block_match = line.match(MARCO_REGEXP)
75
+ block_match = line.match(MACRO_REGEXP)
76
76
  return [line] if block_match.nil?
77
77
 
78
78
  lutaml_document = lutaml_document_from_file_or_cache(document, block_match[1])
@@ -232,7 +232,7 @@ module Metanorma
232
232
  def model_representation(lutaml_document, document, additional_context, options)
233
233
  fill_in_entities_refs_attributes(document, lutaml_document, options)
234
234
  render_result, errors = Utils.render_liquid_string(
235
- template_string: table_template(options['section_depth'] || 2, options['render_style'], options['include_root']),
235
+ template_string: template(options['section_depth'] || 2, options['render_style'], options['include_root']),
236
236
  context_items: create_context_object(lutaml_document,
237
237
  additional_context,
238
238
  options),
@@ -244,7 +244,7 @@ module Metanorma
244
244
  render_result.split("\n")
245
245
  end
246
246
 
247
- def table_template(section_depth, render_style, include_root)
247
+ def template(section_depth, render_style, include_root)
248
248
  include_name = RENDER_STYLES_INCLUDES.fetch(render_style, DEFAULT_RENDER_INCLUDE)
249
249
  result = ""
250
250
  if include_root
@@ -1,3 +1,5 @@
1
+ require "expressir"
2
+ require "expressir/express/parser"
1
3
  require "expressir/express/cache"
2
4
  require "metanorma/plugin/lutaml/liquid/custom_filters"
3
5
  require "metanorma/plugin/lutaml/liquid/multiply_local_file_system"
@@ -1,7 +1,7 @@
1
1
  module Metanorma
2
2
  module Plugin
3
3
  module Lutaml
4
- VERSION = "0.4.15".freeze
4
+ VERSION = "0.4.17".freeze
5
5
  end
6
6
  end
7
7
  end
@@ -1,5 +1,6 @@
1
1
  require "metanorma/plugin/lutaml/version"
2
2
  require "metanorma/plugin/lutaml/lutaml_preprocessor"
3
+ require "metanorma/plugin/lutaml/lutaml_uml_class_preprocessor"
3
4
  require "metanorma/plugin/lutaml/lutaml_uml_attributes_table_preprocessor"
4
5
  require "metanorma/plugin/lutaml/lutaml_uml_datamodel_description_preprocessor"
5
6
  require "metanorma/plugin/lutaml/lutaml_diagram_block"
@@ -12,4 +13,15 @@ module Metanorma
12
13
  module Lutaml
13
14
  end
14
15
  end
16
+
17
+ Asciidoctor::Extensions.register do
18
+ preprocessor Metanorma::Plugin::Lutaml::LutamlPreprocessor
19
+ preprocessor Metanorma::Plugin::Lutaml::LutamlUmlAttributesTablePreprocessor
20
+ preprocessor Metanorma::Plugin::Lutaml::LutamlUmlDatamodelDescriptionPreprocessor
21
+ preprocessor Metanorma::Plugin::Lutaml::LutamlUmlClassPreprocessor
22
+ inline_macro Metanorma::Plugin::Lutaml::LutamlFigureInlineMacro
23
+ inline_macro Metanorma::Plugin::Lutaml::LutamlTableInlineMacro
24
+ block_macro Metanorma::Plugin::Lutaml::LutamlDiagramBlockMacro
25
+ block Metanorma::Plugin::Lutaml::LutamlDiagramBlock
26
+ end
15
27
  end
@@ -28,6 +28,7 @@ Gem::Specification.new do |spec|
28
28
  spec.add_dependency "metanorma"
29
29
  spec.add_dependency "relaton-cli"
30
30
  spec.add_dependency "reverse_adoc"
31
+ spec.add_dependency "expressir"
31
32
 
32
33
  spec.add_development_dependency "byebug"
33
34
  spec.add_development_dependency "equivalent-xml"
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.15
4
+ version: 0.4.17
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-02-08 00:00:00.000000000 Z
11
+ date: 2022-09-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: liquid
@@ -80,6 +80,20 @@ dependencies:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: expressir
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: byebug
85
99
  requirement: !ruby/object:Gem::Requirement
@@ -278,16 +292,16 @@ files:
278
292
  - lib/metanorma/plugin/lutaml/lutaml_preprocessor.rb
279
293
  - lib/metanorma/plugin/lutaml/lutaml_table_inline_macro.rb
280
294
  - lib/metanorma/plugin/lutaml/lutaml_uml_attributes_table_preprocessor.rb
295
+ - lib/metanorma/plugin/lutaml/lutaml_uml_class_preprocessor.rb
281
296
  - lib/metanorma/plugin/lutaml/lutaml_uml_datamodel_description_preprocessor.rb
282
297
  - lib/metanorma/plugin/lutaml/utils.rb
283
298
  - lib/metanorma/plugin/lutaml/version.rb
284
299
  - metanorma-plugin-lutaml.gemspec
285
- - pkg/metanorma-plugin-lutaml-0.2.0.gem
286
300
  homepage: https://github.com/metanorma/metanorma-plugin-lutaml
287
301
  licenses:
288
302
  - BSD-2-Clause
289
303
  metadata: {}
290
- post_install_message:
304
+ post_install_message:
291
305
  rdoc_options: []
292
306
  require_paths:
293
307
  - lib
@@ -302,8 +316,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
302
316
  - !ruby/object:Gem::Version
303
317
  version: '0'
304
318
  requirements: []
305
- rubygems_version: 3.3.3
306
- signing_key:
319
+ rubygems_version: 3.1.6
320
+ signing_key:
307
321
  specification_version: 4
308
322
  summary: Metanorma plugin for LutaML
309
323
  test_files: []
Binary file