metanorma-plugin-lutaml 0.6.5 → 0.6.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 701c14675ce78bd6ddc3f3302679709c852e5572da0779c8f26964c6cac866a3
4
- data.tar.gz: 43d6abe93a90748e2b7a6163d396a43d1f09a8a36f8d0d2e43be34c7492a8daa
3
+ metadata.gz: '0847dcf75a0aa3da0e2179e5575757a140c29caa3d22d3b50cfe5ad04b1327d9'
4
+ data.tar.gz: 11c1e30bf0cbd74d10e6bd2cabb791f11508822baeb56c47622582580b855c35
5
5
  SHA512:
6
- metadata.gz: 5d45281405302619caf401c6f319c4a217c30c34826e466ef874e661b3cfa3c11c9fa2691638de4590d22c68491bbc70abebea078135706d8cfcca86ec927d1f
7
- data.tar.gz: 84b31a07da65105d1640613359e24ba60921c4c8c4ecc467cbdd200fee817a5e009b21d0533e90897151ddf260a6c2c48b68006818e5606e633a64197a2ec0bf
6
+ metadata.gz: f294b6e637b837af3a23939e0c152534bc7a86d7633399855c7e7b9a2373189ab60e9c3076e5fa7e1f1a975374e87413ada116aaed2a18c7be7027550d0b42fe
7
+ data.tar.gz: f418ee4fa767ddfac9e6d9f670cac031a6b86f781ee64717bbf5566b65784392450c038f220b321b22144c6b93cbc8deee57d73bcb3ca2b9ec9bd00b027a127f
@@ -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
@@ -1,4 +1,5 @@
1
- require "reverse_adoc"
1
+ require "coradoc"
2
+ require "coradoc/reverse_adoc"
2
3
 
3
4
  module Metanorma
4
5
  module Plugin
@@ -6,7 +7,7 @@ module Metanorma
6
7
  module Liquid
7
8
  module CustomFilters
8
9
  def html2adoc(input)
9
- ReverseAdoc.convert(input)
10
+ Coradoc::ReverseAdoc.convert(input)
10
11
  end
11
12
 
12
13
  def interpolate(input)
@@ -15,7 +16,7 @@ module Metanorma
15
16
  end
16
17
 
17
18
  def identify(input)
18
- input.split(/(?=[A-Z])/).map(&:downcase).join('-')
19
+ input.split(/(?=[A-Z])/).map(&:downcase).join("-")
19
20
  end
20
21
  end
21
22
  end
@@ -22,7 +22,8 @@ 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, "Illegal template name '#{template_path}'"
25
+ raise ::Liquid::FileSystemError,
26
+ "Illegal template name '#{template_path}'"
26
27
  end
27
28
 
28
29
  result_path = if template_path.include?('/')
@@ -46,11 +47,15 @@ module Metanorma
46
47
  end
47
48
 
48
49
  if result_path.nil?
49
- raise ::Liquid::FileSystemError, "No documents in template path '#{File.expand_path(template_path)}'"
50
+ raise ::Liquid::FileSystemError,
51
+ "No documents in template path '#{File.expand_path(template_path)}'"
50
52
  end
51
53
 
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)}'"
54
+ unless roots.any? do |root|
55
+ File.expand_path(result_path).start_with?(File.expand_path(root))
56
+ end
57
+ raise ::Liquid::FileSystemError,
58
+ "Illegal template path '#{File.expand_path(result_path)}'"
54
59
  end
55
60
 
56
61
  result_path
@@ -16,14 +16,15 @@ module Metanorma
16
16
  REMARKS_ATTRIBUTE = "remarks"
17
17
 
18
18
  def process(document, reader)
19
- r = Asciidoctor::PreprocessorNoIfdefsReader.new(document, reader.lines)
19
+ r = Asciidoctor::PreprocessorNoIfdefsReader.new(document,
20
+ reader.lines)
20
21
  input_lines = r.readlines.to_enum
21
22
 
22
23
  has_lutaml = input_lines.any? { |line| lutaml?(line) }
23
24
 
24
25
  express_indexes = Utils.parse_document_express_indexes(
25
26
  document,
26
- input_lines
27
+ input_lines,
27
28
  )
28
29
 
29
30
  result_content = process_input_lines(
@@ -53,18 +54,18 @@ module Metanorma
53
54
  ::Lutaml::Parser.parse(
54
55
  File.new(
55
56
  Utils.relative_file_path(document, file_path),
56
- encoding: "UTF-8"
57
- )
57
+ encoding: "UTF-8",
58
+ ),
58
59
  )
59
60
  end
60
61
 
61
62
  private
62
63
 
63
64
  def process_input_lines(
64
- document:,
65
+ document:,
65
66
  input_lines:,
66
67
  express_indexes:
67
- )
68
+ )
68
69
 
69
70
  result = []
70
71
  loop do
@@ -73,7 +74,7 @@ module Metanorma
73
74
  document,
74
75
  input_lines,
75
76
  express_indexes,
76
- )
77
+ ),
77
78
  )
78
79
  end
79
80
  result
@@ -99,7 +100,7 @@ module Metanorma
99
100
  index_names: index_names,
100
101
  context_name: context_name,
101
102
  options: options,
102
- indexes: express_indexes
103
+ indexes: express_indexes,
103
104
  )
104
105
  end
105
106
 
@@ -120,23 +121,23 @@ module Metanorma
120
121
 
121
122
  # Does this condition ever happen? That is only if the
122
123
  # `lutaml-express-index` condition is not set
123
- unless indexes[path]
124
+ if indexes[path]
125
+ indexes[path][:serialized_hash] ||= indexes[path][:wrapper].to_liquid
126
+ else
124
127
 
125
128
  full_path = Utils.relative_file_path(document, path)
126
129
  unless File.file?(full_path)
127
130
  raise StandardError.new(
128
131
  "Unable to load EXPRESS index for `#{path}`, " \
129
132
  "please define it at `:lutaml-express-index:` or specify " \
130
- "the full path."
133
+ "the full path.",
131
134
  )
132
135
  end
133
136
  wrapper = load_lutaml_file(document, path)
134
137
  indexes[path] = {
135
138
  wrapper: wrapper,
136
- serialized_hash: wrapper.to_liquid
139
+ serialized_hash: wrapper.to_liquid,
137
140
  }
138
- else
139
- indexes[path][:serialized_hash] ||= indexes[path][:wrapper].to_liquid
140
141
  end
141
142
 
142
143
  indexes[path]
@@ -148,7 +149,7 @@ module Metanorma
148
149
 
149
150
  relative_file_path = Utils.relative_file_path(document, file_path)
150
151
  config_yaml = YAML.safe_load(
151
- File.read(relative_file_path, encoding: "UTF-8")
152
+ File.read(relative_file_path, encoding: "UTF-8"),
152
153
  )
153
154
 
154
155
  options = {}
@@ -156,7 +157,7 @@ module Metanorma
156
157
  unless config_yaml["schemas"].is_a?(Hash)
157
158
  raise StandardError.new(
158
159
  "[lutaml_express] attribute `config_yaml` must point to a YAML " \
159
- "file that has the `schema` key containing a hash."
160
+ "file that has the `schema` key containing a hash.",
160
161
  )
161
162
  end
162
163
 
@@ -186,8 +187,9 @@ module Metanorma
186
187
  schema,
187
188
  options.merge(
188
189
  "relative_path_prefix" =>
189
- Utils.relative_file_path(document, File.dirname(schema["file"]))
190
- )
190
+ Utils.relative_file_path(document,
191
+ File.dirname(schema["file"])),
192
+ ),
191
193
  ) || {}
192
194
  end
193
195
 
@@ -200,7 +202,7 @@ module Metanorma
200
202
  gather_context_items(
201
203
  index_names: index_names,
202
204
  document: document,
203
- indexes: indexes
205
+ indexes: indexes,
204
206
  ).map do |items|
205
207
 
206
208
  serialized_hash = items[:serialized_hash]
@@ -223,7 +225,7 @@ module Metanorma
223
225
  document: document,
224
226
  block_lines: lines,
225
227
  context_items: serialized_hash,
226
- context_name: context_name
228
+ context_name: context_name,
227
229
  )
228
230
  end.flatten
229
231
  rescue StandardError => e
@@ -246,8 +248,8 @@ module Metanorma
246
248
  key,
247
249
  val&.map do |remark|
248
250
  Metanorma::Plugin::Lutaml::ExpressRemarksDecorator
249
- .call(remark, options)
250
- end
251
+ .call(remark, options)
252
+ end,
251
253
  ]
252
254
  end
253
255
 
@@ -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,([^,]+),?([^,]+),?(.+?)?\]/.freeze
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,([^,]+),?([^,]+),?(.+?)?\]/.freeze
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
- #{equalsigns(depth) + ' Enumeration: {{ definition.name }}' unless skip_headers}
112
+ #{"#{equalsigns(depth)} Enumeration: {{ definition.name }}" unless skip_headers}
113
113
  {% else %}
114
- #{equalsigns(depth) + ' Class: {{ definition.name }}' unless skip_headers}
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,([^,]+),?(.+)?\]/.freeze
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"
@@ -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] =
@@ -72,12 +72,11 @@ module Metanorma
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
-
81
80
  rescue Expressir::Error
82
81
  FileUtils.rm_rf(cache_full_path)
83
82
 
@@ -85,9 +84,8 @@ module Metanorma
85
84
  path: path,
86
85
  cache_path: cache_path,
87
86
  document: document,
88
- force_read: true
87
+ force_read: true,
89
88
  )
90
-
91
89
  rescue StandardError => e
92
90
  document.logger.warn("Failed to load #{full_path}: #{e.message}")
93
91
  raise e
@@ -121,26 +119,21 @@ module Metanorma
121
119
  end
122
120
 
123
121
  # TODO: Refactor this using Suma::SchemaConfig
124
- def load_express_from_index(document, path)
122
+ def load_express_from_index(_document, path)
125
123
  yaml_content = YAML.safe_load(File.read(path))
126
124
  schema_yaml_base_path = Pathname.new(File.dirname(path))
127
125
 
128
126
  # If there is a global root path set, all subsequent paths are
129
127
  # relative to it.
130
- if yaml_content['path']
131
- root_schema_path = Pathname.new(yaml_content['path'])
128
+ if yaml_content["path"]
129
+ root_schema_path = Pathname.new(yaml_content["path"])
132
130
  schema_yaml_base_path = schema_yaml_base_path + root_schema_path
133
131
  end
134
132
 
135
133
  files_to_load = yaml_content["schemas"].map do |key, value|
136
-
137
134
  # If there is no path: set for a schema, we assume it uses the
138
135
  # schema name as the #{filename}.exp.
139
- schema_path = if value['path']
140
- Pathname.new(value['path'])
141
- else
142
- Pathname.new("#{key}.exp")
143
- end
136
+ schema_path = Pathname.new(value["path"] || "#{key}.exp")
144
137
 
145
138
  real_schema_path = schema_yaml_base_path + schema_path
146
139
  File.new(real_schema_path.cleanpath.to_s, encoding: "UTF-8")
@@ -171,13 +164,13 @@ module Metanorma
171
164
  lutaml_expressir_wrapper = load_express_repositories(
172
165
  path: path,
173
166
  cache_path: cache,
174
- document: document
167
+ document: document,
175
168
  )
176
169
 
177
170
  if lutaml_expressir_wrapper
178
171
  express_indexes[name] = {
179
172
  wrapper: lutaml_expressir_wrapper,
180
- serialized_hash: nil
173
+ serialized_hash: nil,
181
174
  }
182
175
  end
183
176
  end
@@ -1,7 +1,7 @@
1
1
  module Metanorma
2
2
  module Plugin
3
3
  module Lutaml
4
- VERSION = "0.6.5".freeze
4
+ VERSION = "0.6.6".freeze
5
5
  end
6
6
  end
7
7
  end
@@ -26,11 +26,11 @@ Gem::Specification.new do |spec|
26
26
  spec.require_paths = ["lib"]
27
27
 
28
28
  spec.add_dependency "asciidoctor"
29
+ spec.add_dependency "coradoc"
29
30
  spec.add_dependency "expressir", "~> 1.4.0"
30
31
  spec.add_dependency "liquid"
31
32
  spec.add_dependency "lutaml"
32
33
  spec.add_dependency "relaton-cli"
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.5
4
+ version: 0.6.6
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-05-13 00:00:00.000000000 Z
11
+ date: 2024-06-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: asciidoctor
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: coradoc
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: expressir
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -80,20 +94,6 @@ dependencies:
80
94
  - - ">="
81
95
  - !ruby/object:Gem::Version
82
96
  version: '0'
83
- - !ruby/object:Gem::Dependency
84
- name: reverse_adoc
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - "~>"
88
- - !ruby/object:Gem::Version
89
- version: 0.3.7
90
- type: :runtime
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - "~>"
95
- - !ruby/object:Gem::Version
96
- version: 0.3.7
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: debug
99
99
  requirement: !ruby/object:Gem::Requirement