metanorma-plugin-lutaml 0.7.7 → 0.7.8

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: d59529d97e0b2a61af4daf695ab6e3490ccdb5e99f5a351e53ab8c822c063a17
4
- data.tar.gz: 2a30e8db498027922dc4f848057880a13d4a240310b2c01122ed2176be4cbf2e
3
+ metadata.gz: '091036d68a92b76cdfb383ae829bd65182a26ddc1146cce1d844a5646c27ca83'
4
+ data.tar.gz: 39bfe3ec5d4b57985902f5ab17f6d097db903f3151efee95068cefe4d2861f5e
5
5
  SHA512:
6
- metadata.gz: e5b8fffe0ec8df9e9ae6bddff29202f9c65a40b43a4790980799763cad78f950cab5c59f0b07ac6c7e774f4199f9aa5cf9c9ec2470d4d67622d3e491416de09e
7
- data.tar.gz: c530eea53a62605af3df803eeddffdb5feee15e91856dff2541fe2b5831cd5e27ad5052fab01d101763eb9a890b0154aad28a934a40caf980111d2647eda5448
6
+ metadata.gz: 4276c20cae2b83cc37b562217429e00b951a2e0a73bf384f931b47bd94b71774db3b42d62cfc1c380bf3b64bf9b6d5c6b8d98fbe18b5b2d9426558ba8aa40a1e
7
+ data.tar.gz: 4323e58139487b3192af2da916a8142f1bd56b7cf8d2df3dae2882172ea7cf22c10e0cfd4d31278cbd3e731f2a689ab871e6a5baa1d89d462a95df90ab389500
data/Gemfile CHANGED
@@ -12,4 +12,6 @@ rescue StandardError
12
12
  nil
13
13
  end
14
14
 
15
+ # gem "lutaml", path: "../../lutaml/lutaml"
16
+
15
17
  gem "ogc-gml", github: "lutaml/ogc-gml"
@@ -0,0 +1,67 @@
1
+ # frozen_string_literal: true
2
+
3
+ class KlassTableAttributeDrop < Liquid::Drop
4
+ LOWER_VALUE_MAPPINGS = {
5
+ "C" => "0",
6
+ "M" => "1",
7
+ }.freeze
8
+
9
+ def initialize(attr) # rubocop:disable Lint/MissingSuper
10
+ @attr = attr
11
+ end
12
+
13
+ def id
14
+ @attr[:id]
15
+ end
16
+
17
+ def name
18
+ @attr[:name]
19
+ end
20
+
21
+ def type
22
+ @attr[:type]
23
+ end
24
+
25
+ def xmi_id
26
+ @attr[:xmi_id]
27
+ end
28
+
29
+ def is_derived
30
+ @attr[:is_derived]
31
+ end
32
+
33
+ def cardinality
34
+ min = @attr[:cardinality]["min"]
35
+ min = min.nil? ? nil : LOWER_VALUE_MAPPINGS[min]
36
+
37
+ "#{min}..#{@attr[:cardinality]['max']}"
38
+ end
39
+
40
+ def definition
41
+ @attr[:definition]
42
+ end
43
+
44
+ def association
45
+ @attr[:association]
46
+ end
47
+
48
+ def has_association?
49
+ !!@attr[:association]
50
+ end
51
+
52
+ def upper_klass
53
+ @attr[:upper_klass]
54
+ end
55
+
56
+ def name_ns
57
+ @attr[:name_ns]
58
+ end
59
+
60
+ def type_ns
61
+ @attr[:type_ns]
62
+ end
63
+
64
+ def gen_name
65
+ @attr[:gen_name]
66
+ end
67
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ class KlassTableContentDrop < Liquid::Drop
4
+ def initialize(content) # rubocop:disable Lint/MissingSuper
5
+ @content = content
6
+ end
7
+
8
+ def owned_props
9
+ @content[:owned_props]
10
+ end
11
+
12
+ def assoc_props
13
+ @content[:assoc_props]
14
+ end
15
+
16
+ def inherited_props
17
+ @content[:inherited_props]
18
+ end
19
+
20
+ def inherited_assoc_props
21
+ @content[:inherited_assoc_props]
22
+ end
23
+ end
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ class KlassTableDrop < Liquid::Drop
4
+ def initialize(klass) # rubocop:disable Lint/MissingSuper
5
+ @klass = klass
6
+ end
7
+
8
+ def id
9
+ @klass[:general_id]
10
+ end
11
+
12
+ def name
13
+ @klass[:name]
14
+ end
15
+
16
+ def stereotype
17
+ @klass[:stereotype]
18
+ end
19
+
20
+ def definition
21
+ @klass[:definition]
22
+ end
23
+
24
+ def type
25
+ @klass[:type]
26
+ end
27
+
28
+ def upper_klass
29
+ @klass[:general_upper_klass]
30
+ end
31
+
32
+ def general
33
+ KlassTableGeneralDrop.new(@klass[:general]) if @klass[:general]
34
+ end
35
+
36
+ def has_general?
37
+ !!@klass[:general]
38
+ end
39
+
40
+ def attributes
41
+ @klass[:general_attributes].map do |attr|
42
+ KlassTableAttributeDrop.new(attr)
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ class KlassTableGeneralDrop < Liquid::Drop
4
+ def initialize(gen) # rubocop:disable Lint/MissingSuper
5
+ @gen = gen
6
+ end
7
+
8
+ def id
9
+ @gen[:general_id]
10
+ end
11
+
12
+ def name
13
+ @gen[:general_name]
14
+ end
15
+
16
+ def upper_klass
17
+ @gen[:general_upper_klass]
18
+ end
19
+
20
+ def general
21
+ KlassTableGeneralDrop.new(@gen[:general]) if @gen[:general]
22
+ end
23
+
24
+ def has_general?
25
+ !!@gen[:general]
26
+ end
27
+
28
+ def attributes
29
+ @gen[:general_attributes].map do |attr|
30
+ KlassTableAttributeDrop.new(attr)
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,11 @@
1
+ {%- for attr in attributes -%}
2
+ {%- if attr.has_association? != false -%}
3
+ {%- capture name_col -%}
4
+ {{ attr.name_ns }}:{{ attr.name }}
5
+ ({{ attr.gen_name }})
6
+ {%- endcapture -%}
7
+ | {{ name_col | newline_to_br }}
8
+ | {{ attr.type_ns }}:{{ attr.type }} [{{ attr.cardinality }}]
9
+ | {{ attr.definition }}
10
+ {%- endif -%}
11
+ {%- endfor -%}
@@ -0,0 +1,11 @@
1
+ {%- for attr in attributes -%}
2
+ {%- if attr.has_association? == false -%}
3
+ {%- capture name_col -%}
4
+ {{ attr.name_ns }}:{{ attr.name }}
5
+ ({{ attr.gen_name }})
6
+ {%- endcapture -%}
7
+ | {{ name_col | newline_to_br }}
8
+ | {{ attr.type }} [{{ attr.cardinality }}]
9
+ | {{ attr.definition }}
10
+ {%- endif -%}
11
+ {%- endfor -%}
@@ -0,0 +1,23 @@
1
+ [cols="1a,1a,2a"]
2
+ |===
3
+ | 型の定義
4
+ 2+| {{ root.definition }}
5
+
6
+ h| 上位の型 2+| {{ root.general.upper_klass }}:{{ root.general.name }}
7
+ h| ステレオタイプ 2+| << {{ root.stereotype }} >>
8
+
9
+ 3+h| 継承する属性
10
+ h| 属性名 h| 属性の型及び多重度 h| 定義
11
+ {{ content.inherited_props }}
12
+
13
+ 3+h| 自身に定義された属性
14
+ {{ content.owned_props }}
15
+
16
+ 3+h| 継承する関連役割
17
+ h| 関連役割名 h| 関連役割の型及び多重度 h| 定義
18
+ {{ content.inherited_assoc_props }}
19
+
20
+ 3+h| 自身に定義された関連役割
21
+ h| 関連役割名 h| 関連役割の型及び多重度 h| 定義
22
+ {{ content.assoc_props }}
23
+ |===
@@ -0,0 +1,201 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "liquid_drops/klass_table_drop"
4
+ require_relative "liquid_drops/klass_table_attribute_drop"
5
+ require_relative "liquid_drops/klass_table_general_drop"
6
+ require_relative "liquid_drops/klass_table_content_drop"
7
+
8
+ module Metanorma
9
+ module Plugin
10
+ module Lutaml
11
+ class LutamlKlassTableBlockMacro < ::Asciidoctor::Extensions::BlockMacroProcessor
12
+ DEFAULT_TEMPLATE_PATH = File.join(
13
+ Gem::Specification.find_by_name("metanorma-plugin-lutaml").gem_dir,
14
+ "lib/metanorma/plugin/lutaml/liquid_templates/<NAME>.liquid",
15
+ )
16
+ DEFAULT_TABLE_TEMPLATE = DEFAULT_TEMPLATE_PATH
17
+ .gsub("<NAME>", "_klass_table")
18
+ DEFAULT_ROW_TEMPLATE = DEFAULT_TEMPLATE_PATH
19
+ .gsub("<NAME>", "_klass_row")
20
+ DEFAULT_ASSOC_ROW_TEMPLATE = DEFAULT_TEMPLATE_PATH
21
+ .gsub("<NAME>", "_klass_assoc_row")
22
+
23
+ use_dsl
24
+ named :lutaml_klass_table
25
+
26
+ def process(parent, target, attrs)
27
+ result_path = Utils.relative_file_path(parent.document, target)
28
+
29
+ gen = ::Lutaml::XMI::Parsers::XML.serialize_generalization_by_name(
30
+ result_path, attrs["name"]
31
+ )
32
+
33
+ render(gen, parent, attrs)
34
+ end
35
+
36
+ private
37
+
38
+ def render(gen, parent, attrs) # rubocop:disable Metrics/MethodLength
39
+ content = {}
40
+
41
+ content[:owned_props] = render_owned_props(
42
+ gen, parent, attrs
43
+ )
44
+ content[:assoc_props] = render_assoc_props(
45
+ gen, parent, attrs
46
+ )
47
+ content[:inherited_props] = render_inherited_props(
48
+ gen, parent, attrs
49
+ )
50
+ content[:inherited_assoc_props] = render_inherited_assoc_props(
51
+ gen, parent, attrs
52
+ )
53
+
54
+ # content[:inherited_props] += render_named_inherited_props(
55
+ # gen, parent, attrs, "gml"
56
+ # )
57
+ # content[:inherited_props] += render_named_inherited_props(
58
+ # gen, parent, attrs, "core"
59
+ # )
60
+ # content[:inherited_assoc_props] += render_named_inherited_props(
61
+ # gen, parent, attrs, "gen"
62
+ # )
63
+
64
+ rendered_table = render_table(gen, parent, attrs, content)
65
+
66
+ block = create_open_block(parent, "", attrs)
67
+ parse_content(block, rendered_table, attrs)
68
+ end
69
+
70
+ def render_table(gen, parent, attrs, content)
71
+ table_tmpl = get_template(
72
+ parent.document, attrs["table_template"], :table
73
+ )
74
+
75
+ table_tmpl.assigns["root"] = KlassTableDrop.new(gen)
76
+ table_tmpl.assigns["content"] =
77
+ KlassTableContentDrop.new(content)
78
+
79
+ table_tmpl.render
80
+ end
81
+
82
+ def render_general_rows(general_item, parent, attrs)
83
+ row_tmpl = get_template(
84
+ parent.document, attrs["row_template"], :row
85
+ )
86
+ render_rows(general_item, row_tmpl)
87
+ end
88
+
89
+ def render_assoc_rows(general_item, parent, attrs)
90
+ row_tmpl = get_template(
91
+ parent.document, attrs["assoc_template"], :assoc_row
92
+ )
93
+ render_rows(general_item, row_tmpl)
94
+ end
95
+
96
+ def render_rows(general_item, row_tmpl)
97
+ gen_attrs = general_item[:general_attributes]
98
+ upper_klass = general_item[:general_upper_klass]
99
+ gen_name = general_item[:general_name]
100
+ attributes = prepare_row_drops(gen_attrs, upper_klass, gen_name)
101
+ row_tmpl.assigns["attributes"] = attributes
102
+ row_tmpl.render
103
+ end
104
+
105
+ def prepare_row_drops(gen_attrs, upper_klass, gen_name) # rubocop:disable Metrics/MethodLength
106
+ gen_attrs.map do |attr|
107
+ attr[:gen_name] = gen_name
108
+ attr[:upper_klass] = upper_klass
109
+ attr[:name_ns] = case attr[:type_ns]
110
+ when "core", "gml"
111
+ upper_klass
112
+ else
113
+ attr[:type_ns]
114
+ end
115
+
116
+ attr[:name_ns] = upper_klass if attr[:name_ns].nil?
117
+
118
+ KlassTableAttributeDrop.new(attr)
119
+ end
120
+ end
121
+
122
+ def render_owned_props(gen, parent, attrs)
123
+ render_general_rows(gen, parent, attrs)
124
+ end
125
+
126
+ def render_assoc_props(gen, parent, attrs)
127
+ render_assoc_rows(gen, parent, attrs)
128
+ end
129
+
130
+ def render_gml_inherited_props(gen, parent, attrs)
131
+ render_named_inherited_props(gen, parent, attrs, "gml")
132
+ end
133
+
134
+ def render_core_inherited_props(gen, parent, attrs)
135
+ render_named_inherited_props(gen, parent, attrs, "core")
136
+ end
137
+
138
+ def render_gen_inherited_props(gen, parent, attrs)
139
+ render_named_inherited_props(gen, parent, attrs, "gen")
140
+ end
141
+
142
+ def render_named_inherited_props(gen, parent, attrs, name)
143
+ attr_key = "#{name}_attributes".to_sym
144
+ general_item = {}
145
+ general_item[:general_attributes] = gen[attr_key]
146
+ general_item[:general_upper_klass] = gen[attr_key].first[:upper_klass]
147
+ general_item[:general_name] = name
148
+
149
+ render_general_rows(general_item, parent, attrs)
150
+ end
151
+
152
+ def render_inherited_props(gen, parent, attrs)
153
+ render_inherited_rows(gen, parent, attrs, assoc: false)
154
+ end
155
+
156
+ def render_inherited_assoc_props(gen, parent, attrs)
157
+ render_inherited_rows(gen, parent, attrs, assoc: true)
158
+ end
159
+
160
+ def render_inherited_rows(gen, parent, attrs, assoc: false) # rubocop:disable Metrics/MethodLength
161
+ rendered_rows = ""
162
+ general_item = gen[:general]
163
+
164
+ while general_item && !general_item.empty?
165
+ rendered_rows += if assoc
166
+ render_assoc_rows(general_item, parent, attrs)
167
+ else
168
+ render_general_rows(general_item, parent, attrs)
169
+ end
170
+ general_item = general_item[:general]
171
+ end
172
+
173
+ rendered_rows
174
+ end
175
+
176
+ def get_template(document, template_path, tmpl_type)
177
+ if template_path.nil?
178
+ template_path = get_default_template_path(tmpl_type)
179
+ end
180
+
181
+ rel_tmpl_path = Utils.relative_file_path(
182
+ document, template_path
183
+ )
184
+
185
+ ::Liquid::Template.parse(File.read(rel_tmpl_path))
186
+ end
187
+
188
+ def get_default_template_path(tmpl_type)
189
+ case tmpl_type
190
+ when :row
191
+ DEFAULT_ROW_TEMPLATE
192
+ when :assoc_row
193
+ DEFAULT_ASSOC_ROW_TEMPLATE
194
+ else
195
+ DEFAULT_TABLE_TEMPLATE
196
+ end
197
+ end
198
+ end
199
+ end
200
+ end
201
+ end
@@ -121,10 +121,10 @@ options)
121
121
  end
122
122
  end
123
123
  end
124
- children_pks_daigs = package_flat.call(all_children_packages)
124
+ children_pks_diags = package_flat.call(all_children_packages)
125
125
  ref_dictionary = ref_dictionary
126
126
  .merge(package_flat.call(lutaml_document.packages)
127
- .merge(children_pks_daigs))
127
+ .merge(children_pks_diags))
128
128
  end
129
129
  document.attributes["lutaml_entity_id"] = ref_dictionary
130
130
  end
@@ -138,12 +138,12 @@ options)
138
138
  end
139
139
  end
140
140
  end
141
- children_pks_daigs = package_flat_diagrams.call(
141
+ children_pks_diags = package_flat_diagrams.call(
142
142
  lutaml_document.packages.map(&:children_packages).flatten,
143
143
  )
144
144
  document.attributes["lutaml_figure_id"] = package_flat_diagrams
145
145
  .call(lutaml_document.packages)
146
- .merge(children_pks_daigs)
146
+ .merge(children_pks_diags)
147
147
  end
148
148
 
149
149
  def collect_additional_context(document, input_lines, end_mark)
@@ -265,7 +265,7 @@ options)
265
265
 
266
266
  def config_entity_regexp(entity)
267
267
  additional_sym = ".*" if /\*$/.match?(entity)
268
- %r{^#{Regexp.escape(entity.gsub('*', ''))}#{additional_sym}$}
268
+ %r{^#{Regexp.escape(entity.delete('*'))}#{additional_sym}$}
269
269
  end
270
270
 
271
271
  def model_representation(lutaml_document, document, additional_context,
@@ -1,7 +1,7 @@
1
1
  module Metanorma
2
2
  module Plugin
3
3
  module Lutaml
4
- VERSION = "0.7.7".freeze
4
+ VERSION = "0.7.8".freeze
5
5
  end
6
6
  end
7
7
  end
@@ -11,6 +11,7 @@ require "metanorma/plugin/lutaml/lutaml_ea_diagram_block_macro"
11
11
  require "metanorma/plugin/lutaml/lutaml_gml_dictionary_base"
12
12
  require "metanorma/plugin/lutaml/lutaml_gml_dictionary_block_macro"
13
13
  require "metanorma/plugin/lutaml/lutaml_gml_dictionary_block"
14
+ require "metanorma/plugin/lutaml/lutaml_klass_table_block_macro"
14
15
 
15
16
  module Metanorma
16
17
  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.7.7
4
+ version: 0.7.8
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-09-18 00:00:00.000000000 Z
11
+ date: 2024-09-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: asciidoctor
@@ -332,7 +332,14 @@ files:
332
332
  - lib/metanorma/plugin/lutaml/liquid/multiply_local_file_system.rb
333
333
  - lib/metanorma/plugin/lutaml/liquid_drops/gml_dictionary_drop.rb
334
334
  - lib/metanorma/plugin/lutaml/liquid_drops/gml_dictionary_entry_drop.rb
335
+ - lib/metanorma/plugin/lutaml/liquid_drops/klass_table_attribute_drop.rb
336
+ - lib/metanorma/plugin/lutaml/liquid_drops/klass_table_content_drop.rb
337
+ - lib/metanorma/plugin/lutaml/liquid_drops/klass_table_drop.rb
338
+ - lib/metanorma/plugin/lutaml/liquid_drops/klass_table_general_drop.rb
335
339
  - lib/metanorma/plugin/lutaml/liquid_templates/_diagrams_block.liquid
340
+ - lib/metanorma/plugin/lutaml/liquid_templates/_klass_assoc_row.liquid
341
+ - lib/metanorma/plugin/lutaml/liquid_templates/_klass_row.liquid
342
+ - lib/metanorma/plugin/lutaml/liquid_templates/_klass_table.liquid
336
343
  - lib/metanorma/plugin/lutaml/liquid_templates/_packages.liquid
337
344
  - lib/metanorma/plugin/lutaml/liquid_templates/_packages_class.liquid
338
345
  - lib/metanorma/plugin/lutaml/liquid_templates/_packages_data_dictionary.liquid
@@ -352,6 +359,7 @@ files:
352
359
  - lib/metanorma/plugin/lutaml/lutaml_gml_dictionary_base.rb
353
360
  - lib/metanorma/plugin/lutaml/lutaml_gml_dictionary_block.rb
354
361
  - lib/metanorma/plugin/lutaml/lutaml_gml_dictionary_block_macro.rb
362
+ - lib/metanorma/plugin/lutaml/lutaml_klass_table_block_macro.rb
355
363
  - lib/metanorma/plugin/lutaml/lutaml_preprocessor.rb
356
364
  - lib/metanorma/plugin/lutaml/lutaml_table_inline_macro.rb
357
365
  - lib/metanorma/plugin/lutaml/lutaml_uml_attributes_table_preprocessor.rb