require 'helper' class TestSlimHtmlStructure < TestSlim def test_simple_render # Keep the trailing space behind "body "! source = %q{ html head title Simple Test Title body p Hello World, meet Slim. } assert_html '
Hello World, meet Slim.
', source end def test_relaxed_indentation_of_first_line source = %q{ p .content } assert_html "", source end def test_html_tag_with_text_and_empty_line source = %q{ p Hello p World } assert_html "Hello
World
", source end def test_html_namespaces source = %q{ html:body html:p html:id="test" Text } assert_html 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.
', source end def test_render_with_text_block_with_subsequent_markup source = %q{ p | Lorem ipsum dolor sit amet, consectetur adipiscing elit. p Some more markup } assert_html 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Some more markup
', source end def test_render_with_text_block_with_trailing_whitespace source = %q{ ' this is a link to a href="link" page } assert_html "this is\na link to page", source end def test_nested_text source = %q{ p | This is line one. This is line two. This is line three. This is line four. p This is a new paragraph. } assert_html "This is line one.\n This is line two.\n This is line three.\n This is line four.
This is a new paragraph.
", source end def test_nested_text_with_nested_html_one_same_line source = %q{ p | This is line one. This is line two. span.bold This is a bold line in the paragraph. | This is more content. } assert_html "This is line one.\n This is line two.This is a bold line in the paragraph. This is more content.
", source end def test_nested_text_with_nested_html_one_same_line2 source = %q{ p |This is line one. This is line two. span.bold This is a bold line in the paragraph. | This is more content. } assert_html "This is line one.\n This is line two.This is a bold line in the paragraph. This is more content.
", source end def test_nested_text_with_nested_html source = %q{ p | This is line one. This is line two. This is line three. This is line four. span.bold This is a bold line in the paragraph. | This is more content. } assert_html "This is line one.\n This is line two.\n This is line three.\n This is line four.This is a bold line in the paragraph. This is more content.
", source end def test_simple_paragraph_with_padding source = %q{ p There will be 3 spaces in front of this line. } assert_html 'There will be 3 spaces in front of this line.
', source end def test_paragraph_with_nested_text source = %q{ p This is line one. This is line two. } assert_html "This is line one.\n This is line two.
", source end def test_paragraph_with_padded_nested_text source = %q{ p This is line one. This is line two. } assert_html "This is line one.\n This is line two.
", source end def test_paragraph_with_attributes_and_nested_text source = %q{ p#test class="paragraph" This is line one. This is line two. } assert_html "This is line one.\nThis is line two.
", source end def test_relaxed_text_indentation source = %q{ p | text block text line3 } assert_html "text block\ntext\n line3
", source end def test_output_code_with_leading_spaces source = %q{ p= hello_world p = hello_world p = hello_world } assert_html 'Hello World from @env
Hello World from @env
Hello World from @env
', source end def test_single_quoted_attributes source = %q{ p class='underscored_class_name' = output_number } assert_html '1337
', source end def test_nonstandard_attributes source = %q{ p id="dashed-id" class="underscored_class_name" = output_number } assert_html '1337
', source end def test_nonstandard_shortcut_attributes source = %q{ p#dashed-id.underscored_class_name = output_number } assert_html '1337
', source end def test_dashed_attributes source = %q{ p data-info="Illudium Q-36" = output_number } assert_html '1337
', source end def test_dashed_attributes_with_shortcuts source = %q{ p#marvin.martian data-info="Illudium Q-36" = output_number } assert_html '1337
', source end def test_parens_around_attributes source = %q{ p(id="marvin" class="martian" data-info="Illudium Q-36") = output_number } assert_html '1337
', source end def test_square_brackets_around_attributes source = %q{ p[id="marvin" class="martian" data-info="Illudium Q-36"] = output_number } assert_html '1337
', source end # Regression test for bug #796 def test_square_brackets_around_attributes_multiline_with_tabs source = "div\n\tp[\n\t\tclass=\"martian\"\n\t]\n\tp Next line" assert_html 'Next line
1337
', source end def test_default_attr_delims_option source = %q{ p1337
', str end end def test_custom_attr_delims_option source = %q{ p { foo="bar" } } assert_html '', source assert_html '', source, attr_list_delims: {'{' => '}'} assert_html '{ foo="bar" }
', source, attr_list_delims: {'(' => ')', '[' => ']'} end def test_closed_tag source = %q{ closed/ } assert_html '< x=(1+1) > Hello
', source assert_html '< x=(1+1) > Hello
', source, attr_list_delims: {'{' => '}'} assert_html '{ foo="bar" x=(1+1) }
Hello
', source, attr_list_delims: {'<' => '>'}, code_attr_delims: { '(' => ')' } end def test_attributs_with_parens_and_spaces source = %q{label{ for='filter' }= hello_world} assert_html '', source end def test_attributs_with_parens_and_spaces2 source = %q{label{ for='filter' } = hello_world} assert_html '', source end def test_attributs_with_multiple_spaces source = %q{label for='filter' class="test" = hello_world} assert_html '', source end def test_closed_tag_with_attributes source = %q{ closed id="test" / } assert_html 'Hello
World
", source end def test_render_with_html_conditional_and_tag source = %q{ /[ if IE ] p Get a better browser. } assert_html "", source end def test_render_with_html_conditional_and_method_output source = %q{ /[ if IE ] = message 'hello' } assert_html "", source end def test_multiline_attributes_with_method source = %q{ p1337
', str end end def test_multiline_attributes_with_text_on_same_line source = %q{ pTHE space modulator
', str end end def test_multiline_attributes_with_nested_text source = %q{ pTHE space modulator
', str end end def test_multiline_attributes_with_dynamic_attr source = %q{ pTHE space modulator
', str end end def test_multiline_attributes_with_nested_tag source = %q{ pTHE space modulator
', str end end def test_multiline_attributes_with_nested_text_and_extra_indentation source = %q{ li< id="myid" class="myclass" data-info="myinfo"> a href="link" My Link } Slim::Parser.options[:attr_list_delims].each do |k,v| str = source.sub('<',k).sub('>',v) assert_html '#{hello_world}
span = hello_world } assert_html 'Hello World from @env
Hello World from @env', source end end