diff --git a/lib/haml/engine.rb b/lib/haml/engine.rb index c3da9b06..af90a3ca 100644 --- a/lib/haml/engine.rb +++ b/lib/haml/engine.rb @@ -522,13 +522,10 @@ END # Causes text to be evaluated, and Haml::Helpers#find_and_flatten # to be run on it afterwards. def push_flat_script(text) - unless text.empty? - push_script(text, true) + if text.empty? + raise SyntaxError.new("Tag has no content.") else - unless @block_opened - raise SyntaxError.new('Filters must have nested text.') - end - start_flat(false) + push_script(text, true) end end @@ -717,8 +714,6 @@ END flattened = (action == '~') - warn(FLAT_WARNING) if flattened && !defined?(Test::Unit) - value_exists = !value.empty? literal_attributes = parse_literal_hash(attributes_hash) attributes_hash = "{nil}" if attributes_hash.nil? || literal_attributes || @options[:suppress_eval] @@ -741,7 +736,7 @@ END elsif atomic && value_exists raise SyntaxError.new("Atomic tags can't have content.") elsif parse && !value_exists - raise SyntaxError.new("No tag content to parse.") + raise SyntaxError.new("Tag has no content.") end if !@block_opened && !value_exists && @options[:autoclose].include?(tag_name) @@ -750,7 +745,7 @@ END do_one_liner = value_exists && !parse && Buffer.one_liner?(value) - if(object_ref == "nil" && attributes_hash == "{nil}" && !flattened && (do_one_liner || !value_exists)) + if object_ref == "nil" && attributes_hash == "{nil}" && !flattened && (do_one_liner || !value_exists) # This means that we can render the tag directly to text and not process it in the buffer open_tag = prerender_tag(tag_name, atomic, attributes) @@ -779,7 +774,7 @@ END end close elsif flattened - start_flat(true) + raise SyntaxError.new("Tag has no content.") end end end diff --git a/test/haml/engine_test.rb b/test/haml/engine_test.rb index 592a8745..03dcad01 100644 --- a/test/haml/engine_test.rb +++ b/test/haml/engine_test.rb @@ -137,12 +137,11 @@ class EngineTest < Test::Unit::TestCase def test_syntax_errors errs = [ "!!!\n a", "a\n b", "a\n:foo\nb", "/ a\n b", - "% a", "%p a\n b", "a\n%p=\nb", "%p=\n a", - "a\n%p~\nb", "a\n~\nb", "%p/\n a", "%p\n \t%a b", - "%a\n b\nc", "%a\n b\nc", - ":notafilter\n This isn't\n a filter!", - ".{} a", "\#{} a", ".= 'foo'", "%a/ b" - ] + "% a", "%p a\n b", "a\n%p=\nb", "%p=\n a", + "a\n%p~\nb", "a\n~\nb", "a\n~\n b", "%p~\n b", "%p/\n a", + "%p\n \t%a b", "%a\n b\nc", "%a\n b\nc", + ":notafilter\n This isn't\n a filter!", + ".{} a", "\#{} a", ".= 'foo'", "%a/ b" ] errs.each do |err| begin render(err) diff --git a/test/haml/results/whitespace_handling.xhtml b/test/haml/results/whitespace_handling.xhtml index a435570e..2c49b4d4 100644 --- a/test/haml/results/whitespace_handling.xhtml +++ b/test/haml/results/whitespace_handling.xhtml @@ -33,21 +33,11 @@ foo bar
-___ ,o88888 ,o8888888' ,:o:o:oooo. ,8O88Pd8888" ,.::.::o:ooooOoOoO. ,oO8O8Pd888'" ,.:.::o:ooOoOoOO8O8OOo.8OOPd8O8O" , ..:.::o:ooOoOOOO8OOOOo.FdO8O8" , ..:.::o:ooOoOO8O888O8O,COCOO" , . ..:.::o:ooOoOOOO8OOOOCOCO" . ..:.::o:ooOoOoOO8O8OCCCC"o . ..:.::o:ooooOoCoCCC"o:o . ..:.::o:o:,cooooCo"oo:o: ` . . ..:.:cocoooo"'o:o:::' .` . ..::ccccoc"'o:o:o:::' :.:. ,c:cccc"':.:.:.:.:.' ..:.:"'`::::c:"'..:.:.:.:.:.' http://www.chris.com/ASCII/ ...:.'.:.::::"' . . . . .' .. . ....:."' ` . . . '' . . . ...."' .. . ."' -hrr- . It's a planet! %strong This shouldn't be bold!- This should! -
-foo - bar -
foo bar -\ No newline at end of file + diff --git a/test/haml/templates/whitespace_handling.haml b/test/haml/templates/whitespace_handling.haml index 0d983213..da4b3f59 100644 --- a/test/haml/templates/whitespace_handling.haml +++ b/test/haml/templates/whitespace_handling.haml @@ -10,60 +10,10 @@ ~ "
foo\nbar" %p~ "
foo\nbar" %p~ "foo\nbar" - %pre~ - ___ - ,o88888 - ,o8888888' - ,:o:o:oooo. ,8O88Pd8888" - ,.::.::o:ooooOoOoO. ,oO8O8Pd888'" - ,.:.::o:ooOoOoOO8O8OOo.8OOPd8O8O" - , ..:.::o:ooOoOOOO8OOOOo.FdO8O8" - , ..:.::o:ooOoOO8O888O8O,COCOO" - , . ..:.::o:ooOoOOOO8OOOOCOCO" - . ..:.::o:ooOoOoOO8O8OCCCC"o - . ..:.::o:ooooOoCoCCC"o:o - . ..:.::o:o:,cooooCo"oo:o: - ` . . ..:.:cocoooo"'o:o:::' - .` . ..::ccccoc"'o:o:o:::' - :.:. ,c:cccc"':.:.:.:.:.' - ..:.:"'`::::c:"'..:.:.:.:.:.' http://www.chris.com/ASCII/ - ...:.'.:.::::"' . . . . .' - .. . ....:."' ` . . . '' - . . . ...."' - .. . ."' -hrr- - . - - - It's a planet! - %strong This shouldn't be bold! - %strong This should! - %textarea - ~ - ___ ___ ___ ___ - /\__\ /\ \ /\__\ /\__\ - /:/ / /::\ \ /::| | /:/ / - /:/__/ /:/\:\ \ /:|:| | /:/ / - /::\ \ ___ /::\~\:\ \ /:/|:|__|__ /:/ / - /:/\:\ /\__\ /:/\:\ \:\__\ /:/ |::::\__\ /:/__/ - \/__\:\/:/ / \/__\:\/:/ / \/__/~~/:/ / \:\ \ - \::/ / \::/ / /:/ / \:\ \ - /:/ / /:/ / /:/ / \:\ \ - /:/ / /:/ / /:/ / \:\__\ - \/__/ \/__/ \/__/ \/__/ - - Many - thanks - to - http://www.network-science.de/ascii/ - %strong indeed! .foo ~ 13 ~ ['a', 'b', 'c'].map do |a| - "" -%pre - ~ - foo - bar #whitespace_test = render :file => "_text_area.haml", :locals => { :value => "Oneline" } = render :file => "_text_area.haml", :locals => { :value => "Two\nlines" }