3 ms·
Rails has had Builder::XmlMarkup for a long time. It's been extracted into a gem: https://www.rubydoc.info/gems/builder/Builder/XmlMarkup https://www.rubydoc.in
by kayodelycaon 4y ago
Rails has had Builder::XmlMarkup for a long time. It's been extracted into a gem: https://www.rubydoc.info/gems/builder/Builder/XmlMarkup https://www.rubydoc.info/gems/builder/Builder/XmlMarkup
You could easily write a method to do this:
def html(&blk)
io = StringIO.new()
builder = Builder::XmlMarkup.new(:target => io, :indent => 2)
blk.call(builder)
io.to_s
end
html do |t|
t.span "#{@first_name} #{@last_name}"
end
Not the prettiest, but it doesn't require additional gems or a new syntax highlighter and linter.
- ImaCake 4y agoSurely rux would cover more edge cases than your function? A lot of people would see this function and struggle to understand what it is doing, but if you explicitly use something like rux it's much more obvious. I guess rux would have more overhead than this though.