metanorma-plugin-lutaml 0.7.30 → 0.7.31
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 +10 -8
- data/README.adoc +16 -1030
- data/docs/usages/enterprise_architect.adoc +583 -0
- data/docs/usages/express.adoc +299 -0
- data/docs/usages/json_yaml.adoc +1034 -0
- data/docs/usages/lutaml-gml.adoc +73 -0
- data/docs/usages/lutaml-uml.adoc +73 -0
- data/lib/metanorma/plugin/lutaml/asciidoctor/preprocessor.rb +1 -1
- data/lib/metanorma/plugin/lutaml/base_structured_text_preprocessor.rb +192 -0
- data/lib/metanorma/plugin/lutaml/content.rb +89 -0
- data/lib/metanorma/plugin/lutaml/data2_text_preprocessor.rb +45 -0
- data/lib/metanorma/plugin/lutaml/express_remarks_decorator.rb +19 -6
- data/lib/metanorma/plugin/lutaml/json2_text_preprocessor.rb +43 -0
- data/lib/metanorma/plugin/lutaml/liquid/custom_blocks/key_iterator.rb +31 -0
- data/lib/metanorma/plugin/lutaml/liquid/custom_filters/loadfile.rb +18 -0
- data/lib/metanorma/plugin/lutaml/liquid/custom_filters/replace_regex.rb +14 -0
- data/lib/metanorma/plugin/lutaml/liquid/custom_filters/values.rb +13 -0
- data/lib/metanorma/plugin/lutaml/liquid/multiply_local_file_system.rb +29 -22
- data/lib/metanorma/plugin/lutaml/liquid_drops/gml_dictionary_drop.rb +1 -1
- data/lib/metanorma/plugin/lutaml/lutaml_diagram_base.rb +1 -1
- data/lib/metanorma/plugin/lutaml/lutaml_diagram_block_macro.rb +2 -1
- data/lib/metanorma/plugin/lutaml/lutaml_ea_diagram_block_macro.rb +2 -1
- data/lib/metanorma/plugin/lutaml/lutaml_ea_xmi_base.rb +48 -36
- data/lib/metanorma/plugin/lutaml/lutaml_figure_inline_macro.rb +2 -1
- data/lib/metanorma/plugin/lutaml/lutaml_gml_dictionary_block_macro.rb +3 -1
- data/lib/metanorma/plugin/lutaml/lutaml_klass_table_block_macro.rb +2 -1
- data/lib/metanorma/plugin/lutaml/lutaml_preprocessor.rb +15 -2
- data/lib/metanorma/plugin/lutaml/lutaml_table_inline_macro.rb +2 -1
- data/lib/metanorma/plugin/lutaml/source_extractor.rb +97 -0
- data/lib/metanorma/plugin/lutaml/utils.rb +59 -26
- data/lib/metanorma/plugin/lutaml/version.rb +1 -1
- data/lib/metanorma/plugin/lutaml/yaml2_text_preprocessor.rb +41 -0
- data/lib/metanorma-plugin-lutaml.rb +3 -0
- data/metanorma-plugin-lutaml.gemspec +7 -1
- metadata +35 -6
- data/lib/metanorma/plugin/lutaml/liquid_templates/test.rb +0 -1
- /data/lib/metanorma/plugin/lutaml/liquid/{custom_filters.rb → custom_filters/html2adoc.rb} +0 -0
@@ -20,39 +20,46 @@ module Metanorma
|
|
20
20
|
File.read(full_path)
|
21
21
|
end
|
22
22
|
|
23
|
-
def full_path(template_path)
|
23
|
+
def full_path(template_path) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity
|
24
24
|
unless %r{\A[^./][a-zA-Z0-9_/]+\z}.match?(template_path)
|
25
25
|
raise ::Liquid::FileSystemError,
|
26
26
|
"Illegal template name '#{template_path}'"
|
27
27
|
end
|
28
28
|
|
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
|
-
|
29
|
+
result_path = if template_path.include?("/")
|
30
|
+
roots
|
31
|
+
.map do |root|
|
32
|
+
patterns.map do |pattern|
|
33
|
+
File.join(
|
34
|
+
root,
|
35
|
+
File.dirname(template_path),
|
36
|
+
pattern % File.basename(template_path),
|
37
|
+
)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
.flatten
|
41
|
+
.find { |path| File.file?(path) }
|
42
|
+
else
|
43
|
+
roots
|
44
|
+
.map do |root|
|
45
|
+
patterns.map do |pattern|
|
46
|
+
File.join(root, pattern % template_path)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
.flatten
|
50
|
+
.find { |path| File.file?(path) }
|
51
|
+
end
|
48
52
|
|
49
53
|
if result_path.nil?
|
50
54
|
raise ::Liquid::FileSystemError,
|
51
|
-
"No documents in template path
|
55
|
+
"No documents in template path: " \
|
56
|
+
" #{File.expand_path(template_path)}"
|
52
57
|
end
|
53
58
|
|
54
59
|
unless roots.any? do |root|
|
55
|
-
File.expand_path(result_path).start_with?(
|
60
|
+
File.expand_path(result_path).start_with?(
|
61
|
+
File.expand_path(root),
|
62
|
+
)
|
56
63
|
end
|
57
64
|
raise ::Liquid::FileSystemError,
|
58
65
|
"Illegal template path '#{File.expand_path(result_path)}'"
|
@@ -42,7 +42,7 @@ module Metanorma
|
|
42
42
|
end
|
43
43
|
|
44
44
|
# if no :imagesdir: leave image file in lutaml
|
45
|
-
def generate_file(parent, _reader, uml_document)
|
45
|
+
def generate_file(parent, _reader, uml_document) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
|
46
46
|
formatter = ::Lutaml::Formatter::Graphviz.new
|
47
47
|
formatter.type = :png
|
48
48
|
|
@@ -5,7 +5,8 @@ require "metanorma/plugin/lutaml/lutaml_diagram_base"
|
|
5
5
|
module Metanorma
|
6
6
|
module Plugin
|
7
7
|
module Lutaml
|
8
|
-
class LutamlDiagramBlockMacro <
|
8
|
+
class LutamlDiagramBlockMacro <
|
9
|
+
::Asciidoctor::Extensions::BlockMacroProcessor
|
9
10
|
include LutamlDiagramBase
|
10
11
|
|
11
12
|
use_dsl
|
@@ -5,7 +5,8 @@ require "metanorma/plugin/lutaml/lutaml_diagram_base"
|
|
5
5
|
module Metanorma
|
6
6
|
module Plugin
|
7
7
|
module Lutaml
|
8
|
-
class LutamlEaDiagramBlockMacro <
|
8
|
+
class LutamlEaDiagramBlockMacro <
|
9
|
+
::Asciidoctor::Extensions::BlockMacroProcessor
|
9
10
|
include LutamlDiagramBase
|
10
11
|
include LutamlEaXmiBase
|
11
12
|
|
@@ -6,12 +6,14 @@ require "asciidoctor/reader"
|
|
6
6
|
require "lutaml"
|
7
7
|
require "lutaml/uml"
|
8
8
|
require "lutaml/formatter"
|
9
|
-
|
9
|
+
require_relative "utils"
|
10
10
|
|
11
11
|
module Metanorma
|
12
12
|
module Plugin
|
13
13
|
module Lutaml
|
14
14
|
module LutamlEaXmiBase
|
15
|
+
include Utils
|
16
|
+
|
15
17
|
LIQUID_INCLUDE_PATH = File.join(
|
16
18
|
Gem.loaded_specs["metanorma-plugin-lutaml"].full_gem_path,
|
17
19
|
"lib", "metanorma", "plugin", "lutaml", "liquid_templates"
|
@@ -27,11 +29,22 @@ module Metanorma
|
|
27
29
|
SUPPORTED_NESTED_MACRO = %w[
|
28
30
|
before diagram_include_block after include_block package_text
|
29
31
|
].freeze
|
30
|
-
XMI_INDEX_REGEXP =
|
32
|
+
XMI_INDEX_REGEXP = %r{
|
33
|
+
^:lutaml-xmi-index: # Start of the pattern
|
34
|
+
(?<index_name>.+?) # Capture index name
|
35
|
+
; # Separator
|
36
|
+
(?<index_path>.+?) # Capture index path
|
37
|
+
;? # Optional separator
|
38
|
+
(?<config_group> # Optional config group
|
39
|
+
\s*config= # Config prefix
|
40
|
+
(?<config_path>.+) # Capture config path
|
41
|
+
)? # End of optional group
|
42
|
+
$ # End of the pattern
|
43
|
+
}x.freeze
|
31
44
|
|
32
45
|
# search document for block `lutaml_ea_xmi`
|
33
46
|
# or `lutaml_uml_datamodel_description`
|
34
|
-
# read include
|
47
|
+
# read include directives that goes after that in block and transform
|
35
48
|
# into yaml2text blocks
|
36
49
|
def process(document, reader)
|
37
50
|
r = Asciidoctor::PreprocessorNoIfdefsReader.new document, reader.lines
|
@@ -108,14 +121,6 @@ module Metanorma
|
|
108
121
|
lutaml_xmi_index[:path]
|
109
122
|
end
|
110
123
|
|
111
|
-
def processed_lines(document, input_lines)
|
112
|
-
result = []
|
113
|
-
loop do
|
114
|
-
result.push(*process_text_blocks(document, input_lines))
|
115
|
-
end
|
116
|
-
result
|
117
|
-
end
|
118
|
-
|
119
124
|
def get_macro_regexp
|
120
125
|
self.class.const_get(:MACRO_REGEXP)
|
121
126
|
end
|
@@ -160,7 +165,7 @@ module Metanorma
|
|
160
165
|
)
|
161
166
|
end
|
162
167
|
|
163
|
-
def load_lutaml_doc_and_config(document, xmi_or_index, config_yaml_path)
|
168
|
+
def load_lutaml_doc_and_config(document, xmi_or_index, config_yaml_path) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
|
164
169
|
index = xmi_or_index.match(/index=(.*)/)
|
165
170
|
|
166
171
|
if index
|
@@ -284,32 +289,39 @@ module Metanorma
|
|
284
289
|
package_level(lutaml_document["packages"].first, level - 1)
|
285
290
|
end
|
286
291
|
|
287
|
-
def create_context_object(
|
292
|
+
def create_context_object( # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
|
293
|
+
lutaml_document, additional_context, options,
|
294
|
+
context_name = "context"
|
295
|
+
)
|
288
296
|
root_package = package_level(lutaml_document.to_liquid,
|
289
297
|
options.package_root_level || 1)
|
298
|
+
contexts = {}
|
299
|
+
contexts[context_name] = {
|
300
|
+
"name" => root_package["name"],
|
301
|
+
"root_packages" => [root_package],
|
302
|
+
"additional_context" => additional_context
|
303
|
+
.merge("external_classes" => options.external_classes),
|
304
|
+
}
|
305
|
+
|
290
306
|
if options.packages.nil?
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
"additional_context" => additional_context
|
296
|
-
.merge("external_classes" => options.external_classes),
|
297
|
-
"name" => root_package["name"],
|
298
|
-
}
|
307
|
+
contexts[context_name]["render_nested_packages"] = true
|
308
|
+
contexts[context_name]["packages"] = root_package["packages"]
|
309
|
+
|
310
|
+
return contexts
|
299
311
|
end
|
300
312
|
|
301
313
|
all_packages = [root_package, *root_package["children_packages"]]
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
314
|
+
contexts[context_name].merge!(
|
315
|
+
{
|
316
|
+
"packages" => sort_and_filter_out_packages(all_packages, options),
|
317
|
+
"package_entities" => package_hash(options, "render_entities"),
|
318
|
+
"package_skip_sections" => package_hash(options, "skip_tables"),
|
319
|
+
"render_nested_packages" => options.render_nested_packages ||
|
320
|
+
false,
|
321
|
+
},
|
322
|
+
)
|
323
|
+
|
324
|
+
contexts
|
313
325
|
end
|
314
326
|
|
315
327
|
def package_hash(options, key)
|
@@ -376,10 +388,10 @@ module Metanorma
|
|
376
388
|
template_string: template(options.section_depth || 2,
|
377
389
|
options.render_style,
|
378
390
|
options.include_root),
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
391
|
+
contexts: create_context_object(lutaml_doc,
|
392
|
+
add_context,
|
393
|
+
options,
|
394
|
+
"context"),
|
383
395
|
document: document,
|
384
396
|
include_path: template_path(document, options.template_path),
|
385
397
|
)
|
@@ -3,8 +3,10 @@
|
|
3
3
|
module Metanorma
|
4
4
|
module Plugin
|
5
5
|
module Lutaml
|
6
|
-
class LutamlGmlDictionaryBlockMacro <
|
6
|
+
class LutamlGmlDictionaryBlockMacro <
|
7
|
+
::Asciidoctor::Extensions::BlockMacroProcessor
|
7
8
|
include LutamlGmlDictionaryBase
|
9
|
+
|
8
10
|
use_dsl
|
9
11
|
named :lutaml_gml_dictionary
|
10
12
|
|
@@ -3,7 +3,8 @@
|
|
3
3
|
module Metanorma
|
4
4
|
module Plugin
|
5
5
|
module Lutaml
|
6
|
-
class LutamlKlassTableBlockMacro <
|
6
|
+
class LutamlKlassTableBlockMacro <
|
7
|
+
::Asciidoctor::Extensions::BlockMacroProcessor
|
7
8
|
include LutamlEaXmiBase
|
8
9
|
|
9
10
|
DEFAULT_TEMPLATE = File.join(
|
@@ -14,6 +14,19 @@ module Metanorma
|
|
14
14
|
# Class for processing Lutaml files
|
15
15
|
class LutamlPreprocessor < ::Asciidoctor::Extensions::Preprocessor
|
16
16
|
REMARKS_ATTRIBUTE = "remarks"
|
17
|
+
EXPRESS_PREPROCESSOR_REGEX = %r{
|
18
|
+
^ # Start of line
|
19
|
+
\[ # Opening bracket
|
20
|
+
(?:\blutaml\b| # Match lutaml or
|
21
|
+
\blutaml_express\b| # lutaml_express or
|
22
|
+
\blutaml_express_liquid\b) # lutaml_express_liquid
|
23
|
+
, # Comma separator
|
24
|
+
(?<index_names>[^,]+)? # Optional index names
|
25
|
+
,? # Optional comma
|
26
|
+
(?<context_name>[^,]+)? # Optional context name
|
27
|
+
(?<options>,.*)? # Optional options
|
28
|
+
\] # Closing bracket
|
29
|
+
}x.freeze
|
17
30
|
|
18
31
|
def process(document, reader) # rubocop:disable Metrics/MethodLength
|
19
32
|
r = Asciidoctor::PreprocessorNoIfdefsReader.new(document,
|
@@ -47,7 +60,7 @@ module Metanorma
|
|
47
60
|
end
|
48
61
|
|
49
62
|
def lutaml_liquid?(line)
|
50
|
-
line.match(
|
63
|
+
line.match(EXPRESS_PREPROCESSOR_REGEX)
|
51
64
|
end
|
52
65
|
|
53
66
|
def load_express_lutaml_file(document, file_path)
|
@@ -180,7 +193,7 @@ module Metanorma
|
|
180
193
|
end
|
181
194
|
end
|
182
195
|
|
183
|
-
def read_config_yaml_file(document, file_path)
|
196
|
+
def read_config_yaml_file(document, file_path) # rubocop:disable Metrics/MethodLength
|
184
197
|
return {} if file_path.nil?
|
185
198
|
|
186
199
|
relative_file_path = Utils.relative_file_path(document, file_path)
|
@@ -3,7 +3,8 @@
|
|
3
3
|
module Metanorma
|
4
4
|
module Plugin
|
5
5
|
module Lutaml
|
6
|
-
class LutamlTableInlineMacro <
|
6
|
+
class LutamlTableInlineMacro <
|
7
|
+
::Asciidoctor::Extensions::InlineMacroProcessor
|
7
8
|
include LutamlDiagramBase
|
8
9
|
SUPPORTED_OPTIONS = %w[class enum data_type].freeze
|
9
10
|
|
@@ -0,0 +1,97 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "utils"
|
4
|
+
|
5
|
+
module Metanorma
|
6
|
+
module Plugin
|
7
|
+
module Lutaml
|
8
|
+
class SourceExtractor
|
9
|
+
include Utils
|
10
|
+
|
11
|
+
# example:
|
12
|
+
# - [[abc]]
|
13
|
+
ANCHOR_REGEX_1 = /^\[\[(?<id>[^\]]*)\]\]\s*$/.freeze
|
14
|
+
|
15
|
+
# examples:
|
16
|
+
# - [#abc]
|
17
|
+
# - [source#abc,ruby]
|
18
|
+
ANCHOR_REGEX_2 = /^\[[^#,]*#(?<id>[^,\]]*)[,\]]/.freeze
|
19
|
+
|
20
|
+
# examples:
|
21
|
+
# - [id=abc]
|
22
|
+
# - [source,id="abc"]
|
23
|
+
ANCHOR_REGEX_3 = /^\[(?:.+,)?id=['"]?(?<id>[^,\]'"]*)['"]?[,\]]/.freeze
|
24
|
+
|
25
|
+
def initialize(document, input_lines)
|
26
|
+
@document = document
|
27
|
+
@input_lines = input_lines
|
28
|
+
|
29
|
+
@document.attributes["source_blocks"] ||= {}
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.extract(document, input_lines)
|
33
|
+
new(document, input_lines).extract
|
34
|
+
end
|
35
|
+
|
36
|
+
def extract # rubocop:disable Metrics/AbcSize
|
37
|
+
lines = @input_lines.to_enum
|
38
|
+
|
39
|
+
loop do
|
40
|
+
line = lines.next
|
41
|
+
|
42
|
+
if /^embed::|^include::/.match?(line.strip)
|
43
|
+
file_lines = read(filename(@document, line)) or next
|
44
|
+
SourceExtractor.extract(@document, file_lines)
|
45
|
+
elsif m = match_anchor(line)
|
46
|
+
@document.attributes["source_blocks"][m[:id]] = read_section lines
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
private
|
52
|
+
|
53
|
+
def match_anchor(line)
|
54
|
+
line.match(ANCHOR_REGEX_1) ||
|
55
|
+
line.match(ANCHOR_REGEX_2) ||
|
56
|
+
line.match(ANCHOR_REGEX_3)
|
57
|
+
end
|
58
|
+
|
59
|
+
def readlines_safe(file)
|
60
|
+
return [] if file.eof?
|
61
|
+
|
62
|
+
file.readlines
|
63
|
+
end
|
64
|
+
|
65
|
+
def read(inc_path)
|
66
|
+
inc_path or return nil
|
67
|
+
::File.open inc_path, "r" do |fd|
|
68
|
+
readlines_safe(fd).map(&:chomp)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def filename(document, line)
|
73
|
+
m = /(^include::|^embed::)([^\[]+)\[/.match(line)
|
74
|
+
return nil unless m
|
75
|
+
|
76
|
+
file_path = relative_file_path(document, m[2])
|
77
|
+
|
78
|
+
File.exist?(file_path) ? file_path : nil
|
79
|
+
end
|
80
|
+
|
81
|
+
def read_section(lines)
|
82
|
+
m = lines.next.match(/^--+/)
|
83
|
+
return "" unless m
|
84
|
+
|
85
|
+
end_mark = m[0]
|
86
|
+
current_section = []
|
87
|
+
|
88
|
+
while (line = lines.next) != end_mark
|
89
|
+
current_section << line
|
90
|
+
end
|
91
|
+
|
92
|
+
current_section.join("\n")
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
@@ -1,22 +1,30 @@
|
|
1
1
|
require "expressir"
|
2
2
|
require "expressir/express/parser"
|
3
3
|
require "expressir/express/cache"
|
4
|
-
require "metanorma/plugin/lutaml/liquid/custom_filters"
|
5
4
|
require "metanorma/plugin/lutaml/liquid/multiply_local_file_system"
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
end
|
12
|
-
liquid_klass.register_filter(Metanorma::Plugin::Lutaml::Liquid::CustomFilters)
|
5
|
+
require "metanorma/plugin/lutaml/liquid/custom_blocks/key_iterator"
|
6
|
+
require "metanorma/plugin/lutaml/liquid/custom_filters/html2adoc"
|
7
|
+
require "metanorma/plugin/lutaml/liquid/custom_filters/values"
|
8
|
+
require "metanorma/plugin/lutaml/liquid/custom_filters/replace_regex"
|
9
|
+
require "metanorma/plugin/lutaml/liquid/custom_filters/loadfile"
|
13
10
|
|
14
11
|
module Metanorma
|
15
12
|
module Plugin
|
16
13
|
module Lutaml
|
17
14
|
# Helpers for lutaml macros
|
18
15
|
module Utils
|
19
|
-
LUTAML_EXP_IDX_TAG =
|
16
|
+
LUTAML_EXP_IDX_TAG = %r{
|
17
|
+
^:lutaml-express-index: # Start of the pattern
|
18
|
+
(?<index_name>.+?) # Capture index name
|
19
|
+
; # Separator
|
20
|
+
(?<index_path>.+?) # Capture index path
|
21
|
+
;? # Optional separator
|
22
|
+
(?<cache_group> # Optional cache group
|
23
|
+
\s*cache= # Cache prefix
|
24
|
+
(?<cache_path>.+) # Capture cache path
|
25
|
+
)? # End of optional group
|
26
|
+
$ # End of the pattern
|
27
|
+
}x.freeze
|
20
28
|
|
21
29
|
module_function
|
22
30
|
|
@@ -29,29 +37,54 @@ module Metanorma
|
|
29
37
|
.system_path(file_path, docfile_directory)
|
30
38
|
end
|
31
39
|
|
32
|
-
def render_liquid_string(
|
33
|
-
|
34
|
-
|
35
|
-
|
40
|
+
def render_liquid_string( # rubocop:disable Metrics/MethodLength,Metrics/AbcSize
|
41
|
+
template_string:, contexts:, document:,
|
42
|
+
include_path: nil, template_path: nil
|
43
|
+
)
|
36
44
|
# Allow includes for the template
|
37
45
|
include_paths = [
|
38
46
|
Utils.relative_file_path(document, ""),
|
39
|
-
include_path,
|
47
|
+
include_path, template_path
|
40
48
|
].compact
|
41
49
|
|
50
|
+
if template_path
|
51
|
+
template_string = File.read(template_path)
|
52
|
+
end
|
53
|
+
|
54
|
+
liquid_template = ::Liquid::Template
|
55
|
+
.parse(template_string, environment: create_liquid_environment)
|
42
56
|
liquid_template.registers[:file_system] =
|
43
57
|
::Metanorma::Plugin::Lutaml::Liquid::LocalFileSystem
|
44
58
|
.new(include_paths, ["%s.liquid", "_%s.liquid", "_%s.adoc"])
|
45
|
-
|
46
59
|
rendered_string = liquid_template
|
47
|
-
.render(
|
48
|
-
strict_variables:
|
60
|
+
.render(contexts,
|
61
|
+
strict_variables: false,
|
49
62
|
error_mode: :warn)
|
50
63
|
|
51
64
|
[rendered_string, liquid_template.errors]
|
52
65
|
end
|
53
66
|
|
54
|
-
def
|
67
|
+
def create_liquid_environment
|
68
|
+
::Liquid::Environment.new.tap do |liquid_env|
|
69
|
+
liquid_env.register_tag(
|
70
|
+
"keyiterator",
|
71
|
+
::Metanorma::Plugin::Lutaml::Liquid::CustomBlocks::KeyIterator,
|
72
|
+
)
|
73
|
+
liquid_env.register_filter(
|
74
|
+
::Metanorma::Plugin::Lutaml::Liquid::CustomFilters,
|
75
|
+
)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def processed_lines(document, input_lines)
|
80
|
+
result = []
|
81
|
+
loop do
|
82
|
+
result.push(*process_text_blocks(document, input_lines))
|
83
|
+
end
|
84
|
+
result
|
85
|
+
end
|
86
|
+
|
87
|
+
def notify_render_errors(_document, errors)
|
55
88
|
errors.each do |error_obj|
|
56
89
|
::Metanorma::Util.log(
|
57
90
|
"[metanorma-plugin-lutaml] Liquid render error: " \
|
@@ -61,8 +94,9 @@ module Metanorma
|
|
61
94
|
end
|
62
95
|
end
|
63
96
|
|
64
|
-
def load_express_repositories(
|
65
|
-
force_read: false
|
97
|
+
def load_express_repositories( # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity
|
98
|
+
path:, cache_path:, document:, force_read: false
|
99
|
+
)
|
66
100
|
cache_full_path = cache_path &&
|
67
101
|
Utils.relative_file_path(document, cache_path)
|
68
102
|
|
@@ -130,7 +164,7 @@ force_read: false)
|
|
130
164
|
end
|
131
165
|
|
132
166
|
# TODO: Refactor this using Suma::SchemaConfig
|
133
|
-
def load_express_from_index(_document, path)
|
167
|
+
def load_express_from_index(_document, path) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
|
134
168
|
yaml_content = YAML.safe_load(File.read(path))
|
135
169
|
schema_yaml_base_path = Pathname.new(File.dirname(path))
|
136
170
|
|
@@ -153,7 +187,7 @@ force_read: false)
|
|
153
187
|
::Lutaml::Parser.parse(files_to_load)
|
154
188
|
end
|
155
189
|
|
156
|
-
def parse_document_express_indexes(document, input_lines)
|
190
|
+
def parse_document_express_indexes(document, input_lines) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity
|
157
191
|
express_indexes = {}
|
158
192
|
loop do
|
159
193
|
line = input_lines.next
|
@@ -169,7 +203,8 @@ force_read: false)
|
|
169
203
|
cache = match[:cache_path]&.strip
|
170
204
|
|
171
205
|
unless name && path
|
172
|
-
raise StandardError.new("No name and path set in
|
206
|
+
raise StandardError.new("No name and path set in " \
|
207
|
+
"`:lutaml-express-index:` attribute.")
|
173
208
|
end
|
174
209
|
|
175
210
|
lutaml_expressir_model = load_express_repositories(
|
@@ -179,9 +214,7 @@ force_read: false)
|
|
179
214
|
)
|
180
215
|
|
181
216
|
if lutaml_expressir_model
|
182
|
-
express_indexes[name] = {
|
183
|
-
model: lutaml_expressir_model,
|
184
|
-
}
|
217
|
+
express_indexes[name] = { model: lutaml_expressir_model }
|
185
218
|
end
|
186
219
|
end
|
187
220
|
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "content"
|
4
|
+
require_relative "base_structured_text_preprocessor"
|
5
|
+
|
6
|
+
module Metanorma
|
7
|
+
module Plugin
|
8
|
+
module Lutaml
|
9
|
+
class Yaml2TextPreprocessor < BaseStructuredTextPreprocessor
|
10
|
+
include Content
|
11
|
+
# search document for block `yaml2text`
|
12
|
+
# after that take template from block and read file into this template
|
13
|
+
# example:
|
14
|
+
# [yaml2text,foobar.yaml]
|
15
|
+
# ----
|
16
|
+
# === {item.name}
|
17
|
+
# {item.desc}
|
18
|
+
#
|
19
|
+
# {item.symbol}:: {item.symbol_def}
|
20
|
+
# ----
|
21
|
+
#
|
22
|
+
# with content of `foobar.yaml` file equal to:
|
23
|
+
# - name: spaghetti
|
24
|
+
# desc: wheat noodles of 9mm diameter
|
25
|
+
# symbol: SPAG
|
26
|
+
# symbol_def: the situation is message like spaghetti at a kid's
|
27
|
+
#
|
28
|
+
# will produce:
|
29
|
+
# === spaghetti
|
30
|
+
# wheat noodles of 9mm diameter
|
31
|
+
#
|
32
|
+
# SPAG:: the situation is message like spaghetti at a kid's meal
|
33
|
+
|
34
|
+
def initialize(config = {})
|
35
|
+
super
|
36
|
+
@config[:block_name] = "yaml2text"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -1,5 +1,8 @@
|
|
1
1
|
require "metanorma/plugin/lutaml/version"
|
2
2
|
require "metanorma/plugin/lutaml/config"
|
3
|
+
require "metanorma/plugin/lutaml/json2_text_preprocessor"
|
4
|
+
require "metanorma/plugin/lutaml/yaml2_text_preprocessor"
|
5
|
+
require "metanorma/plugin/lutaml/data2_text_preprocessor"
|
3
6
|
require "metanorma/plugin/lutaml/lutaml_preprocessor"
|
4
7
|
require "metanorma/plugin/lutaml/lutaml_uml_datamodel_description_preprocessor"
|
5
8
|
require "metanorma/plugin/lutaml/lutaml_ea_xmi_preprocessor"
|