metanorma-plugin-lutaml 0.7.81 → 0.7.82

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: 1dfb4b9c90d1ffba66925177643b11f954b9aa0640e3fdc0c3beefec359267f5
4
- data.tar.gz: b211eedd83758587686f9387f8e9875b52d0c9252632fedb7b9aacbd31e405a4
3
+ metadata.gz: b1efa6443af45e749f5578728610b36ddbedda93a095d9073d97b1a548c92f02
4
+ data.tar.gz: 104d464781a93e4a1fa451bfbfaae51d326952dd4fe01e36a286bf2901fa2891
5
5
  SHA512:
6
- metadata.gz: ed7b5fe9f10850fe9a3066c73996f38eb73445c5265a790685cc4af60b6c95740ab1e0860239ff5ba03156307c0c08715c5be3e671798533faf43ea25b9c88f9
7
- data.tar.gz: ea8a4b896bd48f51fa4214c5e2d81fd24bc3bfe059a457d2cbed544e2d23f7a12c0a02eb47d92667c4e9d407ff72ac5a9e1b1a8e120947a4678c71ecf11df0cf
6
+ metadata.gz: 1f0b801c559b4f4d05bf51d9c0c1055e206a2d600b86bd989d562addbb207bace2eb3b8bd97c9a7302dbadd6a6afe1271b15ac57d13cfb182668c95bb4c8e368
7
+ data.tar.gz: cebe8b6d029acbe9cb08f25f73718dfb5a52dc220003ccf8b3c2a87da95a11fd6931fd3fa0719a7fa45e64aada47ea3c3040a29277f8df075305ed6d0201cdd9
@@ -30,8 +30,19 @@ module Metanorma
30
30
  #
31
31
  # (written on one line in a document)
32
32
  #
33
+ # XML Schema definitions with XML instance documents — the schema
34
+ # (XSD) derives the model classes in-memory and the instance document
35
+ # parses against them (needs lutaml-model >= 0.8.176):
36
+ #
37
+ # [lutaml_data,<schema.xsd>,<instance.xml>,<context>]
38
+ # ----
39
+ # {% for ft in context.CTS100FCFeatureCatalogue.s100_fc_feature_types %}
40
+ # {{ ft.name }}
41
+ # {% endfor %}
42
+ # ----
33
43
  class LutamlDataPreprocessor < BasePreprocessor
34
- DATA_FILE_EXTENSIONS = %w[.lml .yaml .yml .json].freeze
44
+ DATA_FILE_EXTENSIONS = %w[.lml .yaml .yml .json .xml].freeze
45
+ SCHEMA_EXTENSIONS = %w[.xsd].freeze
35
46
  DEFAULT_CONTEXT_NAME = "lutaml_data"
36
47
  PROVIDER_SOURCE = /\Aprovider:(?<name>[^.]+)\.(?<query>.+)\z/
37
48
 
@@ -119,16 +130,25 @@ module Metanorma
119
130
  end
120
131
 
121
132
  def data_file?(segment)
122
- DATA_FILE_EXTENSIONS.include?(File.extname(segment))
133
+ DATA_FILE_EXTENSIONS.include?(File.extname(segment).downcase)
123
134
  end
124
135
 
125
- def render_data_template(document:, lines:, # rubocop:disable Metrics/ParameterLists
136
+ def render_data_template(document:, lines:, # rubocop:disable Metrics/ParameterLists,Metrics/MethodLength
126
137
  definition_file:, instance_file:,
127
138
  context_name:, options:)
128
139
  definition_path, instances_path = resolve_data_paths(
129
140
  document, definition_file, instance_file
130
141
  )
131
142
 
143
+ if SCHEMA_EXTENSIONS.include?(File.extname(definition_path).downcase)
144
+ return render_schema_data_template(
145
+ document: document, lines: lines,
146
+ definition_path: definition_path,
147
+ instances_path: instances_path,
148
+ context_name: context_name, options: options,
149
+ )
150
+ end
151
+
132
152
  compiler = ::Lutaml::Lml::ModelCompiler.new
133
153
  compiler.compile(File.new(definition_path, encoding: "UTF-8"))
134
154
  instances = load_instances(instances_path, compiler)
@@ -219,8 +239,79 @@ module Metanorma
219
239
  [definition_path, instances_path || definition_path]
220
240
  end
221
241
 
242
+ # Schema-driven reading: the XSD is the schema of record. Derive
243
+ # the model classes in-memory (no generated files) and parse the
244
+ # XML instance document against them; liquid sees the parsed
245
+ # model keyed by its root class name, matching the LML flow.
246
+ def render_schema_data_template(document:, lines:,
247
+ definition_path:, instances_path:,
248
+ context_name:, options:)
249
+ # The XSD reader ships inside lutaml-model
250
+ # (lib/lutaml/xml/schema/xsd.rb). Do NOT require the lutaml
251
+ # gem's glue here: its released 0.11.x still vendors a
252
+ # lutaml/model copy whose definitions would shadow the
253
+ # canonical gem's (the vendoring is being removed on the
254
+ # lutaml unvendor branch).
255
+ require "lutaml/model"
256
+
257
+ ::Lutaml::Xml::Schema::Xsd # ensure the schema reader is loaded
258
+
259
+ schema_source = File.read(definition_path, encoding: "UTF-8")
260
+ module_namespace = schema_module_namespace(definition_path)
261
+ target_namespace = schema_target_namespace(definition_path,
262
+ schema_source)
263
+
264
+ ::Lutaml::Model::Schema.from_xml(
265
+ schema_source,
266
+ load_classes: true,
267
+ module_namespace: module_namespace,
268
+ namespace: target_namespace,
269
+ register_id: module_namespace,
270
+ location: definition_path,
271
+ )
272
+
273
+ instances = load_xml_instances(instances_path, module_namespace)
274
+ [render_liquid(lines, document, options, context_name, instances)]
275
+ end
276
+
277
+ def schema_module_namespace(definition_path)
278
+ base = File.basename(definition_path, ".*")
279
+ "LutamlXml#{base.gsub(/[^A-Za-z0-9]/, "_").split("_")
280
+ .reject(&:empty?).map(&:capitalize).join}"
281
+ end
282
+
283
+ def schema_target_namespace(definition_path, source)
284
+ schema = ::Lutaml::Xml::Schema::Xsd.parse(
285
+ source, location: definition_path
286
+ )
287
+ schema.target_namespace
288
+ end
289
+
290
+ def load_xml_instances(instances_path, module_namespace)
291
+ require "nokogiri"
292
+
293
+ instance_xml = File.read(instances_path, encoding: "UTF-8")
294
+ root_name = Nokogiri::XML(instance_xml).root.name
295
+
296
+ namespace = Object.const_get(module_namespace)
297
+ root_class = namespace.constants.filter_map do |const|
298
+ klass = namespace.const_get(const)
299
+ next unless klass.is_a?(Class) && klass < ::Lutaml::Model::Serializable
300
+
301
+ klass.mappings_for(:xml)&.root_element == root_name ? klass : nil
302
+ end.first
303
+
304
+ unless root_class
305
+ raise StandardError,
306
+ "No derived model declares root element `#{root_name}` " \
307
+ "for `#{instances_path}`"
308
+ end
309
+
310
+ [[demodulize(root_class.name), root_class.from_xml(instance_xml)]]
311
+ end
312
+
222
313
  def load_instances(path, compiler)
223
- case File.extname(path)
314
+ case File.extname(path).downcase
224
315
  when ".lml" then load_lml_instances(path, compiler)
225
316
  when ".json" then load_structured_instances(path, compiler,
226
317
  :parse_json_data)
@@ -5,6 +5,10 @@ require "asciidoctor"
5
5
  require "asciidoctor/reader"
6
6
  require "lutaml/uml"
7
7
  require "lutaml/lml"
8
+ # lutaml 0.11.x split the Graphviz formatter out into the lutaml-graphviz
9
+ # gem; requiring it registers Lutaml::Formatter::Graphviz back into
10
+ # Lutaml::Formatter.all.
11
+ require "lutaml/graphviz"
8
12
 
9
13
  module Metanorma
10
14
  module Plugin
@@ -1,7 +1,7 @@
1
1
  module Metanorma
2
2
  module Plugin
3
3
  module Lutaml
4
- VERSION = "0.7.81".freeze
4
+ VERSION = "0.7.82".freeze
5
5
  end
6
6
  end
7
7
  end
@@ -35,6 +35,7 @@ Gem::Specification.new do |spec|
35
35
  spec.add_dependency "isodoc", ">= 3.5.0"
36
36
  spec.add_dependency "liquid", "~> 5"
37
37
  spec.add_dependency "lutaml-jsonschema", "~> 0.1", ">= 0.1.29"
38
+ spec.add_dependency "lutaml-graphviz"
38
39
  spec.add_dependency "lutaml-lml"
39
40
  spec.add_dependency "lutaml-model", "~> 0.8.156"
40
41
  spec.add_dependency "lutaml-uml", ">= 0.5", "< 2"
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.81
4
+ version: 0.7.82
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2026-11-20 00:00:00.000000000 Z
11
+ date: 2026-11-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: asciidoctor
@@ -120,6 +120,20 @@ dependencies:
120
120
  - - ">="
121
121
  - !ruby/object:Gem::Version
122
122
  version: 0.1.29
123
+ - !ruby/object:Gem::Dependency
124
+ name: lutaml-graphviz
125
+ requirement: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - ">="
128
+ - !ruby/object:Gem::Version
129
+ version: '0'
130
+ type: :runtime
131
+ prerelease: false
132
+ version_requirements: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - ">="
135
+ - !ruby/object:Gem::Version
136
+ version: '0'
123
137
  - !ruby/object:Gem::Dependency
124
138
  name: lutaml-lml
125
139
  requirement: !ruby/object:Gem::Requirement