diff --git a/CHANGELOG.md b/CHANGELOG.md index 720fc62e..733bcafa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ ## 3.2.0 (Unreleased) +* HTML5 is now the default output format rather than XHTML. This was already + the default on Rails 3+, so many users will notice no difference. + * The :javascript and :css filters no longer add CDATA tags when the format is html4 or html5. This can be overridden by setting the `cdata` option to `true`. CDATA tags are always added when the format is xhtml. diff --git a/REFERENCE.md b/REFERENCE.md index b45c3756..8cd23d2e 100644 --- a/REFERENCE.md +++ b/REFERENCE.md @@ -1,7 +1,7 @@ # Haml (XHTML Abstraction Markup Language) -Haml is a markup language that's used to cleanly and simply describe the XHTML -of any web document, without the use of inline code. Haml functions as a +Haml is a markup language that's used to cleanly and simply describe the HTML of +any web document, without the use of inline code. Haml functions as a replacement for inline page templating systems such as PHP, ERB, and ASP. However, Haml avoids the need for explicitly coding HTML into the template, because it is actually an abstract description of the HTML, with some code to @@ -651,8 +651,8 @@ is compiled to: You can also specify the specific doctype after the `!!!` When the -[`:format`](#format-option) is set to `:xhtml` (the default except in Rails 3), -the following doctypes are supported: +[`:format`](#format-option) is set to `:xhtml`. The following doctypes are +supported: `!!!` : XHTML 1.0 Transitional
@@ -1232,7 +1232,7 @@ For example, tags like `pre` and `textarea` are whitespace-sensitive; indenting the text makes them render wrong. Haml deals with this by "preserving" newlines before they're put into the document -- -converting them to the XHTML whitespace escape code, ` `. +converting them to the HTML whitespace escape code, ` `. Then Haml won't try to re-format the indentation. Literal `textarea` and `pre` tags automatically preserve content given through `=`. diff --git a/lib/haml/exec.rb b/lib/haml/exec.rb index 3d5de734..3c8edd39 100644 --- a/lib/haml/exec.rb +++ b/lib/haml/exec.rb @@ -218,7 +218,7 @@ END end opts.on('-f', '--format NAME', - 'Output format. Can be xhtml (default), html4, or html5.') do |name| + 'Output format. Can be html5 (default), xhtml, or html4.') do |name| @options[:for_engine][:format] = name.to_sym end diff --git a/lib/haml/options.rb b/lib/haml/options.rb index 88ca9dcf..b653bf64 100644 --- a/lib/haml/options.rb +++ b/lib/haml/options.rb @@ -11,7 +11,7 @@ module Haml :escape_attrs => true, :escape_html => false, :filename => '(haml)', - :format => :xhtml, + :format => :html5, :hyphenate_data_attrs => true, :line => 1, :mime_type => 'text/html', @@ -22,7 +22,7 @@ module Haml :cdata => false } - @valid_formats = [:xhtml, :html4, :html5] + @valid_formats = [:html4, :html5, :xhtml] @buffer_option_keys = [:autoclose, :preserve, :attr_wrapper, :ugly, :format, :encoding, :escape_html, :escape_attrs, :hyphenate_data_attrs, :cdata] @@ -102,11 +102,13 @@ module Haml # inline templates, similar to the last argument to `Kernel#eval`. attr_accessor :line - # Determines the output format. Normally the default is `:xhtml`, although - # under Rails 3 it's `:html5`, since that's the Rails 3's default format. - # Other options are `:html4` and `:html5`, which are identical to `:xhtml` - # except there are no self-closing tags, the XML prolog is ignored and - # correct DOCTYPEs are generated. + # Determines the output format. The default is `:html5`. The other options + # are `:html4` and `:xhtml`. If the output is set to XHTML, then Haml + # automatically generates self-closing tags and wraps the output of the + # Javascript and CSS-like filters inside CDATA. When the output is set to + # :html5 or :html4, XML prologs are ignored. In all cases, an appropriate + # doctype is generated from '!!!'. + # # # If the mime_type of the template being rendered is `text/xml` then a # format of `:xhtml` will be used even if the global output format is set to @@ -223,7 +225,7 @@ module Haml end @format = value end - + undef :cdata def cdata xhtml? || @cdata diff --git a/lib/haml/template.rb b/lib/haml/template.rb index c7f18fdc..2a758455 100644 --- a/lib/haml/template.rb +++ b/lib/haml/template.rb @@ -27,6 +27,5 @@ end Haml::Template.options[:ugly] = !Rails.env.development? Haml::Template.options[:escape_html] = true -Haml::Template.options[:format] = :html5 -require 'haml/template/plugin' \ No newline at end of file +require 'haml/template/plugin' diff --git a/test/engine_test.rb b/test/engine_test.rb index b21b7daf..7a3d7fa6 100644 --- a/test/engine_test.rb +++ b/test/engine_test.rb @@ -173,11 +173,11 @@ class EngineTest < MiniTest::Unit::TestCase end def test_colon_in_class_attr - assert_equal("

\n", render("%p.foo:bar/")) + assert_equal("

\n", render("%p.foo:bar/")) end def test_colon_in_id_attr - assert_equal("

\n", render("%p#foo:bar/")) + assert_equal("

\n", render("%p#foo:bar/")) end def test_dynamic_attributes_with_no_content @@ -258,17 +258,17 @@ HAML end def test_static_attributes_with_empty_attr - assert_equal("\n", render("%img{:src => '/foo.png', :alt => ''}")) + assert_equal("\n", render("%img{:src => '/foo.png', :alt => ''}")) end def test_dynamic_attributes_with_empty_attr - assert_equal("\n", render("%img{:width => nil, :src => '/foo.png', :alt => String.new}")) + assert_equal("\n", render("%img{:width => nil, :src => '/foo.png', :alt => String.new}")) end def test_attribute_hash_with_newlines assert_equal("

foop

\n", render("%p{:a => 'b',\n :c => 'd'} foop")) assert_equal("

\n foop\n

\n", render("%p{:a => 'b',\n :c => 'd'}\n foop")) - assert_equal("

\n", render("%p{:a => 'b',\n :c => 'd'}/")) + assert_equal("

\n", render("%p{:a => 'b',\n :c => 'd'}/")) assert_equal("

\n", render("%p{:a => 'b',\n :c => 'd',\n :e => 'f'}")) end @@ -290,7 +290,7 @@ HAML assert_equal(< true))

foo

-

+

foo

foo bar

@@ -408,7 +408,7 @@ HAML assert_equal(< - + foo bar @@ -909,7 +909,7 @@ HAML end def test_static_attributes_should_be_escaped - assert_equal("\n", + assert_equal("\n", render("%img.atlantis{:style => 'ugly&stupid'}")) assert_equal("
foo
\n", render(".atlantis{:style => 'ugly&stupid'} foo")) @@ -920,13 +920,13 @@ HAML end def test_dynamic_attributes_should_be_escaped - assert_equal("\n", + assert_equal("\n", render("%img{:width => nil, :src => '&foo.png', :alt => String.new}")) assert_equal("

foo

\n", render("%p{:width => nil, :src => '&foo.png', :alt => String.new} foo")) assert_equal("
foo
\n", render("%div{:width => nil, :src => '&foo.png', :alt => String.new}= 'foo'")) - assert_equal("\n", + assert_equal("\n", render("%img{:width => nil, :src => \"foo\\n.png\", :alt => String.new}")) end @@ -1027,9 +1027,9 @@ HAML def test_stop_eval assert_equal("", render("= 'Hello'", :suppress_eval => true)) assert_equal("", render("- haml_concat 'foo'", :suppress_eval => true)) - assert_equal("
\n", render("#foo{:yes => 'no'}/", :suppress_eval => true)) - assert_equal("
\n", render("#foo{:yes => 'no', :call => a_function() }/", :suppress_eval => true)) - assert_equal("
\n", render("%div[1]/", :suppress_eval => true)) + assert_equal("
\n", render("#foo{:yes => 'no'}/", :suppress_eval => true)) + assert_equal("
\n", render("#foo{:yes => 'no', :call => a_function() }/", :suppress_eval => true)) + assert_equal("
\n", render("%div[1]/", :suppress_eval => true)) assert_equal("", render(":ruby\n Kernel.puts 'hello'", :suppress_eval => true)) end @@ -1038,17 +1038,17 @@ HAML render('!!!', :format => :html5).strip) assert_equal('', render('!!! 5').strip) assert_equal('', - render('!!! strict').strip) + render('!!! strict', :format => :xhtml).strip) assert_equal('', - render('!!! frameset').strip) + render('!!! frameset', :format => :xhtml).strip) assert_equal('', - render('!!! mobile').strip) + render('!!! mobile', :format => :xhtml).strip) assert_equal('', - render('!!! basic').strip) + render('!!! basic', :format => :xhtml).strip) assert_equal('', - render('!!! transitional').strip) + render('!!! transitional', :format => :xhtml).strip) assert_equal('', - render('!!!').strip) + render('!!!', :format => :xhtml).strip) assert_equal('', render('!!! strict', :format => :html4).strip) assert_equal('', @@ -1064,14 +1064,14 @@ HAML assert_equal("

\n", render("%p{ :escaped => 'quo\"te'}", :attr_wrapper => '"')) assert_equal("

\n", render("%p{ :escaped => 'quo\\'te'}", :attr_wrapper => '"')) assert_equal("

\n", render("%p{ :escaped => 'q\\'uo\"te'}", :attr_wrapper => '"')) - assert_equal("\n", render("!!! XML", :attr_wrapper => '"')) + assert_equal("\n", render("!!! XML", :attr_wrapper => '"', :format => :xhtml)) end def test_autoclose_option - assert_equal("\n", render("%flaz{:foo => 'bar'}", :autoclose => ["flaz"])) + assert_equal("\n", render("%flaz{:foo => 'bar'}", :autoclose => ["flaz"])) assert_equal(< [/^flaz/])) - - + + HTML %flaz @@ -1140,7 +1140,7 @@ HAML end def test_dynamic_attrs_with_self_closed_tag - assert_equal("\nc\n", render("%a{'b' => 1 + 1}/\n= 'c'\n")) + assert_equal("\nc\n", render("%a{'b' => 1 + 1}/\n= 'c'\n")) end EXCEPTION_MAP.each do |key, value| @@ -1236,8 +1236,8 @@ HAML end def test_non_literal_attributes - assert_equal("

\n", - render("%p{a2, a1, :a3 => 'baz'}/", + assert_equal("

\n", + render("%p{a2, a1, :a3 => 'baz'}", :locals => {:a1 => {:a1 => 'foo'}, :a2 => {:a2 => 'bar'}})) end @@ -1553,9 +1553,9 @@ HAML end def test_truthy_new_attributes - assert_equal("
bar\n", render("%a(href) bar")) + assert_equal("bar\n", render("%a(href) bar", :format => :xhtml)) assert_equal("bar\n", render("%a(href bar='baz') bar", :format => :html5)) - assert_equal("bar\n", render("%a(href=true) bar")) + assert_equal("bar\n", render("%a(href=true) bar")) assert_equal("bar\n", render("%a(href=false) bar")) end diff --git a/test/filters_test.rb b/test/filters_test.rb index e981fb2b..a50319bb 100644 --- a/test/filters_test.rb +++ b/test/filters_test.rb @@ -140,7 +140,7 @@ class JavascriptFilterTest < MiniTest::Unit::TestCase end test "should never HTML-escape ampersands" do - html = "\n" + html = "\n" haml = %Q{:javascript\n & < > \#{"&"}} assert_equal(html, render(haml, :escape_html => true)) end @@ -178,10 +178,10 @@ class JavascriptFilterTest < MiniTest::Unit::TestCase end class CSSFilterTest < MiniTest::Unit::TestCase - test "should wrap output in CDATA and a CSS tag" do + test "should wrap output in CDATA and a CSS tag when output is XHTML" do html = "\n" haml = ":css\n foo" - assert_equal(html, render(haml)) + assert_equal(html, render(haml, :format => :xhtml)) end test "should not include type in HTML 5 output" do diff --git a/test/haml-spec b/test/haml-spec index 15288201..519e0703 160000 --- a/test/haml-spec +++ b/test/haml-spec @@ -1 +1 @@ -Subproject commit 15288201caf6bbf982953acdba8da7380d0fcad0 +Subproject commit 519e0703fc8306d81ffbae58fdd81e748b7bce5a diff --git a/test/helper_test.rb b/test/helper_test.rb index 8e01e4fc..7cf36c6c 100644 --- a/test/helper_test.rb +++ b/test/helper_test.rb @@ -275,7 +275,7 @@ HAML end def test_haml_tag_with_data_hash - assert_equal("

foo

\n", + assert_equal("

foo

\n", render("- haml_tag :p, 'foo', :data => {:foo => 'bar', :baz => true}")) end diff --git a/test/template_test.rb b/test/template_test.rb index 30ac48a3..0f11948f 100644 --- a/test/template_test.rb +++ b/test/template_test.rb @@ -70,6 +70,7 @@ class TemplateTest < MiniTest::Unit::TestCase def render(text, opts = {}) return @base.render(:inline => text, :type => :haml) if opts == :action_view + opts = opts.merge(:format => :xhtml) Haml::Engine.new(text, opts).to_html(@base) end @@ -117,14 +118,14 @@ class TemplateTest < MiniTest::Unit::TestCase def test_templates_should_render_correctly_with_render_proc assert_renders_correctly("standard") do |name| - engine = Haml::Engine.new(File.read(File.dirname(__FILE__) + "/templates/#{name}.haml")) + engine = Haml::Engine.new(File.read(File.dirname(__FILE__) + "/templates/#{name}.haml"), :format => :xhtml) engine.render_proc(@base).call end end def test_templates_should_render_correctly_with_def_method assert_renders_correctly("standard") do |name| - engine = Haml::Engine.new(File.read(File.dirname(__FILE__) + "/templates/#{name}.haml")) + engine = Haml::Engine.new(File.read(File.dirname(__FILE__) + "/templates/#{name}.haml"), :format => :xhtml) engine.def_method(@base, "render_standard") @base.render_standard end