News for hackers. Stuff that matters.
Re:HTML_slice: Enable Ruby classes the ability to generate r... by petepete on Thursday January 02, 2025 @12:03PM (#42576194)
Rails gives you the tools to do much of this already.

For example, this:

    html_slice :stuff do
      h1 'hello world' # @html_slice[:default] << '<h1>hello world</h1>'
      text # @html_slice[:default] << '<p>Lorem ipsum dolor sit amet</p>'
      div do
        _ '<b> some raw html </b>'
      end
    end
Could be written in a helper like this:

    safe_join([
      tag.h1('Hello world'),
      tag.p('Lorem ipsum dolor sit amet'),
      tag.div(<<~RAW.html_safe)
        <b>some raw html</b>
      RAW
    ])
Re:HTML_slice: Enable Ruby classes the ability to generate r... by rootedbox on Thursday January 02, 2025 @12:24PM (#42576412)
Yah I think html_slice would be ok in a ruby only project. But as the mantra goes if in rails do it the rails way. Helpers are great!
Re:HTML_slice: Enable Ruby classes the ability to generate r... by doright on Thursday January 02, 2025 @01:48PM (#42577392)
Nokogiri also has something similar; I've used it in a couple projects where I needed to output XML.

https://nokogiri.org/rdoc/Nokogiri/XML/Builder.html

https://nokogiri.org/rdoc/Nokogiri/HTML5/Builder.html

Re:HTML_slice: Enable Ruby classes the ability to generate r... by urronglol on Thursday January 02, 2025 @03:11PM (#42578305)
That syntax looks horrendous