3

Is there a ruby equivalent of ColdFusions cfdump tag.

which can dump any object as a html formatted output.

I want to use this to be able to dump any object into an email html body.

I know there is Pretty Print and other gems out there that output colour coded well formatted strings to the console, but I want to be able to generate a html string, dumping out the entire data type I need.

divibisan
  • 11,659
  • 11
  • 40
  • 58
theog
  • 2,062
  • 2
  • 14
  • 13

3 Answers3

2

There's a CodeRay colorizer.

CodeRay.scan("5.times do\n  puts 'Hello, world!'\nend", :ruby).
        div(:line_numbers => :table)

I use it to highlight JSON snippets in my wiki, so if you pretty print objects to JSON and then pass it through coderay, it'll certainly work.

Sergio Tulentsev
  • 226,338
  • 43
  • 373
  • 367
0

The rails-cfdump project is abandoned, but it looks like its output is very similar to CF's <cfdump>/WriteDump().

Chris Peters
  • 17,918
  • 6
  • 49
  • 65
0

The dom gem that I have developed lets you write HTML string from Ruby code. Using it, you can do things like:

require "dom"
["foo".dom(:span, class: "bold"), "bar"].dom(:div).dom(:body).dom(:html)
# => "<html><body><div><span class=\"bold\">foo</span>bar</div></body></html>"
sawa
  • 165,429
  • 45
  • 277
  • 381