metanorma-plugin-lutaml 0.6.2 → 0.6.4
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 +4 -4
- data/Gemfile +1 -5
- data/README.adoc +8 -6
- data/lib/metanorma/plugin/lutaml/express_remarks_decorator.rb +1 -1
- data/lib/metanorma/plugin/lutaml/liquid/custom_filters.rb +1 -1
- data/lib/metanorma/plugin/lutaml/liquid/multiply_local_file_system.rb +23 -29
- data/lib/metanorma/plugin/lutaml/lutaml_preprocessor.rb +71 -46
- data/lib/metanorma/plugin/lutaml/lutaml_uml_attributes_table_preprocessor.rb +1 -1
- data/lib/metanorma/plugin/lutaml/lutaml_uml_class_preprocessor.rb +3 -3
- data/lib/metanorma/plugin/lutaml/lutaml_uml_datamodel_description_preprocessor.rb +2 -2
- data/lib/metanorma/plugin/lutaml/utils.rb +10 -7
- data/lib/metanorma/plugin/lutaml/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e52ac2333cb4e251e5d531e8909d1a763a6f05960ad886136741676639235e44
|
4
|
+
data.tar.gz: 7f3e2daffb58c5074928121da9f4951f85a704e1cb8d8e666e5cfcfcdff90e7c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bc3b7a23fef7ba9b8b7537ea94d5b28c548b0f55409e4dbf6e8cac0d35742d2126d4831a9bc1747647ac5d9e3c3f4f1ed3d4b00eb0ffeeae0251b65d6301833e
|
7
|
+
data.tar.gz: e56cad378a1131c70ebc0a47e2d44cbdba2fda3bc4a56f866a4a3e3b45268eeb02fa859e02d48904a8b4b90fe0699fc99c607853e9509b41221953917ed2a0f0
|
data/Gemfile
CHANGED
data/README.adoc
CHANGED
@@ -154,11 +154,11 @@ per-block via a separate YAML file.
|
|
154
154
|
|
155
155
|
[source,adoc]
|
156
156
|
----
|
157
|
-
:lutaml-express-index:
|
157
|
+
:lutaml-express-index: all_schemas; ../schemas_all.yaml;
|
158
158
|
|
159
|
-
[lutaml_express,
|
159
|
+
[lutaml_express,all_schemas,context,leveloffset=+1,config_yaml=schemas.yaml]
|
160
160
|
---
|
161
|
-
{% assign selected =
|
161
|
+
{% assign selected = context.schemas | where: "selected" %}
|
162
162
|
{% render "templates/resources/schema" for selected as schema %}
|
163
163
|
---
|
164
164
|
----
|
@@ -178,14 +178,16 @@ schemas:
|
|
178
178
|
...
|
179
179
|
----
|
180
180
|
|
181
|
-
And `
|
181
|
+
And `schemas.yaml` only selects 2 schemas:
|
182
182
|
|
183
183
|
[source,yaml]
|
184
184
|
----
|
185
185
|
---
|
186
186
|
schemas:
|
187
|
-
|
188
|
-
|
187
|
+
action_schema:
|
188
|
+
anything: ...
|
189
|
+
application_context_schema:
|
190
|
+
anything: ...
|
189
191
|
----
|
190
192
|
|
191
193
|
The resulting block adds the `select` attribute to every schema of the the
|
@@ -48,7 +48,7 @@ module Metanorma
|
|
48
48
|
# When we are dealing with a relative path of a template:
|
49
49
|
# ../path/to/file we need to transform it into
|
50
50
|
# the absolute one because `image::` macro wont understand it other way
|
51
|
-
prefixed_path = File.absolute_path(prefixed_path) if prefixed_path.start_with?(
|
51
|
+
prefixed_path = File.absolute_path(prefixed_path) if prefixed_path.start_with?('../')
|
52
52
|
full_path = File.expand_path(prefixed_path)
|
53
53
|
"#{$1}#{$2}#{full_path}#{$4}"
|
54
54
|
end
|
@@ -22,41 +22,35 @@ module Metanorma
|
|
22
22
|
|
23
23
|
def full_path(template_path)
|
24
24
|
unless %r{\A[^./][a-zA-Z0-9_/]+\z}.match?(template_path)
|
25
|
-
raise ::Liquid::FileSystemError,
|
26
|
-
"Illegal template name '#{template_path}'"
|
25
|
+
raise ::Liquid::FileSystemError, "Illegal template name '#{template_path}'"
|
27
26
|
end
|
28
27
|
|
29
|
-
result_path = if template_path.include?(
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
end
|
28
|
+
result_path = if template_path.include?('/')
|
29
|
+
roots
|
30
|
+
.map do |root|
|
31
|
+
patterns.map do |pattern|
|
32
|
+
File.join(root, File.dirname(template_path), pattern % File.basename(template_path))
|
33
|
+
end
|
34
|
+
end
|
35
|
+
.flatten
|
36
|
+
.find { |path| File.file?(path) }
|
37
|
+
else
|
38
|
+
roots
|
39
|
+
.map do |root|
|
40
|
+
patterns.map do |pattern|
|
41
|
+
File.join(root, pattern % template_path)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
.flatten
|
45
|
+
.find { |path| File.file?(path) }
|
46
|
+
end
|
49
47
|
|
50
48
|
if result_path.nil?
|
51
|
-
raise ::Liquid::FileSystemError,
|
52
|
-
"No documents in template path '#{File.expand_path(template_path)}'"
|
49
|
+
raise ::Liquid::FileSystemError, "No documents in template path '#{File.expand_path(template_path)}'"
|
53
50
|
end
|
54
51
|
|
55
|
-
unless roots.any?
|
56
|
-
|
57
|
-
end
|
58
|
-
raise ::Liquid::FileSystemError,
|
59
|
-
"Illegal template path '#{File.expand_path(result_path)}'"
|
52
|
+
unless roots.any? { |root| File.expand_path(result_path).start_with?(File.expand_path(root)) }
|
53
|
+
raise ::Liquid::FileSystemError, "Illegal template path '#{File.expand_path(result_path)}'"
|
60
54
|
end
|
61
55
|
|
62
56
|
result_path
|
@@ -16,14 +16,14 @@ module Metanorma
|
|
16
16
|
REMARKS_ATTRIBUTE = "remarks"
|
17
17
|
|
18
18
|
def process(document, reader)
|
19
|
-
r = Asciidoctor::PreprocessorNoIfdefsReader.new(document,
|
20
|
-
reader.lines)
|
19
|
+
r = Asciidoctor::PreprocessorNoIfdefsReader.new(document, reader.lines)
|
21
20
|
input_lines = r.readlines.to_enum
|
22
21
|
|
23
22
|
has_lutaml = input_lines.any? { |line| lutaml?(line) }
|
23
|
+
|
24
24
|
express_indexes = Utils.parse_document_express_indexes(
|
25
25
|
document,
|
26
|
-
input_lines
|
26
|
+
input_lines
|
27
27
|
)
|
28
28
|
|
29
29
|
result_content = process_input_lines(
|
@@ -53,18 +53,18 @@ module Metanorma
|
|
53
53
|
::Lutaml::Parser.parse(
|
54
54
|
File.new(
|
55
55
|
Utils.relative_file_path(document, file_path),
|
56
|
-
encoding: "UTF-8"
|
57
|
-
)
|
56
|
+
encoding: "UTF-8"
|
57
|
+
)
|
58
58
|
)
|
59
59
|
end
|
60
60
|
|
61
61
|
private
|
62
62
|
|
63
63
|
def process_input_lines(
|
64
|
-
|
64
|
+
document:,
|
65
65
|
input_lines:,
|
66
66
|
express_indexes:
|
67
|
-
|
67
|
+
)
|
68
68
|
|
69
69
|
result = []
|
70
70
|
loop do
|
@@ -73,7 +73,7 @@ module Metanorma
|
|
73
73
|
document,
|
74
74
|
input_lines,
|
75
75
|
express_indexes,
|
76
|
-
)
|
76
|
+
)
|
77
77
|
)
|
78
78
|
end
|
79
79
|
result
|
@@ -99,7 +99,7 @@ module Metanorma
|
|
99
99
|
index_names: index_names,
|
100
100
|
context_name: context_name,
|
101
101
|
options: options,
|
102
|
-
indexes: express_indexes
|
102
|
+
indexes: express_indexes
|
103
103
|
)
|
104
104
|
end
|
105
105
|
|
@@ -118,36 +118,63 @@ module Metanorma
|
|
118
118
|
# TODO: decide how to handle expressir multiply file parse as one
|
119
119
|
# object and lutaml
|
120
120
|
|
121
|
-
# Does this condition ever happen? That is only if the
|
122
|
-
|
123
|
-
|
124
|
-
|
121
|
+
# Does this condition ever happen? That is only if the
|
122
|
+
# `lutaml-express-index` condition is not set
|
123
|
+
unless indexes[path]
|
124
|
+
|
125
|
+
full_path = Utils.relative_file_path(document, path)
|
126
|
+
unless File.file?(full_path)
|
127
|
+
raise StandardError.new(
|
128
|
+
"Unable to load EXPRESS index for `#{path}`, " \
|
129
|
+
"please define it at `:lutaml-express-index:` or specify " \
|
130
|
+
"the full path."
|
131
|
+
)
|
132
|
+
end
|
125
133
|
wrapper = load_lutaml_file(document, path)
|
126
134
|
indexes[path] = {
|
127
135
|
wrapper: wrapper,
|
128
|
-
serialized_hash: wrapper.to_liquid
|
136
|
+
serialized_hash: wrapper.to_liquid
|
129
137
|
}
|
138
|
+
else
|
139
|
+
indexes[path][:serialized_hash] ||= indexes[path][:wrapper].to_liquid
|
130
140
|
end
|
131
141
|
|
132
142
|
indexes[path]
|
133
143
|
end
|
134
144
|
end
|
135
145
|
|
136
|
-
def
|
137
|
-
return
|
146
|
+
def read_config_yaml_file(document, file_path)
|
147
|
+
return {} if file_path.nil?
|
138
148
|
|
139
149
|
relative_file_path = Utils.relative_file_path(document, file_path)
|
140
|
-
YAML.safe_load(
|
150
|
+
config_yaml = YAML.safe_load(
|
151
|
+
File.read(relative_file_path, encoding: "UTF-8")
|
152
|
+
)
|
153
|
+
|
154
|
+
options = {}
|
155
|
+
if config_yaml["schemas"]
|
156
|
+
unless config_yaml["schemas"].is_a?(Hash)
|
157
|
+
raise StandardError.new(
|
158
|
+
"[lutaml_express] attribute `config_yaml` must point to a YAML " \
|
159
|
+
"file that has the `schema` key containing a hash."
|
160
|
+
)
|
161
|
+
end
|
162
|
+
|
163
|
+
options["selected_schemas"] = config_yaml["schemas"].keys
|
164
|
+
end
|
165
|
+
|
166
|
+
options
|
141
167
|
end
|
142
168
|
|
143
|
-
def decorate_schema_object(schema:, document:, indexes:, index_names:,
|
144
|
-
selected:, options:)
|
169
|
+
def decorate_schema_object(schema:, document:, indexes:, index_names:, selected:, options:)
|
145
170
|
# Mark a schema as "selected" with `.selected`
|
146
171
|
schema["selected"] = true if selected
|
147
172
|
|
148
173
|
# Provide pretty-formatted code under `.formatted`
|
149
|
-
|
150
|
-
|
174
|
+
index_found_key, index_found_value = indexes.detect do |k,v|
|
175
|
+
found = v[:wrapper].original_document.schemas.detect do |s|
|
176
|
+
s.id == schema["id"]
|
177
|
+
end
|
151
178
|
end
|
152
179
|
|
153
180
|
schema["formatted"] = index_found_value[:wrapper].original_document.schemas.detect do |s|
|
@@ -159,46 +186,44 @@ selected:, options:)
|
|
159
186
|
schema,
|
160
187
|
options.merge(
|
161
188
|
"relative_path_prefix" =>
|
162
|
-
Utils.relative_file_path(document,
|
163
|
-
|
164
|
-
),
|
189
|
+
Utils.relative_file_path(document, File.dirname(schema["file"]))
|
190
|
+
)
|
165
191
|
) || {}
|
166
192
|
end
|
167
193
|
|
168
|
-
def render_template(document:, lines:, context_name:, index_names:,
|
169
|
-
options:, indexes:)
|
170
|
-
config_yaml_path = options.delete("config_yaml")
|
171
|
-
config_yaml = if config_yaml_path
|
172
|
-
parse_yaml_config_file(document, config_yaml_path)
|
173
|
-
else
|
174
|
-
{}
|
175
|
-
end
|
194
|
+
def render_template(document:, lines:, context_name:, index_names:, options:, indexes:)
|
176
195
|
|
177
|
-
|
196
|
+
config_yaml_path = options.delete("config_yaml")
|
197
|
+
config = read_config_yaml_file(document, config_yaml_path)
|
198
|
+
selected_schemas = config["selected_schemas"]
|
178
199
|
|
179
200
|
gather_context_items(
|
180
201
|
index_names: index_names,
|
181
202
|
document: document,
|
182
|
-
indexes: indexes
|
203
|
+
indexes: indexes
|
183
204
|
).map do |items|
|
205
|
+
|
184
206
|
serialized_hash = items[:serialized_hash]
|
185
207
|
|
186
|
-
serialized_hash["schemas"]
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
208
|
+
if serialized_hash["schemas"]
|
209
|
+
serialized_hash["schemas"].map! do |schema|
|
210
|
+
|
211
|
+
decorate_schema_object(
|
212
|
+
schema: schema,
|
213
|
+
document: document,
|
214
|
+
index_names: index_names,
|
215
|
+
indexes: indexes,
|
216
|
+
selected: selected_schemas && selected_schemas.include?(schema["id"]),
|
217
|
+
options: options
|
218
|
+
)
|
219
|
+
end
|
195
220
|
end
|
196
221
|
|
197
222
|
render_block(
|
198
223
|
document: document,
|
199
224
|
block_lines: lines,
|
200
225
|
context_items: serialized_hash,
|
201
|
-
context_name: context_name
|
226
|
+
context_name: context_name
|
202
227
|
)
|
203
228
|
end.flatten
|
204
229
|
rescue StandardError => e
|
@@ -221,8 +246,8 @@ options:, indexes:)
|
|
221
246
|
key,
|
222
247
|
val&.map do |remark|
|
223
248
|
Metanorma::Plugin::Lutaml::ExpressRemarksDecorator
|
224
|
-
|
225
|
-
end
|
249
|
+
.call(remark, options)
|
250
|
+
end
|
226
251
|
]
|
227
252
|
end
|
228
253
|
|
@@ -9,7 +9,7 @@ module Metanorma
|
|
9
9
|
# @example [lutaml_uml_attributes_table,path/to/lutaml,EntityName]
|
10
10
|
class LutamlUmlAttributesTablePreprocessor < LutamlUmlClassPreprocessor
|
11
11
|
MACRO_REGEXP =
|
12
|
-
/\[lutaml_uml_attributes_table,([^,]+),?([^,]+),?(.+?)?\]
|
12
|
+
/\[lutaml_uml_attributes_table,([^,]+),?([^,]+),?(.+?)?\]/
|
13
13
|
|
14
14
|
# rubocop:disable Layout/IndentHeredoc
|
15
15
|
def template(options)
|
@@ -15,7 +15,7 @@ module Metanorma
|
|
15
15
|
# @example [lutaml_uml_class,path/to/lutaml,EntityName]
|
16
16
|
class LutamlUmlClassPreprocessor < ::Asciidoctor::Extensions::Preprocessor
|
17
17
|
MACRO_REGEXP =
|
18
|
-
/\[lutaml_uml_class,([^,]+),?([^,]+),?(.+?)?\]
|
18
|
+
/\[lutaml_uml_class,([^,]+),?([^,]+),?(.+?)?\]/
|
19
19
|
|
20
20
|
def get_macro_regexp
|
21
21
|
self.class.const_get(:MACRO_REGEXP)
|
@@ -109,9 +109,9 @@ module Metanorma
|
|
109
109
|
|
110
110
|
<<~TEMPLATE
|
111
111
|
{% if definition.keyword == 'enumeration' %}
|
112
|
-
#{
|
112
|
+
#{equalsigns(depth) + ' Enumeration: {{ definition.name }}' unless skip_headers}
|
113
113
|
{% else %}
|
114
|
-
#{
|
114
|
+
#{equalsigns(depth) + ' Class: {{ definition.name }}' unless skip_headers}
|
115
115
|
{% endif %}
|
116
116
|
|
117
117
|
#{equalsigns(depth + 1)} Description
|
@@ -16,7 +16,7 @@ module Metanorma
|
|
16
16
|
class LutamlUmlDatamodelDescriptionPreprocessor <
|
17
17
|
::Asciidoctor::Extensions::Preprocessor
|
18
18
|
MACRO_REGEXP =
|
19
|
-
/\[lutaml_uml_datamodel_description,([^,]+),?(.+)?\]
|
19
|
+
/\[lutaml_uml_datamodel_description,([^,]+),?(.+)?\]/
|
20
20
|
LIQUID_INCLUDE_PATH = File.join(
|
21
21
|
Gem.loaded_specs["metanorma-plugin-lutaml"].full_gem_path,
|
22
22
|
"lib", "metanorma", "plugin", "lutaml", "liquid_templates"
|
@@ -92,7 +92,7 @@ module Metanorma
|
|
92
92
|
def fill_in_entities_refs_attributes(document, lutaml_document_wrapper,
|
93
93
|
options)
|
94
94
|
lutaml_document = lutaml_document_wrapper.original_document
|
95
|
-
options.fetch(RENDER_STYLE_ATTRIBUTE, "default")
|
95
|
+
render_style = options.fetch(RENDER_STYLE_ATTRIBUTE, "default")
|
96
96
|
all_children_packages = lutaml_document.packages
|
97
97
|
.map(&:children_packages).flatten
|
98
98
|
package_flat_packages = lambda do |pks|
|
@@ -31,7 +31,7 @@ module Metanorma
|
|
31
31
|
# Allow includes for the template
|
32
32
|
include_paths = [
|
33
33
|
Utils.relative_file_path(document, ""),
|
34
|
-
include_path
|
34
|
+
include_path
|
35
35
|
].compact
|
36
36
|
|
37
37
|
liquid_template.registers[:file_system] =
|
@@ -54,8 +54,8 @@ module Metanorma
|
|
54
54
|
end
|
55
55
|
end
|
56
56
|
|
57
|
-
def load_express_repositories(path:, cache_path:, document:,
|
58
|
-
|
57
|
+
def load_express_repositories(path:, cache_path:, document:, force_read: false)
|
58
|
+
|
59
59
|
cache_full_path = cache_path &&
|
60
60
|
Utils.relative_file_path(document, cache_path)
|
61
61
|
|
@@ -72,11 +72,12 @@ force_read: false)
|
|
72
72
|
save_express_repo_to_cache(
|
73
73
|
cache_full_path,
|
74
74
|
lutaml_wrapper.original_document,
|
75
|
-
document
|
75
|
+
document
|
76
76
|
)
|
77
77
|
end
|
78
78
|
|
79
79
|
lutaml_wrapper
|
80
|
+
|
80
81
|
rescue Expressir::Error
|
81
82
|
FileUtils.rm_rf(cache_full_path)
|
82
83
|
|
@@ -84,8 +85,9 @@ force_read: false)
|
|
84
85
|
path: path,
|
85
86
|
cache_path: cache_path,
|
86
87
|
document: document,
|
87
|
-
force_read: true
|
88
|
+
force_read: true
|
88
89
|
)
|
90
|
+
|
89
91
|
rescue StandardError => e
|
90
92
|
document.logger.warn("Failed to load #{full_path}: #{e.message}")
|
91
93
|
raise e
|
@@ -131,6 +133,7 @@ force_read: false)
|
|
131
133
|
File.new(Utils.relative_file_path(document, path),
|
132
134
|
encoding: "UTF-8")
|
133
135
|
end
|
136
|
+
|
134
137
|
::Lutaml::Parser.parse(files_to_load)
|
135
138
|
end
|
136
139
|
|
@@ -156,13 +159,13 @@ force_read: false)
|
|
156
159
|
lutaml_expressir_wrapper = load_express_repositories(
|
157
160
|
path: path,
|
158
161
|
cache_path: cache,
|
159
|
-
document: document
|
162
|
+
document: document
|
160
163
|
)
|
161
164
|
|
162
165
|
if lutaml_expressir_wrapper
|
163
166
|
express_indexes[name] = {
|
164
167
|
wrapper: lutaml_expressir_wrapper,
|
165
|
-
serialized_hash: nil
|
168
|
+
serialized_hash: nil
|
166
169
|
}
|
167
170
|
end
|
168
171
|
end
|
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.6.
|
4
|
+
version: 0.6.4
|
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-05-
|
11
|
+
date: 2024-05-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: asciidoctor
|