4 ms·
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
by petepete 2y ago
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
])
- rootedbox 2y agoYah 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!
- doright 2y agoNokogiri 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/XML/Builder.html https://nokogiri.org/rdoc/Nokogiri/HTML5/Builder.html https://nokogiri.org/rdoc/Nokogiri/HTML5/Builder.html
- urronglol 2y agoThat syntax looks horrendous