metanorma-plugin-lutaml 0.7.23 → 0.7.24

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: 86941bc530959fd2a6023671bfac6d46e18ac1095db5903b67b3be22f411372d
4
- data.tar.gz: f4cbcf8affd7ffffb7773ad3a9e7c6d008d176dfe3a507a2ba146cd38ba57e88
3
+ metadata.gz: ca6fb652af0690c22f2677cfe39f2546cecf24a46f539fe190b5d56023d942da
4
+ data.tar.gz: 99b7de7844b8e9f3e2fce736f7c931a8dd2a5b1c95bf93b57520b3261f5c2b3e
5
5
  SHA512:
6
- metadata.gz: 3a2dc0a28276e48230002049ba5946821c81d231be38494f978e5ad7298836b3ea1852be10314a8cfe7a86f775a097407c67a541f6f3c633e4a1dc32d6206702
7
- data.tar.gz: 0eda7cedc08c10bb6b0da49cfabb0f72e6a3a22355b784d9f633217be0f7bdec1946fe269deeb7d460a468f91d7004cc08df747018217239580e2d8566337791
6
+ metadata.gz: 754f952fbbad357aab40b9ab7e6d53af6e8195a797f8d3d4086265cfbb5d0360502b5f03bb68ce0ef02eeb51ff457931116e586273c60e2186fab49103dd33cc
7
+ data.tar.gz: '08cf1a352e910912d8d1c4323f5336e1e05da8fb30746a730ebd830e85e5adc07c55b23f8a01c048f4781de2b85f9295940c383b3057c2d502ec16fd0bef9745'
data/Gemfile CHANGED
@@ -11,3 +11,17 @@ begin
11
11
  rescue StandardError
12
12
  nil
13
13
  end
14
+
15
+ gem "debug"
16
+ gem "equivalent-xml"
17
+ gem "metanorma-standoc"
18
+ gem "rake"
19
+ gem "rspec"
20
+ gem "rspec-html-matchers"
21
+ gem "rubocop"
22
+ gem "rubocop-performance"
23
+ gem "simplecov"
24
+ gem "timecop"
25
+ gem "vcr"
26
+ gem "webmock"
27
+ gem "xml-c14n"
data/README.adoc CHANGED
@@ -300,6 +300,25 @@ via Liquid:
300
300
  NOTE: This functionality is used in the ISO 10303 SRL to load the full schema
301
301
  set at once but only render the selected schemas in individual documents.
302
302
 
303
+ === Using `include_path`
304
+
305
+ This functionality allows `[lutaml_express_liquid]` blocks to load templates
306
+ from the paths other than the location of the document.
307
+
308
+ [source,adoc]
309
+ -----
310
+ :lutaml-express-index: all_schemas; ../schemas_all.yaml;
311
+
312
+ [lutaml_express_liquid,all_schemas,context,config_yaml=schemas.yaml,include_path=../templates]
313
+ ---
314
+ {% assign selected = context.schemas | where: "selected" %}
315
+ {% render "templates/resources/schema" for selected as schema %}
316
+ ----
317
+ -----
318
+
319
+ The resulting block adds the `include_path` to the Liquid renderer. The path is
320
+ resolved based on the location of the document. You can add multiple paths by
321
+ separating them with commas.
303
322
 
304
323
  == Usage with Lutaml-UML
305
324
 
@@ -871,7 +890,9 @@ that specifies:
871
890
  * What render style is desired;
872
891
 
873
892
  * Location of the root package (which package should the iterative process start
874
- at).
893
+ at);
894
+
895
+ * Which EA extensions to be loaded.
875
896
 
876
897
  The format for using the YAML configuration file:
877
898
 
@@ -887,6 +908,9 @@ packages:
887
908
  - skip: four
888
909
  render_style: entity_list | data_dictionary | default
889
910
  section_depth: 2
911
+ ea_extension:
912
+ - "CityGML_MDG_Technology.xml"
913
+ - "xmi_definition_for_some_standard.xml"
890
914
  ----
891
915
 
892
916
  Where:
@@ -929,6 +953,12 @@ equal to 2, root package will be `one-1`.
929
953
  ]
930
954
  ----
931
955
 
956
+ * `ea_extension` - optional, list of EA extensions to load. Some XMI files may
957
+ contain elements that cannot be resolved by default, for example CityGML
958
+ elements. You can use `ea_extension` to load the definition of these elements
959
+ in XML format (`CityGML_MDG_Technology.xml`) in order to resolve them. The
960
+ location of the xml files is relative to the config YAML file.
961
+
932
962
  Usage with command:
933
963
 
934
964
  [source,adoc]
@@ -105,10 +105,11 @@ module Metanorma
105
105
  def gather_context_liquid_items( # rubocop:disable Metrics/AbcSize,Metrics/MethodLength,Metrics/ParameterLists
106
106
  index_names:, document:, indexes:, options: {}
107
107
  )
108
- index_names.map do |path|
109
- if indexes[path]
110
- indexes[path][:liquid_drop] ||=
111
- indexes[path][:model].to_liquid(options: options)
108
+ index_names.map do |path| # rubocop:disable Metrics/BlockLength
109
+ if indexes[path] && indexes[path][:model]
110
+ repo = indexes[path][:model]
111
+ repo = update_repo(options, repo)
112
+ indexes[path][:liquid_drop] ||= repo.to_liquid
112
113
  else
113
114
  full_path = Utils.relative_file_path(document, path)
114
115
  unless File.file?(full_path)
@@ -118,9 +119,10 @@ module Metanorma
118
119
  "the full path.",
119
120
  )
120
121
  end
121
- express_model = load_express_lutaml_file(document, path)
122
+ repo = load_express_lutaml_file(document, path)
123
+ repo = update_repo(options, repo)
122
124
  indexes[path] = {
123
- liquid_drop: express_model.to_liquid(options: options),
125
+ liquid_drop: repo.to_liquid,
124
126
  }
125
127
  end
126
128
 
@@ -128,7 +130,63 @@ module Metanorma
128
130
  end
129
131
  end
130
132
 
131
- def read_config_yaml_file(document, file_path) # rubocop:disable Metrics/MethodLength
133
+ def update_repo(options, repo)
134
+ # Unwrap repo if it's a cache
135
+ repo = repo.content if repo.is_a? Expressir::Model::Cache
136
+
137
+ # Process each schema
138
+ repo.schemas.each do |schema|
139
+ update_schema_selection(schema, options)
140
+ options["relative_path_prefix"] =
141
+ relative_path_prefix(options, schema)
142
+ update_schema_remarks(schema, options)
143
+ end
144
+
145
+ repo
146
+ end
147
+
148
+ def update_schema_selection(schema, options)
149
+ return unless options["selected_schemas"]
150
+
151
+ schema.selected = options["selected_schemas"].include?(schema.file_basename) ||
152
+ options["selected_schemas"].include?(schema.id)
153
+ end
154
+
155
+ def update_schema_remarks(schema, options)
156
+ # Update schema-level remarks
157
+ schema.remarks = decorate_remarks(options, schema.remarks)
158
+
159
+ # Update remark items
160
+ return unless schema.remark_items
161
+
162
+ schema.remark_items.each do |ri|
163
+ ri.remarks = decorate_remarks(options, ri.remarks)
164
+ end
165
+ end
166
+
167
+ def relative_path_prefix(options, model)
168
+ return nil if options.nil? || options["document"].nil?
169
+
170
+ document = options["document"]
171
+ file_path = File.dirname(model.file)
172
+ docfile_directory = File.dirname(
173
+ document.attributes["docfile"] || ".",
174
+ )
175
+ document
176
+ .path_resolver
177
+ .system_path(file_path, docfile_directory)
178
+ end
179
+
180
+ def decorate_remarks(options, remarks)
181
+ return [] unless remarks
182
+
183
+ remarks.map do |remark|
184
+ ::Expressir::Express::ExpressRemarksDecorator
185
+ .call(remark, options)
186
+ end
187
+ end
188
+
189
+ def read_config_yaml_file(document, file_path)
132
190
  return {} if file_path.nil?
133
191
 
134
192
  relative_file_path = Utils.relative_file_path(document, file_path)
@@ -136,29 +194,24 @@ module Metanorma
136
194
  File.read(relative_file_path, encoding: "UTF-8"),
137
195
  )
138
196
 
139
- options = {}
140
- if config_yaml["schemas"]
141
- unless config_yaml["schemas"].is_a?(Hash)
142
- raise StandardError.new(
143
- "[lutaml_express_liquid] attribute `config_yaml` must point " \
144
- "to a YAML file that has the `schema` key containing a hash.",
145
- )
146
- end
197
+ return {} unless config_yaml["schemas"]
147
198
 
148
- options["selected_schemas"] = config_yaml["schemas"].keys
199
+ unless config_yaml["schemas"].is_a?(Hash)
200
+ raise StandardError.new(
201
+ "[lutaml_express_liquid] attribute `config_yaml` must point " \
202
+ "to a YAML file that has the `schemas` key containing a hash.",
203
+ )
149
204
  end
150
205
 
151
- options
206
+ { "selected_schemas" => config_yaml["schemas"].keys }
152
207
  end
153
208
 
154
209
  def render_liquid_template(document:, lines:, context_name:, # rubocop:disable Metrics/AbcSize,Metrics/MethodLength,Metrics/ParameterLists
155
- index_names:, options:, indexes:)
156
- config_yaml_path = options.delete("config_yaml")
157
- config = read_config_yaml_file(document, config_yaml_path)
158
- if config["selected_schemas"]
159
- options["selected_schemas"] = config["selected_schemas"]
160
- end
210
+ index_names:, options:, indexes:)
211
+ # Process options and configuration
212
+ options = process_options(document, options)
161
213
 
214
+ # Get all context items in one go
162
215
  all_items = gather_context_liquid_items(
163
216
  index_names: index_names,
164
217
  document: document,
@@ -166,19 +219,23 @@ index_names:, options:, indexes:)
166
219
  options: options.merge("document" => document),
167
220
  )
168
221
 
169
- # Allow includes for the template
170
- include_paths = [
171
- Utils.relative_file_path(document, ""),
172
- options["include_path"],
173
- ].compact
222
+ # Setup include paths for liquid templates
223
+ include_paths = [Utils.relative_file_path(document, "")]
224
+ options["include_path"]&.split(",")&.each do |path|
225
+ # resolve include_path relative to the document
226
+ include_paths.push(Utils.relative_file_path(document, path))
227
+ end
228
+
229
+ file_system = ::Metanorma::Plugin::Lutaml::Liquid::LocalFileSystem
230
+ .new(include_paths, ["%s.liquid", "_%s.liquid", "_%s.adoc"])
174
231
 
232
+ # Parse template once outside the loop
233
+ template = ::Liquid::Template.parse(lines.join("\n"))
234
+ template.registers[:file_system] = file_system
235
+
236
+ # Render for each item
175
237
  all_items.map do |item|
176
- repo_drop = item[:liquid_drop]
177
- template = ::Liquid::Template.parse(lines.join("\n"))
178
- template.registers[:file_system] =
179
- ::Metanorma::Plugin::Lutaml::Liquid::LocalFileSystem
180
- .new(include_paths, ["%s.liquid", "_%s.liquid", "_%s.adoc"])
181
- template.assigns[context_name] = repo_drop
238
+ template.assigns[context_name] = item[:liquid_drop]
182
239
  template.render
183
240
  end.flatten
184
241
  rescue StandardError => e
@@ -186,10 +243,21 @@ index_names:, options:, indexes:)
186
243
  "[LutamlPreprocessor] Failed to parse LutaML block: #{e.message}",
187
244
  :error,
188
245
  )
189
- # [] # Return empty array to avoid breaking the document
190
246
  raise e
191
247
  end
192
248
 
249
+ def process_options(document, options)
250
+ # Process config file if specified
251
+ if (config_yaml_path = options.delete("config_yaml"))
252
+ config = read_config_yaml_file(document, config_yaml_path)
253
+ if config["selected_schemas"]
254
+ options["selected_schemas"] =
255
+ config["selected_schemas"]
256
+ end
257
+ end
258
+ options
259
+ end
260
+
193
261
  def parse_options(options_string)
194
262
  options_string
195
263
  .to_s
@@ -1,7 +1,7 @@
1
1
  module Metanorma
2
2
  module Plugin
3
3
  module Lutaml
4
- VERSION = "0.7.23".freeze
4
+ VERSION = "0.7.24".freeze
5
5
  end
6
6
  end
7
7
  end
@@ -27,23 +27,9 @@ Gem::Specification.new do |spec|
27
27
 
28
28
  spec.add_dependency "asciidoctor"
29
29
  spec.add_dependency "coradoc", "~> 1.1.1"
30
- spec.add_dependency "expressir", "~> 2.1.11"
30
+ spec.add_dependency "expressir", "~> 2.1.13"
31
31
  spec.add_dependency "liquid"
32
32
  spec.add_dependency "lutaml", "~> 0.9.25"
33
- spec.add_dependency "ogc-gml", "1.0.0"
33
+ spec.add_dependency "ogc-gml", "~>1.0.0"
34
34
  spec.add_dependency "relaton-cli"
35
-
36
- spec.add_development_dependency "debug"
37
- spec.add_development_dependency "equivalent-xml"
38
- spec.add_development_dependency "metanorma-standoc", "~> 3.0"
39
- spec.add_development_dependency "rake", "~> 13"
40
- spec.add_development_dependency "rspec", "~> 3.6"
41
- spec.add_development_dependency "rspec-html-matchers"
42
- spec.add_development_dependency "rubocop", "~> 1.58"
43
- spec.add_development_dependency "rubocop-performance", "~> 1.19"
44
- spec.add_development_dependency "simplecov", "~> 0.15"
45
- spec.add_development_dependency "timecop", "~> 0.9"
46
- spec.add_development_dependency "vcr", "~> 5.0.0"
47
- spec.add_development_dependency "webmock"
48
- spec.add_development_dependency "xml-c14n"
49
35
  end
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.23
4
+ version: 0.7.24
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-03-14 00:00:00.000000000 Z
11
+ date: 2025-03-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: asciidoctor
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 2.1.11
47
+ version: 2.1.13
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.11
54
+ version: 2.1.13
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: liquid
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -84,14 +84,14 @@ dependencies:
84
84
  name: ogc-gml
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - '='
87
+ - - "~>"
88
88
  - !ruby/object:Gem::Version
89
89
  version: 1.0.0
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
96
  version: 1.0.0
97
97
  - !ruby/object:Gem::Dependency
@@ -108,188 +108,6 @@ dependencies:
108
108
  - - ">="
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
- - !ruby/object:Gem::Dependency
112
- name: debug
113
- requirement: !ruby/object:Gem::Requirement
114
- requirements:
115
- - - ">="
116
- - !ruby/object:Gem::Version
117
- version: '0'
118
- type: :development
119
- prerelease: false
120
- version_requirements: !ruby/object:Gem::Requirement
121
- requirements:
122
- - - ">="
123
- - !ruby/object:Gem::Version
124
- version: '0'
125
- - !ruby/object:Gem::Dependency
126
- name: equivalent-xml
127
- requirement: !ruby/object:Gem::Requirement
128
- requirements:
129
- - - ">="
130
- - !ruby/object:Gem::Version
131
- version: '0'
132
- type: :development
133
- prerelease: false
134
- version_requirements: !ruby/object:Gem::Requirement
135
- requirements:
136
- - - ">="
137
- - !ruby/object:Gem::Version
138
- version: '0'
139
- - !ruby/object:Gem::Dependency
140
- name: metanorma-standoc
141
- requirement: !ruby/object:Gem::Requirement
142
- requirements:
143
- - - "~>"
144
- - !ruby/object:Gem::Version
145
- version: '3.0'
146
- type: :development
147
- prerelease: false
148
- version_requirements: !ruby/object:Gem::Requirement
149
- requirements:
150
- - - "~>"
151
- - !ruby/object:Gem::Version
152
- version: '3.0'
153
- - !ruby/object:Gem::Dependency
154
- name: rake
155
- requirement: !ruby/object:Gem::Requirement
156
- requirements:
157
- - - "~>"
158
- - !ruby/object:Gem::Version
159
- version: '13'
160
- type: :development
161
- prerelease: false
162
- version_requirements: !ruby/object:Gem::Requirement
163
- requirements:
164
- - - "~>"
165
- - !ruby/object:Gem::Version
166
- version: '13'
167
- - !ruby/object:Gem::Dependency
168
- name: rspec
169
- requirement: !ruby/object:Gem::Requirement
170
- requirements:
171
- - - "~>"
172
- - !ruby/object:Gem::Version
173
- version: '3.6'
174
- type: :development
175
- prerelease: false
176
- version_requirements: !ruby/object:Gem::Requirement
177
- requirements:
178
- - - "~>"
179
- - !ruby/object:Gem::Version
180
- version: '3.6'
181
- - !ruby/object:Gem::Dependency
182
- name: rspec-html-matchers
183
- requirement: !ruby/object:Gem::Requirement
184
- requirements:
185
- - - ">="
186
- - !ruby/object:Gem::Version
187
- version: '0'
188
- type: :development
189
- prerelease: false
190
- version_requirements: !ruby/object:Gem::Requirement
191
- requirements:
192
- - - ">="
193
- - !ruby/object:Gem::Version
194
- version: '0'
195
- - !ruby/object:Gem::Dependency
196
- name: rubocop
197
- requirement: !ruby/object:Gem::Requirement
198
- requirements:
199
- - - "~>"
200
- - !ruby/object:Gem::Version
201
- version: '1.58'
202
- type: :development
203
- prerelease: false
204
- version_requirements: !ruby/object:Gem::Requirement
205
- requirements:
206
- - - "~>"
207
- - !ruby/object:Gem::Version
208
- version: '1.58'
209
- - !ruby/object:Gem::Dependency
210
- name: rubocop-performance
211
- requirement: !ruby/object:Gem::Requirement
212
- requirements:
213
- - - "~>"
214
- - !ruby/object:Gem::Version
215
- version: '1.19'
216
- type: :development
217
- prerelease: false
218
- version_requirements: !ruby/object:Gem::Requirement
219
- requirements:
220
- - - "~>"
221
- - !ruby/object:Gem::Version
222
- version: '1.19'
223
- - !ruby/object:Gem::Dependency
224
- name: simplecov
225
- requirement: !ruby/object:Gem::Requirement
226
- requirements:
227
- - - "~>"
228
- - !ruby/object:Gem::Version
229
- version: '0.15'
230
- type: :development
231
- prerelease: false
232
- version_requirements: !ruby/object:Gem::Requirement
233
- requirements:
234
- - - "~>"
235
- - !ruby/object:Gem::Version
236
- version: '0.15'
237
- - !ruby/object:Gem::Dependency
238
- name: timecop
239
- requirement: !ruby/object:Gem::Requirement
240
- requirements:
241
- - - "~>"
242
- - !ruby/object:Gem::Version
243
- version: '0.9'
244
- type: :development
245
- prerelease: false
246
- version_requirements: !ruby/object:Gem::Requirement
247
- requirements:
248
- - - "~>"
249
- - !ruby/object:Gem::Version
250
- version: '0.9'
251
- - !ruby/object:Gem::Dependency
252
- name: vcr
253
- requirement: !ruby/object:Gem::Requirement
254
- requirements:
255
- - - "~>"
256
- - !ruby/object:Gem::Version
257
- version: 5.0.0
258
- type: :development
259
- prerelease: false
260
- version_requirements: !ruby/object:Gem::Requirement
261
- requirements:
262
- - - "~>"
263
- - !ruby/object:Gem::Version
264
- version: 5.0.0
265
- - !ruby/object:Gem::Dependency
266
- name: webmock
267
- requirement: !ruby/object:Gem::Requirement
268
- requirements:
269
- - - ">="
270
- - !ruby/object:Gem::Version
271
- version: '0'
272
- type: :development
273
- prerelease: false
274
- version_requirements: !ruby/object:Gem::Requirement
275
- requirements:
276
- - - ">="
277
- - !ruby/object:Gem::Version
278
- version: '0'
279
- - !ruby/object:Gem::Dependency
280
- name: xml-c14n
281
- requirement: !ruby/object:Gem::Requirement
282
- requirements:
283
- - - ">="
284
- - !ruby/object:Gem::Version
285
- version: '0'
286
- type: :development
287
- prerelease: false
288
- version_requirements: !ruby/object:Gem::Requirement
289
- requirements:
290
- - - ">="
291
- - !ruby/object:Gem::Version
292
- version: '0'
293
111
  description: Metanorma plugin for LutaML
294
112
  email:
295
113
  - open.source@ribose.com
@@ -303,10 +121,8 @@ files:
303
121
  - ".hound.yml"
304
122
  - ".rubocop.yml"
305
123
  - CODE_OF_CONDUCT.md
306
- - Dockerfile
307
124
  - Gemfile
308
125
  - LICENSE
309
- - Makefile
310
126
  - README.adoc
311
127
  - Rakefile
312
128
  - bin/console
data/Dockerfile DELETED
@@ -1,4 +0,0 @@
1
- FROM ruby:2.6
2
- COPY . .
3
- RUN gem install bundler:2.1.4
4
- RUN bundle install
data/Makefile DELETED
@@ -1,2 +0,0 @@
1
- fix-lint-staged:
2
- git status --short | egrep '^(A|M)' | awk '{ print $$2}' | grep -v db/schema.rb | xargs bundle exec rubocop -a