moxml 0.5.78 → 0.5.79
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/README.adoc +40 -3
- data/lib/moxml/adapter/leptris.rb +2 -4
- data/lib/moxml/adapter/nokogiri.rb +12 -0
- data/lib/moxml/version.rb +1 -1
- data/spec/moxml/document_parse_diagnostics_spec.rb +12 -0
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 9314d43b66d5890286b147d882d0200e33adee9e61209e8088674be8205e11ea
|
|
4
|
+
data.tar.gz: 3ec14b4892a6ae2f0dd2a8d2bded06b86a0c86ce742b20f6763478df4a851963
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: bb2f60f496656598a90121c56039f620e4a46518753c9062262d4aa21a7c56db6b3d8b1fa5d3d87f4f45773a1de03d63e731e10ee95fc9fbe1c6d8bab5c3122d
|
|
7
|
+
data.tar.gz: 59d27148762e9b3837feb218bd42820a3a17291b8ac266b8868b730b19dc0d4d84abaa238f60e32a279c31673593dfc70f809d4cefd8b60c6deae173e8f63745
|
data/README.adoc
CHANGED
|
@@ -103,9 +103,10 @@ entity references (`entity_mode: :keep`), 1.9.193.4+ native plan rows
|
|
|
103
103
|
executor (`Moxml::StructPlan`; the floor is the varargs-mint fix),
|
|
104
104
|
1.9.204+ native document-level parts (created DOCTYPEs as native
|
|
105
105
|
nodes, document-PI removal, declaration clear). Current
|
|
106
|
-
recommendation: 1.9.
|
|
107
|
-
|
|
108
|
-
borrowed-text-run
|
|
106
|
+
recommendation: 1.9.228+ (the #318 text-set fix train; carries
|
|
107
|
+
the plan-ABI surface — bound plan rows, typed scalars, fused
|
|
108
|
+
Descriptor#materialize — plus the 1.9.217+ borrowed-text-run and
|
|
109
|
+
1.9.221+ memory wins).
|
|
109
110
|
|===
|
|
110
111
|
|
|
111
112
|
NOTE: moxml's dev Gemfile pins `leptris ~> 1.9.174`, `nokogiri ~> 1.18`,
|
|
@@ -644,6 +645,42 @@ root.add_child(title)
|
|
|
644
645
|
puts doc.to_xml(indent: 2)
|
|
645
646
|
----
|
|
646
647
|
|
|
648
|
+
=== Fast paths and diagnostics
|
|
649
|
+
|
|
650
|
+
Read-only attribute listing without Attribute node objects — the
|
|
651
|
+
walk-hot shape when only names and values are needed (leptris
|
|
652
|
+
answers in one C crossing; document order, duplicates included):
|
|
653
|
+
|
|
654
|
+
[source,ruby]
|
|
655
|
+
----
|
|
656
|
+
element.attribute_pairs.each do |name, value|
|
|
657
|
+
# names are shared frozen strings; dup before mutating
|
|
658
|
+
end
|
|
659
|
+
----
|
|
660
|
+
|
|
661
|
+
Typed struct members on `Moxml::StructPlan` — the executor casts
|
|
662
|
+
in C with no intermediate String (unparseable input degrades to
|
|
663
|
+
the raw String):
|
|
664
|
+
|
|
665
|
+
[source,ruby]
|
|
666
|
+
----
|
|
667
|
+
plan = Moxml::StructPlan.new do
|
|
668
|
+
element "item", Item,
|
|
669
|
+
attrs: { "price" => [:price, :float], "qty" => [:qty, :integer] },
|
|
670
|
+
text: [:label, :integer]
|
|
671
|
+
end
|
|
672
|
+
----
|
|
673
|
+
|
|
674
|
+
Recover-class parse diagnostics (duplicate-attribute events and
|
|
675
|
+
siblings) on adapters with the surface; `[]` elsewhere. Read
|
|
676
|
+
while the document is alive:
|
|
677
|
+
|
|
678
|
+
[source,ruby]
|
|
679
|
+
----
|
|
680
|
+
doc.parse_diagnostics
|
|
681
|
+
# => [{ kind: :recover, message: "Attribute a redefined" }]
|
|
682
|
+
----
|
|
683
|
+
|
|
647
684
|
== Real-world examples
|
|
648
685
|
|
|
649
686
|
Practical, runnable examples demonstrating Moxml usage in common scenarios are
|
|
@@ -353,10 +353,8 @@ module Moxml
|
|
|
353
353
|
}.freeze
|
|
354
354
|
|
|
355
355
|
def wrap_binding_node(node, context)
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
return cached if cached
|
|
359
|
-
end
|
|
356
|
+
cached = node.instance_variable_get(:@moxml_wrapper)
|
|
357
|
+
return cached if cached
|
|
360
358
|
|
|
361
359
|
entry = BINDING_FAST_WRAP[node.class]
|
|
362
360
|
return nil unless entry
|
|
@@ -294,6 +294,18 @@ module Moxml
|
|
|
294
294
|
element[name.to_s] = value.to_s
|
|
295
295
|
end
|
|
296
296
|
|
|
297
|
+
# Cross-adapter parity for Document#parse_diagnostics
|
|
298
|
+
# (#271): Nokogiri's doc.errors already carries recover-
|
|
299
|
+
# mode entries; mapped into the same { kind:, message: }
|
|
300
|
+
# shape. Kind is :error — Nokogiri does not classify.
|
|
301
|
+
def parse_diagnostics(native_doc)
|
|
302
|
+
return [] unless native_doc.respond_to?(:errors)
|
|
303
|
+
|
|
304
|
+
native_doc.errors.map do |e|
|
|
305
|
+
{ kind: :error, message: e.message.to_s }
|
|
306
|
+
end
|
|
307
|
+
end
|
|
308
|
+
|
|
297
309
|
def attributes(element)
|
|
298
310
|
# attribute_nodes, not attributes.values: the attributes Hash
|
|
299
311
|
# is keyed by local name, so xmi:type and type collide and
|
data/lib/moxml/version.rb
CHANGED
|
@@ -40,4 +40,16 @@ RSpec.describe Moxml::Document do
|
|
|
40
40
|
rescue StandardError, LoadError
|
|
41
41
|
skip "rexml adapter unavailable"
|
|
42
42
|
end
|
|
43
|
+
|
|
44
|
+
it "maps nokogiri doc.errors into the same shape" do
|
|
45
|
+
ctx = Moxml.new(:nokogiri)
|
|
46
|
+
doc = ctx.parse(%(<r a="1" a="2"/>), recover: true) ||
|
|
47
|
+
ctx.parse(%(<r a="1" a="2"/>))
|
|
48
|
+
diags = doc.parse_diagnostics
|
|
49
|
+
expect(diags).not_to be_empty
|
|
50
|
+
expect(diags.first[:kind]).to eq(:error)
|
|
51
|
+
expect(diags.first[:message]).to be_a(String)
|
|
52
|
+
rescue StandardError, LoadError
|
|
53
|
+
skip "nokogiri adapter unavailable"
|
|
54
|
+
end
|
|
43
55
|
end
|