Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Enhancement] Allow builder to continue serializing content after comment #2188

Open
wbrisett opened this issue Feb 3, 2021 · 3 comments
Open

Comments

@wbrisett
Copy link

wbrisett commented Feb 3, 2021

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.

@wbrisett wbrisett added the state/needs-triage Inbox for non-installation-related bug reports or help requests label Feb 3, 2021
@flavorjones
Copy link
Member

Hey, @wbrisett! 👋

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?

@flavorjones flavorjones added meta/feature-request and removed state/needs-triage Inbox for non-installation-related bug reports or help requests labels Feb 3, 2021
@wbrisett
Copy link
Author

wbrisett commented Feb 3, 2021

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.

@jsx150

This comment has been minimized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants