From 260945fe6f1ffdb692a6b8513b762670d071ca68 Mon Sep 17 00:00:00 2001 From: wakou Date: Sat, 3 Jun 2000 18:22:23 +0000 Subject: Sun Jun 4 03:17:36 2000 Wakou Aoyama * lib/cig.rb: improve: CGI::pretty() git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@728 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- lib/cgi.rb | 58 ++++++++++++++++++++++++++++++---------------------------- 1 file changed, 30 insertions(+), 28 deletions(-) (limited to 'lib') diff --git a/lib/cgi.rb b/lib/cgi.rb index a8e4bee1fa..a738587e5e 100644 --- a/lib/cgi.rb +++ b/lib/cgi.rb @@ -5,7 +5,7 @@ $Date$ cgi.rb -Version 1.50 +Version 1.60 Copyright (C) 2000 Network Applied Communication Laboratory, Inc. Copyright (C) 2000 Information-technology Promotion Agency, Japan @@ -94,14 +94,14 @@ and cgi.cookies is a hash. for name, cookie in cgi.cookies cookie.expires = Time.now + 30 end - cgi.out({ "cookie" => cgi.cookies }){} + cgi.out("cookie" => cgi.cookies){"string"} cgi.cookies # { "name1" => cookie1, "name2" => cookie2, ... } require "cgi" cgi = CGI.new cgi.cookies['name'].expires = Time.now + 30 - cgi.out({ "cookie" => cgi.cookies['name'] }){} + cgi.out("cookie" => cgi.cookies['name']){"string"} and see MAKE COOKIE OBJECT. @@ -145,27 +145,27 @@ HTTP_REFERER HTTP_USER_AGENT require "cgi" cgi = CGI.new("html3") # add HTML generation methods - cgi.out{ - cgi.html{ + cgi.out() do + cgi.html() do cgi.head{ cgi.title{"TITLE"} } + - cgi.body{ - cgi.form{ + cgi.body() do + cgi.form() do cgi.textarea("get_text") + cgi.br + cgi.submit - } + - cgi.pre{ + end + + cgi.pre() do CGI::escapeHTML( "params: " + cgi.params.inspect + "\n" + "cookies: " + cgi.cookies.inspect + "\n" + - ENV.collect{|key, value| + ENV.collect() do |key, value| key + " --> " + value + "\n" - }.to_s + end.join("") ) - } - } - } - } + end + end + end + end # add HTML generation methods CGI.new("html3") # html3.2 @@ -185,7 +185,7 @@ class CGI EOL = CR + LF v = $-v $-v = false - VERSION = "1.50" + VERSION = "1.60" RELEASE_DATE = "$Date$" $-v = v @@ -925,19 +925,15 @@ convert string charset, and set language to "ja". # # =end - def CGI::pretty_shift(string, shift = " ") - shift = " " if true == shift - string.gsub(/\n(?!\z)/n, "\n" + shift) - end - def CGI::pretty_nest(string, shift = " ") - string.gsub(/(<(\w+).*?>)((?:.|\n)*?)(<\/\2>)/n) do - $1 + CGI::pretty_shift(CGI::pretty_nest($3, shift), shift) + $4 - end - end def CGI::pretty(string, shift = " ") - CGI::pretty_nest( - string.gsub(/<(?:.|\n)*?>/n, "\n\\0").gsub(/<(?:.|\n)*?>(?!\n)/n, "\\0\n"), shift - ) + lines = string.gsub(/(?!\A)<(?:.|\n)*?>/n, "\n\\0").gsub(/<(?:.|\n)*?>(?!\n)/n, "\\0\n") + end_pos = 0 + while end_pos = lines.index(/^<\/(\w+)/n, end_pos) + element = $1.dup + start_pos = lines.rindex(/^\s*<#{element}/ni, end_pos) + lines[start_pos ... end_pos] = "__" + lines[start_pos ... end_pos].gsub(/\n(?!\z)/n, "\n" + shift) + "__" + end + lines.gsub(/^(\s*)__(?=<\/?\w)/n, '\1') end @@ -1907,6 +1903,12 @@ end == HISTORY +=== Version 1.60 - wakou + +2000/06/03 18:16:17 + +- improve: CGI::pretty() + === Version 1.50 - wakou 2000/05/30 19:04:08 -- cgit v1.2.3