html5_support_lib_cgi.patch

Marcus Stollsteimer, 06/24/2012 06:53 AM

Download (3.46 KB)

View differences:

lib/cgi/html.rb (Arbeitskopie)
920 920

  
921 921
      # O O or - O
922 922
      for element in %w[ HTML BODY P DT DD LI OPTION THEAD TFOOT TBODY
923
          COLGROUP TR TH TD HEAD]
923
          COLGROUP TR TH TD HEAD ]
924 924
        methods += <<-BEGIN + nO_element_def(element) + <<-END
925 925
          def #{element.downcase}(attributes = {})
926 926
        BEGIN
......
1016 1016
    end
1017 1017

  
1018 1018
  end # Html4Fr
1019
end
1020 1019

  
1021 1020

  
1021
  # Mixin module for HTML version 5 generation methods.
1022
  module Html5 # :nodoc:
1023

  
1024
    # The DOCTYPE declaration for this version of HTML
1025
    def doctype
1026
      %|<!DOCTYPE HTML>|
1027
    end
1028

  
1029
    # Initialise the HTML generation methods for this version.
1030
    def element_init
1031
      extend TagMaker
1032
      methods = ""
1033
      # - -
1034
      for element in %w[ SECTION NAV ARTICLE ASIDE HGROUP
1035
        FOOTER FIGURE FIGCAPTION S TIME U MARK RUBY BDI IFRAME
1036
        VIDEO AUDIO CANVAS DATALIST OUTPUT PROGRESS METER DETAILS
1037
        SUMMARY MENU DIALOG I B SMALL EM STRONG DFN CODE SAMP KBD
1038
        VAR CITE ABBR SUB SUP SPAN BDO ADDRESS DIV MAP OBJECT
1039
        H1 H2 H3 H4 H5 H6 PRE Q INS DEL DL OL UL LABEL SELECT
1040
        FIELDSET LEGEND BUTTON TABLE TITLE STYLE SCRIPT NOSCRIPT
1041
        TEXTAREA FORM A BLOCKQUOTE CAPTION ]
1042
        methods += <<-BEGIN + nn_element_def(element) + <<-END
1043
          def #{element.downcase}(attributes = {})
1044
        BEGIN
1045
          end
1046
        END
1047
      end
1048

  
1049
      # - O EMPTY
1050
      for element in %w[ IMG BASE BR AREA LINK PARAM HR INPUT COL META
1051
        COMMAND EMBED KEYGEN SOURCE TRACK WBR ]
1052
        methods += <<-BEGIN + nOE_element_def(element) + <<-END
1053
          def #{element.downcase}(attributes = {})
1054
        BEGIN
1055
          end
1056
        END
1057
      end
1058

  
1059
      # O O or - O
1060
      for element in %w[ HTML HEAD BODY P DT DD LI OPTION THEAD TFOOT TBODY
1061
          OPTGROUP COLGROUP RT RP TR TH TD ]
1062
        methods += <<-BEGIN + nO_element_def(element) + <<-END
1063
          def #{element.downcase}(attributes = {})
1064
        BEGIN
1065
          end
1066
        END
1067
      end
1068
      eval(methods)
1069
    end
1070

  
1071
  end # Html5
1072
end
lib/cgi/core.rb (Arbeitskopie)
770 770
  #     "html4":: HTML 4.0
771 771
  #     "html4Tr":: HTML 4.0 Transitional
772 772
  #     "html4Fr":: HTML 4.0 with Framesets
773
  #     "html5":: HTML 5
773 774
  #
774 775
  # <tt>block</tt>::
775 776
  #   If provided, the block is called when an invalid encoding is
......
830 831
      extend Html4Fr
831 832
      element_init()
832 833
      extend HtmlExtension
834
    when "html5"
835
      require 'cgi/html'
836
      extend Html5
837
      element_init()
838
      extend HtmlExtension
833 839
    end
834 840
  end
835 841

  
test/cgi/test_cgi_core.rb (Arbeitskopie)
353 353
    cgi = CGI.new('html4Fr')
354 354
    expected = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">'
355 355
    assert_equal(expected, cgi.doctype)
356
    ## html5
357
    cgi = CGI.new('html5')
358
    expected = '<!DOCTYPE HTML>'
359
    assert_equal(expected, cgi.doctype)
360
    # cgi.header not broken
361
    expected = "Content-Type: text/html\r\n\r\n"
362
    actual = cgi.header
363
    assert_equal(expected, actual)
356 364
  end
357 365

  
358 366