metanorma-plugin-lutaml 0.6.2 → 0.6.3
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/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 +53 -41
- 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 +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 19d2399f31818f5f72d0f6237199042a1b729457039c033e5a45d29645b56eda
|
4
|
+
data.tar.gz: 0a3a779c6e6b556c7597fc2f9fc708565fb3e0841969eccc855334fcf9e98a88
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a03c8868605097a556281eae23b1f2a9b40f3991e7f7304c0f70ef2d3f8e8477fbd69389c2c49482b0774b729dbb02a8bbb39f3949b7453a5542e4a957c4a70e
|
7
|
+
data.tar.gz: 1001f84dc00d0430552d89f63525af328fa1d2fec6143ce7fbf5c49764f83f5d27b0673d4c57756514498236eb91857cadaf981400097e2d1556f8a554d962c1
|
data/Gemfile
CHANGED
@@ -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,15 +118,25 @@ 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]
|
@@ -140,14 +150,15 @@ module Metanorma
|
|
140
150
|
YAML.safe_load(File.read(relative_file_path, encoding: "UTF-8"))
|
141
151
|
end
|
142
152
|
|
143
|
-
def decorate_schema_object(schema:, document:, indexes:, index_names:,
|
144
|
-
selected:, options:)
|
153
|
+
def decorate_schema_object(schema:, document:, indexes:, index_names:, selected:, options:)
|
145
154
|
# Mark a schema as "selected" with `.selected`
|
146
155
|
schema["selected"] = true if selected
|
147
156
|
|
148
157
|
# Provide pretty-formatted code under `.formatted`
|
149
|
-
|
150
|
-
|
158
|
+
index_found_key, index_found_value = indexes.detect do |k,v|
|
159
|
+
found = v[:wrapper].original_document.schemas.detect do |s|
|
160
|
+
s.id == schema["id"]
|
161
|
+
end
|
151
162
|
end
|
152
163
|
|
153
164
|
schema["formatted"] = index_found_value[:wrapper].original_document.schemas.detect do |s|
|
@@ -159,46 +170,47 @@ selected:, options:)
|
|
159
170
|
schema,
|
160
171
|
options.merge(
|
161
172
|
"relative_path_prefix" =>
|
162
|
-
Utils.relative_file_path(document,
|
163
|
-
|
164
|
-
),
|
173
|
+
Utils.relative_file_path(document, File.dirname(schema["file"]))
|
174
|
+
)
|
165
175
|
) || {}
|
166
176
|
end
|
167
177
|
|
168
|
-
def render_template(document:, lines:, context_name:, index_names:,
|
169
|
-
|
178
|
+
def render_template(document:, lines:, context_name:, index_names:, options:, indexes:)
|
179
|
+
|
170
180
|
config_yaml_path = options.delete("config_yaml")
|
171
|
-
config_yaml =
|
172
|
-
|
173
|
-
|
174
|
-
{}
|
175
|
-
end
|
181
|
+
config_yaml = config_yaml_path ?
|
182
|
+
parse_yaml_config_file(document, config_yaml_path) :
|
183
|
+
{}
|
176
184
|
|
177
185
|
selected_schemas = config_yaml["schemas"]
|
178
186
|
|
179
187
|
gather_context_items(
|
180
188
|
index_names: index_names,
|
181
189
|
document: document,
|
182
|
-
indexes: indexes
|
190
|
+
indexes: indexes
|
183
191
|
).map do |items|
|
192
|
+
|
184
193
|
serialized_hash = items[:serialized_hash]
|
185
194
|
|
186
|
-
serialized_hash["schemas"]
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
+
if serialized_hash["schemas"]
|
196
|
+
serialized_hash["schemas"].map! do |schema|
|
197
|
+
|
198
|
+
decorate_schema_object(
|
199
|
+
schema: schema,
|
200
|
+
document: document,
|
201
|
+
index_names: index_names,
|
202
|
+
indexes: indexes,
|
203
|
+
selected: selected_schemas && selected_schemas.include?(schema["id"]),
|
204
|
+
options: options
|
205
|
+
)
|
206
|
+
end
|
195
207
|
end
|
196
208
|
|
197
209
|
render_block(
|
198
210
|
document: document,
|
199
211
|
block_lines: lines,
|
200
212
|
context_items: serialized_hash,
|
201
|
-
context_name: context_name
|
213
|
+
context_name: context_name
|
202
214
|
)
|
203
215
|
end.flatten
|
204
216
|
rescue StandardError => e
|
@@ -221,8 +233,8 @@ options:, indexes:)
|
|
221
233
|
key,
|
222
234
|
val&.map do |remark|
|
223
235
|
Metanorma::Plugin::Lutaml::ExpressRemarksDecorator
|
224
|
-
|
225
|
-
end
|
236
|
+
.call(remark, options)
|
237
|
+
end
|
226
238
|
]
|
227
239
|
end
|
228
240
|
|
@@ -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
|