module CGI::Util

def pretty(string, shift = " ")


#
#
#
#
print CGI.pretty("", "\t")

#
#
#
#
print CGI.pretty("")

unit to use; it defaults to two spaces.
+string+ is the HTML string to indent. +shift+ is the indentation

Prettify (indent) an HTML string.
def pretty(string, shift = "  ")
  lines = string.gsub(/(?!\A)<.*?>/m, "\n\\0").gsub(/<.*?>(?!\n)/m, "\\0\n")
  end_pos = 0
  while end_pos = lines.index(/^<\/(\w+)/, end_pos)
    element = $1.dup
    start_pos = lines.rindex(/^\s*<#{element}/i, end_pos)
    lines[start_pos ... end_pos] = "__" + lines[start_pos ... end_pos].gsub(/\n(?!\z)/, "\n" + shift) + "__"
  end
  lines.gsub(/^((?:#{Regexp::quote(shift)})*)__(?=<\/?\w)/, '\1')
end

def rfc1123_date(time)

# Sat, 01 Jan 2000 00:00:00 GMT
CGI.rfc1123_date(Time.now)

Format a +Time+ object as a String using the format specified by RFC 1123.
def rfc1123_date(time)
  time.getgm.strftime("%a, %d %b %Y %T GMT")
end