metanorma-plugin-lutaml 0.7.31 → 0.7.32
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/docs/usages/json_yaml.adoc +16 -0
- data/lib/metanorma/plugin/lutaml/base_structured_text_preprocessor.rb +0 -4
- data/lib/metanorma/plugin/lutaml/content.rb +26 -12
- data/lib/metanorma/plugin/lutaml/file_not_found_error.rb +10 -0
- data/lib/metanorma/plugin/lutaml/parse_error.rb +10 -0
- data/lib/metanorma/plugin/lutaml/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cd1f666910d8626ed3c60a6543c1d0922a1b988941acb672484757dc42e4e1d2
|
4
|
+
data.tar.gz: f40aa319451eaf3444f9bbb06a45aa2f28281fb81d9bc0db40fa5f2699c52d6d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '096af413077b87f001e1746914fe05f833c83ff698d60383c57e7daf4aa88aae61244d034836ea01eb66bd787940065c4689210d2e9bf7de69b499e6ee96adf5'
|
7
|
+
data.tar.gz: 9873bf6b1a5439de6c1aa6480631fc820a0a857e079438fa7ee987cd3fa6a2d069976986d587345bd9e1f4a6466efcae087d06f88647316d3b1afbb46021c0ae
|
data/docs/usages/json_yaml.adoc
CHANGED
@@ -604,6 +604,22 @@ dolor sit
|
|
604
604
|
====
|
605
605
|
|
606
606
|
|
607
|
+
=== Error Handling
|
608
|
+
|
609
|
+
==== Invalid JSON or YAML file
|
610
|
+
|
611
|
+
If the specified file is an invalid JSON or YAML file, the block will raise an
|
612
|
+
error when the document is processed. The error will be:
|
613
|
+
`Metanorma::Plugin::Lutaml::ParseError`.
|
614
|
+
|
615
|
+
Detailed error messages will also be provided for troubleshooting.
|
616
|
+
|
617
|
+
==== Invalid path of file
|
618
|
+
|
619
|
+
If the specified file path does not exist, the block will raise an
|
620
|
+
error when the document is processed. The error will be:
|
621
|
+
`Metanorma::Plugin::Lutaml::FileNotFoundError`.
|
622
|
+
|
607
623
|
=== Advanced usage
|
608
624
|
|
609
625
|
==== General
|
@@ -93,10 +93,6 @@ module Metanorma
|
|
93
93
|
include_path: include_path,
|
94
94
|
template_path: template_path,
|
95
95
|
)
|
96
|
-
rescue StandardError => e
|
97
|
-
::Metanorma::Util.log("Failed to parse #{config[:block_name]} \
|
98
|
-
block: #{e.message}", :error)
|
99
|
-
[]
|
100
96
|
end
|
101
97
|
|
102
98
|
def resolve_context(document, block_match) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
|
@@ -2,6 +2,8 @@
|
|
2
2
|
|
3
3
|
require "json"
|
4
4
|
require "yaml"
|
5
|
+
require_relative "file_not_found_error"
|
6
|
+
require_relative "parse_error"
|
5
7
|
|
6
8
|
module Metanorma
|
7
9
|
module Plugin
|
@@ -10,21 +12,15 @@ module Metanorma
|
|
10
12
|
protected
|
11
13
|
|
12
14
|
# https://ruby-doc.org/stdlib-2.5.1/libdoc/psych/rdoc/Psych.html#method-c-safe_load
|
13
|
-
def yaml_content_from_file(resolved_file_path)
|
14
|
-
unless File.exist?(resolved_file_path)
|
15
|
-
::Metanorma::Util.log(
|
16
|
-
"YAML file referenced in [yaml2text] block not found: " \
|
17
|
-
"#{resolved_file_path}", :error
|
18
|
-
)
|
19
|
-
return
|
20
|
-
end
|
21
|
-
|
15
|
+
def yaml_content_from_file(resolved_file_path)
|
22
16
|
YAML.safe_load(
|
23
17
|
File.read(resolved_file_path, encoding: "UTF-8"),
|
24
18
|
permitted_classes: [Date, Time, Symbol],
|
25
19
|
permitted_symbols: [],
|
26
20
|
aliases: true,
|
27
21
|
)
|
22
|
+
rescue StandardError => e
|
23
|
+
raise_parsing_error(e, resolved_file_path, type: :yaml, from: :file)
|
28
24
|
end
|
29
25
|
|
30
26
|
def yaml_content_from_anchor(document, anchor)
|
@@ -34,14 +30,34 @@ module Metanorma
|
|
34
30
|
permitted_symbols: [],
|
35
31
|
aliases: true,
|
36
32
|
)
|
33
|
+
rescue StandardError => e
|
34
|
+
raise_parsing_error(e, resolved_file_path, type: :yaml, from: :anchor)
|
37
35
|
end
|
38
36
|
|
39
37
|
def json_content_from_file(resolved_file_path)
|
40
38
|
JSON.parse(File.read(resolved_file_path, encoding: "UTF-8"))
|
39
|
+
rescue StandardError => e
|
40
|
+
raise_parsing_error(e, resolved_file_path, type: :json, from: :file)
|
41
41
|
end
|
42
42
|
|
43
43
|
def json_content_from_anchor(document, anchor)
|
44
44
|
JSON.parse(document.attributes["source_blocks"][anchor])
|
45
|
+
rescue StandardError => e
|
46
|
+
raise_parsing_error(e, resolved_file_path, type: :json, from: :anchor)
|
47
|
+
end
|
48
|
+
|
49
|
+
def raise_parsing_error(error, file_or_anchor, type: :json, from: :file)
|
50
|
+
err_msg = "Error parsing #{type} from #{from} " \
|
51
|
+
"#{file_or_anchor}: #{error.message}"
|
52
|
+
::Metanorma::Util.log(err_msg, :error)
|
53
|
+
raise ::Metanorma::Plugin::Lutaml::ParseError.new err_msg
|
54
|
+
end
|
55
|
+
|
56
|
+
def raise_file_not_found_error(file_path)
|
57
|
+
err_msg = "File referenced in [{data|yaml|json}2text] block " \
|
58
|
+
"not found: #{file_path}"
|
59
|
+
::Metanorma::Util.log(err_msg, :error)
|
60
|
+
raise ::Metanorma::Plugin::Lutaml::FileNotFoundError.new err_msg
|
45
61
|
end
|
46
62
|
|
47
63
|
def content_from_file(document, file_path)
|
@@ -51,9 +67,7 @@ module Metanorma
|
|
51
67
|
|
52
68
|
def load_content_from_file(resolved_file_path)
|
53
69
|
unless File.exist?(resolved_file_path)
|
54
|
-
|
55
|
-
.log("Failed to load content from file: #{resolved_file_path}",
|
56
|
-
:error)
|
70
|
+
raise_file_not_found_error(resolved_file_path)
|
57
71
|
end
|
58
72
|
|
59
73
|
if json_file?(resolved_file_path)
|
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.32
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ribose Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-05-
|
11
|
+
date: 2025-05-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: asciidoctor
|
@@ -158,6 +158,7 @@ files:
|
|
158
158
|
- lib/metanorma/plugin/lutaml/content.rb
|
159
159
|
- lib/metanorma/plugin/lutaml/data2_text_preprocessor.rb
|
160
160
|
- lib/metanorma/plugin/lutaml/express_remarks_decorator.rb
|
161
|
+
- lib/metanorma/plugin/lutaml/file_not_found_error.rb
|
161
162
|
- lib/metanorma/plugin/lutaml/json2_text_preprocessor.rb
|
162
163
|
- lib/metanorma/plugin/lutaml/liquid/custom_blocks/key_iterator.rb
|
163
164
|
- lib/metanorma/plugin/lutaml/liquid/custom_filters/html2adoc.rb
|
@@ -193,6 +194,7 @@ files:
|
|
193
194
|
- lib/metanorma/plugin/lutaml/lutaml_preprocessor.rb
|
194
195
|
- lib/metanorma/plugin/lutaml/lutaml_table_inline_macro.rb
|
195
196
|
- lib/metanorma/plugin/lutaml/lutaml_uml_datamodel_description_preprocessor.rb
|
197
|
+
- lib/metanorma/plugin/lutaml/parse_error.rb
|
196
198
|
- lib/metanorma/plugin/lutaml/source_extractor.rb
|
197
199
|
- lib/metanorma/plugin/lutaml/utils.rb
|
198
200
|
- lib/metanorma/plugin/lutaml/version.rb
|