nested cgi.tag to create HTML document : HTML « CGI « Ruby






nested cgi.tag to create HTML document


#!/usr/bin/ruby

require 'cgi'

cgi = CGI.new('html3')

processes = 'ps aux'.collect { |proc| proc.split(/\s+/, 11) }

title = %{Processes running on #{ENV['SERVER_NAME'] || %x{hostname}.strip}}

cgi.out do
  cgi.html do
    cgi.head { cgi.title { title } } + cgi.body do
      cgi.table do
        (processes.collect do |fields|
          cgi.tr { fields.collect { |field| cgi.td { field } }.join " " }
        end).join "\n"
      end
    end
  end
end

exit 0

 








Related examples in the same category

1.CGI.escape and CGI.unescape.
2.CGI.escapeHTML
3.CGI.escapeElement
4.CGI.unescapeHTML
5.Generating HTML
6.Output a string to web
7.CGI for creating a web page
8.Create a hash of HTTP response headers