moxml 0.5.102 → 0.5.103
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/lib/moxml/adapter/leptris.rb +50 -2
- data/lib/moxml/version.rb +1 -1
- data/spec/moxml/xslt/stylesheet_spec.rb +19 -6
- 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: 566f2842eac4e01753965cb5f56eada53d6683b3ef6b576015eb4b0da572ae67
|
|
4
|
+
data.tar.gz: ccc15ef083358a018e1536983017c6681c70c11ccbb4678ac123e5b0b2c9aada
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 2c29296b60bedabbc512c9f5c454b0195b3632dbf9952b0c397fc3bad6554135dd3096a04a34e1abddf9ce40088af4856b2ead7d8ca69a4eb251dc3db38286b3
|
|
7
|
+
data.tar.gz: fd1684a85d2ace2191b33bf996a12e8bea6cb535a340732cccee3318abc6649ba2e07548509d1469959e10ee711ecec650f8ec6b4525beb6a66e2c9a75a81c1d
|
|
@@ -507,7 +507,37 @@ module Moxml
|
|
|
507
507
|
raise Moxml::XsltError, "stylesheet compile failed: #{e.message}"
|
|
508
508
|
end
|
|
509
509
|
|
|
510
|
+
# Bindings >= 1.9.290.0 thread top-level xsl:param overrides
|
|
511
|
+
# (leptris#1478); older bindings raise the typed error (the
|
|
512
|
+
# #360 face gap, face-probed so a misrelease degrades instead
|
|
513
|
+
# of NoMethodError-ing — the 1.9.199.0 lesson).
|
|
514
|
+
NATIVE_XSLT_PARAMS =
|
|
515
|
+
NATIVE_READ_LAYER &&
|
|
516
|
+
Gem::Version.new(::Leptris::VERSION) >= Gem::Version.new("1.9.290.0") &&
|
|
517
|
+
::Leptris::XML::XSLT::Stylesheet.instance_method(:apply_to)
|
|
518
|
+
.parameters.size > 1
|
|
519
|
+
|
|
520
|
+
# The seam contract passes the libxslt flat quoted array; the
|
|
521
|
+
# binding wants the raw name => value hash (leptris#1478
|
|
522
|
+
# matches nokogiri's quoted-string semantics internally).
|
|
523
|
+
def self.flat_params_to_hash(params)
|
|
524
|
+
return params if params.is_a?(Hash)
|
|
525
|
+
return {} if params.nil? || params.empty?
|
|
526
|
+
|
|
527
|
+
params.each_slice(2).to_h { |name, value| [name, unquote_param(value)] }
|
|
528
|
+
end
|
|
529
|
+
|
|
530
|
+
def self.unquote_param(value)
|
|
531
|
+
str = value.to_s
|
|
532
|
+
str.start_with?("'") && str.end_with?("'") && str.length >= 2 ? str[1..-2] : str
|
|
533
|
+
end
|
|
534
|
+
|
|
510
535
|
def self.xslt_apply_document(sheet, document_native, params)
|
|
536
|
+
if NATIVE_XSLT_PARAMS
|
|
537
|
+
return sheet.apply_to(document_native,
|
|
538
|
+
params: flat_params_to_hash(params))
|
|
539
|
+
end
|
|
540
|
+
|
|
511
541
|
assert_xslt_no_params(params)
|
|
512
542
|
sheet.apply_to(document_native)
|
|
513
543
|
rescue ::Leptris::XML::XPathError => e
|
|
@@ -515,6 +545,11 @@ module Moxml
|
|
|
515
545
|
end
|
|
516
546
|
|
|
517
547
|
def self.xslt_apply_string(sheet, document_native, params)
|
|
548
|
+
if NATIVE_XSLT_PARAMS
|
|
549
|
+
return sheet.serialize(document_native,
|
|
550
|
+
params: flat_params_to_hash(params))
|
|
551
|
+
end
|
|
552
|
+
|
|
518
553
|
assert_xslt_no_params(params)
|
|
519
554
|
sheet.serialize(document_native)
|
|
520
555
|
rescue ::Leptris::XML::XPathError => e
|
|
@@ -525,8 +560,9 @@ module Moxml
|
|
|
525
560
|
return if params.nil? || params.empty?
|
|
526
561
|
|
|
527
562
|
raise Moxml::XsltError,
|
|
528
|
-
"XSLT params are not threaded by
|
|
529
|
-
"(leptris-ruby#360);
|
|
563
|
+
"XSLT params are not threaded by this binding " \
|
|
564
|
+
"(leptris-ruby#360); upgrade to leptris >= 1.9.290.0 or " \
|
|
565
|
+
"pass an empty params hash"
|
|
530
566
|
end
|
|
531
567
|
|
|
532
568
|
def self.native_c14n_byte_safe?
|
|
@@ -2016,11 +2052,23 @@ module Moxml
|
|
|
2016
2052
|
new_node
|
|
2017
2053
|
end
|
|
2018
2054
|
|
|
2055
|
+
NATIVE_APPEND_CHILDREN =
|
|
2056
|
+
NATIVE_READ_LAYER &&
|
|
2057
|
+
Gem::Version.new(::Leptris::VERSION) >= Gem::Version.new("1.9.290.0")
|
|
2058
|
+
|
|
2019
2059
|
def replace_children(node, new_children)
|
|
2020
2060
|
if NATIVE_READ_LAYER
|
|
2021
2061
|
node = to_binding(node)
|
|
2022
2062
|
new_children = new_children.map { |child| to_binding(child) }
|
|
2023
2063
|
end
|
|
2064
|
+
if NATIVE_APPEND_CHILDREN && !new_children.empty?
|
|
2065
|
+
# One crossing to clear, one to append N (leptris-ruby#366's
|
|
2066
|
+
# bulk face; the old path paid an append crossing per child).
|
|
2067
|
+
::Leptris::XML::FFI.check_status(
|
|
2068
|
+
::Leptris::XML::FFI.leptris_element_remove_children(node.c_ptr),
|
|
2069
|
+
)
|
|
2070
|
+
return node.append_children(new_children)
|
|
2071
|
+
end
|
|
2024
2072
|
node.children = new_children
|
|
2025
2073
|
end
|
|
2026
2074
|
|
data/lib/moxml/version.rb
CHANGED
|
@@ -4,8 +4,9 @@ require "spec_helper"
|
|
|
4
4
|
|
|
5
5
|
# The Moxml::XSLT contract: compile once, apply many. Only engines
|
|
6
6
|
# with an XSLT processor implement it (nokogiri/libxslt; leptris
|
|
7
|
-
# covering XSLT 1.0-3.0).
|
|
8
|
-
#
|
|
7
|
+
# covering XSLT 1.0-3.0). Bindings >= 1.9.290.0 thread top-level
|
|
8
|
+
# params (leptris#1478); older bindings raise Moxml::XsltError
|
|
9
|
+
# citing leptris-ruby#360.
|
|
9
10
|
SHEET_COUNT = <<~XSL
|
|
10
11
|
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
|
|
11
12
|
<xsl:template match="/"><out><xsl:value-of select="count(//i)"/></out></xsl:template>
|
|
@@ -77,10 +78,22 @@ RSpec.describe "Moxml::XSLT" do
|
|
|
77
78
|
expect(sheet.apply_to_string(doc)).to include("plain text result")
|
|
78
79
|
end
|
|
79
80
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
81
|
+
if Gem::Version.new(Leptris::VERSION) >= Gem::Version.new("1.9.290.0")
|
|
82
|
+
it "threads top-level params (leptris#1478)" do
|
|
83
|
+
sheet = ctx.xslt(<<~XSL)
|
|
84
|
+
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
|
|
85
|
+
<xsl:param name="n" select="'0'"/>
|
|
86
|
+
<xsl:template match="/"><out><xsl:value-of select="$n"/></out></xsl:template>
|
|
87
|
+
</xsl:stylesheet>
|
|
88
|
+
XSL
|
|
89
|
+
expect(sheet.apply_to_string(doc, params: { "n" => "7" })).to include("7")
|
|
90
|
+
end
|
|
91
|
+
else
|
|
92
|
+
it "raises XsltError on non-empty params (leptris-ruby#360)" do
|
|
93
|
+
sheet = ctx.xslt(SHEET_COUNT)
|
|
94
|
+
expect { sheet.apply_to(doc, params: { "n" => "7" }) }
|
|
95
|
+
.to raise_error(Moxml::XsltError, /params.*#360/)
|
|
96
|
+
end
|
|
84
97
|
end
|
|
85
98
|
|
|
86
99
|
it "reports support" do
|