moxml 0.6.20 → 0.6.21
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/Gemfile +1 -1
- data/README.adoc +1 -1
- data/lib/moxml/builder.rb +19 -2
- data/lib/moxml/version.rb +1 -1
- data/spec/moxml/builder_spec.rb +12 -0
- data/spec/moxml/builder_yield_spec.rb +62 -0
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 69067673035541114de7ece6594d659e3b1f664f8392e6760dacabac00636526
|
|
4
|
+
data.tar.gz: 77a12103407b1d58bd90d51c6148c5b7f2832869b93074aa89e303e714060c7e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a04b0ee4b33048b9f59b0199e0c4bd62a73d730794defce0b37d6697b81ca914fd339320aa39d815a7286c6ce761d179942ab8cf40877f0f2829b590b5ffd84e
|
|
7
|
+
data.tar.gz: bedd8753aeb05ab885fe8288810b576329b02399081e2c9b854d1f2df55b4bc7d5ca67da11e237bc55574cbad1aa9da182aadf32157dbca4cd8553a43c9a3d2b
|
data/Gemfile
CHANGED
data/README.adoc
CHANGED
|
@@ -128,7 +128,7 @@ pair serves; cross-import schema sets (`Context#xsd_set`) ride the
|
|
|
128
128
|
compile_set face (1.9.386.0 ✓, the floor now requires it).
|
|
129
129
|
|===
|
|
130
130
|
|
|
131
|
-
NOTE: moxml's dev Gemfile pins `leptris ~> 1.9.
|
|
131
|
+
NOTE: moxml's dev Gemfile pins `leptris ~> 1.9.449` (the tested pair; the gemspec itself has zero runtime dependencies). The adapter enforces the floor at load.
|
|
132
132
|
`ox ~> 2.14`, `libxml-ruby >= 5.0`, and the vendored oga fork — the CI
|
|
133
133
|
matrix tests exactly those floors.
|
|
134
134
|
|
data/lib/moxml/builder.rb
CHANGED
|
@@ -176,6 +176,14 @@ module Moxml
|
|
|
176
176
|
eval_block: true)
|
|
177
177
|
end
|
|
178
178
|
|
|
179
|
+
# Nokogiri Builder parity: `n << "text"` inside an element block
|
|
180
|
+
# appends escaped text (the metanorma converter helpers use this
|
|
181
|
+
# shape through `node.send(name, **attrs) { |n| n << val }`).
|
|
182
|
+
def <<(content)
|
|
183
|
+
text(content)
|
|
184
|
+
self
|
|
185
|
+
end
|
|
186
|
+
|
|
179
187
|
def text(content)
|
|
180
188
|
return face_content { @face.text(content) } if @face
|
|
181
189
|
|
|
@@ -365,7 +373,16 @@ module Moxml
|
|
|
365
373
|
end
|
|
366
374
|
|
|
367
375
|
def run_builder_block(block, eval_block)
|
|
368
|
-
eval_block ? instance_eval(&block) : block
|
|
376
|
+
eval_block ? instance_eval(&block) : yield_scope(block)
|
|
377
|
+
end
|
|
378
|
+
|
|
379
|
+
# #598: a one-arg element block receives the Builder itself with
|
|
380
|
+
# its position on the new element - the face stack (face path)
|
|
381
|
+
# and the @current switch (tree path) already place writes there,
|
|
382
|
+
# so `n << val` appends and `n.child` nests, the nokogiri
|
|
383
|
+
# NodeBuilder contract the metanorma converters build through.
|
|
384
|
+
def yield_scope(block)
|
|
385
|
+
block.arity.zero? ? block.call : block.call(self)
|
|
369
386
|
end
|
|
370
387
|
|
|
371
388
|
def face_escape(value)
|
|
@@ -437,7 +454,7 @@ block: nil, eval_block: true)
|
|
|
437
454
|
previous = @current
|
|
438
455
|
@current = el
|
|
439
456
|
begin
|
|
440
|
-
eval_block ? instance_eval(&block) : block
|
|
457
|
+
eval_block ? instance_eval(&block) : yield_scope(block)
|
|
441
458
|
ensure
|
|
442
459
|
@current = previous
|
|
443
460
|
end
|
data/lib/moxml/version.rb
CHANGED
data/spec/moxml/builder_spec.rb
CHANGED
|
@@ -318,4 +318,16 @@ RSpec.describe Moxml::Builder do
|
|
|
318
318
|
expect(builder.document.root.name).to eq("root")
|
|
319
319
|
end
|
|
320
320
|
end
|
|
321
|
+
|
|
322
|
+
describe "Builder#<<" do
|
|
323
|
+
it "appends escaped text inside an element block" do
|
|
324
|
+
builder = Moxml.fragment(:leptris)
|
|
325
|
+
builder.build do
|
|
326
|
+
element("p") do |n|
|
|
327
|
+
n << "A & B"
|
|
328
|
+
end
|
|
329
|
+
end
|
|
330
|
+
expect(builder.to_xml).to eq("<p>A & B</p>")
|
|
331
|
+
end
|
|
332
|
+
end
|
|
321
333
|
end
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
|
|
5
|
+
# lutaml/moxml#598: element blocks yield nil — nokogiri's Builder
|
|
6
|
+
# yields a scope bound to the created element, and the metanorma
|
|
7
|
+
# converter suite's 82+ call sites build through exactly that shape
|
|
8
|
+
# (`node.send(name, **attrs) { |n| n << val }`). The yield hands the
|
|
9
|
+
# Builder itself with its position on the new element (the face
|
|
10
|
+
# stack and the tree-path @current switch already place writes there
|
|
11
|
+
# for the zero-arg style), so `n <<` appends and `n.child` nests.
|
|
12
|
+
RSpec.describe "the yielded element scope (#598)" do
|
|
13
|
+
describe "fragment mode (tree path)" do
|
|
14
|
+
it "yields a scope whose << appends into the element" do
|
|
15
|
+
out = Moxml.fragment(:leptris) do |xml|
|
|
16
|
+
xml.title { |n| n << "T" }
|
|
17
|
+
end.to_xml
|
|
18
|
+
|
|
19
|
+
expect(out).to eq("<title>T</title>")
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
it "nests one-arg scopes" do
|
|
23
|
+
out = Moxml.fragment(:leptris) do |xml|
|
|
24
|
+
xml.p { |n| n.em { |e| e << "deep" } }
|
|
25
|
+
end.to_xml
|
|
26
|
+
|
|
27
|
+
expect(out).to eq("<p><em>deep</em></p>")
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
it "keeps the zero-arg style working" do
|
|
31
|
+
out = Moxml.fragment(:leptris) do |xml|
|
|
32
|
+
xml.p { text("plain") }
|
|
33
|
+
end.to_xml
|
|
34
|
+
|
|
35
|
+
expect(out).to eq("<p>plain</p>")
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
describe "document mode (face path)" do
|
|
40
|
+
it "yields a scope whose << appends into the element" do
|
|
41
|
+
ctx = Moxml.new(:leptris)
|
|
42
|
+
builder = Moxml::Builder.new(ctx)
|
|
43
|
+
doc = builder.build do |xml|
|
|
44
|
+
xml.root { |_n| xml.title { |n2| n2 << "T" } }
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
expect(doc.to_xml).to include("<title>T</title>")
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
it "nests one-arg scopes through the face" do
|
|
51
|
+
ctx = Moxml.new(:leptris)
|
|
52
|
+
builder = Moxml::Builder.new(ctx)
|
|
53
|
+
doc = builder.build do |xml|
|
|
54
|
+
xml.root { |_n| xml.p { |n2| n2.em { |e| e << "deep" } } }
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
# the face path pretty-prints - the structure is the contract
|
|
58
|
+
expect(doc.to_xml).to include("<p>")
|
|
59
|
+
expect(doc.to_xml).to include("<em>deep</em>")
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: moxml
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.6.
|
|
4
|
+
version: 0.6.21
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Ribose Inc.
|
|
@@ -529,6 +529,7 @@ files:
|
|
|
529
529
|
- spec/moxml/attribute_spec.rb
|
|
530
530
|
- spec/moxml/builder_namespaces_spec.rb
|
|
531
531
|
- spec/moxml/builder_spec.rb
|
|
532
|
+
- spec/moxml/builder_yield_spec.rb
|
|
532
533
|
- spec/moxml/c14n/adapter_delegation_spec.rb
|
|
533
534
|
- spec/moxml/c14n/api_spec.rb
|
|
534
535
|
- spec/moxml/c14n/c14n_spec.rb
|