lutaml-model 0.8.156 → 0.8.158
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 +4 -4
- data/.github/workflows/opal.yml +5 -17
- data/.rubocop.yml +10 -0
- data/Rakefile +5 -1
- data/docs/_guides/opal.adoc +11 -0
- data/docs/_pages/serialization_adapters.adoc +47 -2
- data/lib/compat/opal/monitor.rb +31 -0
- data/lib/compat/opal/moxml/adapter/customized_rexml/entity_reference.rb +9 -0
- data/lib/compat/opal/moxml/adapter/customized_rexml/formatter.rb +225 -0
- data/lib/compat/opal/moxml/adapter/customized_rexml.rb +11 -0
- data/lib/compat/opal/moxml_boot.rb +66 -71
- data/lib/compat/opal/objectspace_shim.rb +23 -0
- data/lib/compat/opal/rexml/namespace.rb +59 -0
- data/lib/compat/opal/rexml/parsers/baseparser.rb +1016 -0
- data/lib/compat/opal/rexml/source.rb +214 -0
- data/lib/compat/opal/rexml/text.rb +426 -0
- data/lib/compat/opal/rexml/xmltokens.rb +45 -0
- data/lib/compat/opal/rexml_compat.rb +85 -0
- data/lib/lutaml/model/adapter_resolver.rb +29 -0
- data/lib/lutaml/model/cached_type_resolver/concurrent_map_cache.rb +3 -1
- data/lib/lutaml/model/cached_type_resolver/mutex_hash_cache.rb +3 -1
- data/lib/lutaml/model/cached_type_resolver.rb +13 -22
- data/lib/lutaml/model/collection.rb +54 -5
- data/lib/lutaml/model/mapping/mapping_rule.rb +28 -4
- data/lib/lutaml/model/serialize/builder.rb +1 -1
- data/lib/lutaml/model/serialize/format_conversion.rb +26 -1
- data/lib/lutaml/model/serialize.rb +6 -1
- data/lib/lutaml/model/services/rule_value_extractor.rb +39 -35
- data/lib/lutaml/model/utils.rb +8 -1
- data/lib/lutaml/model/version.rb +1 -1
- data/lib/lutaml/xml/adapter/oga_adapter.rb +4 -0
- data/lib/lutaml/xml/adapter/rexml_adapter.rb +4 -0
- data/lib/lutaml/xml/leptris/plan_hydrator.rb +14 -7
- data/lib/lutaml/xml/leptris/plan_order.rb +24 -7
- data/lib/lutaml/xml/model_transform.rb +21 -3
- data/lib/lutaml/xml/parse_session.rb +4 -3
- data/lib/lutaml/xml/xml_attribute.rb +31 -11
- data/lutaml-model.gemspec +6 -4
- data/spec/lutaml/model/collection_scalar_maps_spec.rb +58 -0
- data/spec/lutaml/xml/opal_xml_spec.rb +10 -0
- metadata +16 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 74c783e3897939ae61d1cbd03782641f0ed8facb94ed8098588a7491504db44c
|
|
4
|
+
data.tar.gz: c30df2f8628c15e232559c658ca820e1d4597b976a87d98936703c64bf99d5c9
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 2c48df71e7b19c791954371707b6ff671f2fd234f8de0be7ef4c5dbce1838b7ab349b669124793c15037f6bdd788a9260924e195cfc1d34ca779ecc9f07471ab
|
|
7
|
+
data.tar.gz: f4069257888fb2b6c9fa5e9bd8913fd7bb2b0a369c5d65336f154902e96b5d5e3295c182adef140e78a0cb3ee008d8a8dceaefa0563fee71ee16a70bf3309c1d
|
data/.github/workflows/opal.yml
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
# DEPRECATED: the Opal lane is on the deprecation path (the moxml-ts
|
|
2
|
+
# wasm binding is the JavaScript endgame). The lane stays green — the
|
|
3
|
+
# boot repair chain lives in lib/compat/opal — but it is
|
|
4
|
+
# maintenance-only and non-gating; removal is planned for a future
|
|
5
|
+
# release.
|
|
1
6
|
name: opal
|
|
2
7
|
|
|
3
8
|
on:
|
|
@@ -56,22 +61,5 @@ jobs:
|
|
|
56
61
|
- name: Install dependencies
|
|
57
62
|
run: bundle install
|
|
58
63
|
|
|
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
64
|
- name: Run Opal tests
|
|
77
65
|
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
|
-
|
|
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|
|
data/docs/_guides/opal.adoc
CHANGED
|
@@ -11,6 +11,17 @@ nav_order: 99
|
|
|
11
11
|
|
|
12
12
|
== Overview
|
|
13
13
|
|
|
14
|
+
[IMPORTANT]
|
|
15
|
+
====
|
|
16
|
+
Opal support in lutaml-model is **deprecated**. The Opal boot lane, its
|
|
17
|
+
compat shims, and the vendored Opal forks remain functional in the 0.8
|
|
18
|
+
line but receive maintenance-only attention, and removal is planned for
|
|
19
|
+
a future release. New JavaScript-targeted work is directed at the
|
|
20
|
+
moxml-ts wasm binding instead.
|
|
21
|
+
====
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
14
25
|
https://opalrb.com[Opal] is a Ruby-to-JavaScript compiler that allows Ruby code to run in the browser. Lutaml::Model supports running under Opal, enabling XML/JSON/YAML serialization in client-side applications.
|
|
15
26
|
|
|
16
27
|
The XML parsing layer is provided by the https://github.com/lutaml/moxml[moxml] gem (v0.2+), which detects the Opal runtime and uses the REXML adapter automatically.
|
|
@@ -190,11 +190,19 @@ Requires native extensions (i.e. compiled C code).
|
|
|
190
190
|
Requires the `nokogiri` gem.
|
|
191
191
|
|
|
192
192
|
Oga::
|
|
193
|
-
(optional)
|
|
193
|
+
(optional, *deprecated*)
|
|
194
194
|
Pure Ruby XML parser.
|
|
195
195
|
Does not require native extensions.
|
|
196
196
|
Requires the `oga` gem.
|
|
197
197
|
|
|
198
|
+
[NOTE]
|
|
199
|
+
====
|
|
200
|
+
The Oga engine is deprecated: moxml's default engine (Nokogiri, or the
|
|
201
|
+
leptris native engine when present) is the supported XML lane.
|
|
202
|
+
Selecting Oga emits a deprecation warning; removal is planned for a
|
|
203
|
+
future release.
|
|
204
|
+
====
|
|
205
|
+
|
|
198
206
|
Ox::
|
|
199
207
|
(optional)
|
|
200
208
|
Fast XML parser and object serializer for Ruby, implemented partially in C.
|
|
@@ -202,13 +210,21 @@ Requires native extensions (i.e. compiled C code).
|
|
|
202
210
|
Requires the `ox` gem.
|
|
203
211
|
|
|
204
212
|
REXML::
|
|
205
|
-
(optional)
|
|
213
|
+
(optional, *deprecated*)
|
|
206
214
|
Pure Ruby XML parser, bundled as a default gem with Ruby.
|
|
207
215
|
Moved from standard library to a default gem in Ruby 3.0.
|
|
208
216
|
Opal-compatible: Opal reimplements `strscan` and `stringio` in its stdlib,
|
|
209
217
|
enabling REXML to compile cleanly to JavaScript.
|
|
210
218
|
Requires the `rexml` gem (bundled with Ruby by default).
|
|
211
219
|
|
|
220
|
+
[NOTE]
|
|
221
|
+
====
|
|
222
|
+
The REXML engine is deprecated: moxml's default engine (Nokogiri, or
|
|
223
|
+
the leptris native engine when present) is the supported XML lane.
|
|
224
|
+
Selecting REXML emits a deprecation warning; removal is planned for a
|
|
225
|
+
future release.
|
|
226
|
+
====
|
|
227
|
+
|
|
212
228
|
|
|
213
229
|
.Using an XML adapter
|
|
214
230
|
[source,ruby]
|
|
@@ -358,3 +374,32 @@ NOTE: The `:tomlib` TOML adapter is disabled on Windows due to segmentation
|
|
|
358
374
|
fault issues. Attempting to configure `:tomlib` on Windows will raise an
|
|
359
375
|
`ArgumentError`. Use `:teptris` (native, all platforms) or `:toml_rb` on
|
|
360
376
|
Windows instead.
|
|
377
|
+
|
|
378
|
+
=== Overriding the engine for a format (supported seam)
|
|
379
|
+
|
|
380
|
+
The link:../guides/native-engines[native-engine auto-detection] selects
|
|
381
|
+
the fastest available engine per format at boot. When an application
|
|
382
|
+
needs a specific engine regardless of the bundle (for example fontist's
|
|
383
|
+
parse-only yeptris override), the supported seam is
|
|
384
|
+
`Lutaml::Model::AdapterResolver`:
|
|
385
|
+
|
|
386
|
+
[source,ruby]
|
|
387
|
+
----
|
|
388
|
+
# Pin a named adapter type for a format (validated and loaded eagerly).
|
|
389
|
+
Lutaml::Model::AdapterResolver.set_adapter_type(:yaml, :yeptris)
|
|
390
|
+
|
|
391
|
+
# Pin a pre-resolved adapter class (e.g. a subclass customizing one
|
|
392
|
+
# operation — fontist's parse-only override is exactly this shape).
|
|
393
|
+
Lutaml::Model::AdapterResolver.set_adapter_class(
|
|
394
|
+
:yaml, Fontist::Yaml::YeptrisAdapter
|
|
395
|
+
)
|
|
396
|
+
|
|
397
|
+
# Pass a nil class to unset a pin and return to auto-detection.
|
|
398
|
+
Lutaml::Model::AdapterResolver.set_adapter_class(:yaml, nil)
|
|
399
|
+
----
|
|
400
|
+
|
|
401
|
+
Resolution order: a thread-local `AdapterScope` override, then an
|
|
402
|
+
explicitly pinned adapter (never falls through to detection), then
|
|
403
|
+
bundle-based auto-detection, then the format's default adapter. The
|
|
404
|
+
same seam covers every registered format: `:xml`, `:yaml`, `:json`,
|
|
405
|
+
`: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,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 "<"
|
|
115
|
+
when ">" then ">"
|
|
116
|
+
when "&" then "&"
|
|
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 "<"
|
|
215
|
+
when ">" then ">"
|
|
216
|
+
when "&" then "&"
|
|
217
|
+
when '"' then """
|
|
218
|
+
# when "'" then '''
|
|
219
|
+
end
|
|
220
|
+
end
|
|
221
|
+
end
|
|
222
|
+
end
|
|
223
|
+
end
|
|
224
|
+
end
|
|
225
|
+
end
|
|
@@ -1,73 +1,68 @@
|
|
|
1
|
-
|
|
1
|
+
require "moxml/version"
|
|
2
2
|
|
|
3
|
-
#
|
|
4
|
-
#
|
|
5
|
-
|
|
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
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
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
|