1
0
Fork 0
mirror of https://github.com/haml/haml.git synced 2022-11-09 12:33:31 -05:00
haml--haml/spec/hamlit/ugly_spec.rb

913 lines
23 KiB
Ruby
Raw Normal View History

2015-03-27 03:40:15 -04:00
require "haml"
2015-03-29 09:27:11 -04:00
# This is a spec converted by haml-spec.
2015-03-29 09:08:23 -04:00
# See: https://github.com/haml/haml-spec
describe "haml ugly mode" do
2015-03-27 03:40:15 -04:00
def assert_pretty(haml, locals, options)
engine = Haml::Engine.new(haml, options)
hamlit = Hamlit::Template.new(options) { haml }
2015-03-27 08:21:32 -04:00
expect(hamlit.render(Object.new, locals)).to eq(engine.render(Object.new, locals))
2015-03-27 03:40:15 -04:00
end
def assert_ugly(haml, locals, options)
2015-03-27 04:13:08 -04:00
assert_pretty(haml, locals, { ugly: true }.merge(options))
2015-03-27 00:14:20 -04:00
end
2015-03-22 11:42:05 -04:00
context "headers" do
specify "an XHTML XML prolog" do
2015-03-27 00:14:20 -04:00
haml = %q{!!! XML}
2015-03-27 21:53:56 -04:00
html = %q{<?xml version='1.0' encoding='utf-8' ?>}
2015-03-27 00:14:20 -04:00
locals = {}
options = {:format=>:xhtml}
2015-03-27 03:40:15 -04:00
assert_ugly(haml, locals, options)
2015-03-22 11:42:05 -04:00
end
specify "an XHTML default (transitional) doctype" do
2015-03-27 00:14:20 -04:00
haml = %q{!!!}
2015-03-27 21:53:56 -04:00
html = %q{<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">}
2015-03-27 00:14:20 -04:00
locals = {}
options = {:format=>:xhtml}
2015-03-27 03:40:15 -04:00
assert_ugly(haml, locals, options)
2015-03-22 11:42:05 -04:00
end
specify "an XHTML 1.1 doctype" do
2015-03-27 00:14:20 -04:00
haml = %q{!!! 1.1}
2015-03-27 21:53:56 -04:00
html = %q{<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">}
2015-03-27 00:14:20 -04:00
locals = {}
options = {:format=>:xhtml}
2015-03-27 03:40:15 -04:00
assert_ugly(haml, locals, options)
2015-03-22 11:42:05 -04:00
end
specify "an XHTML 1.2 mobile doctype" do
2015-03-27 00:14:20 -04:00
haml = %q{!!! mobile}
2015-03-27 21:53:56 -04:00
html = %q{<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.2//EN" "http://www.openmobilealliance.org/tech/DTD/xhtml-mobile12.dtd">}
2015-03-27 00:14:20 -04:00
locals = {}
options = {:format=>:xhtml}
2015-03-27 03:40:15 -04:00
assert_ugly(haml, locals, options)
2015-03-22 11:42:05 -04:00
end
specify "an XHTML 1.1 basic doctype" do
2015-03-27 00:14:20 -04:00
haml = %q{!!! basic}
2015-03-27 21:53:56 -04:00
html = %q{<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML Basic 1.1//EN" "http://www.w3.org/TR/xhtml-basic/xhtml-basic11.dtd">}
2015-03-27 00:14:20 -04:00
locals = {}
options = {:format=>:xhtml}
2015-03-27 03:40:15 -04:00
assert_ugly(haml, locals, options)
2015-03-22 11:42:05 -04:00
end
specify "an XHTML 1.0 frameset doctype" do
2015-03-27 00:14:20 -04:00
haml = %q{!!! frameset}
2015-03-27 21:53:56 -04:00
html = %q{<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">}
2015-03-27 00:14:20 -04:00
locals = {}
options = {:format=>:xhtml}
2015-03-27 03:40:15 -04:00
assert_ugly(haml, locals, options)
2015-03-22 11:42:05 -04:00
end
specify "an HTML 5 doctype with XHTML syntax" do
2015-03-27 00:14:20 -04:00
haml = %q{!!! 5}
2015-03-27 21:53:56 -04:00
html = %q{<!DOCTYPE html>}
2015-03-27 00:14:20 -04:00
locals = {}
options = {:format=>:xhtml}
2015-03-27 03:40:15 -04:00
assert_ugly(haml, locals, options)
2015-03-22 11:42:05 -04:00
end
specify "an HTML 5 XML prolog (silent)" do
2015-03-27 00:14:20 -04:00
haml = %q{!!! XML}
2015-03-27 21:53:56 -04:00
html = %q{}
2015-03-27 00:14:20 -04:00
locals = {}
options = {:format=>:html5}
2015-03-27 03:40:15 -04:00
assert_ugly(haml, locals, options)
2015-03-22 11:42:05 -04:00
end
specify "an HTML 5 doctype" do
2015-03-27 00:14:20 -04:00
haml = %q{!!!}
2015-03-27 21:53:56 -04:00
html = %q{<!DOCTYPE html>}
2015-03-27 00:14:20 -04:00
locals = {}
options = {:format=>:html5}
2015-03-27 03:40:15 -04:00
assert_ugly(haml, locals, options)
2015-03-22 11:42:05 -04:00
end
specify "an HTML 4 XML prolog (silent)" do
2015-03-27 00:14:20 -04:00
haml = %q{!!! XML}
2015-03-27 21:53:56 -04:00
html = %q{}
2015-03-27 00:14:20 -04:00
locals = {}
options = {:format=>:html4}
2015-03-27 03:40:15 -04:00
assert_ugly(haml, locals, options)
2015-03-22 11:42:05 -04:00
end
specify "an HTML 4 default (transitional) doctype" do
2015-03-27 00:14:20 -04:00
haml = %q{!!!}
2015-03-27 21:53:56 -04:00
html = %q{<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">}
2015-03-27 00:14:20 -04:00
locals = {}
options = {:format=>:html4}
2015-03-27 03:40:15 -04:00
assert_ugly(haml, locals, options)
2015-03-22 11:42:05 -04:00
end
specify "an HTML 4 frameset doctype" do
2015-03-27 00:14:20 -04:00
haml = %q{!!! frameset}
2015-03-27 21:53:56 -04:00
html = %q{<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">}
2015-03-27 00:14:20 -04:00
locals = {}
options = {:format=>:html4}
2015-03-27 03:40:15 -04:00
assert_ugly(haml, locals, options)
2015-03-22 11:42:05 -04:00
end
specify "an HTML 4 strict doctype" do
2015-03-27 00:14:20 -04:00
haml = %q{!!! strict}
2015-03-27 21:53:56 -04:00
html = %q{<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">}
2015-03-27 00:14:20 -04:00
locals = {}
options = {:format=>:html4}
2015-03-27 03:40:15 -04:00
assert_ugly(haml, locals, options)
2015-03-22 11:42:05 -04:00
end
end
context "basic Haml tags and CSS" do
specify "a simple Haml tag" do
2015-03-27 00:14:20 -04:00
haml = %q{%p}
2015-03-27 21:53:56 -04:00
html = %q{<p></p>}
2015-03-27 00:14:20 -04:00
locals = {}
options = {}
2015-03-27 03:40:15 -04:00
assert_ugly(haml, locals, options)
2015-03-22 11:42:05 -04:00
end
specify "a self-closing tag (XHTML)" do
2015-03-27 00:14:20 -04:00
haml = %q{%meta}
2015-03-27 21:53:56 -04:00
html = %q{<meta />}
2015-03-27 00:14:20 -04:00
locals = {}
options = {:format=>:xhtml}
2015-03-27 03:40:15 -04:00
assert_ugly(haml, locals, options)
2015-03-22 11:42:05 -04:00
end
specify "a self-closing tag (HTML4)" do
2015-03-27 00:14:20 -04:00
haml = %q{%meta}
2015-03-27 21:53:56 -04:00
html = %q{<meta>}
2015-03-27 00:14:20 -04:00
locals = {}
options = {:format=>:html4}
2015-03-27 03:40:15 -04:00
assert_ugly(haml, locals, options)
2015-03-22 11:42:05 -04:00
end
specify "a self-closing tag (HTML5)" do
2015-03-27 00:14:20 -04:00
haml = %q{%meta}
2015-03-27 21:53:56 -04:00
html = %q{<meta>}
2015-03-27 00:14:20 -04:00
locals = {}
options = {:format=>:html5}
2015-03-27 03:40:15 -04:00
assert_ugly(haml, locals, options)
2015-03-22 11:42:05 -04:00
end
specify "a self-closing tag ('/' modifier + XHTML)" do
2015-03-27 00:14:20 -04:00
haml = %q{%zzz/}
2015-03-27 21:53:56 -04:00
html = %q{<zzz />}
2015-03-27 00:14:20 -04:00
locals = {}
options = {:format=>:xhtml}
2015-03-27 03:40:15 -04:00
assert_ugly(haml, locals, options)
2015-03-22 11:42:05 -04:00
end
specify "a self-closing tag ('/' modifier + HTML5)" do
2015-03-27 00:14:20 -04:00
haml = %q{%zzz/}
2015-03-27 21:53:56 -04:00
html = %q{<zzz>}
2015-03-27 00:14:20 -04:00
locals = {}
options = {:format=>:html5}
2015-03-27 03:40:15 -04:00
assert_ugly(haml, locals, options)
2015-03-22 11:42:05 -04:00
end
specify "a tag with a CSS class" do
2015-03-27 00:14:20 -04:00
haml = %q{%p.class1}
2015-03-27 21:53:56 -04:00
html = %q{<p class='class1'></p>}
2015-03-27 00:14:20 -04:00
locals = {}
options = {}
2015-03-27 03:40:15 -04:00
assert_ugly(haml, locals, options)
2015-03-22 11:42:05 -04:00
end
specify "a tag with multiple CSS classes" do
2015-03-27 00:14:20 -04:00
haml = %q{%p.class1.class2}
2015-03-27 21:53:56 -04:00
html = %q{<p class='class1 class2'></p>}
2015-03-27 00:14:20 -04:00
locals = {}
options = {}
2015-03-27 03:40:15 -04:00
assert_ugly(haml, locals, options)
2015-03-22 11:42:05 -04:00
end
specify "a tag with a CSS id" do
2015-03-27 00:14:20 -04:00
haml = %q{%p#id1}
2015-03-27 21:53:56 -04:00
html = %q{<p id='id1'></p>}
2015-03-27 00:14:20 -04:00
locals = {}
options = {}
2015-03-27 03:40:15 -04:00
assert_ugly(haml, locals, options)
2015-03-22 11:42:05 -04:00
end
specify "a tag with multiple CSS id's" do
2015-03-27 00:14:20 -04:00
haml = %q{%p#id1#id2}
2015-03-27 21:53:56 -04:00
html = %q{<p id='id2'></p>}
2015-03-27 00:14:20 -04:00
locals = {}
options = {}
2015-03-27 03:40:15 -04:00
assert_ugly(haml, locals, options)
2015-03-22 11:42:05 -04:00
end
specify "a tag with a class followed by an id" do
2015-03-27 00:14:20 -04:00
haml = %q{%p.class1#id1}
2015-03-27 21:53:56 -04:00
html = %q{<p class='class1' id='id1'></p>}
2015-03-27 00:14:20 -04:00
locals = {}
options = {}
2015-03-27 03:40:15 -04:00
assert_ugly(haml, locals, options)
2015-03-22 11:42:05 -04:00
end
specify "a tag with an id followed by a class" do
2015-03-27 00:14:20 -04:00
haml = %q{%p#id1.class1}
2015-03-27 21:53:56 -04:00
html = %q{<p class='class1' id='id1'></p>}
2015-03-27 00:14:20 -04:00
locals = {}
options = {}
2015-03-27 03:40:15 -04:00
assert_ugly(haml, locals, options)
2015-03-22 11:42:05 -04:00
end
specify "an implicit div with a CSS id" do
2015-03-27 00:14:20 -04:00
haml = %q{#id1}
2015-03-27 21:53:56 -04:00
html = %q{<div id='id1'></div>}
2015-03-27 00:14:20 -04:00
locals = {}
options = {}
2015-03-27 03:40:15 -04:00
assert_ugly(haml, locals, options)
2015-03-22 11:42:05 -04:00
end
specify "an implicit div with a CSS class" do
2015-03-27 00:14:20 -04:00
haml = %q{.class1}
2015-03-27 21:53:56 -04:00
html = %q{<div class='class1'></div>}
2015-03-27 00:14:20 -04:00
locals = {}
options = {}
2015-03-27 03:40:15 -04:00
assert_ugly(haml, locals, options)
2015-03-22 11:42:05 -04:00
end
specify "multiple simple Haml tags" do
2015-03-27 00:14:20 -04:00
haml = %q{%div
2015-03-22 11:32:40 -04:00
%div
%p}
2015-03-27 21:53:56 -04:00
html = %q{<div>
<div>
<p></p>
</div>
</div>}
2015-03-27 00:14:20 -04:00
locals = {}
options = {}
2015-03-27 03:40:15 -04:00
assert_ugly(haml, locals, options)
2015-03-22 11:42:05 -04:00
end
end
context "tags with unusual HTML characters" do
specify "a tag with colons" do
2015-03-27 00:14:20 -04:00
haml = %q{%ns:tag}
2015-03-27 21:53:56 -04:00
html = %q{<ns:tag></ns:tag>}
2015-03-27 00:14:20 -04:00
locals = {}
options = {}
2015-03-27 03:40:15 -04:00
assert_ugly(haml, locals, options)
2015-03-22 11:42:05 -04:00
end
specify "a tag with underscores" do
2015-03-27 00:14:20 -04:00
haml = %q{%snake_case}
2015-03-27 21:53:56 -04:00
html = %q{<snake_case></snake_case>}
2015-03-27 00:14:20 -04:00
locals = {}
options = {}
2015-03-27 03:40:15 -04:00
assert_ugly(haml, locals, options)
2015-03-22 11:42:05 -04:00
end
specify "a tag with dashes" do
2015-03-27 00:14:20 -04:00
haml = %q{%dashed-tag}
2015-03-27 21:53:56 -04:00
html = %q{<dashed-tag></dashed-tag>}
2015-03-27 00:14:20 -04:00
locals = {}
options = {}
2015-03-27 03:40:15 -04:00
assert_ugly(haml, locals, options)
2015-03-22 11:42:05 -04:00
end
specify "a tag with camelCase" do
2015-03-27 00:14:20 -04:00
haml = %q{%camelCase}
2015-03-27 21:53:56 -04:00
html = %q{<camelCase></camelCase>}
2015-03-27 00:14:20 -04:00
locals = {}
options = {}
2015-03-27 03:40:15 -04:00
assert_ugly(haml, locals, options)
2015-03-22 11:42:05 -04:00
end
specify "a tag with PascalCase" do
2015-03-27 00:14:20 -04:00
haml = %q{%PascalCase}
2015-03-27 21:53:56 -04:00
html = %q{<PascalCase></PascalCase>}
2015-03-27 00:14:20 -04:00
locals = {}
options = {}
2015-03-27 03:40:15 -04:00
assert_ugly(haml, locals, options)
2015-03-22 11:42:05 -04:00
end
end
context "tags with unusual CSS identifiers" do
specify "an all-numeric class" do
2015-03-27 00:14:20 -04:00
haml = %q{.123}
2015-03-27 21:53:56 -04:00
html = %q{<div class='123'></div>}
2015-03-27 00:14:20 -04:00
locals = {}
options = {}
2015-03-27 03:40:15 -04:00
assert_ugly(haml, locals, options)
2015-03-22 11:42:05 -04:00
end
specify "a class with underscores" do
2015-03-27 00:14:20 -04:00
haml = %q{.__}
2015-03-27 21:53:56 -04:00
html = %q{<div class='__'></div>}
2015-03-27 00:14:20 -04:00
locals = {}
options = {}
2015-03-27 03:40:15 -04:00
assert_ugly(haml, locals, options)
2015-03-22 11:42:05 -04:00
end
specify "a class with dashes" do
2015-03-27 00:14:20 -04:00
haml = %q{.--}
2015-03-27 21:53:56 -04:00
html = %q{<div class='--'></div>}
2015-03-27 00:14:20 -04:00
locals = {}
options = {}
2015-03-27 03:40:15 -04:00
assert_ugly(haml, locals, options)
2015-03-22 11:42:05 -04:00
end
end
context "tags with inline content" do
specify "Inline content simple tag" do
2015-03-27 00:14:20 -04:00
haml = %q{%p hello}
2015-03-27 21:53:56 -04:00
html = %q{<p>hello</p>}
2015-03-27 00:14:20 -04:00
locals = {}
options = {}
2015-03-27 03:40:15 -04:00
assert_ugly(haml, locals, options)
2015-03-22 11:42:05 -04:00
end
specify "Inline content tag with CSS" do
2015-03-27 00:14:20 -04:00
haml = %q{%p.class1 hello}
2015-03-27 21:53:56 -04:00
html = %q{<p class='class1'>hello</p>}
2015-03-27 00:14:20 -04:00
locals = {}
options = {}
2015-03-27 03:40:15 -04:00
assert_ugly(haml, locals, options)
2015-03-22 11:42:05 -04:00
end
specify "Inline content multiple simple tags" do
2015-03-27 00:14:20 -04:00
haml = %q{%div
2015-03-22 11:32:40 -04:00
%div
%p text}
2015-03-27 21:53:56 -04:00
html = %q{<div>
<div>
<p>text</p>
</div>
</div>}
2015-03-27 00:14:20 -04:00
locals = {}
options = {}
2015-03-27 03:40:15 -04:00
assert_ugly(haml, locals, options)
2015-03-22 11:42:05 -04:00
end
2015-03-22 11:32:40 -04:00
end
2015-03-22 11:42:05 -04:00
context "tags with nested content" do
specify "Nested content simple tag" do
2015-03-27 00:14:20 -04:00
haml = %q{%p
2015-03-22 11:32:40 -04:00
hello}
2015-03-27 21:53:56 -04:00
html = %q{<p>
hello
</p>}
2015-03-27 00:14:20 -04:00
locals = {}
options = {}
2015-03-27 03:40:15 -04:00
assert_ugly(haml, locals, options)
2015-03-22 11:42:05 -04:00
end
specify "Nested content tag with CSS" do
2015-03-27 00:14:20 -04:00
haml = %q{%p.class1
2015-03-22 11:32:40 -04:00
hello}
2015-03-27 21:53:56 -04:00
html = %q{<p class='class1'>
hello
</p>}
2015-03-27 00:14:20 -04:00
locals = {}
options = {}
2015-03-27 03:40:15 -04:00
assert_ugly(haml, locals, options)
2015-03-22 11:42:05 -04:00
end
specify "Nested content multiple simple tags" do
2015-03-27 00:14:20 -04:00
haml = %q{%div
2015-03-22 11:32:40 -04:00
%div
%p
text}
2015-03-27 21:53:56 -04:00
html = %q{<div>
<div>
<p>
text
</p>
</div>
</div>}
2015-03-27 00:14:20 -04:00
locals = {}
options = {}
2015-03-27 03:40:15 -04:00
assert_ugly(haml, locals, options)
2015-03-22 11:42:05 -04:00
end
end
context "tags with HTML-style attributes" do
specify "HTML-style one attribute" do
2015-03-27 00:14:20 -04:00
haml = %q{%p(a='b')}
2015-03-27 21:53:56 -04:00
html = %q{<p a='b'></p>}
2015-03-27 00:14:20 -04:00
locals = {}
options = {}
2015-03-27 03:40:15 -04:00
assert_ugly(haml, locals, options)
2015-03-22 11:42:05 -04:00
end
specify "HTML-style multiple attributes" do
2015-03-27 00:14:20 -04:00
haml = %q{%p(a='b' c='d')}
2015-03-27 21:53:56 -04:00
html = %q{<p a='b' c='d'></p>}
2015-03-27 00:14:20 -04:00
locals = {}
options = {}
2015-03-27 03:40:15 -04:00
assert_ugly(haml, locals, options)
2015-03-22 11:42:05 -04:00
end
2015-03-28 21:22:45 -04:00
specify "HTML-style attributes separated with newlines" do
2015-03-27 00:14:20 -04:00
haml = %q{%p(a='b'
2015-03-22 11:32:40 -04:00
c='d')}
2015-03-27 21:53:56 -04:00
html = %q{<p a='b' c='d'></p>}
2015-03-27 00:14:20 -04:00
locals = {}
options = {}
2015-03-27 03:40:15 -04:00
assert_ugly(haml, locals, options)
2015-03-22 11:42:05 -04:00
end
specify "HTML-style interpolated attribute" do
2015-03-27 00:14:20 -04:00
haml = %q{%p(a="#{var}")}
2015-03-27 21:53:56 -04:00
html = %q{<p a='value'></p>}
2015-03-27 00:14:20 -04:00
locals = {:var=>"value"}
options = {}
2015-03-27 03:40:15 -04:00
assert_ugly(haml, locals, options)
2015-03-22 11:42:05 -04:00
end
specify "HTML-style 'class' as an attribute" do
2015-03-27 00:14:20 -04:00
haml = %q{%p(class='class1')}
2015-03-27 21:53:56 -04:00
html = %q{<p class='class1'></p>}
2015-03-27 00:14:20 -04:00
locals = {}
options = {}
2015-03-27 03:40:15 -04:00
assert_ugly(haml, locals, options)
2015-03-22 11:42:05 -04:00
end
specify "HTML-style tag with a CSS class and 'class' as an attribute" do
2015-03-27 00:14:20 -04:00
haml = %q{%p.class2(class='class1')}
2015-03-27 21:53:56 -04:00
html = %q{<p class='class1 class2'></p>}
2015-03-27 00:14:20 -04:00
locals = {}
options = {}
2015-03-27 03:40:15 -04:00
assert_ugly(haml, locals, options)
2015-03-22 11:42:05 -04:00
end
specify "HTML-style tag with 'id' as an attribute" do
2015-03-27 00:14:20 -04:00
haml = %q{%p(id='1')}
2015-03-27 21:53:56 -04:00
html = %q{<p id='1'></p>}
2015-03-27 00:14:20 -04:00
locals = {}
options = {}
2015-03-27 03:40:15 -04:00
assert_ugly(haml, locals, options)
2015-03-22 11:42:05 -04:00
end
specify "HTML-style tag with a CSS id and 'id' as an attribute" do
2015-03-27 00:14:20 -04:00
haml = %q{%p#id(id='1')}
2015-03-27 21:53:56 -04:00
html = %q{<p id='id_1'></p>}
2015-03-27 00:14:20 -04:00
locals = {}
options = {}
2015-03-27 03:40:15 -04:00
assert_ugly(haml, locals, options)
2015-03-22 11:42:05 -04:00
end
specify "HTML-style tag with a variable attribute" do
2015-03-27 00:14:20 -04:00
haml = %q{%p(class=var)}
2015-03-27 21:53:56 -04:00
html = %q{<p class='hello'></p>}
2015-03-27 00:14:20 -04:00
locals = {:var=>"hello"}
options = {}
2015-03-27 03:40:15 -04:00
assert_ugly(haml, locals, options)
2015-03-22 11:42:05 -04:00
end
specify "HTML-style tag with a CSS class and 'class' as a variable attribute" do
2015-03-27 00:14:20 -04:00
haml = %q{.hello(class=var)}
2015-03-27 21:53:56 -04:00
html = %q{<div class='hello world'></div>}
2015-03-27 00:14:20 -04:00
locals = {:var=>"world"}
options = {}
2015-03-27 03:40:15 -04:00
assert_ugly(haml, locals, options)
2015-03-22 11:42:05 -04:00
end
specify "HTML-style tag multiple CSS classes (sorted correctly)" do
2015-03-27 00:14:20 -04:00
haml = %q{.z(class=var)}
2015-03-27 21:53:56 -04:00
html = %q{<div class='a z'></div>}
2015-03-27 00:14:20 -04:00
locals = {:var=>"a"}
options = {}
2015-03-27 03:40:15 -04:00
assert_ugly(haml, locals, options)
2015-03-22 11:42:05 -04:00
end
2015-03-27 21:38:05 -04:00
specify "HTML-style tag with an atomic attribute" do
2015-03-27 21:38:05 -04:00
haml = %q{%a(flag)}
2015-03-27 21:53:56 -04:00
html = %q{<a flag></a>}
2015-03-27 21:38:05 -04:00
locals = {}
options = {}
assert_ugly(haml, locals, options)
end
2015-03-22 11:42:05 -04:00
end
context "tags with Ruby-style attributes" do
specify "Ruby-style one attribute" do
2015-03-27 00:14:20 -04:00
haml = %q{%p{:a => 'b'}}
2015-03-27 21:53:56 -04:00
html = %q{<p a='b'></p>}
2015-03-27 00:14:20 -04:00
locals = {}
options = {}
2015-03-27 03:40:15 -04:00
assert_ugly(haml, locals, options)
2015-03-22 11:42:05 -04:00
end
specify "Ruby-style attributes hash with whitespace" do
2015-03-27 00:14:20 -04:00
haml = %q{%p{ :a => 'b' }}
2015-03-27 21:53:56 -04:00
html = %q{<p a='b'></p>}
2015-03-27 00:14:20 -04:00
locals = {}
options = {}
2015-03-27 03:40:15 -04:00
assert_ugly(haml, locals, options)
2015-03-22 11:42:05 -04:00
end
specify "Ruby-style interpolated attribute" do
2015-03-27 00:14:20 -04:00
haml = %q{%p{:a =>"#{var}"}}
2015-03-27 21:53:56 -04:00
html = %q{<p a='value'></p>}
2015-03-27 00:14:20 -04:00
locals = {:var=>"value"}
options = {}
2015-03-27 03:40:15 -04:00
assert_ugly(haml, locals, options)
2015-03-22 11:42:05 -04:00
end
specify "Ruby-style multiple attributes" do
2015-03-27 00:14:20 -04:00
haml = %q{%p{ :a => 'b', 'c' => 'd' }}
2015-03-27 21:53:56 -04:00
html = %q{<p a='b' c='d'></p>}
2015-03-27 00:14:20 -04:00
locals = {}
options = {}
2015-03-27 03:40:15 -04:00
assert_ugly(haml, locals, options)
2015-03-22 11:42:05 -04:00
end
2015-03-29 09:02:08 -04:00
specify "Ruby-style attributes separated with newlines" do
2015-03-27 00:14:20 -04:00
haml = %q{%p{ :a => 'b',
2015-03-22 11:32:40 -04:00
'c' => 'd' }}
2015-03-27 21:53:56 -04:00
html = %q{<p a='b' c='d'></p>}
2015-03-27 00:14:20 -04:00
locals = {}
options = {}
2015-03-27 03:40:15 -04:00
assert_ugly(haml, locals, options)
2015-03-22 11:42:05 -04:00
end
specify "Ruby-style 'class' as an attribute" do
2015-03-27 00:14:20 -04:00
haml = %q{%p{:class => 'class1'}}
2015-03-27 21:53:56 -04:00
html = %q{<p class='class1'></p>}
2015-03-27 00:14:20 -04:00
locals = {}
options = {}
2015-03-27 03:40:15 -04:00
assert_ugly(haml, locals, options)
2015-03-22 11:42:05 -04:00
end
specify "Ruby-style tag with a CSS class and 'class' as an attribute" do
2015-03-27 00:14:20 -04:00
haml = %q{%p.class2{:class => 'class1'}}
2015-03-27 21:53:56 -04:00
html = %q{<p class='class1 class2'></p>}
2015-03-27 00:14:20 -04:00
locals = {}
options = {}
2015-03-27 03:40:15 -04:00
assert_ugly(haml, locals, options)
2015-03-22 11:42:05 -04:00
end
specify "Ruby-style tag with 'id' as an attribute" do
2015-03-27 00:14:20 -04:00
haml = %q{%p{:id => '1'}}
2015-03-27 21:53:56 -04:00
html = %q{<p id='1'></p>}
2015-03-27 00:14:20 -04:00
locals = {}
options = {}
2015-03-27 03:40:15 -04:00
assert_ugly(haml, locals, options)
2015-03-22 11:42:05 -04:00
end
specify "Ruby-style tag with a CSS id and 'id' as an attribute" do
2015-03-27 00:14:20 -04:00
haml = %q{%p#id{:id => '1'}}
2015-03-27 21:53:56 -04:00
html = %q{<p id='id_1'></p>}
2015-03-27 00:14:20 -04:00
locals = {}
options = {}
2015-03-27 03:40:15 -04:00
assert_ugly(haml, locals, options)
2015-03-22 11:42:05 -04:00
end
specify "Ruby-style tag with a CSS id and a numeric 'id' as an attribute" do
2015-03-27 00:14:20 -04:00
haml = %q{%p#id{:id => 1}}
2015-03-27 21:53:56 -04:00
html = %q{<p id='id_1'></p>}
2015-03-27 00:14:20 -04:00
locals = {}
options = {}
2015-03-27 03:40:15 -04:00
assert_ugly(haml, locals, options)
2015-03-22 11:42:05 -04:00
end
specify "Ruby-style tag with a variable attribute" do
2015-03-27 00:14:20 -04:00
haml = %q{%p{:class => var}}
2015-03-27 21:53:56 -04:00
html = %q{<p class='hello'></p>}
2015-03-27 00:14:20 -04:00
locals = {:var=>"hello"}
options = {}
2015-03-27 03:40:15 -04:00
assert_ugly(haml, locals, options)
2015-03-22 11:42:05 -04:00
end
2015-03-28 07:03:50 -04:00
specify "Ruby-style tag with a CSS class and 'class' as a variable attribute" do
2015-03-27 00:14:20 -04:00
haml = %q{.hello{:class => var}}
2015-03-27 21:53:56 -04:00
html = %q{<div class='hello world'></div>}
2015-03-27 00:14:20 -04:00
locals = {:var=>"world"}
options = {}
2015-03-27 03:40:15 -04:00
assert_ugly(haml, locals, options)
2015-03-22 11:42:05 -04:00
end
specify "Ruby-style tag multiple CSS classes (sorted correctly)" do
2015-03-27 00:14:20 -04:00
haml = %q{.z{:class => var}}
2015-03-27 21:53:56 -04:00
html = %q{<div class='a z'></div>}
2015-03-27 00:14:20 -04:00
locals = {:var=>"a"}
options = {}
2015-03-27 03:40:15 -04:00
assert_ugly(haml, locals, options)
2015-03-22 11:42:05 -04:00
end
end
context "silent comments" do
specify "an inline silent comment" do
2015-03-27 00:14:20 -04:00
haml = %q{-# hello}
2015-03-27 21:53:56 -04:00
html = %q{}
2015-03-27 00:14:20 -04:00
locals = {}
options = {}
2015-03-27 03:40:15 -04:00
assert_ugly(haml, locals, options)
2015-03-22 11:42:05 -04:00
end
specify "a nested silent comment" do
2015-03-27 00:14:20 -04:00
haml = %q{-#
2015-03-22 11:32:40 -04:00
hello}
2015-03-27 21:53:56 -04:00
html = %q{}
2015-03-27 00:14:20 -04:00
locals = {}
options = {}
2015-03-27 03:40:15 -04:00
assert_ugly(haml, locals, options)
2015-03-22 11:42:05 -04:00
end
specify "a multiply nested silent comment" do
2015-03-27 00:14:20 -04:00
haml = %q{-#
2015-03-22 11:32:40 -04:00
%div
foo}
2015-03-27 21:53:56 -04:00
html = %q{}
2015-03-27 00:14:20 -04:00
locals = {}
options = {}
2015-03-27 03:40:15 -04:00
assert_ugly(haml, locals, options)
2015-03-22 11:42:05 -04:00
end
specify "a multiply nested silent comment with inconsistent indents" do
2015-03-27 00:14:20 -04:00
haml = %q{-#
2015-03-22 11:32:40 -04:00
%div
foo}
2015-03-27 21:53:56 -04:00
html = %q{}
2015-03-27 00:14:20 -04:00
locals = {}
options = {}
2015-03-27 03:40:15 -04:00
assert_ugly(haml, locals, options)
2015-03-22 11:42:05 -04:00
end
end
context "markup comments" do
specify "an inline markup comment" do
2015-03-27 00:14:20 -04:00
haml = %q{/ comment}
2015-03-27 21:53:56 -04:00
html = %q{<!-- comment -->}
2015-03-27 00:14:20 -04:00
locals = {}
options = {}
2015-03-27 03:40:15 -04:00
assert_ugly(haml, locals, options)
2015-03-22 11:42:05 -04:00
end
specify "a nested markup comment" do
2015-03-27 00:14:20 -04:00
haml = %q{/
2015-03-22 11:32:40 -04:00
comment
comment2}
2015-03-27 21:53:56 -04:00
html = %q{<!--
comment
comment2
-->}
2015-03-27 00:14:20 -04:00
locals = {}
options = {}
2015-03-27 03:40:15 -04:00
assert_ugly(haml, locals, options)
2015-03-22 11:42:05 -04:00
end
2015-03-22 11:32:40 -04:00
end
2015-03-22 11:42:05 -04:00
context "conditional comments" do
2015-03-28 20:52:33 -04:00
specify "a conditional comment" do
2015-03-27 00:14:20 -04:00
haml = %q{/[if IE]
2015-03-22 11:32:40 -04:00
%p a}
2015-03-27 21:53:56 -04:00
html = %q{<!--[if IE]>
<p>a</p>
<![endif]-->}
2015-03-27 00:14:20 -04:00
locals = {}
options = {}
2015-03-27 03:40:15 -04:00
assert_ugly(haml, locals, options)
2015-03-22 11:42:05 -04:00
end
end
context "internal filters" do
specify "content in an 'escaped' filter" do
2015-03-27 00:14:20 -04:00
haml = %q{:escaped
2015-03-22 11:32:40 -04:00
<&">}
2015-03-27 21:53:56 -04:00
html = %q{&lt;&amp;&quot;&gt;}
2015-03-27 00:14:20 -04:00
locals = {}
options = {}
2015-03-27 03:40:15 -04:00
assert_ugly(haml, locals, options)
2015-03-22 11:42:05 -04:00
end
specify "content in a 'preserve' filter" do
2015-03-27 00:14:20 -04:00
haml = %q{:preserve
2015-03-22 11:32:40 -04:00
hello
%p}
2015-03-27 21:53:56 -04:00
html = %q{hello&#x000A;
<p></p>}
2015-03-27 00:14:20 -04:00
locals = {}
options = {}
2015-03-27 03:40:15 -04:00
assert_ugly(haml, locals, options)
2015-03-22 11:42:05 -04:00
end
specify "content in a 'plain' filter" do
2015-03-27 00:14:20 -04:00
haml = %q{:plain
2015-03-22 11:32:40 -04:00
hello
%p}
2015-03-27 21:53:56 -04:00
html = %q{hello
<p></p>}
2015-03-27 00:14:20 -04:00
locals = {}
options = {}
2015-03-27 03:40:15 -04:00
assert_ugly(haml, locals, options)
2015-03-22 11:42:05 -04:00
end
specify "content in a 'css' filter (XHTML)" do
2015-03-27 00:14:20 -04:00
haml = %q{:css
2015-03-22 11:32:40 -04:00
hello
%p}
2015-03-27 21:53:56 -04:00
html = %q{<style type='text/css'>
/*<![CDATA[*/
hello
/*]]>*/
</style>
<p></p>}
2015-03-27 00:14:20 -04:00
locals = {}
options = {:format=>:xhtml}
2015-03-27 03:40:15 -04:00
assert_ugly(haml, locals, options)
2015-03-22 11:42:05 -04:00
end
specify "content in a 'javascript' filter (XHTML)" do
2015-03-27 00:14:20 -04:00
haml = %q{:javascript
2015-03-22 11:32:40 -04:00
a();
%p}
2015-03-27 21:53:56 -04:00
html = %q{<script type='text/javascript'>
//<![CDATA[
a();
//]]>
</script>
<p></p>}
2015-03-27 00:14:20 -04:00
locals = {}
options = {:format=>:xhtml}
2015-03-27 03:40:15 -04:00
assert_ugly(haml, locals, options)
2015-03-22 11:42:05 -04:00
end
specify "content in a 'css' filter (HTML)" do
2015-03-27 00:14:20 -04:00
haml = %q{:css
2015-03-22 11:32:40 -04:00
hello
%p}
2015-03-27 21:53:56 -04:00
html = %q{<style>
hello
</style>
<p></p>}
2015-03-27 00:14:20 -04:00
locals = {}
options = {:format=>:html5}
2015-03-27 03:40:15 -04:00
assert_ugly(haml, locals, options)
2015-03-22 11:42:05 -04:00
end
specify "content in a 'javascript' filter (HTML)" do
2015-03-27 00:14:20 -04:00
haml = %q{:javascript
2015-03-22 11:32:40 -04:00
a();
%p}
2015-03-27 21:53:56 -04:00
html = %q{<script>
a();
</script>
<p></p>}
2015-03-27 00:14:20 -04:00
locals = {}
options = {:format=>:html5}
2015-03-27 03:40:15 -04:00
assert_ugly(haml, locals, options)
2015-03-22 11:42:05 -04:00
end
end
context "Ruby-style interpolation" do
specify "interpolation inside inline content" do
2015-03-27 00:14:20 -04:00
haml = %q{%p #{var}}
2015-03-27 21:53:56 -04:00
html = %q{<p>value</p>}
2015-03-27 00:14:20 -04:00
locals = {:var=>"value"}
options = {}
2015-03-27 03:40:15 -04:00
assert_ugly(haml, locals, options)
2015-03-22 11:42:05 -04:00
end
specify "no interpolation when escaped" do
2015-03-27 00:14:20 -04:00
haml = %q{%p \#{var}}
2015-03-27 21:53:56 -04:00
html = %q{<p>#{var}</p>}
2015-03-27 00:14:20 -04:00
locals = {:var=>"value"}
options = {}
2015-03-27 03:40:15 -04:00
assert_ugly(haml, locals, options)
2015-03-22 11:42:05 -04:00
end
specify "interpolation when the escape character is escaped" do
2015-03-27 00:14:20 -04:00
haml = %q{%p \\#{var}}
2015-03-27 21:53:56 -04:00
html = %q{<p>\value</p>}
2015-03-27 00:14:20 -04:00
locals = {:var=>"value"}
options = {}
2015-03-27 03:40:15 -04:00
assert_ugly(haml, locals, options)
2015-03-22 11:42:05 -04:00
end
specify "interpolation inside filtered content" do
2015-03-27 00:14:20 -04:00
haml = %q{:plain
2015-03-22 11:32:40 -04:00
#{var} interpolated: #{var}}
2015-03-27 21:53:56 -04:00
html = %q{value interpolated: value}
2015-03-27 00:14:20 -04:00
locals = {:var=>"value"}
options = {}
2015-03-27 03:40:15 -04:00
assert_ugly(haml, locals, options)
2015-03-22 11:42:05 -04:00
end
end
context "HTML escaping" do
specify "code following '&='" do
2015-03-27 00:14:20 -04:00
haml = %q{&= '<"&>'}
2015-03-27 21:53:56 -04:00
html = %q{&lt;&quot;&amp;&gt;}
2015-03-27 00:14:20 -04:00
locals = {}
options = {}
2015-03-27 03:40:15 -04:00
assert_ugly(haml, locals, options)
2015-03-22 11:42:05 -04:00
end
specify "code following '=' when escape_haml is set to true" do
2015-03-27 00:14:20 -04:00
haml = %q{= '<"&>'}
2015-03-27 21:53:56 -04:00
html = %q{&lt;&quot;&amp;&gt;}
2015-03-27 00:14:20 -04:00
locals = {}
options = {:escape_html=>"true"}
2015-03-27 03:40:15 -04:00
assert_ugly(haml, locals, options)
2015-03-22 11:42:05 -04:00
end
specify "code following '!=' when escape_haml is set to true" do
2015-03-27 00:14:20 -04:00
haml = %q{!= '<"&>'}
2015-03-27 21:53:56 -04:00
html = %q{<"&>}
2015-03-27 00:14:20 -04:00
locals = {}
options = {:escape_html=>"true"}
2015-03-27 03:40:15 -04:00
assert_ugly(haml, locals, options)
2015-03-22 11:42:05 -04:00
end
end
context "boolean attributes" do
specify "boolean attribute with XHTML" do
2015-03-27 00:14:20 -04:00
haml = %q{%input(checked=true)}
2015-03-27 21:53:56 -04:00
html = %q{<input checked='checked' />}
2015-03-27 00:14:20 -04:00
locals = {}
options = {:format=>:xhtml}
2015-03-27 03:40:15 -04:00
assert_ugly(haml, locals, options)
2015-03-22 11:42:05 -04:00
end
specify "boolean attribute with HTML" do
2015-03-27 00:14:20 -04:00
haml = %q{%input(checked=true)}
2015-03-27 21:53:56 -04:00
html = %q{<input checked>}
2015-03-27 00:14:20 -04:00
locals = {}
options = {:format=>:html5}
2015-03-27 03:40:15 -04:00
assert_ugly(haml, locals, options)
2015-03-22 11:42:05 -04:00
end
end
context "whitespace preservation" do
specify "following the '~' operator" do
2015-03-27 00:14:20 -04:00
haml = %q{~ "Foo\n<pre>Bar\nBaz</pre>"}
2015-03-27 21:53:56 -04:00
html = %q{Foo
<pre>Bar&#x000A;Baz</pre>}
2015-03-27 00:14:20 -04:00
locals = {}
options = {}
2015-03-27 03:40:15 -04:00
assert_ugly(haml, locals, options)
2015-03-22 11:42:05 -04:00
end
specify "inside a textarea tag" do
2015-03-27 00:14:20 -04:00
haml = %q{%textarea
2015-03-22 11:32:40 -04:00
hello
hello}
2015-03-27 21:53:56 -04:00
html = %q{<textarea>hello
hello</textarea>}
2015-03-27 00:14:20 -04:00
locals = {}
options = {}
2015-03-27 03:40:15 -04:00
assert_ugly(haml, locals, options)
2015-03-22 11:42:05 -04:00
end
specify "inside a pre tag" do
2015-03-27 00:14:20 -04:00
haml = %q{%pre
2015-03-22 11:32:40 -04:00
hello
hello}
2015-03-27 21:53:56 -04:00
html = %q{<pre>hello
hello</pre>}
2015-03-27 00:14:20 -04:00
locals = {}
options = {}
2015-03-27 03:40:15 -04:00
assert_ugly(haml, locals, options)
2015-03-22 11:42:05 -04:00
end
end
context "whitespace removal" do
specify "a tag with '>' appended and inline content" do
2015-03-27 00:14:20 -04:00
haml = %q{%li hello
2015-03-22 11:32:40 -04:00
%li> world
%li again}
2015-03-27 21:53:56 -04:00
html = %q{<li>hello</li><li>world</li><li>again</li>}
2015-03-27 00:14:20 -04:00
locals = {}
options = {}
2015-03-27 03:40:15 -04:00
assert_ugly(haml, locals, options)
2015-03-22 11:42:05 -04:00
end
specify "a tag with '>' appended and nested content" do
2015-03-27 00:14:20 -04:00
haml = %q{%li hello
2015-03-22 11:32:40 -04:00
%li>
world
%li again}
2015-03-27 21:53:56 -04:00
html = %q{<li>hello</li><li>
world
</li><li>again</li>}
2015-03-27 00:14:20 -04:00
locals = {}
options = {}
2015-03-27 03:40:15 -04:00
assert_ugly(haml, locals, options)
2015-03-22 11:42:05 -04:00
end
specify "a tag with '<' appended" do
2015-03-27 00:14:20 -04:00
haml = %q{%p<
2015-03-22 11:32:40 -04:00
hello
world}
2015-03-27 21:53:56 -04:00
html = %q{<p>hello
world</p>}
2015-03-27 00:14:20 -04:00
locals = {}
options = {}
2015-03-27 03:40:15 -04:00
assert_ugly(haml, locals, options)
2015-03-22 11:42:05 -04:00
end
2015-03-22 11:32:40 -04:00
end
end