[前][次][番号順一覧][スレッド一覧]

ruby-changes:25409

From: xibbar <ko1@a...>
Date: Sun, 4 Nov 2012 20:48:16 +0900 (JST)
Subject: [ruby-changes:25409] xibbar:r37466 (trunk): * lib/cgi.rb, lib/cgi/*/rb: rename CGI#header to

xibbar	2012-11-04 20:48:05 +0900 (Sun, 04 Nov 2012)

  New Revision: 37466

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=37466

  Log:
    * lib/cgi.rb, lib/cgi/*/rb: rename CGI#header to
        CGI#http_header,
        add  and update HTML5 tag generater.  [Bug #7110]
        Patch provided by Marcus Stollsteimer, thank you !

  Modified files:
    trunk/ChangeLog
    trunk/lib/cgi/core.rb
    trunk/lib/cgi/html.rb
    trunk/lib/cgi.rb
    trunk/test/cgi/test_cgi_core.rb
    trunk/test/cgi/test_cgi_header.rb
    trunk/test/cgi/test_cgi_modruby.rb
    trunk/test/cgi/test_cgi_tag_helper.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 37465)
+++ ChangeLog	(revision 37466)
@@ -1,3 +1,12 @@
+<<<<<<< HEAD
+=======
+Sun Nov  4 20:29:46 2012  Takeyuki FUJIOKA  <xibbar@r...>
+
+	* lib/cgi.rb, lib/cgi/*/rb: rename CGI#header to CGI#http_header,
+	  add  and update HTML5 tag generater.  [Bug #7110]
+	  Patch provided by Marcus Stollsteimer, thank you !
+
+>>>>>>> * lib/fileutils.rb (module FileUtils): repatch [ruby-core:39622]
 Sun Nov  4 11:47:39 2012  Masaki Matsushita  <glass.saga@g...>
 
 	* lib/fileutils.rb (module FileUtils): repatch [ruby-core:39622]
Index: lib/cgi.rb
===================================================================
--- lib/cgi.rb	(revision 37465)
+++ lib/cgi.rb	(revision 37466)
@@ -122,7 +122,7 @@
 #
 # The simplest way to send output to the HTTP client is using the #out() method.
 # This takes the HTTP headers as a hash parameter, and the body content
-# via a block.  The headers can be generated as a string using the #header()
+# via a block.  The headers can be generated as a string using the #http_header()
 # method.  The output stream can be written directly to using the #print()
 # method.
 #
@@ -262,6 +262,7 @@
 #   CGI.new("html4")    # html4.01 (Strict)
 #   CGI.new("html4Tr")  # html4.01 Transitional
 #   CGI.new("html4Fr")  # html4.01 Frameset
+#   CGI.new("html5")    # html5
 #
 
 class CGI
Index: lib/cgi/html.rb
===================================================================
--- lib/cgi/html.rb	(revision 37465)
+++ lib/cgi/html.rb	(revision 37466)
@@ -1035,7 +1035,7 @@
       extend TagMaker
       methods = ""
       # - -
-      for element in %w[ SECTION NAV ARTICLE ASIDE HGROUP
+      for element in %w[ SECTION NAV ARTICLE ASIDE HGROUP HEADER
         FOOTER FIGURE FIGCAPTION S TIME U MARK RUBY BDI IFRAME
         VIDEO AUDIO CANVAS DATALIST OUTPUT PROGRESS METER DETAILS
         SUMMARY MENU DIALOG I B SMALL EM STRONG DFN CODE SAMP KBD
Index: lib/cgi/core.rb
===================================================================
--- lib/cgi/core.rb	(revision 37465)
+++ lib/cgi/core.rb	(revision 37466)
@@ -67,8 +67,8 @@
   # Create an HTTP header block as a string.
   #
   # :call-seq:
-  #   header(content_type_string="text/html")
-  #   header(headers_hash)
+  #   http_header(content_type_string="text/html")
+  #   http_header(headers_hash)
   #
   # Includes the empty line that ends the header block.
   #
@@ -127,29 +127,29 @@
   #
   # Examples:
   #
-  #   header
+  #   http_header
   #     # Content-Type: text/html
   #
-  #   header("text/plain")
+  #   http_header("text/plain")
   #     # Content-Type: text/plain
   #
-  #   header("nph"        => true,
-  #          "status"     => "OK",  # == "200 OK"
-  #            # "status"     => "200 GOOD",
-  #          "server"     => ENV['SERVER_SOFTWARE'],
-  #          "connection" => "close",
-  #          "type"       => "text/html",
-  #          "charset"    => "iso-2022-jp",
-  #            # Content-Type: text/html; charset=iso-2022-jp
-  #          "length"     => 103,
-  #          "language"   => "ja",
-  #          "expires"    => Time.now + 30,
-  #          "cookie"     => [cookie1, cookie2],
-  #          "my_header1" => "my_value"
-  #          "my_header2" => "my_value")
+  #   http_header("nph"        => true,
+  #               "status"     => "OK",  # == "200 OK"
+  #                 # "status"     => "200 GOOD",
+  #               "server"     => ENV['SERVER_SOFTWARE'],
+  #               "connection" => "close",
+  #               "type"       => "text/html",
+  #               "charset"    => "iso-2022-jp",
+  #                 # Content-Type: text/html; charset=iso-2022-jp
+  #               "length"     => 103,
+  #               "language"   => "ja",
+  #               "expires"    => Time.now + 30,
+  #               "cookie"     => [cookie1, cookie2],
+  #               "my_header1" => "my_value"
+  #               "my_header2" => "my_value")
   #
   # This method does not perform charset conversion.
-  def header(options='text/html')
+  def http_header(options='text/html')
     if options.is_a?(String)
       content_type = options
       buf = _header_for_string(content_type)
@@ -170,7 +170,7 @@
       buf << EOL    # empty line of separator
       return buf
     end
-  end # header()
+  end # http_header()
 
   def _header_for_string(content_type) #:nodoc:
     buf = ''
@@ -283,7 +283,7 @@
   # +content_type_string+::
   #   If a string is passed, it is assumed to be the content type.
   # +headers_hash+::
-  #   This is a Hash of headers, similar to that used by #header.
+  #   This is a Hash of headers, similar to that used by #http_header.
   # +block+::
   #   A block is required and should evaluate to the body of the response.
   #
@@ -344,7 +344,7 @@
     options["length"] = content.bytesize.to_s
     output = stdoutput
     output.binmode if defined? output.binmode
-    output.print header(options)
+    output.print http_header(options)
     output.print content unless "HEAD" == env_table['REQUEST_METHOD']
   end
 
Index: test/cgi/test_cgi_modruby.rb
===================================================================
--- test/cgi/test_cgi_modruby.rb	(revision 37465)
+++ test/cgi/test_cgi_modruby.rb	(revision 37466)
@@ -30,7 +30,7 @@
     cgi = CGI.new
     assert(req._setup_cgi_env_invoked?)
     assert(! req._send_http_header_invoked?)
-    actual = cgi.header
+    actual = cgi.http_header
     assert_equal('', actual)
     assert_equal('text/html', req.content_type)
     assert(req._send_http_header_invoked?)
@@ -51,7 +51,7 @@
     }
     assert(req._setup_cgi_env_invoked?)
     assert(! req._send_http_header_invoked?)
-    actual = cgi.header(options)
+    actual = cgi.http_header(options)
     assert_equal('', actual)
     assert_equal('image/gif', req.content_type)
     assert_equal('403 Forbidden', req.status_line)
@@ -71,7 +71,7 @@
       'status'   => '200 OK',
       'location' => 'http://www.example.com/',
     }
-    cgi.header(options)
+    cgi.http_header(options)
     assert_equal('200 OK', req.status_line)  # should be '302 Found' ?
     assert_equal(302, req.status)
     assert_equal('http://www.example.com/', req.headers_out['location'])
Index: test/cgi/test_cgi_core.rb
===================================================================
--- test/cgi/test_cgi_core.rb	(revision 37465)
+++ test/cgi/test_cgi_core.rb	(revision 37466)
@@ -357,10 +357,6 @@
     cgi = CGI.new('html5')
     expected = '<!DOCTYPE HTML>'
     assert_equal(expected, cgi.doctype)
-    # cgi.header not broken
-    expected = "Content-Type: text/html\r\n\r\n"
-    actual = cgi.header
-    assert_equal(expected, actual)
   end
 
 
Index: test/cgi/test_cgi_header.rb
===================================================================
--- test/cgi/test_cgi_header.rb	(revision 37465)
+++ test/cgi/test_cgi_header.rb	(revision 37466)
@@ -21,28 +21,28 @@
   end
 
 
-  def test_cgi_header_simple
+  def test_cgi_http_header_simple
     cgi = CGI.new
     ## default content type
     expected = "Content-Type: text/html\r\n\r\n"
-    actual = cgi.header
+    actual = cgi.http_header
     assert_equal(expected, actual)
     ## content type specified as string
     expected = "Content-Type: text/xhtml; charset=utf8\r\n\r\n"
-    actual = cgi.header('text/xhtml; charset=utf8')
+    actual = cgi.http_header('text/xhtml; charset=utf8')
     assert_equal(expected, actual)
     ## content type specified as hash
     expected = "Content-Type: image/png\r\n\r\n"
-    actual = cgi.header('type'=>'image/png')
+    actual = cgi.http_header('type'=>'image/png')
     assert_equal(expected, actual)
     ## charset specified
     expected = "Content-Type: text/html; charset=utf8\r\n\r\n"
-    actual = cgi.header('charset'=>'utf8')
+    actual = cgi.http_header('charset'=>'utf8')
     assert_equal(expected, actual)
   end
 
 
-  def test_cgi_header_complex
+  def test_cgi_http_header_complex
     cgi = CGI.new
     options = {
       'type'       => 'text/xhtml',
@@ -64,12 +64,12 @@
     expected << "Expires: Sun, 23 Jan 2000 12:34:56 GMT\r\n"
     expected << "location: http://www.ruby-lang.org/\r\n"
     expected << "\r\n"
-    actual = cgi.header(options)
+    actual = cgi.http_header(options)
     assert_equal(expected, actual)
   end
 
 
-  def test_cgi_header_argerr
+  def test_cgi_http_header_argerr
     cgi = CGI.new
     #expected = NoMethodError  # must be ArgumentError
     if RUBY_VERSION>="1.9.0"
@@ -78,12 +78,12 @@
       expected = NoMethodError   # for Ruby1.8
     end
     assert_raise(expected) do
-      cgi.header(nil)
+      cgi.http_header(nil)
     end
   end
 
 
-  def test_cgi_header_cookie
+  def test_cgi_http_header_cookie
     cgi = CGI.new
     cookie1 = CGI::Cookie.new('name1', 'abc', '123')
     cookie2 = CGI::Cookie.new('name'=>'name2', 'value'=>'value2', 'secure'=>true)
@@ -92,25 +92,25 @@
     c1    = "Set-Cookie: name1=abc&123; path=\r\n"
     c2    = "Set-Cookie: name2=value2; path=; secure\r\n"
     ## CGI::Cookie object
-    actual = cgi.header('cookie'=>cookie1)
+    actual = cgi.http_header('cookie'=>cookie1)
     expected = ctype + c1 + sep
     assert_equal(expected, actual)
     ## String
-    actual = cgi.header('cookie'=>cookie2.to_s)
+    actual = cgi.http_header('cookie'=>cookie2.to_s)
     expected = ctype + c2 + sep
     assert_equal(expected, actual)
     ## Array
-    actual = cgi.header('cookie'=>[cookie1, cookie2])
+    actual = cgi.http_header('cookie'=>[cookie1, cookie2])
     expected = ctype + c1 + c2 + sep
     assert_equal(expected, actual)
     ## Hash
-    actual = cgi.header('cookie'=>{'name1'=>cookie1, 'name2'=>cookie2})
+    actual = cgi.http_header('cookie'=>{'name1'=>cookie1, 'name2'=>cookie2})
     expected = ctype + c1 + c2 + sep
     assert_equal(expected, actual)
   end
 
 
-  def test_cgi_header_output_cookies
+  def test_cgi_http_header_output_cookies
     cgi = CGI.new
     ## output cookies
     cookies = [ CGI::Cookie.new('name1', 'abc', '123'),
@@ -122,28 +122,28 @@
     expected << "Set-Cookie: name2=value2; path=; secure\r\n"
     expected << "\r\n"
     ## header when string
-    actual = cgi.header('text/html; charset=utf8')
+    actual = cgi.http_header('text/html; charset=utf8')
     assert_equal(expected, actual)
     ## _header_for_string
-    actual = cgi.header('type'=>'text/html', 'charset'=>'utf8')
+    actual = cgi.http_header('type'=>'text/html', 'charset'=>'utf8')
     assert_equal(expected, actual)
   end
 
 
-  def test_cgi_header_nph
+  def test_cgi_http_header_nph
     time_start = Time.now.to_i
     cgi = CGI.new
     ## 'nph' is true
     ENV['SERVER_SOFTWARE'] = 'Apache 2.2.0'
-    actual1 = cgi.header('nph'=>true)
+    actual1 = cgi.http_header('nph'=>true)
     ## when old IIS, NPH-mode is forced
     ENV['SERVER_SOFTWARE'] = 'IIS/4.0'
-    actual2 = cgi.header
-    actual3 = cgi.header('status'=>'REDIRECT', 'location'=>'http://www.example.com/')
+    actual2 = cgi.http_header
+    actual3 = cgi.http_header('status'=>'REDIRECT', 'location'=>'http://www.example.com/')
     ## newer IIS doesn't require NPH-mode   ## [ruby-dev:30537]
     ENV['SERVER_SOFTWARE'] = 'IIS/5.0'
-    actual4 = cgi.header
-    actual5 = cgi.header('status'=>'REDIRECT', 'location'=>'http://www.example.com/')
+    actual4 = cgi.http_header
+    actual5 = cgi.http_header('status'=>'REDIRECT', 'location'=>'http://www.example.com/')
     time_end = Time.now.to_i
     date = /^Date: ([A-Z][a-z]{2}, \d{2} [A-Z][a-z]{2} \d{4} \d\d:\d\d:\d\d GMT)\r\n/
     [actual1, actual2, actual3].each do |actual|
Index: test/cgi/test_cgi_tag_helper.rb
===================================================================
--- test/cgi/test_cgi_tag_helper.rb	(revision 37465)
+++ test/cgi/test_cgi_tag_helper.rb	(revision 37466)
@@ -338,4 +338,17 @@
   end
 =end
 
+  def test_cgi_tag_helper_html5
+    @environ = {
+      'REQUEST_METHOD' => 'GET',
+    }
+    ENV.update(@environ)
+    ## html5
+    cgi = CGI.new('html5')
+    assert_equal('<HEADER></HEADER>',cgi.header)
+    assert_equal('<FOOTER></FOOTER>',cgi.footer)
+    assert_equal('<ARTICLE></ARTICLE>',cgi.article)
+    assert_equal('<SECTION></SECTION>',cgi.section)
+  end
+
 end

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]