require 'spec_helper'
describe Fu::Mustache do
it "can build a div from a single class" do
Fu.to_mustache(".klass").should eq '
'
end
it "can add multiple classes by appending" do
Fu.to_mustache(".klass.odd").should eq ''
end
it "allows tag type to be specified on the line" do
Fu.to_mustache("%video").should eq ""
end
it "knows that some tags are self closing" do
Fu.to_mustache("%br").should eq "
"
end
it "can specify a tag name, classes and a dom-id just by piling on statements" do
result = Fu.to_mustache("%tag.klass1.klass2#identifier")
result.should =~ /^\This is a title"
end
it "allows the designer to provide arbitrary attributes" do
result = Fu.to_mustache <<-END
%tag (a=1, b=2, data-c =
"Dette er en stor verdi")
END
result.should eq ''
end
it "inserts children as sub nodes and concatenates sibling nodes" do
result = Fu.to_mustache <<-END
%section
%p
This is
some text
for this paragraph.
This is added too
But this is outside
END
result.should eq "This is some text for this paragraph. This is added too
But this is outside"
end
it "handles complex hierarchies with attributes and cdata and multiple siblings at the root level" do
result = Fu.to_mustache <<-END
%section
%h1.header This is a header
%p(data-bananas="healthy but radioactive")
This is body
%details
%ul.big_list
%li Item 1
%li Item 2
%li Item 3
%details.secondary
%p
Some details
%section.number2
Other stuff
END
result.should eq ''
end
it "handles mustache sections" do
result = Fu.to_mustache <<-END
{{#children}}
{{name}} and {{address}}
END
result.should eq "{{#children}}{{name}} and {{address}}{{/children}}"
end
it "handles mustache inverted sections" do
result = Fu.to_mustache <<-END
{{^children}}
{{name}} and {{address}}
END
result.should eq "{{^children}}{{name}} and {{address}}{{/children}}"
end
it "handles mustache in attributes" do
Fu.to_mustache('%p(data-bingo="{{bingo}}")').should eq ''
end
it "handles escaped quote characters in attribute values" do
Fu.to_mustache('%p(data-quoted="\\"")').should eq ''
end
it "handle empty lines with spaces okay" do
Fu.to_mustache <<-END
%p
%p
END
end
it "never escapes the gt-character of include-statements" do
Fu.to_mustache("Bingo{{>partial}}bongo").should eq "Bingo{{>partial}}bongo"
end
end