Hacker News new | past | comments | ask | show | jobs | submit login

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
    ])



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!


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


That syntax looks horrendous




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: