Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 967
theog Avatar asked Mar 16 '26 00:03

theog


1 Answers

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.

like image 82
Sergio Tulentsev Avatar answered Mar 18 '26 15:03

Sergio Tulentsev