theog theog - 5 months ago 14
HTML Question

ruby dump object to html formatted string

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.


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.