metanorma-plugin-lutaml 0.7.27 → 0.7.29

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: a13084276fa3469960665b5591f55c725bd5c0764694dc5c23874175539fcec7
4
- data.tar.gz: 36bc60f0e6c845c629c42658d7ec05f660378d5083dfd3199c066a50030ae865
3
+ metadata.gz: 3dd121eb5e209d2e11649e523ca637ec20c13776fc487a06b0f6f5c1bd0a6cfd
4
+ data.tar.gz: f6116b75a333054a2e5a9a39dbdafc558d8a4da566810dd75f9fe573beba56fc
5
5
  SHA512:
6
- metadata.gz: 26804996b13e88130f617c11ed5689117adcfe944acc3f2910e87ad7b8f25048268c63d0986787fe6470ffa80fb7a2eeaed8a73f449d98b91de07623ec93af34
7
- data.tar.gz: 34cb8cd2cad5803b28e998a1d9496b634ac14a091a75199c004147b94f45477cd47362d5bd6f12d7c8d12a1730fac515f82f653a9cbd55e7bc3af2293be81c69
6
+ metadata.gz: e4ee32d5341f80f1c8792cc35e43c6f0d77a5eda123edf4ee4e7f5ba42ca68151213c7d5142549cf0bc681750f136f3a1b2821881653a99c69b1cf3da430ee2b
7
+ data.tar.gz: c361d3764d7895dde4d9bb545d7d3adc4ea3651892690424fff8a38945ccaaec41961cb207282ae76eef1d3d007e2ac624253b2659e242cbe3f204200f176069
data/README.adoc CHANGED
@@ -252,8 +252,8 @@ per-block via a separate YAML file.
252
252
 
253
253
  [lutaml_express_liquid,all_schemas,context,config_yaml=schemas.yaml]
254
254
  ---
255
- {% assign selected = context.schemas | where: "selected" %}
256
- {% render "templates/resources/schema" for selected as schema %}
255
+ {% assign all_schemas = repo.schemas %}
256
+ {% render "templates/resources/schema" for ordered_schemas as schema %}
257
257
  ----
258
258
  -----
259
259
 
@@ -284,16 +284,16 @@ schemas:
284
284
  anything: ...
285
285
  ----
286
286
 
287
- The resulting block adds the `select` attribute to every schema of the the
288
- "context" object, which allows you to filter those out for complex operations
289
- via Liquid:
287
+ The resulting block adds the `ordered_schemas` context to allows you to filter
288
+ out the schemas you want to render according to the order in the config_yaml.
290
289
 
291
290
  [source,liquid]
292
291
  ----
293
292
  [lutaml_express_liquid,schemas_1,repo,config_yaml=select.yaml]
294
293
  ---
295
- {% assign selected = repo.schemas | where: "selected" %}
296
- ... do things with `selected` ...
294
+ {% assign all_schemas = repo.schemas %}
295
+ {% render "templates/resources/schema" for ordered_schemas as schema %}
296
+ ...
297
297
  ---
298
298
  ----
299
299
 
@@ -311,8 +311,9 @@ from the paths other than the location of the document.
311
311
 
312
312
  [lutaml_express_liquid,all_schemas,context,config_yaml=schemas.yaml,include_path=../templates]
313
313
  ---
314
- {% assign selected = context.schemas | where: "selected" %}
315
- {% render "templates/resources/schema" for selected as schema %}
314
+ {% assign all_schemas = repo.schemas %}
315
+ {% render "templates/resources/schema" for ordered_schemas as schema %}
316
+ ...
316
317
  ----
317
318
  -----
318
319
 
@@ -48,23 +48,6 @@ module Metanorma
48
48
  doc
49
49
  end
50
50
 
51
- def get_path_from_index(parent, index_name) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
52
- lutaml_xmi_index = parent.document
53
- .attributes["lutaml_xmi_index"][index_name]
54
-
55
- if lutaml_xmi_index.nil? || lutaml_xmi_index[:path].nil?
56
- ::Metanorma::Util.log(
57
- "[metanorma-plugin-lutaml] lutaml_xmi_index error: " \
58
- "XMI index #{index_name} path not found!",
59
- :error,
60
- )
61
-
62
- return nil
63
- end
64
-
65
- lutaml_xmi_index[:path]
66
- end
67
-
68
51
  def img_src_path(document, attrs, diagram)
69
52
  base_path = attrs["base_path"]
70
53
  format = attrs["format"] || "png"
@@ -85,6 +85,29 @@ module Metanorma
85
85
  )
86
86
  end
87
87
 
88
+ def get_xmi_path(parent, target, attrs)
89
+ return get_path_from_index(parent, attrs["index"]) if attrs["index"]
90
+
91
+ Utils.relative_file_path(parent.document, target)
92
+ end
93
+
94
+ def get_path_from_index(parent, index_name) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
95
+ lutaml_xmi_index = parent.document
96
+ .attributes["lutaml_xmi_index"][index_name]
97
+
98
+ if lutaml_xmi_index.nil? || lutaml_xmi_index[:path].nil?
99
+ ::Metanorma::Util.log(
100
+ "[metanorma-plugin-lutaml] lutaml_xmi_index error: " \
101
+ "XMI index #{index_name} path not found!",
102
+ :error,
103
+ )
104
+
105
+ return nil
106
+ end
107
+
108
+ lutaml_xmi_index[:path]
109
+ end
110
+
88
111
  def processed_lines(document, input_lines)
89
112
  result = []
90
113
  loop do
@@ -97,7 +120,7 @@ module Metanorma
97
120
  self.class.const_get(:MACRO_REGEXP)
98
121
  end
99
122
 
100
- def process_xmi_index_lines(document, line)
123
+ def process_xmi_index_lines(document, line) # rubocop:disable Metrics/AbcSize
101
124
  block_match = line.match(XMI_INDEX_REGEXP)
102
125
 
103
126
  return if block_match.nil?
@@ -15,8 +15,8 @@ module Metanorma
15
15
  use_dsl
16
16
  named :lutaml_klass_table
17
17
 
18
- def process(parent, target, attrs)
19
- xmi_path = Utils.relative_file_path(parent.document, target)
18
+ def process(parent, target, attrs) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
19
+ xmi_path = get_xmi_path(parent, target, attrs)
20
20
 
21
21
  if attrs["template"]
22
22
  attrs["template"] = Utils.relative_file_path(
@@ -137,7 +137,6 @@ module Metanorma
137
137
 
138
138
  # Process each schema
139
139
  repo.schemas.each do |schema|
140
- update_schema_selection(schema, options)
141
140
  options["relative_path_prefix"] =
142
141
  relative_path_prefix(options, schema)
143
142
  update_remarks(schema, options)
@@ -146,13 +145,6 @@ module Metanorma
146
145
  repo
147
146
  end
148
147
 
149
- def update_schema_selection(schema, options)
150
- return unless options["selected_schemas"]
151
-
152
- schema.selected = options["selected_schemas"].include?(schema.file_basename) ||
153
- options["selected_schemas"].include?(schema.id)
154
- end
155
-
156
148
  def update_remarks(model, options)
157
149
  model.remarks = decorate_remarks(options, model.remarks)
158
150
  model.remark_items&.each do |ri|
@@ -215,10 +207,8 @@ module Metanorma
215
207
 
216
208
  # Get all context items in one go
217
209
  all_items = gather_context_liquid_items(
218
- index_names: index_names,
219
- document: document,
220
- indexes: indexes,
221
- options: options.merge("document" => document),
210
+ index_names: index_names, document: document, indexes: indexes,
211
+ options: options.merge("document" => document)
222
212
  )
223
213
 
224
214
  # Setup include paths for liquid templates
@@ -238,17 +228,33 @@ module Metanorma
238
228
  # Render for each item
239
229
  all_items.map do |item|
240
230
  template.assigns[context_name] = item[:liquid_drop]
231
+ template.assigns["ordered_schemas"] = reorder_schemas(
232
+ item[:liquid_drop], options
233
+ )
241
234
  template.assigns["schemas_order"] = options["selected_schemas"]
242
235
  template.render
243
236
  end.flatten
244
237
  rescue StandardError => e
245
- ::Metanorma::Util.log(
246
- "[LutamlPreprocessor] Failed to parse LutaML block: #{e.message}",
247
- :error,
248
- )
238
+ ::Metanorma::Util
239
+ .log("[LutamlPreprocessor] Failed to parse LutaML block: " \
240
+ "#{e.message}", :error)
249
241
  raise e
250
242
  end
251
243
 
244
+ def reorder_schemas(repo_liquid, options)
245
+ return repo_liquid.schemas unless options["selected_schemas"]
246
+
247
+ ordered_schemas = []
248
+ options["selected_schemas"].each do |schema_name|
249
+ ordered_schema = repo_liquid.schemas.find do |schema|
250
+ schema.id == schema_name || schema.file_basename == schema_name
251
+ end
252
+ ordered_schemas.push(ordered_schema)
253
+ end
254
+
255
+ ordered_schemas
256
+ end
257
+
252
258
  def process_options(document, options)
253
259
  # Process config file if specified
254
260
  if (config_yaml_path = options.delete("config_yaml"))
@@ -1,7 +1,7 @@
1
1
  module Metanorma
2
2
  module Plugin
3
3
  module Lutaml
4
- VERSION = "0.7.27".freeze
4
+ VERSION = "0.7.29".freeze
5
5
  end
6
6
  end
7
7
  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.27
4
+ version: 0.7.29
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-04-24 00:00:00.000000000 Z
11
+ date: 2025-05-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: asciidoctor