lutaml-model 0.8.156 → 0.8.157

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: aea44d04f4ea5075f73510466aebf1b3bc292a54cab063e9cffc79d05c0e4eb9
4
- data.tar.gz: 1048189e193d315c9f72e61642e74480f68c1017d4114bff0e840b86d69f0d8a
3
+ metadata.gz: 5a7a7b4352ec266e959f6a4304acafba60a4433953c36fdd3c4cfc2d7bafeccf
4
+ data.tar.gz: 827c5280c74a9d9c6a517adc00779444ba0c305fbecab9ab8ccc491a2f09ddc0
5
5
  SHA512:
6
- metadata.gz: 36ab80411f6db38bf0b8caa500f676a9facdb7bcbd4faf1b5181fde640bd1772b4627df71f6a35c8995dbe5d59c53a16ff1413b4365cd1fc5fa50b47d341460c
7
- data.tar.gz: 3a83803c58cfd44d76baa13572285349c682484d8e501c86a51144c03f69b09fc3afd3edcff68df68d5a6ff4d619a4273a894162bc688debd501727c4e1785b9
6
+ metadata.gz: bc20f062d7a51cd5c9bcaf5e7df729ba80551e161a146611773d5e8697650fa9dad7f83424c93ef95e0b75fe4db118b844ef2661891b6499c896c226f29c3d0e
7
+ data.tar.gz: 1874b8520c7cca77ffaac37e985f69d80fcb242d8c66b53e10c94cf4f8c12eee9930650e6f36cb03b93ce3f5e3c15115136deebb0865c438f79884bc24f881c8
@@ -56,22 +56,5 @@ jobs:
56
56
  - name: Install dependencies
57
57
  run: bundle install
58
58
 
59
- - name: Pin moxml to the 0.5 line for the Opal boot
60
- # moxml 0.6 deleted lib/compat/opal (moxml#516) and the boot
61
- # manifest appends that path (#914); the lane stays on 0.5.x
62
- # until it migrates to the moxml-ts wasm binding. The gemspec
63
- # admits both lines (>= 0.5.139, < 0.7), so this lockfile-local
64
- # pin selects the Opal-compatible one without restricting
65
- # CRuby consumers. The constraint rides a workspace-local
66
- # Gemfile append — `bundle update` has no --version switch, and
67
- # the repo's Gemfile/gemspec must stay dual-line for CRuby.
68
- run: |
69
- cat >> Gemfile <<'EOF'
70
-
71
- # CI-local pin (opal.yml): the Opal boot needs moxml 0.5.x.
72
- gem "moxml", "~> 0.5.139"
73
- EOF
74
- bundle update moxml
75
-
76
59
  - name: Run Opal tests
77
60
  run: bundle exec rake spec:opal
data/.rubocop.yml CHANGED
@@ -17,6 +17,16 @@ AllCops:
17
17
  - '**/*.md'
18
18
  - 'niso-jats/**/*'
19
19
  - 'sts-ruby/**/*'
20
+ # Vendored from lutaml/moxml 0.5.167's lib/compat/opal (the rexml
21
+ # Opal shadows moxml 0.6 no longer ships); upstream style, kept
22
+ # byte-identical so diffs against the source stay meaningful.
23
+ - 'lib/compat/opal/rexml/**/*'
24
+ - 'lib/compat/opal/rexml_compat.rb'
25
+ - 'lib/compat/opal/moxml/**/*'
26
+ # Opal stdlib shims keep stdlib spellings and pass-through
27
+ # semantics; style cops do not apply.
28
+ - 'lib/compat/opal/monitor.rb'
29
+ - 'lib/compat/opal/objectspace_shim.rb'
20
30
 
21
31
  Style/OneClassPerFile:
22
32
  inherit_mode:
data/Rakefile CHANGED
@@ -31,7 +31,11 @@ begin
31
31
  moxml_gem_dir = Gem::Specification.find_by_name("moxml")&.gem_dir
32
32
  if moxml_gem_dir
33
33
  Opal.append_path File.join(moxml_gem_dir, "lib")
34
- Opal.append_path File.join(moxml_gem_dir, "lib/compat/opal")
34
+ # moxml 0.5 shipped lib/compat/opal (rexml shadows for the boot);
35
+ # the 0.6 line no longer carries it — append only when present so
36
+ # the boot works on both lines.
37
+ compat_dir = File.join(moxml_gem_dir, "lib/compat/opal")
38
+ Opal.append_path compat_dir if File.directory?(compat_dir)
35
39
  end
36
40
 
37
41
  rexml_lib = $LOAD_PATH.find do |p|
@@ -358,3 +358,32 @@ NOTE: The `:tomlib` TOML adapter is disabled on Windows due to segmentation
358
358
  fault issues. Attempting to configure `:tomlib` on Windows will raise an
359
359
  `ArgumentError`. Use `:teptris` (native, all platforms) or `:toml_rb` on
360
360
  Windows instead.
361
+
362
+ === Overriding the engine for a format (supported seam)
363
+
364
+ The link:../guides/native-engines[native-engine auto-detection] selects
365
+ the fastest available engine per format at boot. When an application
366
+ needs a specific engine regardless of the bundle (for example fontist's
367
+ parse-only yeptris override), the supported seam is
368
+ `Lutaml::Model::AdapterResolver`:
369
+
370
+ [source,ruby]
371
+ ----
372
+ # Pin a named adapter type for a format (validated and loaded eagerly).
373
+ Lutaml::Model::AdapterResolver.set_adapter_type(:yaml, :yeptris)
374
+
375
+ # Pin a pre-resolved adapter class (e.g. a subclass customizing one
376
+ # operation — fontist's parse-only override is exactly this shape).
377
+ Lutaml::Model::AdapterResolver.set_adapter_class(
378
+ :yaml, Fontist::Yaml::YeptrisAdapter
379
+ )
380
+
381
+ # Pass a nil class to unset a pin and return to auto-detection.
382
+ Lutaml::Model::AdapterResolver.set_adapter_class(:yaml, nil)
383
+ ----
384
+
385
+ Resolution order: a thread-local `AdapterScope` override, then an
386
+ explicitly pinned adapter (never falls through to detection), then
387
+ bundle-based auto-detection, then the format's default adapter. The
388
+ same seam covers every registered format: `:xml`, `:yaml`, `:json`,
389
+ `:toml`, and the key-value formats.
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Opal shim: the monitor stdlib (MonitorMixin) is not packaged for
4
+ # Opal, and moxml 0.6's NativeAttachment requires it at load time.
5
+ # The JS runtime is single-threaded, so the monitor contract reduces
6
+ # to pass-through: synchronize yields, lock/try_lock succeed, unlock
7
+ # is a no-op. Aliases cover the MonitorMixin spellings.
8
+ #
9
+ class Monitor # rubocop:disable Naming/PredicateMethod -- stdlib spellings
10
+ def synchronize
11
+ yield
12
+ end
13
+
14
+ def lock; end
15
+
16
+ def try_lock
17
+ true
18
+ end
19
+
20
+ def unlock; end
21
+
22
+ def locked?
23
+ false
24
+ end
25
+
26
+ alias mon_enter lock
27
+ alias mon_exit unlock
28
+ alias mon_synchronize synchronize
29
+ alias mon_locked? locked?
30
+ alias mon_try_lock try_lock
31
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Moxml
4
+ module Adapter
5
+ module CustomizedRexml
6
+ EntityReference = ::Moxml::Entity::Reference
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,225 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rexml/formatters/pretty"
4
+
5
+ module Moxml
6
+ module Adapter
7
+ module CustomizedRexml
8
+ # Custom REXML formatter that fixes indentation and wrapping issues
9
+ class Formatter < ::REXML::Formatters::Pretty
10
+ def initialize(indentation: 2, self_close_empty: false, adapter: nil)
11
+ @indentation = " " * indentation
12
+ @level = 0
13
+ @compact = true
14
+ @width = -1 # Disable line wrapping
15
+ @self_close_empty = self_close_empty
16
+ @adapter = adapter
17
+ end
18
+
19
+ def write(node, output)
20
+ case node
21
+ when ::REXML::XMLDecl
22
+ write_declaration(node, output)
23
+ when ::Moxml::Adapter::CustomizedRexml::EntityReference
24
+ output << "&#{node.name};"
25
+ else
26
+ super
27
+ end
28
+ end
29
+
30
+ def indented?
31
+ !@indentation.empty?
32
+ end
33
+
34
+ def write_element(node, output)
35
+ output << "<#{node.expanded_name}"
36
+ write_attributes(node, output)
37
+
38
+ # Check for entity refs stored in adapter attachments
39
+ entity_refs = @adapter&.attachments&.get(node, :entity_refs)
40
+ child_sequence = @adapter&.attachments&.get(node, :child_sequence)
41
+
42
+ has_no_children = node.children.empty? && !(entity_refs && !entity_refs.empty?)
43
+
44
+ if has_no_children && @self_close_empty
45
+ output << "/>"
46
+ return
47
+ end
48
+
49
+ output << ">"
50
+
51
+ has_text = node.children.any? { |c| c.is_a?(::REXML::Text) && !c.to_s.strip.empty? }
52
+ has_elements = node.children.any?(::REXML::Element)
53
+ indent_children = indented? && has_elements && !has_text
54
+
55
+ # Handle children based on content type
56
+ all_children_empty = node.children.empty? && !(entity_refs && !entity_refs.empty?)
57
+ unless all_children_empty
58
+ @level += @indentation.length if indent_children
59
+
60
+ if entity_refs && !entity_refs.empty? && child_sequence
61
+ eref_idx = 0
62
+ native_idx = 0
63
+ child_sequence.each do |type|
64
+ case type
65
+ when :native
66
+ if native_idx < node.children.size
67
+ child = node.children[native_idx]
68
+ native_idx += 1
69
+ next if child.is_a?(::REXML::Text) &&
70
+ child.to_s.strip.empty? &&
71
+ !(child.next_sibling.nil? && child.previous_sibling.nil?)
72
+
73
+ output << "\n" << (" " * @level) if indent_children
74
+ write(child, output)
75
+ end
76
+ when :eref
77
+ if eref_idx < entity_refs.size
78
+ output << "\n" << (" " * @level) if indent_children
79
+ write(entity_refs[eref_idx], output)
80
+ eref_idx += 1
81
+ end
82
+ end
83
+ end
84
+ else
85
+ node.children.each_with_index do |child, _index|
86
+ next if child.is_a?(::REXML::Text) &&
87
+ child.to_s.strip.empty? &&
88
+ !(child.next_sibling.nil? && child.previous_sibling.nil?)
89
+
90
+ output << "\n" << (" " * @level) if indent_children
91
+ write(child, output)
92
+ end
93
+ end
94
+
95
+ if indent_children
96
+ @level -= @indentation.length
97
+ output << "\n" << (" " * @level)
98
+ end
99
+ end
100
+
101
+ output << "</#{node.expanded_name}>"
102
+ end
103
+
104
+ def write_text(node, output)
105
+ text = node.value
106
+ return if text.empty?
107
+
108
+ output << escape_text(text)
109
+ end
110
+
111
+ def escape_text(text)
112
+ text.to_s.gsub(/[<>&]/) do |match|
113
+ case match
114
+ when "<" then "&lt;"
115
+ when ">" then "&gt;"
116
+ when "&" then "&amp;"
117
+ end
118
+ end
119
+ end
120
+
121
+ private
122
+
123
+ def find_significant_sibling(node, direction)
124
+ method = direction == :next ? :next_sibling : :previous_sibling
125
+ sibling = node.send(method)
126
+ sibling = sibling.send(method) while sibling.is_a?(::REXML::Text) && sibling.to_s.strip.empty?
127
+ sibling
128
+ end
129
+
130
+ def write_cdata(node, output)
131
+ # output << ' ' * @level
132
+ output << ::REXML::CData::START
133
+ output << node.to_s.gsub(::REXML::CData::STOP, "]]]]><![CDATA[>")
134
+ output << ::REXML::CData::STOP
135
+ # output << "\n"
136
+ end
137
+
138
+ def write_comment(node, output)
139
+ # output << ' ' * @level
140
+ output << "<!--"
141
+ output << node.to_s
142
+ output << "-->"
143
+ # output << "\n"
144
+ end
145
+
146
+ def write_instruction(node, output)
147
+ # output << ' ' * @level
148
+ output << "<?"
149
+ output << node.target
150
+ output << " "
151
+ output << node.content if node.content
152
+ output << "?>"
153
+ # output << "\n"
154
+ end
155
+
156
+ def write_document(node, output)
157
+ node.children.each do |child|
158
+ write(child, output)
159
+ # output << "\n" unless child == node.children.last
160
+ end
161
+ end
162
+
163
+ def write_doctype(node, output)
164
+ output << "<!DOCTYPE "
165
+ output << node.name
166
+ output << " "
167
+ output << node.external_id if node.external_id
168
+ output << ">"
169
+ # output << "\n"
170
+ end
171
+
172
+ def write_declaration(node, output)
173
+ output << "<?xml"
174
+ output << %( version="#{node.version}") if node.version
175
+ if node.writeencoding
176
+ output << %( encoding="#{node.encoding.to_s.upcase}")
177
+ end
178
+ output << %( standalone="#{node.standalone}") if node.standalone
179
+ output << "?>"
180
+ # output << "\n"
181
+ end
182
+
183
+ def write_attributes(node, output)
184
+ # First write namespace declarations
185
+ node.attributes.each do |name, attr|
186
+ next unless name.to_s.start_with?("xmlns:") || name.to_s == "xmlns"
187
+
188
+ name = "xmlns" if name.to_s == "xmlns:"
189
+ value = attr.is_a?(::REXML::Attribute) ? attr.value : attr
190
+ output << " #{name}=\"#{value}\""
191
+ end
192
+
193
+ # Then write regular attributes
194
+ node.attributes.each do |name, attr| # rubocop:disable Style/CombinableLoops
195
+ next if name.to_s.start_with?("xmlns:") || name.to_s == "xmlns"
196
+
197
+ output << " "
198
+ output << if attr.is_a?(::REXML::Attribute) && attr.prefix
199
+ "#{attr.prefix}:#{attr.name}"
200
+ else
201
+ name.to_s
202
+ end
203
+
204
+ output << "=\""
205
+ value = attr.is_a?(::REXML::Attribute) ? attr.value : attr
206
+ output << escape_attribute_value(value.to_s)
207
+ output << "\""
208
+ end # rubocop:enable Style/CombinableLoops
209
+ end
210
+
211
+ def escape_attribute_value(value)
212
+ value.to_s.gsub(/[<>&"]/) do |match|
213
+ case match
214
+ when "<" then "&lt;"
215
+ when ">" then "&gt;"
216
+ when "&" then "&amp;"
217
+ when '"' then "&quot;"
218
+ # when "'" then '&apos;'
219
+ end
220
+ end
221
+ end
222
+ end
223
+ end
224
+ end
225
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Moxml
4
+ module Adapter
5
+ module CustomizedRexml
6
+ autoload :EntityReference,
7
+ "moxml/adapter/customized_rexml/entity_reference"
8
+ autoload :Formatter, "moxml/adapter/customized_rexml/formatter"
9
+ end
10
+ end
11
+ end
@@ -1,73 +1,68 @@
1
- # frozen_string_literal: true
1
+ require "moxml/version"
2
2
 
3
- # Opal-only boot for moxml — mirrors moxml's shipped
4
- # `lib/compat/opal/moxml_boot.rb` so both Oga and REXML adapters are
5
- # eager-loaded (Opal ignores autoload; without this, nested Moxml
6
- # constants NameError at runtime).
7
- #
8
- # Requires the REXML gem's lib dir to be on Opal's load path so
9
- # `require "rexml/formatters/pretty"` (pulled in by moxml's
10
- # customized_rexml/formatter) resolves. The Rakefile sets that up.
11
- #
12
- # moxml's own boot loads the same list. We maintain our own copy so we
13
- # can reorder or gate entries if a future moxml release introduces an
14
- # Opal-incompatible file before its shipped boot catches up.
3
+ # ObjectSpace shim: moxml 0.6 registers GC finalizers on Opal, which
4
+ # carries no ObjectSpace constant; the shim is a guarded no-op there.
5
+ require "objectspace_shim"
15
6
 
16
- if RUBY_ENGINE == "opal"
17
- require "moxml/version"
18
- require "moxml/error"
19
- require "moxml/native_attachment"
20
- require "moxml/native_attachment/opal"
21
- require "moxml/xml_utils"
22
- require "moxml/xml_utils/encoder"
23
- require "moxml/node"
24
- require "moxml/node_set"
25
- require "moxml/document"
26
- require "moxml/element"
27
- require "moxml/attribute"
28
- require "moxml/text"
29
- require "moxml/cdata"
30
- require "moxml/comment"
31
- require "moxml/processing_instruction"
32
- require "moxml/declaration"
33
- require "moxml/namespace"
34
- require "moxml/doctype"
35
- require "moxml/entity_reference"
36
- require "moxml/entity_registry"
37
- require "moxml/entity"
38
- require "moxml/entity/restorer"
39
- require "moxml/entity/reference"
40
- require "moxml/xml_emitter"
41
- require "moxml/adapter"
42
- require "moxml/adapter/base"
43
- require "moxml/adapter/customized_rexml"
44
- require "moxml/adapter/customized_rexml/entity_reference"
45
- require "moxml/adapter/customized_rexml/formatter"
46
- require "moxml/sax"
47
- require "moxml/sax/handler"
48
- require "moxml/sax/element_handler"
49
- require "moxml/sax/block_handler"
50
- require "moxml/sax/namespace_splitter"
51
- require "moxml/adapter/rexml"
52
- require "moxml/adapter/customized_oga"
53
- require "moxml/adapter/customized_oga/entity_decoder"
54
- require "moxml/adapter/customized_oga/raw_value_override"
55
- require "moxml/adapter/customized_oga/xml_declaration"
56
- require "moxml/adapter/customized_oga/xml_generator"
57
- require "moxml/adapter/oga"
58
- require "moxml/builder"
59
- require "moxml/context"
60
- require "moxml/config"
61
- require "moxml/xpath"
62
- require "moxml/xpath/engine"
63
- require "moxml/xpath/context"
64
- require "moxml/xpath/conversion"
65
- require "moxml/xpath/cache"
66
- require "moxml/xpath/lexer"
67
- require "moxml/xpath/parser"
68
- require "moxml/xpath/compiler"
69
- require "moxml/xpath/errors"
70
- require "moxml/xpath/ast/node"
71
- require "moxml/xpath/ruby/node"
72
- require "moxml/xpath/ruby/generator"
73
- end
7
+ # The monitor shim must load before moxml files: moxml 0.6's
8
+ # NativeAttachment requires "monitor" at load time.
9
+ require "monitor"
10
+ require "moxml/error"
11
+ require "moxml/native_attachment"
12
+ require "moxml/xml_utils"
13
+ require "moxml/xml_utils/encoder"
14
+ require "moxml/node"
15
+ require "moxml/node_set"
16
+ require "moxml/lazy_node_set"
17
+ require "moxml/document"
18
+ require "moxml/element"
19
+ require "moxml/attribute"
20
+ require "moxml/text"
21
+ require "moxml/cdata"
22
+ require "moxml/comment"
23
+ require "moxml/processing_instruction"
24
+ require "moxml/declaration"
25
+ require "moxml/namespace"
26
+ require "moxml/doctype"
27
+ require "moxml/entity_reference"
28
+ require "moxml/entity_registry"
29
+ require "moxml/entity"
30
+ require "moxml/entity/restorer"
31
+ require "moxml/entity/reference"
32
+ require "moxml/xml_emitter"
33
+ require "moxml/adapter"
34
+ require "moxml/adapter/base"
35
+ require "moxml/adapter/customized_rexml"
36
+ require "moxml/adapter/customized_rexml/entity_reference"
37
+ require "moxml/adapter/customized_rexml/formatter"
38
+ require "moxml/sax"
39
+ require "moxml/sax/handler"
40
+ require "moxml/sax/element_handler"
41
+ require "moxml/sax/block_handler"
42
+ require "moxml/sax/namespace_splitter"
43
+ require "moxml/adapter/rexml"
44
+ require "moxml/adapter/customized_oga"
45
+ require "moxml/adapter/customized_oga/entity_decoder"
46
+ require "moxml/adapter/customized_oga/raw_value_override"
47
+ require "moxml/adapter/customized_oga/xml_declaration"
48
+ require "moxml/adapter/customized_oga/xml_generator"
49
+ require "moxml/adapter/oga"
50
+ require "moxml/builder"
51
+ require "moxml/context"
52
+ require "moxml/config"
53
+ require "moxml/xpath"
54
+ require "moxml/xpath/engine"
55
+ require "moxml/xpath/context"
56
+ require "moxml/xpath/conversion"
57
+ require "moxml/xpath/cache"
58
+ require "moxml/xpath/lexer"
59
+ require "moxml/xpath/parser"
60
+ require "moxml/xpath/compiler"
61
+ require "moxml/xpath/errors"
62
+ require "moxml/xpath/ast/node"
63
+ require "moxml/xpath/ruby/node"
64
+ require "moxml/xpath/ruby/generator"
65
+ require "moxml/reference"
66
+ require "moxml/reference/parser"
67
+ require "moxml/reference/writer"
68
+ require "moxml/reference/normalizer"
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Opal shim: moxml 0.6's NativeAttachment::Native registers GC
4
+ # finalizers through ObjectSpace; JS has no finalization hook, and the
5
+ # Opal runtime does not carry an ObjectSpace at all (the constant is
6
+ # simply absent, so the call site NameErrors). A stubbed ObjectSpace
7
+ # degrades finalizer cleanup — attachments live for the process
8
+ # lifetime, which on the single-threaded JS runtime is the page's
9
+ # lifetime anyway. Existing runtimes that do define ObjectSpace are
10
+ # left untouched.
11
+ unless defined?(ObjectSpace)
12
+ module ObjectSpace
13
+ class << self
14
+ def define_finalizer(_obj, _proc = nil)
15
+ nil
16
+ end
17
+
18
+ def undefine_finalizer(_obj)
19
+ nil
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,59 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rexml/xmltokens"
4
+
5
+ module REXML
6
+ module Namespace
7
+ attr_reader :name, :expanded_name
8
+ attr_accessor :prefix
9
+
10
+ include XMLTokens
11
+
12
+ NAME_WITHOUT_NAMESPACE = /^#{NCNAME_STR}$/
13
+ NAMESPLIT = /^(?:(#{NCNAME_STR}):)?(#{NCNAME_STR})/u
14
+
15
+ def name=(name)
16
+ @expanded_name = name
17
+ if name.match?(NAME_WITHOUT_NAMESPACE)
18
+ @prefix = ""
19
+ @namespace = ""
20
+ @name = name
21
+ elsif name =~ NAMESPLIT
22
+ if $1
23
+ @prefix = $1
24
+ else
25
+ @prefix = ""
26
+ @namespace = ""
27
+ end
28
+ @name = $2
29
+ elsif name == ""
30
+ @prefix = nil
31
+ @namespace = nil
32
+ @name = nil
33
+ else
34
+ message = "name must be \#{PREFIX}:\#{LOCAL_NAME} or \#{LOCAL_NAME}: "
35
+ message += "<#{name.inspect}>"
36
+ raise ArgumentError, message
37
+ end
38
+ end
39
+
40
+ def has_name?(other, ns = nil)
41
+ if ns
42
+ namespace == ns and name == other
43
+ elsif other.include? ":"
44
+ fully_expanded_name == other
45
+ else
46
+ name == other
47
+ end
48
+ end
49
+
50
+ alias :local_name :name
51
+
52
+ def fully_expanded_name
53
+ ns = prefix
54
+ return "#{ns}:#@name" if ns.size.positive?
55
+
56
+ @name
57
+ end
58
+ end
59
+ end