Skip to content

Instantly share code, notes, and snippets.

@romuloceccon
Created April 13, 2011 16:24
Show Gist options
  • Save romuloceccon/917868 to your computer and use it in GitHub Desktop.
Save romuloceccon/917868 to your computer and use it in GitHub Desktop.
Converts a yaml to an html table
require 'yaml'
yaml = YAML.load(STDIN.read)
columns = yaml.values.first.keys.sort
puts "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">"
puts "<html lang=\"en-US\" xml:lang=\"en-US\" xmlns=\"http://www.w3.org/1999/xhtml\">"
puts " <head>"
puts " <meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />"
puts " </head>"
puts " <body>"
puts " <table border=\"1\" cellspacing=\"0\" cellpadding=\"2\">"
puts " <thead>"
puts " <tr>"
columns.each do |col|
puts " <th nowrap=\"1\">"
puts " #{col}"
puts " </th>"
end
puts " </tr>"
puts " </thead>"
puts " <tbody>"
yaml.each do |k, v|
puts " <tr>"
columns.each do |col|
puts " <td nowrap=\"1\">"
puts " #{v[col]}"
puts " </td>"
end
puts " </tr>"
end
puts " </tbody>"
puts " </table>"
puts " </body>"
puts "</html>"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment