From 1cd324151df7ddf2697789c83a6156346b2be93c Mon Sep 17 00:00:00 2001 From: Takashi Kokubun Date: Sun, 11 Oct 2015 20:45:15 +0900 Subject: [PATCH] Json is inconvenient --- benchmark/compile.rake | 6 +- benchmark/profile.rake | 6 +- test/haml-spec/haml_spec_test.rb | 7 +- test/haml-spec/tests.json | 665 ------------------------------- test/haml-spec/tests.yml | 538 +++++++++++++++++++++++++ 5 files changed, 547 insertions(+), 675 deletions(-) delete mode 100644 test/haml-spec/tests.json create mode 100644 test/haml-spec/tests.yml diff --git a/benchmark/compile.rake b/benchmark/compile.rake index 54896fad..64192df7 100644 --- a/benchmark/compile.rake +++ b/benchmark/compile.rake @@ -2,7 +2,7 @@ $:.unshift File.expand_path('../lib', __FILE__) require 'hamlit' require 'faml' -require 'json' +require 'yaml' class Benchmark def self.bench @@ -52,8 +52,8 @@ namespace :benchmark do haml_benchmark = Benchmark.new('haml ') faml_benchmark = Benchmark.new('faml ') hamlit_benchmark = Benchmark.new('hamlit') - json_path = File.expand_path('../test/haml-spec/tests.json', __dir__) - contexts = JSON.parse(File.read(json_path)) + yaml_path = File.expand_path('../test/haml-spec/tests.yml', __dir__) + contexts = YAML.load(File.read(yaml_path)) faml_engine = Faml::Engine.new(filename: '') hamlit_engine = Hamlit::Engine.new diff --git a/benchmark/profile.rake b/benchmark/profile.rake index 6c43d30d..3177f912 100644 --- a/benchmark/profile.rake +++ b/benchmark/profile.rake @@ -1,12 +1,12 @@ $:.unshift File.expand_path('../lib', __FILE__) require 'hamlit' -require 'json' +require 'yaml' desc 'Profile compilation' task :profile do - json_path = File.expand_path('../test/haml-spec/tests.json', __dir__) - contexts = JSON.parse(File.read(json_path)) + yaml_path = File.expand_path('../test/haml-spec/tests.yml', __dir__) + contexts = YAML.load(File.read(yaml_path)) hamlit_engine = Hamlit::Engine.new diff --git a/test/haml-spec/haml_spec_test.rb b/test/haml-spec/haml_spec_test.rb index 94da2c0d..ec26312d 100644 --- a/test/haml-spec/haml_spec_test.rb +++ b/test/haml-spec/haml_spec_test.rb @@ -1,16 +1,15 @@ -require 'rubygems' require 'minitest/autorun' -require 'json' +require 'yaml' require 'haml' require 'hamlit' class HamlTest < MiniTest::Test - contexts = JSON.parse(File.read(File.dirname(__FILE__) + '/tests.json')) + contexts = YAML.load(File.read(File.expand_path('./tests.yml', __dir__))) contexts.each do |context| context[1].each do |name, test| [{ ugly: true }].each do |base_options| - define_method("test_#{base_options[:ugly] ? 'ugly' : 'pretty'}_spec: #{name} (#{context[0]})") do + define_method("test_#{ base_options[:ugly] ? 'ugly' : 'pretty' }_spec: #{name} (#{context[0]})") do haml = test['haml'] locals = Hash[(test['locals'] || {}).map {|x, y| [x.to_sym, y]}] options = Hash[(test['config'] || {}).map {|x, y| [x.to_sym, y]}] diff --git a/test/haml-spec/tests.json b/test/haml-spec/tests.json deleted file mode 100644 index 87847deb..00000000 --- a/test/haml-spec/tests.json +++ /dev/null @@ -1,665 +0,0 @@ -{ - "headers" : { - - "an XHTML XML prolog" : { - "haml" : "!!! XML", - "html" : "", - "config" : { - "format" : "xhtml" - } - }, - - "an XHTML default (transitional) doctype" : { - "haml" : "!!!", - "html" : "", - "config" : { - "format" : "xhtml" - } - }, - - "an XHTML 1.1 doctype" : { - "haml" : "!!! 1.1", - "html" : "", - "config" : { - "format" : "xhtml" - } - }, - - "an XHTML 1.2 mobile doctype" : { - "haml" : "!!! mobile", - "html" : "", - "config" : { - "format" : "xhtml" - } - }, - - "an XHTML 1.1 basic doctype" : { - "haml" : "!!! basic", - "html" : "", - "config" : { - "format" : "xhtml" - } - }, - - "an XHTML 1.0 frameset doctype" : { - "haml" : "!!! frameset", - "html" : "", - "config" : { - "format" : "xhtml" - } - }, - - "an HTML 5 doctype with XHTML syntax" : { - "haml" : "!!! 5", - "html" : "", - "config" : { - "format" : "xhtml" - } - }, - - "an HTML 5 XML prolog (silent)" : { - "haml" : "!!! XML", - "html" : "", - "config" : { - "format" : "html5" - } - }, - - "an HTML 5 doctype" : { - "haml" : "!!!", - "html" : "", - "config" : { - "format" : "html5" - } - }, - - "an HTML 4 XML prolog (silent)" : { - "haml" : "!!! XML", - "html" : "", - "config" : { - "format" : "html4" - } - }, - - "an HTML 4 default (transitional) doctype" : { - "haml" : "!!!", - "html" : "", - "config" : { - "format" : "html4" - } - }, - - "an HTML 4 frameset doctype" : { - "haml" : "!!! frameset", - "html" : "", - "config" : { - "format" : "html4" - } - }, - - "an HTML 4 strict doctype" : { - "haml" : "!!! strict", - "html" : "", - "config" : { - "format" : "html4" - } - } - - }, - - "basic Haml tags and CSS": { - - "a simple Haml tag" : { - "haml" : "%p", - "html" : "

" - }, - - "a self-closing tag (XHTML)" : { - "haml" : "%meta", - "html" : "", - "config" : { - "format" : "xhtml" - } - }, - - "a self-closing tag (HTML4)" : { - "haml" : "%meta", - "html" : "", - "config" : { - "format" : "html4" - } - }, - - "a self-closing tag (HTML5)" : { - "haml" : "%meta", - "html" : "", - "config" : { - "format" : "html5" - } - }, - - "a self-closing tag ('/' modifier + XHTML)" : { - "haml" : "%zzz/", - "html" : "", - "config" : { - "format" : "xhtml" - } - }, - - "a self-closing tag ('/' modifier + HTML5)" : { - "haml" : "%zzz/", - "html" : "", - "config" : { - "format" : "html5" - } - }, - - "a tag with a CSS class" : { - "haml" : "%p.class1", - "html" : "

" - }, - - "a tag with multiple CSS classes" : { - "haml" : "%p.class1.class2", - "html" : "

" - }, - - "a tag with a CSS id" : { - "haml" : "%p#id1", - "html" : "

" - }, - - "a tag with multiple CSS id's" : { - "haml" : "%p#id1#id2", - "html" : "

" - }, - - "a tag with a class followed by an id" : { - "haml" : "%p.class1#id1", - "html" : "

" - }, - - "a tag with an id followed by a class" : { - "haml" : "%p#id1.class1", - "html" : "

" - }, - - "an implicit div with a CSS id" : { - "haml" : "#id1", - "html" : "
" - }, - - "an implicit div with a CSS class" : { - "haml" : ".class1", - "html" : "
" - }, - - "multiple simple Haml tags" : { - "haml" : "%div\n %div\n %p", - "html" : "
\n
\n

\n
\n
" - } - }, - - "tags with unusual HTML characters" : { - - "a tag with colons" : { - "haml" : "%ns:tag", - "html" : "" - }, - - "a tag with underscores" : { - "haml" : "%snake_case", - "html" : "" - }, - - "a tag with dashes" : { - "haml" : "%dashed-tag", - "html" : "" - }, - - "a tag with camelCase" : { - "haml" : "%camelCase", - "html" : "" - }, - - "a tag with PascalCase" : { - "haml" : "%PascalCase", - "html" : "" - } - }, - - "tags with unusual CSS identifiers" : { - - "an all-numeric class" : { - "haml" : ".123", - "html" : "
" - }, - - "a class with underscores" : { - "haml" : ".__", - "html" : "
" - }, - - "a class with dashes" : { - "haml" : ".--", - "html" : "
" - } - }, - - "tags with inline content" : { - - "Inline content simple tag" : { - "haml" : "%p hello", - "html" : "

hello

" - }, - - "Inline content tag with CSS" : { - "haml" : "%p.class1 hello", - "html" : "

hello

" - }, - - "Inline content multiple simple tags" : { - "haml" : "%div\n %div\n %p text", - "html" : "
\n
\n

text

\n
\n
" - } - }, - - "tags with nested content" : { - - "Nested content simple tag" : { - "haml" : "%p\n hello", - "html" : "

\n hello\n

" - }, - - "Nested content tag with CSS" : { - "haml" : "%p.class1\n hello", - "html" : "

\n hello\n

" - }, - - "Nested content multiple simple tags" : { - "haml" : "%div\n %div\n %p\n text", - "html" : "
\n
\n

\n text\n

\n
\n
" - } - }, - - "tags with HTML-style attributes": { - - "HTML-style one attribute" : { - "haml" : "%p(a='b')", - "html" : "

" - }, - - "HTML-style multiple attributes" : { - "haml" : "%p(a='b' c='d')", - "html" : "

" - }, - - "HTML-style attributes separated with newlines" : { - "haml" : "%p(a='b'\n c='d')", - "html" : "

" - }, - - "HTML-style interpolated attribute" : { - "haml" : "%p(a=\"#{var}\")", - "html" : "

", - "locals" : { - "var" : "value" - } - }, - - "HTML-style 'class' as an attribute" : { - "haml" : "%p(class='class1')", - "html" : "

" - }, - - "HTML-style tag with a CSS class and 'class' as an attribute" : { - "haml" : "%p.class2(class='class1')", - "html" : "

" - }, - - "HTML-style tag with 'id' as an attribute" : { - "haml" : "%p(id='1')", - "html" : "

" - }, - - "HTML-style tag with a CSS id and 'id' as an attribute" : { - "haml" : "%p#id(id='1')", - "html" : "

" - }, - - "HTML-style tag with a variable attribute" : { - "haml" : "%p(class=var)", - "html" : "

", - "locals" : { - "var" : "hello" - } - }, - - "HTML-style tag with a CSS class and 'class' as a variable attribute" : { - "haml" : ".hello(class=var)", - "html" : "
", - "locals" : { - "var" : "world" - } - }, - - "HTML-style tag multiple CSS classes (sorted correctly)" : { - "haml" : ".z(class=var)", - "html" : "
", - "locals" : { - "var" : "a" - } - }, - - "HTML-style tag with an atomic attribute" : { - "haml" : "%a(flag)", - "html" : "" - } - }, - - "tags with Ruby-style attributes": { - - "Ruby-style one attribute" : { - "haml" : "%p{:a => 'b'}", - "html" : "

", - "optional" : true - }, - - "Ruby-style attributes hash with whitespace" : { - "haml" : "%p{ :a => 'b' }", - "html" : "

", - "optional" : true - }, - - "Ruby-style interpolated attribute" : { - "haml" : "%p{:a =>\"#{var}\"}", - "html" : "

", - "optional" : true, - "locals" : { - "var" : "value" - } - }, - - "Ruby-style multiple attributes" : { - "haml" : "%p{ :a => 'b', 'c' => 'd' }", - "html" : "

", - "optional" : true - }, - - "Ruby-style attributes separated with newlines" : { - "haml" : "%p{ :a => 'b',\n 'c' => 'd' }", - "html" : "

", - "optional" : true - }, - - "Ruby-style 'class' as an attribute" : { - "haml" : "%p{:class => 'class1'}", - "html" : "

", - "optional" : true - }, - - "Ruby-style tag with a CSS class and 'class' as an attribute" : { - "haml" : "%p.class2{:class => 'class1'}", - "html" : "

", - "optional" : true - }, - - "Ruby-style tag with 'id' as an attribute" : { - "haml" : "%p{:id => '1'}", - "html" : "

", - "optional" : true - }, - - "Ruby-style tag with a CSS id and 'id' as an attribute" : { - "haml" : "%p#id{:id => '1'}", - "html" : "

", - "optional" : true - }, - - "Ruby-style tag with a CSS id and a numeric 'id' as an attribute" : { - "haml" : "%p#id{:id => 1}", - "html" : "

", - "optional" : true - }, - - "Ruby-style tag with a variable attribute" : { - "haml" : "%p{:class => var}", - "html" : "

", - "optional" : true, - "locals" : { - "var" : "hello" - } - }, - - "Ruby-style tag with a CSS class and 'class' as a variable attribute" : { - "haml" : ".hello{:class => var}", - "html" : "
", - "optional" : true, - "locals" : { - "var" : "world" - } - }, - - "Ruby-style tag multiple CSS classes (sorted correctly)" : { - "haml" : ".z{:class => var}", - "html" : "
", - "optional" : true, - "locals" : { - "var" : "a" - } - } - }, - - "silent comments" : { - - "an inline silent comment" : { - "haml" : "-# hello", - "html" : "" - }, - - "a nested silent comment" : { - "haml" : "-#\n hello", - "html" : "" - }, - - "a multiply nested silent comment" : { - "haml" : "-#\n %div\n foo", - "html" : "" - }, - - "a multiply nested silent comment with inconsistent indents" : { - "haml" : "-#\n %div\n foo", - "html" : "" - } - }, - - "markup comments" : { - - "an inline markup comment" : { - "haml" : "/ comment", - "html" : "" - }, - - "a nested markup comment" : { - "haml" : "/\n comment\n comment2", - "html" : "" - } - }, - - "conditional comments": { - "a conditional comment" : { - "haml" : "/[if IE]\n %p a", - "html" : "" - } - }, - - "internal filters": { - - "content in an 'escaped' filter" : { - "haml" : ":escaped\n <&\">", - "html" : "<&">" - }, - - "content in a 'preserve' filter" : { - "haml" : ":preserve\n hello\n\n%p", - "html" : "hello \n

" - }, - - "content in a 'plain' filter" : { - "haml" : ":plain\n hello\n\n%p", - "html" : "hello\n

" - }, - - "content in a 'css' filter (XHTML)" : { - "haml" : ":css\n hello\n\n%p", - "html" : "\n

", - "config" : { - "format" : "xhtml" - } - }, - - "content in a 'javascript' filter (XHTML)" : { - "haml" : ":javascript\n a();\n%p", - "html" : "\n

", - "config" : { - "format" : "xhtml" - } - }, - - "content in a 'css' filter (HTML)" : { - "haml" : ":css\n hello\n\n%p", - "html" : "\n

", - "config" : { - "format" : "html5" - } - }, - - "content in a 'javascript' filter (HTML)" : { - "haml" : ":javascript\n a();\n%p", - "html" : "\n

", - "config" : { - "format" : "html5" - } - } - }, - - "Ruby-style interpolation": { - - "interpolation inside inline content" : { - "haml" : "%p #{var}", - "html" : "

value

", - "optional" : true, - "locals" : { - "var" : "value" - } - }, - - "no interpolation when escaped" : { - "haml" : "%p \\#{var}", - "html" : "

#{var}

", - "optional" : true, - "locals" : { - "var" : "value" - } - }, - - "interpolation when the escape character is escaped" : { - "haml" : "%p \\\\#{var}", - "html" : "

\\value

", - "optional" : true, - "locals" : { - "var" : "value" - } - }, - - "interpolation inside filtered content" : { - "haml" : ":plain\n #{var} interpolated: #{var}", - "html" : "value interpolated: value", - "optional" : true, - "locals" : { - "var" : "value" - } - } - }, - - "HTML escaping" : { - - "code following '&='" : { - "haml" : "&= '<\"&>'", - "html" : "<"&>" - }, - - "code following '=' when escape_haml is set to true" : { - "haml" : "= '<\"&>'", - "html" : "<"&>", - "config" : { - "escape_html" : "true" - } - }, - - "code following '!=' when escape_haml is set to true" : { - "haml" : "!= '<\"&>'", - "html" : "<\"&>", - "config" : { - "escape_html" : "true" - } - } - - }, - - "boolean attributes" : { - - "boolean attribute with XHTML" : { - "haml" : "%input(checked=true)", - "html" : "", - "config" : { - "format" : "xhtml" - } - }, - - "boolean attribute with HTML" : { - "haml" : "%input(checked=true)", - "html" : "", - "config" : { - "format" : "html5" - } - } - }, - - "whitespace preservation" : { - - "following the '~' operator" : { - "haml" : "~ \"Foo\\n
Bar\\nBaz
\"", - "html" : "Foo\n
Bar
Baz
", - "optional" : true - }, - - "inside a textarea tag" : { - "haml" : "%textarea\n hello\n hello", - "html" : "" - }, - - "inside a pre tag" : { - "haml" : "%pre\n hello\n hello", - "html" : "
hello\nhello
" - } - }, - - "whitespace removal" : { - - "a tag with '>' appended and inline content" : { - "haml" : "%li hello\n%li> world\n%li again", - "html" : "
  • hello
  • world
  • again
  • " - }, - - "a tag with '>' appended and nested content" : { - "haml" : "%li hello\n%li>\n world\n%li again", - "html" : "
  • hello
  • \n world\n
  • again
  • " - }, - - "a tag with '<' appended" : { - "haml" : "%p<\n hello\n world", - "html" : "

    hello\nworld

    " - } - } -} diff --git a/test/haml-spec/tests.yml b/test/haml-spec/tests.yml new file mode 100644 index 00000000..4589fe91 --- /dev/null +++ b/test/haml-spec/tests.yml @@ -0,0 +1,538 @@ +--- +headers: + an XHTML XML prolog: + haml: "!!! XML" + html: "" + config: + format: xhtml + an XHTML default (transitional) doctype: + haml: "!!!" + html: + config: + format: xhtml + an XHTML 1.1 doctype: + haml: "!!! 1.1" + html: + config: + format: xhtml + an XHTML 1.2 mobile doctype: + haml: "!!! mobile" + html: + config: + format: xhtml + an XHTML 1.1 basic doctype: + haml: "!!! basic" + html: + config: + format: xhtml + an XHTML 1.0 frameset doctype: + haml: "!!! frameset" + html: + config: + format: xhtml + an HTML 5 doctype with XHTML syntax: + haml: "!!! 5" + html: "" + config: + format: xhtml + an HTML 5 XML prolog (silent): + haml: "!!! XML" + html: '' + config: + format: html5 + an HTML 5 doctype: + haml: "!!!" + html: "" + config: + format: html5 + an HTML 4 XML prolog (silent): + haml: "!!! XML" + html: '' + config: + format: html4 + an HTML 4 default (transitional) doctype: + haml: "!!!" + html: + config: + format: html4 + an HTML 4 frameset doctype: + haml: "!!! frameset" + html: + config: + format: html4 + an HTML 4 strict doctype: + haml: "!!! strict" + html: + config: + format: html4 +basic Haml tags and CSS: + a simple Haml tag: + haml: "%p" + html: "

    " + a self-closing tag (XHTML): + haml: "%meta" + html: "" + config: + format: xhtml + a self-closing tag (HTML4): + haml: "%meta" + html: "" + config: + format: html4 + a self-closing tag (HTML5): + haml: "%meta" + html: "" + config: + format: html5 + a self-closing tag ('/' modifier + XHTML): + haml: "%zzz/" + html: "" + config: + format: xhtml + a self-closing tag ('/' modifier + HTML5): + haml: "%zzz/" + html: "" + config: + format: html5 + a tag with a CSS class: + haml: "%p.class1" + html: "

    " + a tag with multiple CSS classes: + haml: "%p.class1.class2" + html: "

    " + a tag with a CSS id: + haml: "%p#id1" + html: "

    " + a tag with multiple CSS id's: + haml: "%p#id1#id2" + html: "

    " + a tag with a class followed by an id: + haml: "%p.class1#id1" + html: "

    " + a tag with an id followed by a class: + haml: "%p#id1.class1" + html: "

    " + an implicit div with a CSS id: + haml: "#id1" + html: "
    " + an implicit div with a CSS class: + haml: ".class1" + html: "
    " + multiple simple Haml tags: + haml: |- + %div + %div + %p + html: |- +
    +
    +

    +
    +
    +tags with unusual HTML characters: + a tag with colons: + haml: "%ns:tag" + html: "" + a tag with underscores: + haml: "%snake_case" + html: "" + a tag with dashes: + haml: "%dashed-tag" + html: "" + a tag with camelCase: + haml: "%camelCase" + html: "" + a tag with PascalCase: + haml: "%PascalCase" + html: "" +tags with unusual CSS identifiers: + an all-numeric class: + haml: ".123" + html: "
    " + a class with underscores: + haml: ".__" + html: "
    " + a class with dashes: + haml: ".--" + html: "
    " +tags with inline content: + Inline content simple tag: + haml: "%p hello" + html: "

    hello

    " + Inline content tag with CSS: + haml: "%p.class1 hello" + html: "

    hello

    " + Inline content multiple simple tags: + haml: |- + %div + %div + %p text + html: |- +
    +
    +

    text

    +
    +
    +tags with nested content: + Nested content simple tag: + haml: |- + %p + hello + html: |- +

    + hello +

    + Nested content tag with CSS: + haml: |- + %p.class1 + hello + html: |- +

    + hello +

    + Nested content multiple simple tags: + haml: |- + %div + %div + %p + text + html: |- +
    +
    +

    + text +

    +
    +
    +tags with HTML-style attributes: + HTML-style one attribute: + haml: "%p(a='b')" + html: "

    " + HTML-style multiple attributes: + haml: "%p(a='b' c='d')" + html: "

    " + HTML-style attributes separated with newlines: + haml: |- + %p(a='b' + c='d') + html: "

    " + HTML-style interpolated attribute: + haml: '%p(a="#{var}")' + html: "

    " + locals: + var: value + HTML-style 'class' as an attribute: + haml: "%p(class='class1')" + html: "

    " + HTML-style tag with a CSS class and 'class' as an attribute: + haml: "%p.class2(class='class1')" + html: "

    " + HTML-style tag with 'id' as an attribute: + haml: "%p(id='1')" + html: "

    " + HTML-style tag with a CSS id and 'id' as an attribute: + haml: "%p#id(id='1')" + html: "

    " + HTML-style tag with a variable attribute: + haml: "%p(class=var)" + html: "

    " + locals: + var: hello + HTML-style tag with a CSS class and 'class' as a variable attribute: + haml: ".hello(class=var)" + html: "
    " + locals: + var: world + HTML-style tag multiple CSS classes (sorted correctly): + haml: ".z(class=var)" + html: "
    " + locals: + var: a + HTML-style tag with an atomic attribute: + haml: "%a(flag)" + html: "" +tags with Ruby-style attributes: + Ruby-style one attribute: + haml: "%p{:a => 'b'}" + html: "

    " + optional: true + Ruby-style attributes hash with whitespace: + haml: "%p{ :a => 'b' }" + html: "

    " + optional: true + Ruby-style interpolated attribute: + haml: '%p{:a =>"#{var}"}' + html: "

    " + optional: true + locals: + var: value + Ruby-style multiple attributes: + haml: "%p{ :a => 'b', 'c' => 'd' }" + html: "

    " + optional: true + Ruby-style attributes separated with newlines: + haml: |- + %p{ :a => 'b', + 'c' => 'd' } + html: "

    " + optional: true + Ruby-style 'class' as an attribute: + haml: "%p{:class => 'class1'}" + html: "

    " + optional: true + Ruby-style tag with a CSS class and 'class' as an attribute: + haml: "%p.class2{:class => 'class1'}" + html: "

    " + optional: true + Ruby-style tag with 'id' as an attribute: + haml: "%p{:id => '1'}" + html: "

    " + optional: true + Ruby-style tag with a CSS id and 'id' as an attribute: + haml: "%p#id{:id => '1'}" + html: "

    " + optional: true + Ruby-style tag with a CSS id and a numeric 'id' as an attribute: + haml: "%p#id{:id => 1}" + html: "

    " + optional: true + Ruby-style tag with a variable attribute: + haml: "%p{:class => var}" + html: "

    " + optional: true + locals: + var: hello + Ruby-style tag with a CSS class and 'class' as a variable attribute: + haml: ".hello{:class => var}" + html: "
    " + optional: true + locals: + var: world + Ruby-style tag multiple CSS classes (sorted correctly): + haml: ".z{:class => var}" + html: "
    " + optional: true + locals: + var: a +silent comments: + an inline silent comment: + haml: "-# hello" + html: '' + a nested silent comment: + haml: |- + -# + hello + html: '' + a multiply nested silent comment: + haml: |- + -# + %div + foo + html: '' + a multiply nested silent comment with inconsistent indents: + haml: |- + -# + %div + foo + html: '' +markup comments: + an inline markup comment: + haml: "/ comment" + html: "" + a nested markup comment: + haml: |- + / + comment + comment2 + html: |- + +conditional comments: + a conditional comment: + haml: |- + /[if IE] + %p a + html: |- + +internal filters: + content in an 'escaped' filter: + haml: |- + :escaped + <&"> + html: "<&">" + content in a 'preserve' filter: + haml: |- + :preserve + hello + + %p + html: |- + hello +

    + content in a 'plain' filter: + haml: |- + :plain + hello + + %p + html: |- + hello +

    + content in a 'css' filter (XHTML): + haml: |- + :css + hello + + %p + html: |- + +

    + config: + format: xhtml + content in a 'javascript' filter (XHTML): + haml: |- + :javascript + a(); + %p + html: |- + +

    + config: + format: xhtml + content in a 'css' filter (HTML): + haml: |- + :css + hello + + %p + html: |- + +

    + config: + format: html5 + content in a 'javascript' filter (HTML): + haml: |- + :javascript + a(); + %p + html: |- + +

    + config: + format: html5 +Ruby-style interpolation: + interpolation inside inline content: + haml: "%p #{var}" + html: "

    value

    " + optional: true + locals: + var: value + no interpolation when escaped: + haml: "%p \\#{var}" + html: "

    #{var}

    " + optional: true + locals: + var: value + interpolation when the escape character is escaped: + haml: "%p \\\\#{var}" + html: "

    \\value

    " + optional: true + locals: + var: value + interpolation inside filtered content: + haml: |- + :plain + #{var} interpolated: #{var} + html: 'value interpolated: value' + optional: true + locals: + var: value +HTML escaping: + code following '&=': + haml: '&= ''<"&>''' + html: "<"&>" + code following '=' when escape_haml is set to true: + haml: = '<"&>' + html: "<"&>" + config: + escape_html: 'true' + code following '!=' when escape_haml is set to true: + haml: '!= ''<"&>''' + html: <"&> + config: + escape_html: 'true' +boolean attributes: + boolean attribute with XHTML: + haml: "%input(checked=true)" + html: "" + config: + format: xhtml + boolean attribute with HTML: + haml: "%input(checked=true)" + html: "" + config: + format: html5 +whitespace preservation: + following the '~' operator: + haml: ~ "Foo\n
    Bar\nBaz
    " + html: |- + Foo +
    Bar
    Baz
    + optional: true + inside a textarea tag: + haml: |- + %textarea + hello + hello + html: |- + + inside a pre tag: + haml: |- + %pre + hello + hello + html: |- +
    hello
    +      hello
    +whitespace removal: + a tag with '>' appended and inline content: + haml: |- + %li hello + %li> world + %li again + html: "
  • hello
  • world
  • again
  • " + a tag with '>' appended and nested content: + haml: |- + %li hello + %li> + world + %li again + html: |- +
  • hello
  • + world +
  • again
  • + a tag with '<' appended: + haml: |- + %p< + hello + world + html: |- +

    hello + world