moxml 0.6.20 → 0.6.22

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: ce061aa46adbf899670cb1affdffca97602e0365f456dc4305107e92a11e583b
4
- data.tar.gz: bc69d2fa7cacdc27aa5005272da2c1d90841d89b20512b826b0dfbe4d45d9423
3
+ metadata.gz: 0d96cf20ddab1915f70f97da23f4d4f4c29fdb70d932f5bfe8b967a516c9c6fc
4
+ data.tar.gz: '091e0ae806bdad337cd00382d6591eea7ddffed177f450e57f2a5e5bf727faee'
5
5
  SHA512:
6
- metadata.gz: a39797c700876908499d78aba97ddd18ac9f8880285513ee73e7fb74d7b11ab30b8b1a68b6726796023a79a840b9b5e921942d5ba839908a5fdd758b3da802ee
7
- data.tar.gz: 4122c27d3c01a2d826af31b2e6a444aad9c663864a17e2e520580a3b14a8a190afa7bacd56203d26109915fa1e7a36c96ec5078fda42f4acd6b2b4221fca8cc6
6
+ metadata.gz: e4a8447e6b217c0c2dafdf3637bb237ef1f9427a67ba713e878981d343583611fcc7662ee15812671d634092dda42505a7e4df6417d3743e9f16df5d5ffc0bb6
7
+ data.tar.gz: 5206932c75097fb82d3c39a8ca7a0c71e5940fbf0a92df55a5faf2b5dcfab10f892c039c9007ac27dbf048e5912031c2e1c109d888901d299d2202abc176ae0c
data/Gemfile CHANGED
@@ -12,7 +12,7 @@ gem "base64"
12
12
  gem "benchmark"
13
13
  gem "benchmark-ips"
14
14
  gem "get_process_mem"
15
- gem "leptris", "~> 1.9.448"
15
+ gem "leptris", "~> 1.9.450"
16
16
  gem "libxml-ruby", ">= 5.0"
17
17
  gem "nokogiri", "~> 1.18"
18
18
  gem "oga"
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.448` (the tested pair; the gemspec itself has zero runtime dependencies). The adapter enforces the floor at load.
131
+ NOTE: moxml's dev Gemfile pins `leptris ~> 1.9.450` (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.call
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.call
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Moxml
4
- VERSION = "0.6.20"
4
+ VERSION = "0.6.22"
5
5
  end
@@ -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 &amp; 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.20
4
+ version: 0.6.22
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