diff options
author | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 1999-02-10 08:44:29 +0000 |
---|---|---|
committer | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 1999-02-10 08:44:29 +0000 |
commit | 997ff23758884944f28a089eaa50ac7eb1c026c6 (patch) | |
tree | f99563ed31c2f6a8facc7160cccde602d39af79b /lib/cgi-lib.rb | |
parent | d148ffef297193fe5f6639a8bd8c9ee3d3374479 (diff) |
*** empty log message ***
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_3@397 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/cgi-lib.rb')
-rw-r--r-- | lib/cgi-lib.rb | 43 |
1 files changed, 28 insertions, 15 deletions
diff --git a/lib/cgi-lib.rb b/lib/cgi-lib.rb index 2089a9c9a5..83ea6118b9 100644 --- a/lib/cgi-lib.rb +++ b/lib/cgi-lib.rb @@ -38,6 +38,11 @@ # CGI.tag("HR") # } # } +# +# print HTTP header and strings to STDOUT +# CGI.print{ "string" } # add HTTP header "Content-Type: text/html" +# CGI.print("Content-Type: text/plain"){ "string" } +# CGI.print("HTTP/1.0 200 OK", "Content-Type: text/html"){ "string" } # if running on Windows(IIS or PWS) then change cwd. @@ -150,25 +155,33 @@ class CGI < SimpleDelegator (iterator? ? yield.to_s + "</" + escapeHTML(element) + ">" : "") end - def CGI.message(msg, title = "", header = ["Content-Type: text/html"]) - print CGI.header(*header) - print "<html><head><title>" - print title - print "</title></head><body>\n" - print msg - print "</body></html>\n" + def CGI.print(*header) + header.push("Content-Type: text/html") if header.empty? + STDOUT.print CGI.header(*header) + yield.to_s + end + + def CGI.message(message, title = "", header = ["Content-Type: text/html"]) + if message.kind_of?(Hash) + title = message['title'] + header = message['header'] + message = message['body'] + end + CGI.print(*header){ + CGI.tag("HTML"){ + CGI.tag("HEAD"){ CGI.tag("TITLE"){ title } } + + CGI.tag("BODY"){ message } + } + } TRUE end def CGI.error - m = $!.to_s.dup - m.gsub!(/&/, '&') - m.gsub!(/</, '<') - m.gsub!(/>/, '>') - msgs = ["<pre>ERROR: <strong>#{m}</strong>"] - msgs << $@ - msgs << "</pre>" - CGI.message(msgs.join("\n"), "ERROR") + CGI.message({'title'=>'ERROR', 'body'=> + CGI.tag("PRE"){ + "ERROR: " + CGI.tag("STRONG"){ escapeHTML($!.to_s) } + "\n" + + escapeHTML($@.join("\n")) + } + }) exit end end |