nokogiri
nokogiri copied to clipboard
[Enhancement] Allow builder to continue serializing content after comment
In trying to enhance an existing script, I asked on the Nokogiri list about the possibility of enabling Builder to open a comment block, continue serializing data, then closing the comment. It was mentioned that's not currently possible. I am requesting that folks consider this enhancement to builder.
Hey, @wbrisett! :wave:
I was imagining something like this:
#! /usr/bin/env ruby
require 'nokogiri'
require 'minitest/autorun'
class Test < MiniTest::Spec
describe "Builder support for commenting out subtrees" do
it "works like this currently" do
builder = Nokogiri::HTML::Builder.new do |doc|
doc.html do
doc.body do
doc.span do
doc.text "Hello world"
end
end
end
end
assert_includes(builder.to_html, <<~EOF)
<html><body><span>Hello world</span></body></html>
EOF
end
it "might be extended to do this" do
builder = Nokogiri::HTML::Builder.new do |doc|
doc.html do
doc.body do
doc.comment do # added
doc.span do
doc.text "Hello world"
end
end
end
end
end
assert_includes(builder.to_html, <<~EOF)
<html><body><!-- <span>Hello world</span> --></body></html>
EOF
end
end
end
WDYT?
I really think the "extended to do this" version is cleaner and it honestly follows what you have been doing in builder, that is, opens up a block, then you build inside that block until it's time to close.
However, this is exactly what I was hoping for, and if you said, I could only have the first one, I'd find ways to make that work.
Yeah ;hunter