metanorma-plugin-lutaml 0.6.0 → 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/README.adoc +62 -3
- data/lib/metanorma/plugin/lutaml/liquid/multiply_local_file_system.rb +11 -2
- data/lib/metanorma/plugin/lutaml/lutaml_preprocessor.rb +185 -93
- data/lib/metanorma/plugin/lutaml/lutaml_uml_datamodel_description_preprocessor.rb +2 -1
- data/lib/metanorma/plugin/lutaml/utils.rb +70 -48
- data/lib/metanorma/plugin/lutaml/version.rb +1 -1
- data/metanorma-plugin-lutaml.gemspec +1 -1
- metadata +6 -6
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/README.adoc
CHANGED
@@ -28,9 +28,9 @@ LutaML supports accessing EXPRESS models via the
|
|
28
28
|
https://github.com/lutaml/expressir[Expressir] parser.
|
29
29
|
|
30
30
|
|
31
|
-
=== Usage of the `lutaml`
|
31
|
+
=== Usage of the `lutaml` command
|
32
32
|
|
33
|
-
Given an `example.exp` EXPRESS file with
|
33
|
+
Given an `example.exp` EXPRESS file with content:
|
34
34
|
|
35
35
|
[source,exp]
|
36
36
|
----
|
@@ -57,7 +57,7 @@ SCHEMA test_schema 'test';
|
|
57
57
|
END_SCHEMA;
|
58
58
|
----
|
59
59
|
|
60
|
-
And the `lutaml`
|
60
|
+
And the `lutaml` block:
|
61
61
|
|
62
62
|
[source,adoc]
|
63
63
|
-----
|
@@ -137,6 +137,7 @@ Example of usage:
|
|
137
137
|
= Document title
|
138
138
|
Author
|
139
139
|
:lutaml-express-index: index_name; /path/to/express_files; cache=/path/to/cache_file.yaml
|
140
|
+
|
140
141
|
[lutaml,index_name,context]
|
141
142
|
----
|
142
143
|
{% for schema in context.schemas %}
|
@@ -145,6 +146,64 @@ Author
|
|
145
146
|
----
|
146
147
|
-----
|
147
148
|
|
149
|
+
=== Using `config.yaml`
|
150
|
+
|
151
|
+
This functionality allows `[lutaml_express]` blocks to load a full set of
|
152
|
+
EXPRESS schemas in one index, and then provide a select ("filter") option
|
153
|
+
per-block via a separate YAML file.
|
154
|
+
|
155
|
+
[source,adoc]
|
156
|
+
----
|
157
|
+
:lutaml-express-index: schemas_1; schemas_all.yaml;
|
158
|
+
|
159
|
+
[lutaml_express,schemas_1,repo,leveloffset=+1,config_yaml=select.yaml]
|
160
|
+
---
|
161
|
+
{% assign selected = repo.schemas | where: "selected" %}
|
162
|
+
{% render "templates/resources/schema" for selected as schema %}
|
163
|
+
---
|
164
|
+
----
|
165
|
+
|
166
|
+
Where `schemas_all.yml` provides all schemas:
|
167
|
+
|
168
|
+
[source,yaml]
|
169
|
+
----
|
170
|
+
---
|
171
|
+
schemas:
|
172
|
+
action_schema:
|
173
|
+
path: "../../schemas/resources/action_schema/action_schema.exp"
|
174
|
+
application_context_schema:
|
175
|
+
path: "../../schemas/resources/application_context_schema/application_context_schema.exp"
|
176
|
+
approval_schema:
|
177
|
+
path: "../../schemas/resources/approval_schema/approval_schema.exp"
|
178
|
+
...
|
179
|
+
----
|
180
|
+
|
181
|
+
And `select.yaml` only selects 2 schemas:
|
182
|
+
|
183
|
+
[source,yaml]
|
184
|
+
----
|
185
|
+
---
|
186
|
+
schemas:
|
187
|
+
- action_schema
|
188
|
+
- application_context_schema
|
189
|
+
----
|
190
|
+
|
191
|
+
The resulting block adds the `select` attribute to every schema of the the
|
192
|
+
"context" object, which allows you to filter those out for complex operations
|
193
|
+
via Liquid:
|
194
|
+
|
195
|
+
[source,liquid]
|
196
|
+
----
|
197
|
+
[lutaml_express,schemas_1,repo,leveloffset=+1,config_yaml=select.yaml]
|
198
|
+
---
|
199
|
+
{% assign selected = repo.schemas | where: "selected" %}
|
200
|
+
... do things with `selected` ...
|
201
|
+
----
|
202
|
+
|
203
|
+
NOTE: This functionality is used in the ISO 10303 SRL to load the full schema
|
204
|
+
set at once but only render the selected schemas in individual documents.
|
205
|
+
|
206
|
+
|
148
207
|
== Usage with UML
|
149
208
|
|
150
209
|
=== Rendering a LutaML view: `lutaml_diagram`
|
@@ -12,13 +12,18 @@ module Metanorma
|
|
12
12
|
|
13
13
|
def read_template_file(template_path)
|
14
14
|
full_path = full_path(template_path)
|
15
|
-
|
15
|
+
|
16
|
+
unless File.exist?(full_path)
|
17
|
+
raise FileSystemError, "No such template '#{template_path}'"
|
18
|
+
end
|
16
19
|
|
17
20
|
File.read(full_path)
|
18
21
|
end
|
19
22
|
|
20
23
|
def full_path(template_path)
|
21
|
-
|
24
|
+
unless %r{\A[^./][a-zA-Z0-9_/]+\z}.match?(template_path)
|
25
|
+
raise ::Liquid::FileSystemError, "Illegal template name '#{template_path}'"
|
26
|
+
end
|
22
27
|
|
23
28
|
result_path = if template_path.include?('/')
|
24
29
|
roots
|
@@ -40,6 +45,10 @@ module Metanorma
|
|
40
45
|
.find { |path| File.file?(path) }
|
41
46
|
end
|
42
47
|
|
48
|
+
if result_path.nil?
|
49
|
+
raise ::Liquid::FileSystemError, "No documents in template path '#{File.expand_path(template_path)}'"
|
50
|
+
end
|
51
|
+
|
43
52
|
unless roots.any? { |root| File.expand_path(result_path).start_with?(File.expand_path(root)) }
|
44
53
|
raise ::Liquid::FileSystemError, "Illegal template path '#{File.expand_path(result_path)}'"
|
45
54
|
end
|
@@ -16,164 +16,256 @@ module Metanorma
|
|
16
16
|
REMARKS_ATTRIBUTE = "remarks"
|
17
17
|
|
18
18
|
def process(document, reader)
|
19
|
-
r = Asciidoctor::PreprocessorNoIfdefsReader.new
|
19
|
+
r = Asciidoctor::PreprocessorNoIfdefsReader.new(document, reader.lines)
|
20
20
|
input_lines = r.readlines.to_enum
|
21
|
-
|
21
|
+
|
22
|
+
has_lutaml = input_lines.any? { |line| lutaml?(line) }
|
23
|
+
|
22
24
|
express_indexes = Utils.parse_document_express_indexes(
|
23
|
-
document,
|
25
|
+
document,
|
26
|
+
input_lines
|
24
27
|
)
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
+
|
29
|
+
result_content = process_input_lines(
|
30
|
+
document: document,
|
31
|
+
input_lines: input_lines,
|
32
|
+
express_indexes: express_indexes,
|
33
|
+
)
|
34
|
+
|
35
|
+
log(document, result_content) if has_lutaml
|
36
|
+
|
28
37
|
Asciidoctor::PreprocessorNoIfdefsReader.new(document, result_content)
|
29
38
|
end
|
30
39
|
|
31
40
|
protected
|
32
41
|
|
33
|
-
def log(
|
34
|
-
File.open("#{
|
35
|
-
|
36
|
-
f.write(result.join("\n"))
|
42
|
+
def log(doc, text)
|
43
|
+
File.open("#{doc.attr('docfile')}.lutaml.log.txt", "w:UTF-8") do |f|
|
44
|
+
f.write(text.join("\n"))
|
37
45
|
end
|
38
46
|
end
|
39
47
|
|
40
48
|
def lutaml?(line)
|
41
|
-
line.match(/^\[(?:\blutaml\b|\blutaml_express\b),([^,]+)?,?([^,]+)
|
49
|
+
line.match(/^\[(?:\blutaml\b|\blutaml_express\b),(?<index_names>[^,]+)?,?(?<context_name>[^,]+)?(?<options>,.*)?\]/)
|
42
50
|
end
|
43
51
|
|
44
|
-
def
|
45
|
-
|
46
|
-
File.new(
|
47
|
-
|
48
|
-
|
49
|
-
|
52
|
+
def load_lutaml_file(document, file_path)
|
53
|
+
::Lutaml::Parser.parse(
|
54
|
+
File.new(
|
55
|
+
Utils.relative_file_path(document, file_path),
|
56
|
+
encoding: "UTF-8"
|
57
|
+
)
|
58
|
+
)
|
50
59
|
end
|
51
60
|
|
52
61
|
private
|
53
62
|
|
54
|
-
def
|
63
|
+
def process_input_lines(
|
64
|
+
document:,
|
65
|
+
input_lines:,
|
66
|
+
express_indexes:
|
67
|
+
)
|
68
|
+
|
55
69
|
result = []
|
56
70
|
loop do
|
57
|
-
result
|
58
|
-
|
71
|
+
result.push(
|
72
|
+
*process_text_blocks(
|
59
73
|
document,
|
60
74
|
input_lines,
|
61
75
|
express_indexes,
|
62
|
-
)
|
76
|
+
)
|
77
|
+
)
|
63
78
|
end
|
64
79
|
result
|
65
80
|
end
|
66
81
|
|
67
82
|
def process_text_blocks(document, input_lines, express_indexes)
|
68
83
|
line = input_lines.next
|
69
|
-
|
70
|
-
|
84
|
+
block_header_match = lutaml?(line)
|
85
|
+
|
86
|
+
return [line] if block_header_match.nil?
|
87
|
+
|
88
|
+
index_names = block_header_match[:index_names].split(";").map(&:strip)
|
89
|
+
context_name = block_header_match[:context_name].strip
|
90
|
+
|
91
|
+
options = block_header_match[:options] &&
|
92
|
+
parse_options(block_header_match[:options].to_s.strip) || {}
|
71
93
|
|
72
94
|
end_mark = input_lines.next
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
95
|
+
|
96
|
+
render_template(
|
97
|
+
document: document,
|
98
|
+
lines: extract_block_lines(input_lines, end_mark),
|
99
|
+
index_names: index_names,
|
100
|
+
context_name: context_name,
|
101
|
+
options: options,
|
102
|
+
indexes: express_indexes
|
103
|
+
)
|
79
104
|
end
|
80
105
|
|
81
|
-
def
|
82
|
-
|
106
|
+
def extract_block_lines(input_lines, end_mark)
|
107
|
+
block = []
|
83
108
|
while (block_line = input_lines.next) != end_mark
|
84
|
-
|
109
|
+
block.push(block_line)
|
85
110
|
end
|
86
|
-
|
111
|
+
block
|
87
112
|
end
|
88
113
|
|
89
|
-
def
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
114
|
+
def gather_context_items(index_names:, document:, indexes:)
|
115
|
+
index_names.map do |path|
|
116
|
+
# TODO: Rephrase of the below TODO message.
|
117
|
+
# ::Lutaml::Parser.parse(file_list) can return an Array or just one.
|
118
|
+
# TODO: decide how to handle expressir multiply file parse as one
|
119
|
+
# object and lutaml
|
120
|
+
|
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
|
133
|
+
wrapper = load_lutaml_file(document, path)
|
134
|
+
indexes[path] = {
|
135
|
+
wrapper: wrapper,
|
136
|
+
serialized_hash: wrapper.to_liquid
|
137
|
+
}
|
95
138
|
else
|
96
|
-
|
139
|
+
indexes[path][:serialized_hash] ||= indexes[path][:wrapper].to_liquid
|
97
140
|
end
|
141
|
+
|
142
|
+
indexes[path]
|
98
143
|
end
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
144
|
+
end
|
145
|
+
|
146
|
+
def parse_yaml_config_file(document, file_path)
|
147
|
+
return nil if file_path.nil?
|
148
|
+
|
149
|
+
relative_file_path = Utils.relative_file_path(document, file_path)
|
150
|
+
YAML.safe_load(File.read(relative_file_path, encoding: "UTF-8"))
|
151
|
+
end
|
152
|
+
|
153
|
+
def decorate_schema_object(schema:, document:, indexes:, index_names:, selected:, options:)
|
154
|
+
# Mark a schema as "selected" with `.selected`
|
155
|
+
schema["selected"] = true if selected
|
156
|
+
|
157
|
+
# Provide pretty-formatted code under `.formatted`
|
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"]
|
110
161
|
end
|
111
162
|
end
|
112
|
-
|
163
|
+
|
164
|
+
schema["formatted"] = index_found_value[:wrapper].original_document.schemas.detect do |s|
|
165
|
+
s.id == schema["id"]
|
166
|
+
end.to_s(no_remarks: true)
|
167
|
+
|
168
|
+
# Decorate the remaining things
|
169
|
+
decorate_context_items(
|
170
|
+
schema,
|
171
|
+
options.merge(
|
172
|
+
"relative_path_prefix" =>
|
173
|
+
Utils.relative_file_path(document, File.dirname(schema["file"]))
|
174
|
+
)
|
175
|
+
) || {}
|
113
176
|
end
|
114
177
|
|
115
|
-
def
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
178
|
+
def render_template(document:, lines:, context_name:, index_names:, options:, indexes:)
|
179
|
+
|
180
|
+
config_yaml_path = options.delete("config_yaml")
|
181
|
+
config_yaml = config_yaml_path ?
|
182
|
+
parse_yaml_config_file(document, config_yaml_path) :
|
183
|
+
{}
|
184
|
+
|
185
|
+
selected_schemas = config_yaml["schemas"]
|
186
|
+
|
187
|
+
gather_context_items(
|
188
|
+
index_names: index_names,
|
189
|
+
document: document,
|
190
|
+
indexes: indexes
|
191
|
+
).map do |items|
|
192
|
+
|
193
|
+
serialized_hash = items[:serialized_hash]
|
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
|
+
)
|
125
206
|
end
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
207
|
+
end
|
208
|
+
|
209
|
+
render_block(
|
210
|
+
document: document,
|
211
|
+
block_lines: lines,
|
212
|
+
context_items: serialized_hash,
|
213
|
+
context_name: context_name
|
214
|
+
)
|
215
|
+
end.flatten
|
131
216
|
rescue StandardError => e
|
132
|
-
|
217
|
+
raise e
|
218
|
+
document.logger.warn("Failed to parse LutaML block: #{e.message}")
|
133
219
|
[]
|
134
220
|
end
|
135
221
|
|
136
222
|
def parse_options(options_string)
|
137
223
|
options_string
|
138
224
|
.to_s
|
139
|
-
.scan(
|
225
|
+
.scan(/,\s*([^=]+?)=(\s*[^,]+)/)
|
140
226
|
.map { |elem| elem.map(&:strip) }
|
141
227
|
.to_h
|
142
228
|
end
|
143
229
|
|
144
|
-
def
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
elsif key == REMARKS_ATTRIBUTE
|
152
|
-
[key,
|
153
|
-
val&.map do |remark|
|
154
|
-
Metanorma::Plugin::Lutaml::ExpressRemarksDecorator
|
155
|
-
.call(remark, options)
|
156
|
-
end]
|
157
|
-
elsif val.is_a?(Array)
|
158
|
-
[key, val.map { |n| decorate_context_items(n, options) }]
|
159
|
-
else
|
160
|
-
[key, val]
|
230
|
+
def decorate_context_item(key, val, options)
|
231
|
+
if key == REMARKS_ATTRIBUTE
|
232
|
+
return [
|
233
|
+
key,
|
234
|
+
val&.map do |remark|
|
235
|
+
Metanorma::Plugin::Lutaml::ExpressRemarksDecorator
|
236
|
+
.call(remark, options)
|
161
237
|
end
|
162
|
-
|
163
|
-
|
238
|
+
]
|
239
|
+
end
|
240
|
+
|
241
|
+
case val
|
242
|
+
when Hash
|
243
|
+
[key, decorate_context_items(val, options)]
|
244
|
+
when Array
|
245
|
+
[key, val.map { |n| decorate_context_items(n, options) }]
|
246
|
+
else
|
247
|
+
[key, val]
|
248
|
+
end
|
249
|
+
end
|
250
|
+
|
251
|
+
def decorate_context_items(item, options)
|
252
|
+
return item unless item.is_a?(Hash)
|
253
|
+
|
254
|
+
item.map do |(key, val)|
|
255
|
+
decorate_context_item(key, val, options)
|
256
|
+
end.to_h
|
164
257
|
end
|
165
258
|
|
166
|
-
def
|
167
|
-
context_items:,
|
168
|
-
context_name:,
|
169
|
-
document:)
|
259
|
+
def render_block(block_lines:, context_items:, context_name:, document:)
|
170
260
|
render_result, errors = Utils.render_liquid_string(
|
171
|
-
template_string:
|
261
|
+
template_string: block_lines.join("\n"),
|
172
262
|
context_items: context_items,
|
173
263
|
context_name: context_name,
|
174
264
|
document: document,
|
175
265
|
)
|
266
|
+
|
176
267
|
Utils.notify_render_errors(document, errors)
|
268
|
+
|
177
269
|
render_result.split("\n")
|
178
270
|
end
|
179
271
|
end
|
@@ -201,7 +201,8 @@ options)
|
|
201
201
|
end
|
202
202
|
|
203
203
|
def package_entities(options)
|
204
|
-
options["packages"]
|
204
|
+
return {} unless options["packages"]
|
205
|
+
|
205
206
|
options["packages"]
|
206
207
|
.find_all { |entity| entity.is_a?(Hash) && entity.values.first["render_entities"] }
|
207
208
|
.map do |entity|
|
@@ -27,16 +27,22 @@ module Metanorma
|
|
27
27
|
def render_liquid_string(template_string:, context_items:,
|
28
28
|
context_name:, document:, include_path: nil)
|
29
29
|
liquid_template = ::Liquid::Template.parse(template_string)
|
30
|
+
|
30
31
|
# Allow includes for the template
|
31
|
-
include_paths = [
|
32
|
-
|
32
|
+
include_paths = [
|
33
|
+
Utils.relative_file_path(document, ""),
|
34
|
+
include_path
|
35
|
+
].compact
|
36
|
+
|
33
37
|
liquid_template.registers[:file_system] =
|
34
38
|
::Metanorma::Plugin::Lutaml::Liquid::LocalFileSystem
|
35
39
|
.new(include_paths, ["_%s.liquid", "_%s.adoc"])
|
40
|
+
|
36
41
|
rendered_string = liquid_template
|
37
42
|
.render(context_name => context_items,
|
38
43
|
strict_variables: true,
|
39
44
|
error_mode: :warn)
|
45
|
+
|
40
46
|
[rendered_string, liquid_template.errors]
|
41
47
|
end
|
42
48
|
|
@@ -48,37 +54,52 @@ module Metanorma
|
|
48
54
|
end
|
49
55
|
end
|
50
56
|
|
51
|
-
def
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
+
def load_express_repositories(path:, cache_path:, document:, force_read: false)
|
58
|
+
|
59
|
+
cache_full_path = cache_path &&
|
60
|
+
Utils.relative_file_path(document, cache_path)
|
61
|
+
|
62
|
+
# If there is cache and "force read" not set.
|
57
63
|
if !force_read && cache_full_path && File.file?(cache_full_path)
|
58
|
-
return
|
64
|
+
return load_express_repo_from_cache(cache_full_path)
|
59
65
|
end
|
60
66
|
|
67
|
+
# If there is no cache or "force read" is set.
|
61
68
|
full_path = Utils.relative_file_path(document, path)
|
62
|
-
|
69
|
+
lutaml_wrapper = load_express_repo_from_path(document, full_path)
|
70
|
+
|
63
71
|
if cache_full_path && !File.file?(cache_full_path)
|
64
|
-
|
65
|
-
|
72
|
+
save_express_repo_to_cache(
|
73
|
+
cache_full_path,
|
74
|
+
lutaml_wrapper.original_document,
|
75
|
+
document
|
76
|
+
)
|
66
77
|
end
|
67
|
-
|
78
|
+
|
79
|
+
lutaml_wrapper
|
80
|
+
|
68
81
|
rescue Expressir::Error
|
69
82
|
FileUtils.rm_rf(cache_full_path)
|
70
|
-
|
83
|
+
|
84
|
+
load_express_repositories(
|
85
|
+
path: path,
|
86
|
+
cache_path: cache_path,
|
87
|
+
document: document,
|
88
|
+
force_read: true
|
89
|
+
)
|
90
|
+
|
71
91
|
rescue StandardError => e
|
72
92
|
document.logger.warn("Failed to load #{full_path}: #{e.message}")
|
73
|
-
|
93
|
+
raise e
|
94
|
+
# nil
|
74
95
|
end
|
75
96
|
|
76
|
-
def
|
97
|
+
def load_express_repo_from_cache(path)
|
77
98
|
::Lutaml::Parser
|
78
99
|
.parse(File.new(path), ::Lutaml::Parser::EXPRESS_CACHE_PARSE_TYPE)
|
79
100
|
end
|
80
101
|
|
81
|
-
def
|
102
|
+
def save_express_repo_to_cache(path, repository, document)
|
82
103
|
root_path = Pathname.new(relative_file_path(document, ""))
|
83
104
|
Expressir::Express::Cache
|
84
105
|
.to_file(path,
|
@@ -86,47 +107,33 @@ force_read = false)
|
|
86
107
|
root_path: root_path)
|
87
108
|
end
|
88
109
|
|
89
|
-
def
|
90
|
-
if File.directory?(path)
|
91
|
-
return express_from_folder(path)
|
92
|
-
end
|
110
|
+
def load_express_repo_from_path(document, path)
|
111
|
+
return load_express_from_folder(path) if File.directory?(path)
|
93
112
|
|
94
|
-
|
113
|
+
load_express_from_index(document, path)
|
95
114
|
end
|
96
115
|
|
97
|
-
def
|
116
|
+
def load_express_from_folder(folder)
|
98
117
|
files = Dir["#{folder}/*.exp"].map do |nested_path|
|
99
118
|
File.new(nested_path, encoding: "UTF-8")
|
100
119
|
end
|
101
120
|
::Lutaml::Parser.parse(files)
|
102
121
|
end
|
103
122
|
|
104
|
-
def
|
105
|
-
serialized = wrapper.to_liquid
|
106
|
-
serialized["schemas"].map! do |j|
|
107
|
-
j.merge(
|
108
|
-
"relative_path_prefix" => Utils
|
109
|
-
.relative_file_path(document, File.dirname(j["file"])),
|
110
|
-
"formatted" => wrapper.original_document
|
111
|
-
.schemas.detect {|s| s.id == j["id"] }.to_s(no_remarks: true)
|
112
|
-
)
|
113
|
-
end
|
114
|
-
serialized
|
115
|
-
end
|
116
|
-
|
117
|
-
def express_from_index(document, path)
|
123
|
+
def load_express_from_index(document, path)
|
118
124
|
yaml_content = YAML.safe_load(File.read(path))
|
119
125
|
root_path = yaml_content["path"]
|
120
|
-
schemas_paths = yaml_content
|
121
|
-
.fetch("schemas")
|
126
|
+
schemas_paths = yaml_content["schemas"]
|
122
127
|
.map do |(schema_name, schema_values)|
|
123
128
|
schema_values["path"] || File.join(root_path.to_s,
|
124
129
|
"#{schema_name}.exp")
|
125
130
|
end
|
131
|
+
|
126
132
|
files_to_load = schemas_paths.map do |path|
|
127
133
|
File.new(Utils.relative_file_path(document, path),
|
128
134
|
encoding: "UTF-8")
|
129
135
|
end
|
136
|
+
|
130
137
|
::Lutaml::Parser.parse(files_to_load)
|
131
138
|
end
|
132
139
|
|
@@ -134,20 +141,35 @@ force_read = false)
|
|
134
141
|
express_indexes = {}
|
135
142
|
loop do
|
136
143
|
line = input_lines.next
|
144
|
+
|
145
|
+
# Finished parsing document attributes
|
137
146
|
break if line.empty?
|
138
147
|
|
139
148
|
match = line.match(LUTAML_EXP_IDX_TAG)
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
+
next unless match
|
150
|
+
|
151
|
+
name = match[:index_name]&.strip
|
152
|
+
path = match[:index_path]&.strip
|
153
|
+
cache = match[:cache_path]&.strip
|
154
|
+
|
155
|
+
unless name && path
|
156
|
+
raise StandardError.new("No name and path set in `:lutaml-express-index:` attribute.")
|
157
|
+
end
|
158
|
+
|
159
|
+
lutaml_expressir_wrapper = load_express_repositories(
|
160
|
+
path: path,
|
161
|
+
cache_path: cache,
|
162
|
+
document: document
|
163
|
+
)
|
164
|
+
|
165
|
+
if lutaml_expressir_wrapper
|
166
|
+
express_indexes[name] = {
|
167
|
+
wrapper: lutaml_expressir_wrapper,
|
168
|
+
serialized_hash: nil
|
169
|
+
}
|
149
170
|
end
|
150
171
|
end
|
172
|
+
|
151
173
|
express_indexes
|
152
174
|
rescue StopIteration
|
153
175
|
express_indexes
|
@@ -30,7 +30,7 @@ Gem::Specification.new do |spec|
|
|
30
30
|
spec.add_dependency "liquid"
|
31
31
|
spec.add_dependency "lutaml"
|
32
32
|
spec.add_dependency "relaton-cli"
|
33
|
-
spec.add_dependency "reverse_adoc"
|
33
|
+
spec.add_dependency "reverse_adoc", "~> 0.3.7"
|
34
34
|
|
35
35
|
spec.add_development_dependency "debug"
|
36
36
|
spec.add_development_dependency "equivalent-xml"
|
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.3
|
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-
|
11
|
+
date: 2024-05-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: asciidoctor
|
@@ -84,16 +84,16 @@ dependencies:
|
|
84
84
|
name: reverse_adoc
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
|
-
- - "
|
87
|
+
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version:
|
89
|
+
version: 0.3.7
|
90
90
|
type: :runtime
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
|
-
- - "
|
94
|
+
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version:
|
96
|
+
version: 0.3.7
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: debug
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|