summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorxibbar <xibbar@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-10-04 02:20:55 +0000
committerxibbar <xibbar@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-10-04 02:20:55 +0000
commitaeca9656813575c0ffd696115a607a43eb776012 (patch)
tree096a269f55df566e627e11a7a27bad4ecf977032
parent4336caf20422cdaeb99e519e20ff9214667e594d (diff)
* lib/cgi/html5.rb: Add html5 tag maker.
* lib/cgi/core.rb: ditto. [Feature #6637] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37077 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--lib/cgi/core.rb6
-rw-r--r--lib/cgi/html.rb55
-rw-r--r--test/cgi/test_cgi_core.rb8
3 files changed, 67 insertions, 2 deletions
diff --git a/lib/cgi/core.rb b/lib/cgi/core.rb
index e077c6d523..f1e8d3467a 100644
--- a/lib/cgi/core.rb
+++ b/lib/cgi/core.rb
@@ -771,6 +771,7 @@ class CGI
# "html4":: HTML 4.0
# "html4Tr":: HTML 4.0 Transitional
# "html4Fr":: HTML 4.0 with Framesets
+ # "html5":: HTML 5
#
# <tt>block</tt>::
# If provided, the block is called when an invalid encoding is
@@ -831,6 +832,11 @@ class CGI
extend Html4Fr
element_init()
extend HtmlExtension
+ when "html5"
+ require 'cgi/html'
+ extend Html5
+ element_init()
+ extend HtmlExtension
end
end
diff --git a/lib/cgi/html.rb b/lib/cgi/html.rb
index 1d7a815b95..3054279b54 100644
--- a/lib/cgi/html.rb
+++ b/lib/cgi/html.rb
@@ -922,7 +922,7 @@ class CGI
# O O or - O
for element in %w[ HTML BODY P DT DD LI OPTION THEAD TFOOT TBODY
- COLGROUP TR TH TD HEAD]
+ COLGROUP TR TH TD HEAD ]
methods << <<-BEGIN + nO_element_def(element) + <<-END
def #{element.downcase}(attributes = {})
BEGIN
@@ -1020,6 +1020,57 @@ class CGI
end
end # Html4Fr
-end
+ # Mixin module for HTML version 5 generation methods.
+ module Html5 # :nodoc:
+
+ # The DOCTYPE declaration for this version of HTML
+ def doctype
+ %|<!DOCTYPE HTML>|
+ end
+
+ # Initialise the HTML generation methods for this version.
+ def element_init
+ extend TagMaker
+ methods = ""
+ # - -
+ for element in %w[ SECTION NAV ARTICLE ASIDE HGROUP
+ 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
+ VAR CITE ABBR SUB SUP SPAN BDO ADDRESS DIV MAP OBJECT
+ H1 H2 H3 H4 H5 H6 PRE Q INS DEL DL OL UL LABEL SELECT
+ FIELDSET LEGEND BUTTON TABLE TITLE STYLE SCRIPT NOSCRIPT
+ TEXTAREA FORM A BLOCKQUOTE CAPTION ]
+ methods += <<-BEGIN + nn_element_def(element) + <<-END
+ def #{element.downcase}(attributes = {})
+ BEGIN
+ end
+ END
+ end
+
+ # - O EMPTY
+ for element in %w[ IMG BASE BR AREA LINK PARAM HR INPUT COL META
+ COMMAND EMBED KEYGEN SOURCE TRACK WBR ]
+ methods += <<-BEGIN + nOE_element_def(element) + <<-END
+ def #{element.downcase}(attributes = {})
+ BEGIN
+ end
+ END
+ end
+
+ # O O or - O
+ for element in %w[ HTML HEAD BODY P DT DD LI OPTION THEAD TFOOT TBODY
+ OPTGROUP COLGROUP RT RP TR TH TD ]
+ methods += <<-BEGIN + nO_element_def(element) + <<-END
+ def #{element.downcase}(attributes = {})
+ BEGIN
+ end
+ END
+ end
+ eval(methods)
+ end
+
+ end # Html5
+end
diff --git a/test/cgi/test_cgi_core.rb b/test/cgi/test_cgi_core.rb
index dab22d3114..171ff7b8bc 100644
--- a/test/cgi/test_cgi_core.rb
+++ b/test/cgi/test_cgi_core.rb
@@ -353,6 +353,14 @@ class CGICoreTest < Test::Unit::TestCase
cgi = CGI.new('html4Fr')
expected = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">'
assert_equal(expected, cgi.doctype)
+ ## html5
+ 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