summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorwakou <wakou@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2000-06-03 18:22:23 +0000
committerwakou <wakou@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2000-06-03 18:22:23 +0000
commit260945fe6f1ffdb692a6b8513b762670d071ca68 (patch)
tree23d470686817c678cb31fd12babc080a86dc9c05
parentb62cdfe9b5ea559c335fcb8d887ffd1ee0007eca (diff)
Sun Jun 4 03:17:36 2000 Wakou Aoyama <wakou@fsinet.or.jp>
* lib/cig.rb: improve: CGI::pretty() git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@728 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog4
-rw-r--r--lib/cgi.rb58
2 files changed, 34 insertions, 28 deletions
diff --git a/ChangeLog b/ChangeLog
index 90c52541c8..dec011884e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+Sun Jun 4 03:17:36 2000 Wakou Aoyama <wakou@fsinet.or.jp>
+
+ * lib/cig.rb: improve: CGI::pretty()
+
Sun Jun 4 02:01:10 2000 WATANABE Hirofumi <eban@os.rim.or.jp>
* lib/mkmf.rb: do not need to add -L$(topdir) in --enable-shared case.
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".
# </BODY>
# </HTML>
=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