metanorma-plugin-lutaml 0.7.80 → 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: 31d20784c59524dc4c775cf8bc7ab345543da4ec44f04cd69961d20f7a15db24
4
- data.tar.gz: 7532df396b22c7b72c15818e74926964683b2ca363faf25a745193cbc5850675
3
+ metadata.gz: b1efa6443af45e749f5578728610b36ddbedda93a095d9073d97b1a548c92f02
4
+ data.tar.gz: 104d464781a93e4a1fa451bfbfaae51d326952dd4fe01e36a286bf2901fa2891
5
5
  SHA512:
6
- metadata.gz: fd731ef555de17f5de92763b077038b5661c42757b553552bd006e77d020d1c532cb7f4c86e5460f808c0b9738daa549fcbd1d8a194548b436984df23f39a819
7
- data.tar.gz: bb40b6f99bcc348bdd0141bc4078266a3ee0c09d589824aace7cf3e1e129a13afa9466272f1d12f4d5cb8e1645daea133e37a4246ca9ae3fd971466cb6d494a9
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.80".freeze
4
+ VERSION = "0.7.82".freeze
5
5
  end
6
6
  end
7
7
  end
@@ -117,12 +117,27 @@ module Metanorma
117
117
 
118
118
  def add_model_anchor_context(context, root_package)
119
119
  packages = model_packages(root_package)
120
+ register_model_anchors(context, packages, root_package)
121
+ register_anchorable_ids(context, packages, root_package)
122
+ end
123
+
124
+ def register_model_anchors(context, packages, root_package)
120
125
  context["additional_context"]["model_anchors"] =
121
126
  model_reference_targets(packages)
122
127
  .merge(model_anchors(packages))
123
128
  .merge(model_stub_anchors(root_package))
124
129
  end
125
130
 
131
+ # Real model entities AND stubs (#70): both are XMI-declared
132
+ # objects, so their links survive templates that do not render
133
+ # their sections. Only ids the XMI never defines (attribute
134
+ # types, association ends present solely as idrefs) degrade.
135
+ def register_anchorable_ids(context, packages, root_package)
136
+ stub_ids = model_stub_anchors(root_package).keys
137
+ context["additional_context"]["model_anchorable"] =
138
+ model_anchors(packages).keys | stub_ids
139
+ end
140
+
126
141
  # Ids the XMI templates link to (attribute types, association ends),
127
142
  # including ones the XMI never defines. Unnamed; anchors override.
128
143
  def model_reference_targets(packages)
@@ -2,6 +2,7 @@
2
2
 
3
3
  require "asciidoctor"
4
4
  require "asciidoctor/extensions"
5
+ require "set"
5
6
 
6
7
  module Metanorma
7
8
  module Plugin
@@ -16,6 +17,11 @@ module Metanorma
16
17
  (?:,(?<content>.*?))?&gt;&gt;/x)
17
18
 
18
19
  INVENTORY_ATTRIBUTE = "lutaml_model_anchors"
20
+ # Ids of real model entities (classes, enums, data types, packages).
21
+ # These never degrade to plain text (#70): even when the current
22
+ # template does not render their sections, the link must survive
23
+ # for collection-level documents to resolve.
24
+ ANCHORABLE_ATTRIBUTE = "lutaml_model_anchorable"
19
25
 
20
26
  def self.root_document(document)
21
27
  document = document.parent_document while document.parent_document
@@ -32,12 +38,23 @@ module Metanorma
32
38
  .merge!(anchors) { |_, old, new| new || old }
33
39
  end
34
40
 
41
+ # The subset of the inventory that is a real model entity
42
+ # (classes, enums, data types, packages, stubs). Only ids the XMI
43
+ # never defines (attribute types and association ends present
44
+ # solely as idrefs) degrade to plain text; XMI-declared objects
45
+ # stay linked (#70).
46
+ def self.register_anchorable(document, ids)
47
+ document = root_document(document)
48
+ document.attributes[ANCHORABLE_ATTRIBUTE] ||= Set.new
49
+ document.attributes[ANCHORABLE_ATTRIBUTE].merge(ids)
50
+ end
51
+
35
52
  def process(parent, target, attrs)
36
53
  document = self.class.root_document(parent.document)
37
54
  inventory = document.attributes.fetch(INVENTORY_ATTRIBUTE, {})
38
55
  name = inventory[target]
39
56
  text = reference_text(parent, attrs["text"], target, name)
40
- value = if inventory.key?(target) && !anchored?(document, target)
57
+ value = if suppress_link?(document, target)
41
58
  plain_text(parent, text, target)
42
59
  else
43
60
  label = text ? ",#{text}" : ""
@@ -48,6 +65,13 @@ module Metanorma
48
65
 
49
66
  private
50
67
 
68
+ def suppress_link?(document, target)
69
+ inventory = document.attributes.fetch(INVENTORY_ATTRIBUTE, {})
70
+ anchorable = document.attributes.fetch(ANCHORABLE_ATTRIBUTE, Set.new)
71
+ inventory.key?(target) && !anchored?(document, target) &&
72
+ !anchorable.member?(target)
73
+ end
74
+
51
75
  def anchored?(document, target)
52
76
  document.catalog[:refs].key?("section-#{target}")
53
77
  end
@@ -41,6 +41,9 @@ module Metanorma
41
41
  XmiModelReference.register(
42
42
  document, additional_context["model_anchors"] || {}
43
43
  )
44
+ XmiModelReference.register_anchorable(
45
+ document, additional_context["model_anchorable"] || []
46
+ )
44
47
  render_result.split("\n")
45
48
  end
46
49
 
@@ -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.80
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-19 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