metanorma-plugin-lutaml 0.4.5 → 0.4.9

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,11 @@
1
+ .{{ type }} used in {{ package.name }}
2
+ [cols="2a,6a",options="header"]
3
+ |===
4
+ |Name |Description
5
+
6
+ {% for klass in classes %}
7
+ |<<{{ klass.name }}-section,{{ klass.name }}>> «{{ klass.stereotype | default: "Enumeration" }}»
8
+ |{{ klass.definition }}
9
+
10
+ {% endfor %}
11
+ |===
@@ -3,8 +3,9 @@
3
3
  {% elsif is_klass_spare == 'Spare' %}{% continue %}
4
4
  {% endif %}
5
5
  {% assign klass_name = klass.name | downcase | replace: ':', '' | replace: ' ', '_' %}
6
- [[tab-P-{{ package_name }}-E-{{ klass_name }}]]
7
- .Elements of {{ package.name }}::{{ klass.name }}
6
+
7
+ [[section-{{ klass.xmi_id }}]]
8
+ .Elements of {{ package.name }}::{{ klass.name }}&#8221; (enum)
8
9
  [width="100%",cols="a,a,a,a,a,a,a,a"]
9
10
  |===
10
11
 
@@ -24,14 +25,14 @@ h|Inheritance from: 7+| {{ inherited | map: 'member_end' | join: ", " }}
24
25
  h|Generalization of: 7+| {{ generalizations | map: 'member_end' | join: ", " }}
25
26
  {% endif %}
26
27
 
27
- h|Abstract: 7+| {{ klass.is_abstract }}
28
+ h|Abstract: 7+| {% if klass.is_abstract %}True{% else %}False{% endif %}
28
29
  {% assign aggregations = klass.associations | where: "member_end_type", "aggregation" %}
29
30
  {% if aggregations.size > 0 %}
30
31
  .{{aggregations.size | plus: 1}}+h|Associations:
31
- 4+|_Association with:_
32
- |_Obligation_
32
+ 4+| _Association with_
33
+ | _Obligation_
33
34
  | _Maximum occurrence_
34
- |_Provides:_
35
+ | _Provides_
35
36
 
36
37
  {% for assoc in aggregations %}
37
38
  4+| {{assoc.member_end}}
@@ -41,11 +42,11 @@ h|Abstract: 7+| {{ klass.is_abstract }}
41
42
 
42
43
  {% endfor %}
43
44
  {% else %}
44
-
45
- .1+h|Associations: 7+| (none)
45
+ h| Associations: 7+| (none)
46
46
  {% endif %}
47
+
47
48
  {% if klass.values.size > 0 %}
48
- .{{klass.values.size | plus: 1}}+h|Values:
49
+ .{{klass.values.size | plus: 1}}+h| Values:
49
50
  | _Name_
50
51
  6+| _Definition_
51
52
 
@@ -55,7 +56,7 @@ h|Abstract: 7+| {{ klass.is_abstract }}
55
56
 
56
57
  {% endfor %}
57
58
  {% else %}
58
- .1+h|Values:
59
+ h| Values:
59
60
  7+| (none)
60
61
  {% endif %}
61
62
 
@@ -0,0 +1 @@
1
+ k = {"visibility"=>"public", "name"=>nil, "xmi_id"=>"EAID_0BD8DEDF_F024_453d_AA7D_6EBC873FDBB6", "member_end"=>"AbstractFeatureWithLifespan", "member_end_type"=>"inheritance", "member_end_cardinality"=>{"min"=>nil, "max"=>""},"}, "member_end_attribute_name"=>nil, "owner_end"=>"AbstractCityObject", "definition"=>""}{"visibility"=>"public", "name"=>nil, "xmi_id"=>"EAID_1C91D9CF_14CB_400c_A818_7C74428AE5B7", "member_end"=>"AbstractAppearance", "member_end_type"=>"aggregation", "member_end_cardinality"=>{"min"=>"M", "max"=>" "member_end_attribute_name"=>"appearance", "owner_end"=>"AbstractCityObject", "definition"=>"Relates appearances to the city object."}{"visibility"=>"public", "name"=>nil, "xmi_id"=>"EAID_BDD0FCAB_72F7_499b_AC4D_2391D4DE7CAC", "member_end"=>"AbstractGenericAttribute", "member_end_type"=>"aggregation", "member_end_cardinality"=>{"min"=>"M", "max"=>""},"}, "member_end_attribute_name"=>"genericAttribute", "owner_end"=>"AbstractCityObject", "definition"=>"Relates generic attributes to the city object."}{"visibility"=>"public", "name"=>nil, "xmi_id"=>"EAID_C22B8769_C2E7_4e9b_9C0D_138631E90002", "member_end"=>"AbstractCityObject", "member_end_type"=>"aggregation", "member_end_cardinality"=>{"min"=>"M", "max"=>" "member_end_attribute_name"=>"generalizesTo", "owner_end"=>"AbstractCityObject", "definition"=>"Relates generalized representations of the same real-world object in different Levels of Detail to the city object. The direction of this relation is from the city object to the corresponding generalized city objects."}{"visibility"=>"public", "name"=>nil, "xmi_id"=>"EAID_CF0045E1_6BF1_40a7_B08D_9B7B30ECA025", "member_end"=>"ExternalReference", "member_end_type"=>"aggregation", "member_end_cardinality"=>{"min"=>"M", "max"=>""},"}, "member_end_attribute_name"=>"externalReference", "owner_end"=>"AbstractCityObject", "definition"=>"References external objects in other information systems that have a relation to the city object."}{"visibility"=>"public", "name"=>nil, "xmi_id"=>"EAID_D45045CA_AAD6_418a_AF10_F4BC95DE923A", "member_end"=>"AbstractCityObject", "member_end_type"=>"aggregation", "member_end_cardinality"=>{"min"=>"M", "max"=>" "member_end_attribute_name"=>"relatedTo", "owner_end"=>"AbstractCityObject", "definition"=>"Relates other city objects to the city object. It also describes how the city objects are related to each other."}{"visibility"=>"public", "name"=>nil, "xmi_id"=>"EAID_E3BB8700_143D_4dbd_A7EC_49D33C66D430", "member_end"=>"AbstractDynamizer", "member_end_type"=>"aggregation", "member_end_cardinality"=>{"min"=>"M", "max"=>""},"}, "member_end_attribute_name"=>"dynamizer", "owner_end"=>"AbstractCityObject", "definition"=>"Relates Dynamizer objects to the city object. These allow timeseries data to override static attribute values of the city object."}{"visibility"=>"public", "name"=>nil, "owner_end"=>"AbstractCityObject"}{"visibility"=>"public", "name"=>nil, "xmi_id"=>"EAID_BE026036_E811_494c_9776_D1A309393D6D", "member_end"=>"AbstractSpace", "member_end_type"=>"generalization", "member_end_cardinality"=>nil, "member_end_attribute_name"=>nil, "owner_end"=>"AbstractCityObject", "definition"=>""}{"visibility"=>"public", "name"=>nil, "xmi_id"=>"EAID_C2189DFF_0F24_475b_AB55_070CD09A3186", "member_end"=>"AbstractSpaceBoundary", "member_end_type"=>"generalization", "member_end_cardinality"=>{"min"=>nil, "max"=>" "member_end_attribute_name"=>nil, "owner_end"=>"AbstractCityObject", "definition"=>""}{"visibility"=>"public", "name"=>nil, "xmi_id"=>"EAID_C22B8769_C2E7_4e9b_9C0D_138631E90002", "member_end"=>"AbstractCityObject", "member_end_type"=>"aggregation", "member_end_cardinality"=>{"min"=>"M", "max"=>""},"}, "member_end_attribute_name"=>"generalizesTo", "owner_end"=>"AbstractCityObject", "definition"=>"Relates generalized representations of the same real-world object in different Levels of Detail to the city object. The direction of this relation is from the city object to the corresponding generalized city objects."}{"visibility"=>"public", "name"=>nil, "xmi_id"=>"EAID_D45045CA_AAD6_418a_AF10_F4BC95DE923A", "member_end"=>"AbstractCityObject", "member_end_type"=>"aggregation", "member_end_cardinality"=>{"min"=>"M", "max"=>" "member_end_attribute_name"=>"relatedTo", "owner_end"=>"AbstractCityObject", "definition"=>"Relates other city objects to the city object. It also describes how the city objects are related to each other."}{"visibility"=>"public", "name"=>nil, "owner_end"=>"AbstractCityObject"}{"visibility"=>"public", "name"=>nil, "owner_end"=>"AbstractCityObject"}
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Metanorma
4
+ module Plugin
5
+ module Lutaml
6
+ class LutamlFigureInlineMacro < Asciidoctor::Extensions::InlineMacroProcessor
7
+ include LutamlDiagramBase
8
+
9
+ use_dsl
10
+ named :lutaml_figure
11
+
12
+ def process(parent, _target, attrs)
13
+ diagram_key = [attrs["package"], attrs["name"]].compact.join(":")
14
+ return if parent.document.attributes['lutaml_figure_id'].nil?
15
+ xmi_id = parent.document.attributes['lutaml_figure_id'][diagram_key]
16
+ return unless xmi_id
17
+
18
+ %Q(<xref target="figure-#{xmi_id}"></xref>)
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -52,7 +52,7 @@ module Metanorma
52
52
 
53
53
  def process_text_blocks(document, input_lines, express_indexes)
54
54
  line = input_lines.next
55
- block_match = line.match(/^\[lutaml,([^,]+)?,?([^,]+)?,?([^,]+)?\]/)
55
+ block_match = line.match(/^\[lutaml_express,([^,]+)?,?([^,]+)?,?([^,]+)?\]/)
56
56
  return [line] if block_match.nil?
57
57
 
58
58
  end_mark = input_lines.next
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Metanorma
4
+ module Plugin
5
+ module Lutaml
6
+ class LutamlTableInlineMacro < Asciidoctor::Extensions::InlineMacroProcessor
7
+ include LutamlDiagramBase
8
+ SUPPORTED_OPTIONS = %w[class enum data_type]
9
+
10
+ use_dsl
11
+ named :lutaml_table_class
12
+
13
+ def process(parent, _target, attrs)
14
+ keyword = SUPPORTED_OPTIONS.find { |n| attrs[n] }
15
+ entity_key = [keyword, attrs["package"], attrs[keyword]].compact.join(":")
16
+ return if parent.document.attributes['lutaml_entity_id'].nil?
17
+ xmi_id = parent.document.attributes['lutaml_entity_id'][entity_key]
18
+ return unless xmi_id
19
+
20
+ %Q(<xref target="section-#{xmi_id}"></xref>)
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -20,6 +20,15 @@ module Metanorma
20
20
  Gem.loaded_specs["metanorma-plugin-lutaml"].full_gem_path,
21
21
  "lib", "metanorma", "plugin", "lutaml", "liquid_templates"
22
22
  )
23
+ DEFAULT_RENDER_INCLUDE = 'packages'.freeze
24
+ RENDER_STYLES_INCLUDES = {
25
+ 'default' => 'packages',
26
+ 'entity_list' => 'packages_entity_list',
27
+ 'data_dictionary' => 'packages_data_dictionary'
28
+ }.freeze
29
+ RENDER_STYLE_ATTRIBUTE = 'render_style'.freeze
30
+ SUPPORTED_NESTED_MACRO = %w[
31
+ before diagram_include_block after include_block package_text].freeze
23
32
  # search document for block `lutaml_uml_datamodel_description`
24
33
  # read include derectives that goes after that in block and transform
25
34
  # into yaml2text blocks
@@ -57,44 +66,102 @@ module Metanorma
57
66
  block_match = line.match(MARCO_REGEXP)
58
67
  return [line] if block_match.nil?
59
68
 
69
+ lutaml_document = lutaml_document_from_file(document, block_match[1])
70
+ fill_in_diagrams_attributes(document, lutaml_document)
60
71
  model_representation(
61
- lutaml_document_from_file(document, block_match[1]),
72
+ lutaml_document,
62
73
  document,
63
74
  collect_additional_context(input_lines, input_lines.next),
64
75
  parse_yaml_config_file(document, block_match[2]))
65
76
  end
66
77
 
78
+ def fill_in_entities_refs_attributes(document, lutaml_document_wrapper, options)
79
+ lutaml_document = lutaml_document_wrapper.original_document
80
+ render_style = options.fetch(RENDER_STYLE_ATTRIBUTE, 'default')
81
+ all_children_packages = lutaml_document.packages.map(&:children_packages).flatten
82
+ package_flat_packages = lambda do |pks|
83
+ pks.each_with_object({}) do |package, res|
84
+ res[package.name] = package.xmi_id
85
+ end
86
+ end
87
+ children_pks = package_flat_packages.call(all_children_packages)
88
+ ref_dictionary = package_flat_packages.call(lutaml_document.packages)
89
+ .merge(children_pks)
90
+ %w[class enum data_type].each do |type|
91
+ package_flat = lambda do |pks|
92
+ pks.each_with_object({}) do |package, res|
93
+ plural = type == "class" ? "classes" : "#{type}s"
94
+ package.send(plural).map do |entity|
95
+ res["#{type}:#{package.name}:#{entity.name}"] = entity.xmi_id
96
+ end
97
+ end
98
+ end
99
+ children_pks_daigs = package_flat.call(all_children_packages)
100
+ ref_dictionary = ref_dictionary
101
+ .merge(package_flat.call(lutaml_document.packages)
102
+ .merge(children_pks_daigs))
103
+ end
104
+ document.attributes['lutaml_entity_id'] = ref_dictionary
105
+ end
106
+
107
+ def fill_in_diagrams_attributes(document, lutaml_document_wrapper)
108
+ lutaml_document = lutaml_document_wrapper.original_document
109
+ package_flat_diagrams = lambda do |pks|
110
+ pks.each_with_object({}) do |package, res|
111
+ package.diagrams.map { |diag| res["#{package.name}:#{diag.name}"] = diag.xmi_id }
112
+ end
113
+ end
114
+ children_pks_daigs = package_flat_diagrams.call(lutaml_document.packages.map(&:children_packages).flatten)
115
+ document.attributes['lutaml_figure_id'] = package_flat_diagrams.call(lutaml_document.packages)
116
+ .merge(children_pks_daigs)
117
+ end
118
+
67
119
  def collect_additional_context(input_lines, end_mark)
68
- additional_context = {}
120
+ additional_context = Hash.new { |hash, key| hash[key] = [] }
121
+ additional_context['all_macroses'] = []
69
122
  block_lines = []
70
123
  while (block_line = input_lines.next) != end_mark
71
124
  block_lines.push(block_line)
72
125
  end
73
126
  block_document = (Asciidoctor::Document.new(block_lines, {})).parse
74
127
  block_document.blocks.each do |block|
128
+ next unless SUPPORTED_NESTED_MACRO.include?(block.attributes['role'])
129
+
75
130
  attrs = block.attributes
76
131
  name = attrs.delete('role')
77
132
  package = attrs.delete('package')
78
133
  macro_keyword = [name, package].compact.join(";")
79
- additional_context[macro_keyword] = { 'text' => block.lines[1..-2].join("\n") }.merge(attrs)
134
+ block_text = block.lines.length > 0 ? block.lines.join("\n") : ''
135
+ additional_context[macro_keyword].push({ 'text' => block_text }.merge(attrs))
136
+ additional_context['all_macroses'].push({ 'text' => block_text, 'type' => name, 'package' => package }.merge(attrs))
80
137
  end
81
138
  additional_context
82
139
  end
83
140
 
141
+ def package_level(lutaml_document, level)
142
+ return lutaml_document if level <= 0
143
+
144
+ package_level(lutaml_document['packages'].first, level - 1)
145
+ end
146
+
84
147
  def create_context_object(lutaml_document, additional_context, options)
85
- if options.length.zero?
148
+ root_package = package_level(lutaml_document.to_liquid, options['package_root_level'] || 1)
149
+ if options.length.zero? || options['packages'].nil?
86
150
  return {
87
151
  'render_nested_packages' => true,
88
- "packages" => lutaml_document.to_liquid['packages'].first['packages'].first['packages'],
89
- "additional_context" => additional_context
152
+ "packages" => root_package['packages'],
153
+ "root_packages" => [root_package],
154
+ "additional_context" => additional_context,
155
+ "name" => root_package['name']
90
156
  }
91
157
  end
92
158
 
93
- root_package = lutaml_document.to_liquid['packages'].first
94
159
  all_packages = [root_package, *root_package['children_packages']]
95
160
  {
96
161
  "packages" => sort_and_filter_out_packages(all_packages, options),
97
- "additional_context" => additional_context
162
+ "additional_context" => additional_context,
163
+ "root_packages" => [root_package],
164
+ "name" => root_package['name']
98
165
  }
99
166
  end
100
167
 
@@ -132,8 +199,9 @@ module Metanorma
132
199
  end
133
200
 
134
201
  def model_representation(lutaml_document, document, additional_context, options)
202
+ fill_in_entities_refs_attributes(document, lutaml_document, options)
135
203
  render_result, errors = Utils.render_liquid_string(
136
- template_string: table_template,
204
+ template_string: table_template(options['section_depth'] || 2, options['render_style'], options['include_root']),
137
205
  context_items: create_context_object(lutaml_document,
138
206
  additional_context,
139
207
  options),
@@ -145,9 +213,16 @@ module Metanorma
145
213
  render_result.split("\n")
146
214
  end
147
215
 
148
- def table_template
149
- <<~LIQUID
150
- {% include "packages", depth: 2, context: context, additional_context: context.additional_context, render_nested_packages: context.render_nested_packages %}
216
+ def table_template(section_depth, render_style, include_root)
217
+ include_name = RENDER_STYLES_INCLUDES.fetch(render_style, DEFAULT_RENDER_INCLUDE)
218
+ result = ""
219
+ if include_root
220
+ result += <<~LIQUID
221
+ {% include "#{include_name}", context: context.root_packages, additional_context: context.additional_context, render_nested_packages: false %}
222
+ LIQUID
223
+ end
224
+ result += <<~LIQUID
225
+ {% include "#{include_name}", depth: #{section_depth}, context: context, additional_context: context.additional_context, render_nested_packages: context.render_nested_packages %}
151
226
  LIQUID
152
227
  end
153
228
  end
@@ -1,7 +1,7 @@
1
1
  module Metanorma
2
2
  module Plugin
3
3
  module Lutaml
4
- VERSION = "0.4.5".freeze
4
+ VERSION = "0.4.9".freeze
5
5
  end
6
6
  end
7
7
  end
@@ -4,6 +4,8 @@ require "metanorma/plugin/lutaml/lutaml_uml_attributes_table_preprocessor"
4
4
  require "metanorma/plugin/lutaml/lutaml_uml_datamodel_description_preprocessor"
5
5
  require "metanorma/plugin/lutaml/lutaml_diagram_block"
6
6
  require "metanorma/plugin/lutaml/lutaml_diagram_block_macro"
7
+ require "metanorma/plugin/lutaml/lutaml_figure_inline_macro"
8
+ require "metanorma/plugin/lutaml/lutaml_table_inline_macro"
7
9
 
8
10
  module Metanorma
9
11
  module Plugin
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.5
4
+ version: 0.4.9
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-08-05 00:00:00.000000000 Z
11
+ date: 2021-09-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: liquid
@@ -261,12 +261,20 @@ files:
261
261
  - lib/metanorma/plugin/lutaml/liquid_templates/_diagrams_block.liquid
262
262
  - lib/metanorma/plugin/lutaml/liquid_templates/_packages.liquid
263
263
  - lib/metanorma/plugin/lutaml/liquid_templates/_packages_class.liquid
264
+ - lib/metanorma/plugin/lutaml/liquid_templates/_packages_data_dictionary.liquid
265
+ - lib/metanorma/plugin/lutaml/liquid_templates/_packages_data_dictionary_class.liquid
266
+ - lib/metanorma/plugin/lutaml/liquid_templates/_packages_data_dictionary_classes.liquid
264
267
  - lib/metanorma/plugin/lutaml/liquid_templates/_packages_data_type.liquid
268
+ - lib/metanorma/plugin/lutaml/liquid_templates/_packages_entity_list.liquid
269
+ - lib/metanorma/plugin/lutaml/liquid_templates/_packages_entity_list_classes.liquid
265
270
  - lib/metanorma/plugin/lutaml/liquid_templates/_packages_enum.liquid
271
+ - lib/metanorma/plugin/lutaml/liquid_templates/test.rb
266
272
  - lib/metanorma/plugin/lutaml/lutaml_diagram_base.rb
267
273
  - lib/metanorma/plugin/lutaml/lutaml_diagram_block.rb
268
274
  - lib/metanorma/plugin/lutaml/lutaml_diagram_block_macro.rb
275
+ - lib/metanorma/plugin/lutaml/lutaml_figure_inline_macro.rb
269
276
  - lib/metanorma/plugin/lutaml/lutaml_preprocessor.rb
277
+ - lib/metanorma/plugin/lutaml/lutaml_table_inline_macro.rb
270
278
  - lib/metanorma/plugin/lutaml/lutaml_uml_attributes_table_preprocessor.rb
271
279
  - lib/metanorma/plugin/lutaml/lutaml_uml_datamodel_description_preprocessor.rb
272
280
  - lib/metanorma/plugin/lutaml/utils.rb