metanorma-plugin-lutaml 0.6.2 → 0.6.3

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: 56a196838fa30ab8585b1834d115bf6ff99b4b81d33176975b75dc7f5c5cd5bd
4
- data.tar.gz: 458ce39ccac1e11b1dee74289e9e85a06a4ec5fa2faceaa78869ca18cc8dae77
3
+ metadata.gz: 19d2399f31818f5f72d0f6237199042a1b729457039c033e5a45d29645b56eda
4
+ data.tar.gz: 0a3a779c6e6b556c7597fc2f9fc708565fb3e0841969eccc855334fcf9e98a88
5
5
  SHA512:
6
- metadata.gz: 780fa1199a23d199cb8f04d1a1b9b79d416f8aed0a2b442f02baccd370830d76d80fee12c2061e9424c9dd294059f5709b50a0eac7ac9b24fd4b492f54caa839
7
- data.tar.gz: 1582258a02474a3ee351b935afc686a78ed8c82f1cc72efefde7c003110bfaa8fd4189d979b2070e61509d5d4997208b7644daf529c6e221c9e187e4e3def057
6
+ metadata.gz: a03c8868605097a556281eae23b1f2a9b40f3991e7f7304c0f70ef2d3f8e8477fbd69389c2c49482b0774b729dbb02a8bbb39f3949b7453a5542e4a957c4a70e
7
+ data.tar.gz: 1001f84dc00d0430552d89f63525af328fa1d2fec6143ce7fbf5c49764f83f5d27b0673d4c57756514498236eb91857cadaf981400097e2d1556f8a554d962c1
data/Gemfile CHANGED
@@ -6,8 +6,4 @@ git_source(:github) { |repo| "https://github.com/#{repo}" }
6
6
 
7
7
  gemspec
8
8
 
9
- begin
10
- eval_gemfile("Gemfile.devel")
11
- rescue StandardError
12
- nil
13
- end
9
+ eval_gemfile("Gemfile.devel") rescue nil
@@ -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
@@ -15,7 +15,7 @@ module Metanorma
15
15
  end
16
16
 
17
17
  def identify(input)
18
- input.split(/(?=[A-Z])/).map(&:downcase).join("-")
18
+ input.split(/(?=[A-Z])/).map(&:downcase).join('-')
19
19
  end
20
20
  end
21
21
  end
@@ -22,41 +22,35 @@ 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,
26
- "Illegal template name '#{template_path}'"
25
+ raise ::Liquid::FileSystemError, "Illegal template name '#{template_path}'"
27
26
  end
28
27
 
29
- result_path = if template_path.include?("/")
30
- roots
31
- .map do |root|
32
- patterns.map do |pattern|
33
- File.join(root, File.dirname(template_path),
34
- pattern % File.basename(template_path))
35
- end
36
- end
37
- .flatten
38
- .find { |path| File.file?(path) }
39
- else
40
- roots
41
- .map do |root|
42
- patterns.map do |pattern|
43
- File.join(root, pattern % template_path)
44
- end
45
- end
46
- .flatten
47
- .find { |path| File.file?(path) }
48
- end
28
+ result_path = if template_path.include?('/')
29
+ roots
30
+ .map do |root|
31
+ patterns.map do |pattern|
32
+ File.join(root, File.dirname(template_path), pattern % File.basename(template_path))
33
+ end
34
+ end
35
+ .flatten
36
+ .find { |path| File.file?(path) }
37
+ else
38
+ roots
39
+ .map do |root|
40
+ patterns.map do |pattern|
41
+ File.join(root, pattern % template_path)
42
+ end
43
+ end
44
+ .flatten
45
+ .find { |path| File.file?(path) }
46
+ end
49
47
 
50
48
  if result_path.nil?
51
- raise ::Liquid::FileSystemError,
52
- "No documents in template path '#{File.expand_path(template_path)}'"
49
+ raise ::Liquid::FileSystemError, "No documents in template path '#{File.expand_path(template_path)}'"
53
50
  end
54
51
 
55
- unless roots.any? do |root|
56
- File.expand_path(result_path).start_with?(File.expand_path(root))
57
- end
58
- raise ::Liquid::FileSystemError,
59
- "Illegal template path '#{File.expand_path(result_path)}'"
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)}'"
60
54
  end
61
55
 
62
56
  result_path
@@ -16,14 +16,14 @@ module Metanorma
16
16
  REMARKS_ATTRIBUTE = "remarks"
17
17
 
18
18
  def process(document, reader)
19
- r = Asciidoctor::PreprocessorNoIfdefsReader.new(document,
20
- reader.lines)
19
+ r = Asciidoctor::PreprocessorNoIfdefsReader.new(document, reader.lines)
21
20
  input_lines = r.readlines.to_enum
22
21
 
23
22
  has_lutaml = input_lines.any? { |line| lutaml?(line) }
23
+
24
24
  express_indexes = Utils.parse_document_express_indexes(
25
25
  document,
26
- input_lines,
26
+ input_lines
27
27
  )
28
28
 
29
29
  result_content = process_input_lines(
@@ -53,18 +53,18 @@ module Metanorma
53
53
  ::Lutaml::Parser.parse(
54
54
  File.new(
55
55
  Utils.relative_file_path(document, file_path),
56
- encoding: "UTF-8",
57
- ),
56
+ encoding: "UTF-8"
57
+ )
58
58
  )
59
59
  end
60
60
 
61
61
  private
62
62
 
63
63
  def process_input_lines(
64
- document:,
64
+ document:,
65
65
  input_lines:,
66
66
  express_indexes:
67
- )
67
+ )
68
68
 
69
69
  result = []
70
70
  loop do
@@ -73,7 +73,7 @@ module Metanorma
73
73
  document,
74
74
  input_lines,
75
75
  express_indexes,
76
- ),
76
+ )
77
77
  )
78
78
  end
79
79
  result
@@ -99,7 +99,7 @@ module Metanorma
99
99
  index_names: index_names,
100
100
  context_name: context_name,
101
101
  options: options,
102
- indexes: express_indexes,
102
+ indexes: express_indexes
103
103
  )
104
104
  end
105
105
 
@@ -118,15 +118,25 @@ module Metanorma
118
118
  # TODO: decide how to handle expressir multiply file parse as one
119
119
  # object and lutaml
120
120
 
121
- # Does this condition ever happen? That is only if the `lutaml-express-index` condition is not set
122
- if indexes[path]
123
- indexes[path][:serialized_hash] ||= indexes[path][:wrapper].to_liquid
124
- else
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
125
133
  wrapper = load_lutaml_file(document, path)
126
134
  indexes[path] = {
127
135
  wrapper: wrapper,
128
- serialized_hash: wrapper.to_liquid,
136
+ serialized_hash: wrapper.to_liquid
129
137
  }
138
+ else
139
+ indexes[path][:serialized_hash] ||= indexes[path][:wrapper].to_liquid
130
140
  end
131
141
 
132
142
  indexes[path]
@@ -140,14 +150,15 @@ module Metanorma
140
150
  YAML.safe_load(File.read(relative_file_path, encoding: "UTF-8"))
141
151
  end
142
152
 
143
- def decorate_schema_object(schema:, document:, indexes:, index_names:,
144
- selected:, options:)
153
+ def decorate_schema_object(schema:, document:, indexes:, index_names:, selected:, options:)
145
154
  # Mark a schema as "selected" with `.selected`
146
155
  schema["selected"] = true if selected
147
156
 
148
157
  # Provide pretty-formatted code under `.formatted`
149
- _, index_found_value = indexes.detect do |_k, _v|
150
- _
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"]
161
+ end
151
162
  end
152
163
 
153
164
  schema["formatted"] = index_found_value[:wrapper].original_document.schemas.detect do |s|
@@ -159,46 +170,47 @@ selected:, options:)
159
170
  schema,
160
171
  options.merge(
161
172
  "relative_path_prefix" =>
162
- Utils.relative_file_path(document,
163
- File.dirname(schema["file"])),
164
- ),
173
+ Utils.relative_file_path(document, File.dirname(schema["file"]))
174
+ )
165
175
  ) || {}
166
176
  end
167
177
 
168
- def render_template(document:, lines:, context_name:, index_names:,
169
- options:, indexes:)
178
+ def render_template(document:, lines:, context_name:, index_names:, options:, indexes:)
179
+
170
180
  config_yaml_path = options.delete("config_yaml")
171
- config_yaml = if config_yaml_path
172
- parse_yaml_config_file(document, config_yaml_path)
173
- else
174
- {}
175
- end
181
+ config_yaml = config_yaml_path ?
182
+ parse_yaml_config_file(document, config_yaml_path) :
183
+ {}
176
184
 
177
185
  selected_schemas = config_yaml["schemas"]
178
186
 
179
187
  gather_context_items(
180
188
  index_names: index_names,
181
189
  document: document,
182
- indexes: indexes,
190
+ indexes: indexes
183
191
  ).map do |items|
192
+
184
193
  serialized_hash = items[:serialized_hash]
185
194
 
186
- serialized_hash["schemas"]&.map! do |schema|
187
- decorate_schema_object(
188
- schema: schema,
189
- document: document,
190
- index_names: index_names,
191
- indexes: indexes,
192
- selected: selected_schemas && selected_schemas.include?(schema["id"]),
193
- options: options,
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
+ )
206
+ end
195
207
  end
196
208
 
197
209
  render_block(
198
210
  document: document,
199
211
  block_lines: lines,
200
212
  context_items: serialized_hash,
201
- context_name: context_name,
213
+ context_name: context_name
202
214
  )
203
215
  end.flatten
204
216
  rescue StandardError => e
@@ -221,8 +233,8 @@ options:, indexes:)
221
233
  key,
222
234
  val&.map do |remark|
223
235
  Metanorma::Plugin::Lutaml::ExpressRemarksDecorator
224
- .call(remark, options)
225
- end,
236
+ .call(remark, options)
237
+ end
226
238
  ]
227
239
  end
228
240
 
@@ -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,([^,]+),?([^,]+),?(.+?)?\]/.freeze
12
+ /\[lutaml_uml_attributes_table,([^,]+),?([^,]+),?(.+?)?\]/
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,([^,]+),?([^,]+),?(.+?)?\]/.freeze
18
+ /\[lutaml_uml_class,([^,]+),?([^,]+),?(.+?)?\]/
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,([^,]+),?(.+)?\]/.freeze
19
+ /\[lutaml_uml_datamodel_description,([^,]+),?(.+)?\]/
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"
@@ -92,7 +92,7 @@ module Metanorma
92
92
  def fill_in_entities_refs_attributes(document, lutaml_document_wrapper,
93
93
  options)
94
94
  lutaml_document = lutaml_document_wrapper.original_document
95
- options.fetch(RENDER_STYLE_ATTRIBUTE, "default")
95
+ render_style = options.fetch(RENDER_STYLE_ATTRIBUTE, "default")
96
96
  all_children_packages = lutaml_document.packages
97
97
  .map(&:children_packages).flatten
98
98
  package_flat_packages = lambda do |pks|
@@ -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] =
@@ -54,8 +54,8 @@ module Metanorma
54
54
  end
55
55
  end
56
56
 
57
- def load_express_repositories(path:, cache_path:, document:,
58
- force_read: false)
57
+ def load_express_repositories(path:, cache_path:, document:, force_read: false)
58
+
59
59
  cache_full_path = cache_path &&
60
60
  Utils.relative_file_path(document, cache_path)
61
61
 
@@ -72,11 +72,12 @@ force_read: false)
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
+
80
81
  rescue Expressir::Error
81
82
  FileUtils.rm_rf(cache_full_path)
82
83
 
@@ -84,8 +85,9 @@ force_read: false)
84
85
  path: path,
85
86
  cache_path: cache_path,
86
87
  document: document,
87
- force_read: true,
88
+ force_read: true
88
89
  )
90
+
89
91
  rescue StandardError => e
90
92
  document.logger.warn("Failed to load #{full_path}: #{e.message}")
91
93
  raise e
@@ -131,6 +133,7 @@ force_read: false)
131
133
  File.new(Utils.relative_file_path(document, path),
132
134
  encoding: "UTF-8")
133
135
  end
136
+
134
137
  ::Lutaml::Parser.parse(files_to_load)
135
138
  end
136
139
 
@@ -156,13 +159,13 @@ force_read: false)
156
159
  lutaml_expressir_wrapper = load_express_repositories(
157
160
  path: path,
158
161
  cache_path: cache,
159
- document: document,
162
+ document: document
160
163
  )
161
164
 
162
165
  if lutaml_expressir_wrapper
163
166
  express_indexes[name] = {
164
167
  wrapper: lutaml_expressir_wrapper,
165
- serialized_hash: nil,
168
+ serialized_hash: nil
166
169
  }
167
170
  end
168
171
  end
@@ -1,7 +1,7 @@
1
1
  module Metanorma
2
2
  module Plugin
3
3
  module Lutaml
4
- VERSION = "0.6.2".freeze
4
+ VERSION = "0.6.3".freeze
5
5
  end
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: metanorma-plugin-lutaml
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.2
4
+ version: 0.6.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.