metanorma-plugin-lutaml 0.7.31 → 0.7.33

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dda89cf25e4d97114f8285719533a301e4a932b36011212d07dc9c4e386eb8e0
4
- data.tar.gz: b2f0d0296c064be11a5031643bc2ae4d4428b034f475beb6958f24f41d5e3760
3
+ metadata.gz: 249c6be1ae1a19967a906113b2142e3608e65ffc784e85bb990a7226b4818982
4
+ data.tar.gz: 405ea5857dab3f2750d0ab8c4a27c9a0abc119f97dccbe0b67f143cfe780e754
5
5
  SHA512:
6
- metadata.gz: 8c16366f081e6c73776903a6eb930a1b08f0ad7332b6ed240d7318b4a9f2790740cedd20ae68845ffc6205bbb1bc3d629b21c096b7f99534b5b614a32c520d7f
7
- data.tar.gz: 8c7488d45307134a5de8f84adabc88eba63572baa8f5dd19187d823a25a8e46183632e9b47e4e7932833ca291ece2e03db6e118cc533c30f6f3d862c2a049774
6
+ metadata.gz: 3008f74df51c0ed75b44a87acc302ac0fcecf5e4e2501e7c55de8aac6023a7e247df13e088d554b217280c3329049c826768e3d5557cddbd63570810262d7d45
7
+ data.tar.gz: bf0891bae566ccbeaacd9a98516e2495642d9629c8eed5adc8e9b4025338fe1fcfd7aa2c5555f2f0c4e2795d25a4e7ee98c760b7eaf486c16762efb4318533cb
@@ -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) # rubocop:disable Metrics/MethodLength
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
- ::Metanorma::Util
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)
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Metanorma
4
+ module Plugin
5
+ module Lutaml
6
+ class FileNotFoundError < StandardError
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,13 @@
1
+ module Metanorma
2
+ module Plugin
3
+ module Lutaml
4
+ module Liquid
5
+ module CustomFilters
6
+ def file_exist(path)
7
+ File.exist?(path)
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -8,74 +8,122 @@
8
8
  [width="100%",cols="a,a,a,a,a,a,a,a"]
9
9
  |===
10
10
 
11
- h|Name: 7+| {{ klass.name }}
11
+ h|Name 7+| {{ klass.name }}
12
12
 
13
- h|Definition: 7+| {{ klass.definition | html2adoc }}
13
+ h|Definition 7+| {{ klass.definition | html2adoc }}
14
14
 
15
- h|Stereotype: 7+| {{ klass.stereotype | default: 'interface' }}
15
+ h|Stereotype 7+| {{ klass.stereotype | default: 'interface' }}
16
16
 
17
17
  {% assign inherited = klass.associations | where: "member_end_type", "inheritance" %}
18
18
  {% if inherited.size > 0 %}
19
- h|Inheritance from: 7+| {{ inherited | map: 'member_end' | join: ", " }}
19
+ h|Inherits from 7+| {{ inherited | map: 'member_end' | join: ", " }}
20
20
  {% endif %}
21
21
 
22
22
  {% assign generalizations = klass.associations | where: "member_end_type", "generalization" %}
23
23
  {% if generalizations.size > 0 %}
24
- h|Generalization of: 7+| {{ generalizations | map: 'member_end' | join: ", " }}
24
+ h|Generalization of 7+| {{ generalizations | map: 'member_end' | join: ", " }}
25
25
  {% endif %}
26
26
 
27
- h|Abstract: 7+| {% if klass.is_abstract %}True{% else %}False{% endif %}
27
+ h|Abstract 7+| {% if klass.is_abstract %}True{% else %}False{% endif %}
28
28
  {% assign aggregations = klass.associations | where: "member_end_type", "aggregation" %}
29
+
29
30
  {% if aggregations.size > 0 %}
30
- .{{aggregations.size | plus: 1}}+h|Associations:
31
- 4+| _Association with_
32
- | _Obligation_
33
- | _Maximum occurrence_
34
- | _Provides_
31
+
32
+ {% assign associations_colspan = aggregations.size | plus: 1 %}
33
+ {% for assoc in aggregations %}
34
+ {% if assoc.connector && assoc.connector.source %}
35
+ {% assign associations_colspan = associations_colspan | plus: 1 %}
36
+ {% endif %}
37
+ {% if assoc.connector && assoc.connector.target %}
38
+ {% assign associations_colspan = associations_colspan | plus: 1 %}
39
+ {% endif %}
40
+ {% endfor %}
41
+
42
+ .{{associations_colspan}}+h|Associations
43
+ 2+h| _Name_
44
+ 2+h| _Type_
45
+ 3+h| _Definition_
35
46
 
36
47
  {% for assoc in aggregations %}
37
- 4+| {{assoc.member_end}}
38
- | {% if assoc.member_end_cardinality %}{{ assoc.member_end_cardinality.min }}{% endif %}
39
- | {% if assoc.member_end_cardinality %}{{ assoc.member_end_cardinality.max }}{% endif %}
40
- | {{ assoc.member_end_attribute_name }}
48
+
49
+ {% assign member_end_documentation_size = assoc.member_end.definition | size %}
50
+ {% capture member_end_documentation %}{% if member_end_documentation_size > 0 %}{{ assoc.member_end.definition }}{% else %}(none){% endif %}{% endcapture %}
51
+
52
+ 2+| {{ assoc.member_end }}
53
+ 2+| {{ assoc.member_end_attribute_name }}
54
+ 3+| {{ member_end_documentation | html2adoc }}
55
+
56
+ {% if assoc.connector && assoc.connector.source %}
57
+ {% assign source_name_size = assoc.connector.source.name | size %}
58
+ {% capture source_name %}{% if source_name_size > 0 %}{{ assoc.connector.source.name }}{% else %}(self){% endif %}{% endcapture %}
59
+ {% assign source_documentation_size = assoc.connector.source.documentation | size %}
60
+ {% capture source_documentation %}{% if source_documentation_size > 0 %}{{ assoc.connector.source.documentation }}{% else %}(none){% endif %}{% endcapture %}
61
+ {% assign source_multiplicity_size = assoc.connector.source.multiplicity | size %}
62
+ {% capture source_multiplicity %}{% if source_multiplicity_size > 0 %}[{{ assoc.connector.source.multiplicity }}]{% else %}[none]{% endif %}{% endcapture %}
63
+
64
+ 2+| source:{{ source_name }} {{ source_multiplicity }}
65
+ 2+| {{ assoc.connector.source.type }}
66
+ 3+| {{ source_documentation | html2adoc }}
67
+ {% endif %}
68
+
69
+ {% if assoc.connector && assoc.connector.target %}
70
+ {% assign target_name_size = assoc.connector.target.name | size %}
71
+ {% capture target_name %}{% if target_name_size > 0 %}{{ assoc.connector.target.name }}{% else %}(self){% endif %}{% endcapture %}
72
+ {% assign target_documentation_size = assoc.connector.target.documentation | size %}
73
+ {% capture target_documentation %}{% if target_documentation_size > 0 %}{{ assoc.connector.target.documentation }}{% else %}(none){% endif %}{% endcapture %}
74
+ {% assign target_multiplicity_size = assoc.connector.target.multiplicity | size %}
75
+ {% capture target_multiplicity %}{% if target_multiplicity_size > 0 %}[{{ assoc.connector.target.multiplicity }}]{% else %}[none]{% endif %}{% endcapture %}
76
+
77
+ 2+| target:{{ target_name }} {{ target_multiplicity }}
78
+ 2+| {{ assoc.connector.target.type }}
79
+ 3+| {{ target_documentation | html2adoc }}
80
+ {% endif %}
41
81
 
42
82
  {% endfor %}
43
83
  {% else %}
44
- h| Associations: 7+| (none)
84
+ h| Associations 7+| (none)
45
85
  {% endif %}
46
86
 
47
87
  {% if klass.attributes.size > 0 %}
48
- .{{klass.attributes.size | plus: 1}}+h|Public attributes:
49
- | _Name_
50
- 2+| _Definition_
51
- | _Derived_
52
- | _Obligation_
53
- | _Maximum occurrence_
54
- | _Data type_
88
+ .{{klass.attributes.size | plus: 1}}+h|Attributes
89
+ 2+h| _Name_
90
+ 2+h| _Type_
91
+ 3+h| _Definition_
55
92
 
56
93
  {% for attr in klass.attributes %}
57
- | {{attr.name}}
58
- 2+| {{ attr.definition | html2adoc }}
59
- | {{ attr.is_derived }}
60
- | {{attr.cardinality.min}}
61
- | {{attr.cardinality.max}}
62
- | {{attr.type}}
94
+ {% capture attr_cardinality %}[{{attr.cardinality.min}}..{{attr.cardinality.max}}]{% endcapture %}
95
+ {% if attr_cardinality == "[*..*]" or attr_cardinality == "[0..*]" %}
96
+ {% assign attr_cardinality = "[*]" %}
97
+ {% endif %}
98
+ {% if attr_cardinality == "[1..1]" %}
99
+ {% assign attr_cardinality = "[1]" %}
100
+ {% endif %}
101
+ {% if attr_cardinality == "[..]" %}
102
+ {% assign attr_cardinality = "[none]" %}
103
+ {% endif %}
104
+
105
+ {% assign attr_definition_size = attr.definition | size %}
106
+ {% capture attr_definition %}{% if attr_definition_size > 0 %}{{ attr.definition }}{% else %}(none){% endif %}{% endcapture %}
107
+
108
+ 2+| {{ attr.name }} {{ attr_cardinality }}
109
+ 2+| {{ attr.type }}
110
+ 3+| {{ attr_definition | html2adoc }}
63
111
 
64
112
  {% endfor %}
65
113
  {% else %}
66
- h| Public attributes:
114
+ h| Attributes
67
115
  7+| (none)
68
116
  {% endif %}
69
117
 
70
118
  {% if klass.constraints.size > 0 %}
71
- .{{ klass.constraints.size }}+h| Constraints:
119
+ .{{ klass.constraints.size }}+h| Constraints
72
120
  {% for constraint in klass.constraints %}
73
121
  7+| `{{ constraint.body }}`: `{{ constraint.definition | replace: '|', '\|' }}`
74
122
 
75
123
  {% endfor %}
76
124
  {% else %}
77
125
 
78
- h|Constraints: 7+| (none)
126
+ h|Constraints 7+| (none)
79
127
  {% endif %}
80
128
 
81
129
  |===
@@ -33,8 +33,6 @@ module Metanorma
33
33
  reader.lines)
34
34
  input_lines = r.readlines.to_enum
35
35
 
36
- has_lutaml_liquid = input_lines.any? { |line| lutaml_liquid?(line) }
37
-
38
36
  express_indexes = Utils.parse_document_express_indexes(
39
37
  document,
40
38
  input_lines,
@@ -46,19 +44,11 @@ module Metanorma
46
44
  express_indexes: express_indexes,
47
45
  )
48
46
 
49
- log(document, result_content) if has_lutaml_liquid
50
-
51
47
  Asciidoctor::PreprocessorNoIfdefsReader.new(document, result_content)
52
48
  end
53
49
 
54
50
  protected
55
51
 
56
- def log(doc, text)
57
- File.open("#{doc.attr('docfile')}.lutaml.log.txt", "w:UTF-8") do |f|
58
- f.write(text.join("\n"))
59
- end
60
- end
61
-
62
52
  def lutaml_liquid?(line)
63
53
  line.match(EXPRESS_PREPROCESSOR_REGEX)
64
54
  end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Metanorma
4
+ module Plugin
5
+ module Lutaml
6
+ class ParseError < StandardError
7
+ end
8
+ end
9
+ end
10
+ end
@@ -7,6 +7,7 @@ require "metanorma/plugin/lutaml/liquid/custom_filters/html2adoc"
7
7
  require "metanorma/plugin/lutaml/liquid/custom_filters/values"
8
8
  require "metanorma/plugin/lutaml/liquid/custom_filters/replace_regex"
9
9
  require "metanorma/plugin/lutaml/liquid/custom_filters/loadfile"
10
+ require "metanorma/plugin/lutaml/liquid/custom_filters/file_exist"
10
11
 
11
12
  module Metanorma
12
13
  module Plugin
@@ -1,7 +1,7 @@
1
1
  module Metanorma
2
2
  module Plugin
3
3
  module Lutaml
4
- VERSION = "0.7.31".freeze
4
+ VERSION = "0.7.33".freeze
5
5
  end
6
6
  end
7
7
  end
@@ -29,11 +29,11 @@ Gem::Specification.new do |spec|
29
29
  spec.required_ruby_version = ">= 2.7.0" # rubocop:disable Gemspec/RequiredRubyVersion
30
30
 
31
31
  spec.add_dependency "asciidoctor"
32
- spec.add_dependency "coradoc", "~> 1.1.1"
33
- spec.add_dependency "expressir", "~> 2.1.13"
32
+ spec.add_dependency "coradoc", "~> 1.1"
33
+ spec.add_dependency "expressir", "~> 2.1"
34
34
  spec.add_dependency "isodoc"
35
35
  spec.add_dependency "liquid"
36
- spec.add_dependency "lutaml", "~> 0.9.32"
36
+ spec.add_dependency "lutaml", "~> 0.9"
37
37
  spec.add_dependency "ogc-gml", "~>1.0.0"
38
38
  spec.add_dependency "relaton-cli"
39
39
 
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.31
4
+ version: 0.7.33
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-23 00:00:00.000000000 Z
11
+ date: 2025-06-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: asciidoctor
@@ -30,28 +30,28 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 1.1.1
33
+ version: '1.1'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 1.1.1
40
+ version: '1.1'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: expressir
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 2.1.13
47
+ version: '2.1'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: 2.1.13
54
+ version: '2.1'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: isodoc
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -86,14 +86,14 @@ dependencies:
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: 0.9.32
89
+ version: '0.9'
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: 0.9.32
96
+ version: '0.9'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: ogc-gml
99
99
  requirement: !ruby/object:Gem::Requirement
@@ -158,8 +158,10 @@ 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
164
+ - lib/metanorma/plugin/lutaml/liquid/custom_filters/file_exist.rb
163
165
  - lib/metanorma/plugin/lutaml/liquid/custom_filters/html2adoc.rb
164
166
  - lib/metanorma/plugin/lutaml/liquid/custom_filters/loadfile.rb
165
167
  - lib/metanorma/plugin/lutaml/liquid/custom_filters/replace_regex.rb
@@ -193,6 +195,7 @@ files:
193
195
  - lib/metanorma/plugin/lutaml/lutaml_preprocessor.rb
194
196
  - lib/metanorma/plugin/lutaml/lutaml_table_inline_macro.rb
195
197
  - lib/metanorma/plugin/lutaml/lutaml_uml_datamodel_description_preprocessor.rb
198
+ - lib/metanorma/plugin/lutaml/parse_error.rb
196
199
  - lib/metanorma/plugin/lutaml/source_extractor.rb
197
200
  - lib/metanorma/plugin/lutaml/utils.rb
198
201
  - lib/metanorma/plugin/lutaml/version.rb