metanorma-plugin-lutaml 0.7.7 → 0.7.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +0 -2
- data/lib/metanorma/plugin/lutaml/liquid/custom_filters.rb +1 -1
- data/lib/metanorma/plugin/lutaml/liquid_drops/klass_table_attribute_drop.rb +67 -0
- data/lib/metanorma/plugin/lutaml/liquid_drops/klass_table_content_drop.rb +23 -0
- data/lib/metanorma/plugin/lutaml/liquid_drops/klass_table_drop.rb +45 -0
- data/lib/metanorma/plugin/lutaml/liquid_drops/klass_table_general_drop.rb +33 -0
- data/lib/metanorma/plugin/lutaml/liquid_templates/_klass_assoc_row.liquid +11 -0
- data/lib/metanorma/plugin/lutaml/liquid_templates/_klass_row.liquid +11 -0
- data/lib/metanorma/plugin/lutaml/liquid_templates/_klass_table.liquid +23 -0
- data/lib/metanorma/plugin/lutaml/lutaml_ea_xmi_preprocessor.rb +310 -0
- data/lib/metanorma/plugin/lutaml/lutaml_klass_table_block_macro.rb +201 -0
- data/lib/metanorma/plugin/lutaml/lutaml_uml_datamodel_description_preprocessor.rb +5 -5
- data/lib/metanorma/plugin/lutaml/version.rb +1 -1
- data/lib/metanorma-plugin-lutaml.rb +2 -0
- metadata +11 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 29510e3dd02119b47d1d179c94d0a954b596dc0255410091d8c0db366e6a4dd3
|
4
|
+
data.tar.gz: b2502ffd6bea597bc56c8882712c58d13e72799eca5387c76329a9ef813d62eb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b06a2f0d8be8e9073c3f631b260d8e88525353afb8e4e6cdf11bd6db9d78994543eb6a9acda9a2602212943ff972a700efa7c7d3dc870951cd3f2c6e5a219ff2
|
7
|
+
data.tar.gz: c80c2d456bec408dccb3c621397bc9313e2cc6a53cf7c5671d504737087ebb597b446d2fc043e3deaaf809a0941f0f3b732837bf4b5aee404685d70cd6ab0d27
|
data/Gemfile
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
require "coradoc"
|
2
|
-
require "coradoc/input/html"
|
3
2
|
|
4
3
|
module Metanorma
|
5
4
|
module Plugin
|
@@ -7,6 +6,7 @@ module Metanorma
|
|
7
6
|
module Liquid
|
8
7
|
module CustomFilters
|
9
8
|
def html2adoc(input)
|
9
|
+
# Coradoc::ReverseAdoc.convert(input)
|
10
10
|
Coradoc::Input::HTML.convert(input)
|
11
11
|
end
|
12
12
|
|
@@ -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,310 @@
|
|
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 "xmi"
|
9
|
+
require "lutaml/xmi"
|
10
|
+
require "metanorma/plugin/lutaml/utils"
|
11
|
+
require "metanorma/plugin/lutaml/asciidoctor/preprocessor"
|
12
|
+
|
13
|
+
module Metanorma
|
14
|
+
module Plugin
|
15
|
+
module Lutaml
|
16
|
+
# Macro for quick rendering of datamodel attributes/values tables
|
17
|
+
# from liquid drop object
|
18
|
+
class LutamlEaXmiPreprocessor <
|
19
|
+
::Asciidoctor::Extensions::Preprocessor
|
20
|
+
MACRO_REGEXP =
|
21
|
+
/\[lutaml_ea_xmi,([^,]+),?(.+)?\]/.freeze
|
22
|
+
LIQUID_INCLUDE_PATH = File.join(
|
23
|
+
Gem.loaded_specs["metanorma-plugin-lutaml"].full_gem_path,
|
24
|
+
"lib", "metanorma", "plugin", "lutaml", "liquid_templates"
|
25
|
+
)
|
26
|
+
DEFAULT_RENDER_INCLUDE = "packages"
|
27
|
+
RENDER_STYLES_INCLUDES = {
|
28
|
+
"default" => "packages",
|
29
|
+
"entity_list" => "packages_entity_list",
|
30
|
+
"entity_list_class" => "packages_entity_list_class",
|
31
|
+
"data_dictionary" => "packages_data_dictionary",
|
32
|
+
}.freeze
|
33
|
+
RENDER_STYLE_ATTRIBUTE = "render_style"
|
34
|
+
SUPPORTED_NESTED_MACRO = %w[
|
35
|
+
before diagram_include_block after include_block package_text
|
36
|
+
].freeze
|
37
|
+
# search document for block `lutaml_ea_xmi`
|
38
|
+
# read include derectives that goes after that in block and transform
|
39
|
+
# into yaml2text blocks
|
40
|
+
def process(document, reader)
|
41
|
+
r = Asciidoctor::PreprocessorNoIfdefsReader.new document, reader.lines
|
42
|
+
input_lines = r.readlines.to_enum
|
43
|
+
Asciidoctor::PreprocessorNoIfdefsReader
|
44
|
+
.new(document, processed_lines(document, input_lines))
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
def lutaml_document_from_file_or_cache(document, file_path, yaml_config)
|
50
|
+
full_path = Utils.relative_file_path(document, file_path)
|
51
|
+
if document.attributes["lutaml_xmi_cache"] &&
|
52
|
+
document.attributes["lutaml_xmi_cache"][full_path]
|
53
|
+
return document.attributes["lutaml_xmi_cache"][full_path]
|
54
|
+
end
|
55
|
+
|
56
|
+
yaml_config["ea_extension"]&.each do |ea_extension_path|
|
57
|
+
ea_extension_full_path = File.expand_path(
|
58
|
+
ea_extension_path, File.dirname(file_path)
|
59
|
+
)
|
60
|
+
Xmi::EaRoot.load_extension(ea_extension_full_path)
|
61
|
+
end
|
62
|
+
|
63
|
+
result_document = ::Lutaml::XMI::Parsers::XML.serialize_xmi_to_liquid(
|
64
|
+
File.new(
|
65
|
+
full_path, encoding: "UTF-8"
|
66
|
+
),
|
67
|
+
)
|
68
|
+
|
69
|
+
document.attributes["lutaml_xmi_cache"] ||= {}
|
70
|
+
document.attributes["lutaml_xmi_cache"][full_path] = result_document
|
71
|
+
result_document
|
72
|
+
end
|
73
|
+
|
74
|
+
def parse_yaml_config_file(document, file_path)
|
75
|
+
return {} if file_path.nil?
|
76
|
+
|
77
|
+
relative_file_path = Utils.relative_file_path(document, file_path)
|
78
|
+
YAML.safe_load(File.read(relative_file_path, encoding: "UTF-8"))
|
79
|
+
end
|
80
|
+
|
81
|
+
def processed_lines(document, input_lines)
|
82
|
+
result = []
|
83
|
+
loop do
|
84
|
+
result.push(*process_text_blocks(document, input_lines))
|
85
|
+
end
|
86
|
+
result
|
87
|
+
end
|
88
|
+
|
89
|
+
def process_text_blocks(document, input_lines)
|
90
|
+
line = input_lines.next
|
91
|
+
block_match = line.match(MACRO_REGEXP)
|
92
|
+
|
93
|
+
return [line] if block_match.nil?
|
94
|
+
|
95
|
+
yaml_config = parse_yaml_config_file(document, block_match[2])
|
96
|
+
lutaml_document = lutaml_document_from_file_or_cache(document,
|
97
|
+
block_match[1],
|
98
|
+
yaml_config)
|
99
|
+
fill_in_diagrams_attributes(document, lutaml_document)
|
100
|
+
model_representation(
|
101
|
+
lutaml_document, document,
|
102
|
+
collect_additional_context(document, input_lines, input_lines.next),
|
103
|
+
yaml_config
|
104
|
+
)
|
105
|
+
end
|
106
|
+
|
107
|
+
def fill_in_entities_refs_attributes(document,
|
108
|
+
lutaml_document, options)
|
109
|
+
# render_style = options.fetch(RENDER_STYLE_ATTRIBUTE, "default")
|
110
|
+
all_children_packages = lutaml_document.packages
|
111
|
+
.map(&:children_packages).flatten
|
112
|
+
package_flat_packages = lambda do |pks|
|
113
|
+
pks.each_with_object({}) do |package, res|
|
114
|
+
res[package.name] = package.xmi_id
|
115
|
+
end
|
116
|
+
end
|
117
|
+
children_pks = package_flat_packages.call(all_children_packages)
|
118
|
+
ref_dictionary = package_flat_packages.call(lutaml_document.packages)
|
119
|
+
.merge(children_pks)
|
120
|
+
%w[class enum data_type].each do |type|
|
121
|
+
package_flat = lambda do |pks|
|
122
|
+
pks.each_with_object({}) do |package, res|
|
123
|
+
plural = type == "class" ? "classes" : "#{type}s"
|
124
|
+
package.send(plural).map do |entity|
|
125
|
+
res["#{type}:#{package.name}:#{entity.name}"] = entity.xmi_id
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
children_pks_diags = package_flat.call(all_children_packages)
|
130
|
+
ref_dictionary = ref_dictionary
|
131
|
+
.merge(package_flat.call(lutaml_document.packages)
|
132
|
+
.merge(children_pks_diags))
|
133
|
+
end
|
134
|
+
document.attributes["lutaml_entity_id"] = ref_dictionary
|
135
|
+
end
|
136
|
+
|
137
|
+
def fill_in_diagrams_attributes(document, lutaml_document)
|
138
|
+
package_flat_diagrams = lambda do |pks|
|
139
|
+
pks.each_with_object({}) do |package, res|
|
140
|
+
package.diagrams.map do |diag|
|
141
|
+
res["#{package.name}:#{diag.name}"] = diag.xmi_id
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
145
|
+
children_pks_diags = package_flat_diagrams.call(
|
146
|
+
lutaml_document.packages.map(&:children_packages).flatten,
|
147
|
+
)
|
148
|
+
|
149
|
+
document.attributes["lutaml_figure_id"] = package_flat_diagrams
|
150
|
+
.call(lutaml_document.packages)
|
151
|
+
.merge(children_pks_diags)
|
152
|
+
end
|
153
|
+
|
154
|
+
def collect_additional_context(document, input_lines, end_mark)
|
155
|
+
additional_context = Hash.new { |hash, key| hash[key] = [] }
|
156
|
+
additional_context["all_macros"] = []
|
157
|
+
block_lines = []
|
158
|
+
while (block_line = input_lines.next) != end_mark
|
159
|
+
block_lines.push(block_line)
|
160
|
+
end
|
161
|
+
processed_lines =
|
162
|
+
process(document, ::Asciidoctor::PreprocessorReader.new(
|
163
|
+
document, block_lines
|
164
|
+
))
|
165
|
+
.read_lines
|
166
|
+
block_document = ::Asciidoctor::Document
|
167
|
+
.new(processed_lines, {}).parse
|
168
|
+
block_document.blocks.each do |block|
|
169
|
+
next unless SUPPORTED_NESTED_MACRO.include?(block.attributes["role"])
|
170
|
+
|
171
|
+
attrs = block.attributes
|
172
|
+
name = attrs.delete("role")
|
173
|
+
package = attrs.delete("package")
|
174
|
+
macro_keyword = [name, package].compact.join(";")
|
175
|
+
block_text = block.lines.length.positive? ? block.lines.join("\n") : ""
|
176
|
+
additional_context[macro_keyword]
|
177
|
+
.push({ "text" => block_text }.merge(attrs))
|
178
|
+
additional_context["all_macros"]
|
179
|
+
.push({ "text" => block_text,
|
180
|
+
"type" => name, "package" => package }.merge(attrs))
|
181
|
+
end
|
182
|
+
additional_context
|
183
|
+
end
|
184
|
+
|
185
|
+
def package_level(lutaml_document, level)
|
186
|
+
return lutaml_document if level <= 0
|
187
|
+
|
188
|
+
package_level(lutaml_document["packages"].first, level - 1)
|
189
|
+
end
|
190
|
+
|
191
|
+
def create_context_object(lutaml_document, additional_context, options)
|
192
|
+
root_package = package_level(lutaml_document.to_liquid,
|
193
|
+
options["package_root_level"] || 1)
|
194
|
+
if options.empty? || options["packages"].nil?
|
195
|
+
return {
|
196
|
+
"render_nested_packages" => true,
|
197
|
+
"packages" => root_package["packages"],
|
198
|
+
"root_packages" => [root_package],
|
199
|
+
"additional_context" => additional_context
|
200
|
+
.merge("external_classes" => options["external_classes"]),
|
201
|
+
"name" => root_package["name"],
|
202
|
+
}
|
203
|
+
end
|
204
|
+
|
205
|
+
all_packages = [root_package, *root_package["children_packages"]]
|
206
|
+
{
|
207
|
+
"packages" => sort_and_filter_out_packages(all_packages, options),
|
208
|
+
"package_entities" => package_entities(options),
|
209
|
+
"package_skip_sections" => package_skip_sections(options),
|
210
|
+
"additional_context" => additional_context
|
211
|
+
.merge("external_classes" => options["external_classes"]),
|
212
|
+
"root_packages" => [root_package],
|
213
|
+
"render_nested_packages" => options["render_nested_packages"] ||
|
214
|
+
false,
|
215
|
+
"name" => root_package["name"],
|
216
|
+
}
|
217
|
+
end
|
218
|
+
|
219
|
+
def package_entities(options)
|
220
|
+
return {} unless options["packages"]
|
221
|
+
|
222
|
+
options["packages"]
|
223
|
+
.find_all { |entity| entity.is_a?(Hash) && entity.values.first["render_entities"] }
|
224
|
+
.map do |entity|
|
225
|
+
[entity.keys.first,
|
226
|
+
entity.values.first["render_entities"].map { |n| [n, true] }.to_h]
|
227
|
+
end.to_h
|
228
|
+
end
|
229
|
+
|
230
|
+
def package_skip_sections(options)
|
231
|
+
return {} unless options["packages"]
|
232
|
+
|
233
|
+
options["packages"]
|
234
|
+
.find_all { |entity| entity.is_a?(Hash) && entity.values.first["skip_tables"] }
|
235
|
+
.map do |entity|
|
236
|
+
[entity.keys.first, entity.values.first["skip_tables"].map do |n|
|
237
|
+
[n, true]
|
238
|
+
end.to_h]
|
239
|
+
end.to_h
|
240
|
+
end
|
241
|
+
|
242
|
+
def sort_and_filter_out_packages(all_packages, options)
|
243
|
+
return all_packages if options["packages"].nil?
|
244
|
+
|
245
|
+
result = []
|
246
|
+
# Step one - filter out all skipped packages
|
247
|
+
options["packages"]
|
248
|
+
.find_all { |entity| entity.is_a?(Hash) && entity["skip"] }
|
249
|
+
.each do |entity|
|
250
|
+
entity_regexp = config_entity_regexp(entity["skip"])
|
251
|
+
all_packages
|
252
|
+
.delete_if { |package| package["name"] =~ entity_regexp }
|
253
|
+
end
|
254
|
+
# Step two - select supplied packages by pattern
|
255
|
+
options["packages"]
|
256
|
+
.find_all { |entity| entity.is_a?(String) || (entity.is_a?(Hash) && !entity["skip"]) }
|
257
|
+
.each do |entity_obj|
|
258
|
+
entity = entity_obj.is_a?(String) ? entity_obj : entity_obj.keys.first
|
259
|
+
entity_regexp = config_entity_regexp(entity)
|
260
|
+
all_packages.each do |package|
|
261
|
+
if package["name"]&.match?(entity_regexp)
|
262
|
+
result.push(package)
|
263
|
+
all_packages
|
264
|
+
.delete_if { |nest_package| nest_package["name"] == package["name"] }
|
265
|
+
end
|
266
|
+
end
|
267
|
+
end
|
268
|
+
result
|
269
|
+
end
|
270
|
+
|
271
|
+
def config_entity_regexp(entity)
|
272
|
+
additional_sym = ".*" if /\*$/.match?(entity)
|
273
|
+
%r{^#{Regexp.escape(entity.delete('*'))}#{additional_sym}$}
|
274
|
+
end
|
275
|
+
|
276
|
+
def model_representation(lutaml_document, document, additional_context,
|
277
|
+
options)
|
278
|
+
fill_in_entities_refs_attributes(document, lutaml_document, options)
|
279
|
+
render_result, errors = Utils.render_liquid_string(
|
280
|
+
template_string: template(options["section_depth"] || 2,
|
281
|
+
options["render_style"],
|
282
|
+
options["include_root"]),
|
283
|
+
context_items: create_context_object(lutaml_document,
|
284
|
+
additional_context,
|
285
|
+
options),
|
286
|
+
context_name: "context",
|
287
|
+
document: document,
|
288
|
+
include_path: LIQUID_INCLUDE_PATH,
|
289
|
+
)
|
290
|
+
Utils.notify_render_errors(document, errors)
|
291
|
+
render_result.split("\n")
|
292
|
+
end
|
293
|
+
|
294
|
+
def template(section_depth, render_style, include_root)
|
295
|
+
include_name = RENDER_STYLES_INCLUDES.fetch(render_style,
|
296
|
+
DEFAULT_RENDER_INCLUDE)
|
297
|
+
result = ""
|
298
|
+
if include_root
|
299
|
+
result += <<~LIQUID
|
300
|
+
{% include "#{include_name}", package_skip_sections: context.package_skip_sections, package_entities: context.package_entities, context: context.root_packages, additional_context: context.additional_context, render_nested_packages: false %}
|
301
|
+
LIQUID
|
302
|
+
end
|
303
|
+
result + <<~LIQUID
|
304
|
+
{% include "#{include_name}", depth: #{section_depth}, package_skip_sections: context.package_skip_sections, package_entities: context.package_entities, context: context, additional_context: context.additional_context, render_nested_packages: context.render_nested_packages %}
|
305
|
+
LIQUID
|
306
|
+
end
|
307
|
+
end
|
308
|
+
end
|
309
|
+
end
|
310
|
+
end
|
@@ -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
|
-
|
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(
|
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
|
-
|
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(
|
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.
|
268
|
+
%r{^#{Regexp.escape(entity.delete('*'))}#{additional_sym}$}
|
269
269
|
end
|
270
270
|
|
271
271
|
def model_representation(lutaml_document, document, additional_context,
|
@@ -3,6 +3,7 @@ require "metanorma/plugin/lutaml/lutaml_preprocessor"
|
|
3
3
|
require "metanorma/plugin/lutaml/lutaml_uml_class_preprocessor"
|
4
4
|
require "metanorma/plugin/lutaml/lutaml_uml_attributes_table_preprocessor"
|
5
5
|
require "metanorma/plugin/lutaml/lutaml_uml_datamodel_description_preprocessor"
|
6
|
+
require "metanorma/plugin/lutaml/lutaml_ea_xmi_preprocessor"
|
6
7
|
require "metanorma/plugin/lutaml/lutaml_diagram_block"
|
7
8
|
require "metanorma/plugin/lutaml/lutaml_diagram_block_macro"
|
8
9
|
require "metanorma/plugin/lutaml/lutaml_figure_inline_macro"
|
@@ -11,6 +12,7 @@ require "metanorma/plugin/lutaml/lutaml_ea_diagram_block_macro"
|
|
11
12
|
require "metanorma/plugin/lutaml/lutaml_gml_dictionary_base"
|
12
13
|
require "metanorma/plugin/lutaml/lutaml_gml_dictionary_block_macro"
|
13
14
|
require "metanorma/plugin/lutaml/lutaml_gml_dictionary_block"
|
15
|
+
require "metanorma/plugin/lutaml/lutaml_klass_table_block_macro"
|
14
16
|
|
15
17
|
module Metanorma
|
16
18
|
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.
|
4
|
+
version: 0.7.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: 2024-09-
|
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
|
@@ -348,10 +355,12 @@ files:
|
|
348
355
|
- lib/metanorma/plugin/lutaml/lutaml_diagram_block.rb
|
349
356
|
- lib/metanorma/plugin/lutaml/lutaml_diagram_block_macro.rb
|
350
357
|
- lib/metanorma/plugin/lutaml/lutaml_ea_diagram_block_macro.rb
|
358
|
+
- lib/metanorma/plugin/lutaml/lutaml_ea_xmi_preprocessor.rb
|
351
359
|
- lib/metanorma/plugin/lutaml/lutaml_figure_inline_macro.rb
|
352
360
|
- lib/metanorma/plugin/lutaml/lutaml_gml_dictionary_base.rb
|
353
361
|
- lib/metanorma/plugin/lutaml/lutaml_gml_dictionary_block.rb
|
354
362
|
- lib/metanorma/plugin/lutaml/lutaml_gml_dictionary_block_macro.rb
|
363
|
+
- lib/metanorma/plugin/lutaml/lutaml_klass_table_block_macro.rb
|
355
364
|
- lib/metanorma/plugin/lutaml/lutaml_preprocessor.rb
|
356
365
|
- lib/metanorma/plugin/lutaml/lutaml_table_inline_macro.rb
|
357
366
|
- lib/metanorma/plugin/lutaml/lutaml_uml_attributes_table_preprocessor.rb
|