Get rid of one trailing newline when preserve-ing text.

This commit is contained in:
Nathan Weizenbaum 2008-05-10 22:00:19 -07:00
parent d085523f19
commit ad2ed968de
4 changed files with 16 additions and 16 deletions

View File

@ -84,7 +84,7 @@ module Haml
def preserve(input = '', &block)
return preserve(capture_haml(&block)) if block
input.gsub(/\n/, '
').gsub(/\r/, '')
input.chomp("\n").gsub(/\n/, '
').gsub(/\r/, '')
end
alias_method :flatten, :preserve

View File

@ -141,12 +141,12 @@ class HelperTest < Test::Unit::TestCase
end
def test_find_and_preserve_with_block
assert_equal("<pre>&#x000A; Foo&#x000A; Bar&#x000A;</pre>\nFoo\nBar\n",
assert_equal("<pre>&#x000A; Foo&#x000A; Bar</pre>\nFoo\nBar\n",
render("= find_and_preserve do\n %pre\n Foo\n Bar\n Foo\n Bar"))
end
def test_preserve_with_block
assert_equal("<pre>&#x000A; Foo&#x000A; Bar&#x000A;</pre>&#x000A;Foo&#x000A;Bar&#x000A;\n",
assert_equal("<pre>&#x000A; Foo&#x000A; Bar&#x000A;</pre>&#x000A;Foo&#x000A;Bar\n",
render("= preserve do\n %pre\n Foo\n Bar\n Foo\n Bar"))
end

View File

@ -41,8 +41,8 @@ This
\\
<p>
<pre>
This pre is pretty deeply&#x000A; nested.&#x000A; Does interpolation work?&#x000A;
This one is, too.&#x000A;Nested, that is.&#x000A;&#x000A;
This pre is pretty deeply&#x000A; nested.&#x000A; Does interpolation work?
This one is, too.&#x000A;Nested, that is.&#x000A;
</pre>
</p>
<ul>

View File

@ -12,16 +12,16 @@
<div class='text_area_test_area'>
<textarea>Oneline</textarea>
</div>
<textarea>BLAH&#x000A;</textarea>
<textarea>BLAH</textarea>
<div class='text_area_test_area'>
<textarea>Two&#x000A;lines</textarea>
</div>
<textarea>BLAH&#x000A;</textarea>
<textarea>BLAH</textarea>
<div id='flattened'>
<div class='text_area_test_area'>
<textarea>Two&#x000A;lines</textarea>
</div>
<textarea>BLAH&#x000A;</textarea>
<textarea>BLAH</textarea>
</div>
</div>
<div class='hithere'>
@ -36,7 +36,7 @@
</div>
<div class='foo'>
13
<textarea>&#x000A;a&#x000A;</textarea><textarea>&#x000A;b&#x000A;</textarea><textarea>&#x000A;c&#x000A;</textarea>
<textarea>&#x000A;a</textarea><textarea>&#x000A;b</textarea><textarea>&#x000A;c</textarea>
</div>
<div id='whitespace_test'>
<div class='text_area_test_area'>
@ -52,16 +52,16 @@
<div class='text_area_test_area'>
<textarea>Oneline</textarea>
</div>
<textarea>BLAH&#x000A;</textarea>
<textarea>BLAH</textarea>
<div class='text_area_test_area'>
<textarea>Two&#x000A;lines</textarea>
</div>
<textarea>BLAH&#x000A;</textarea>
<textarea>BLAH</textarea>
<div id='flattened'>
<div class='text_area_test_area'>
<textarea>Two&#x000A;lines</textarea>
</div>
<textarea>BLAH&#x000A;</textarea>
<textarea>BLAH</textarea>
</div>
</div>
<div class='hithere'>
@ -74,11 +74,11 @@
bar
</p>
<pre>
___&#x000A; ,o88888&#x000A; ,o8888888'&#x000A; ,:o:o:oooo. ,8O88Pd8888"&#x000A; ,.::.::o:ooooOoOoO. ,oO8O8Pd888'"&#x000A; ,.:.::o:ooOoOoOO8O8OOo.8OOPd8O8O"&#x000A; , ..:.::o:ooOoOOOO8OOOOo.FdO8O8"&#x000A; , ..:.::o:ooOoOO8O888O8O,COCOO"&#x000A; , . ..:.::o:ooOoOOOO8OOOOCOCO"&#x000A; . ..:.::o:ooOoOoOO8O8OCCCC"o&#x000A; . ..:.::o:ooooOoCoCCC"o:o&#x000A; . ..:.::o:o:,cooooCo"oo:o:&#x000A; ` . . ..:.:cocoooo"'o:o:::'&#x000A; .` . ..::ccccoc"'o:o:o:::'&#x000A; :.:. ,c:cccc"':.:.:.:.:.'&#x000A; ..:.:"'`::::c:"'..:.:.:.:.:.' http://www.chris.com/ASCII/&#x000A; ...:.'.:.::::"' . . . . .'&#x000A; .. . ....:."' ` . . . ''&#x000A; . . . ...."'&#x000A; .. . ."' -hrr-&#x000A; .&#x000A;&#x000A;&#x000A; It's a planet!&#x000A;%strong This shouldn't be bold!&#x000A;
___&#x000A; ,o88888&#x000A; ,o8888888'&#x000A; ,:o:o:oooo. ,8O88Pd8888"&#x000A; ,.::.::o:ooooOoOoO. ,oO8O8Pd888'"&#x000A; ,.:.::o:ooOoOoOO8O8OOo.8OOPd8O8O"&#x000A; , ..:.::o:ooOoOOOO8OOOOo.FdO8O8"&#x000A; , ..:.::o:ooOoOO8O888O8O,COCOO"&#x000A; , . ..:.::o:ooOoOOOO8OOOOCOCO"&#x000A; . ..:.::o:ooOoOoOO8O8OCCCC"o&#x000A; . ..:.::o:ooooOoCoCCC"o:o&#x000A; . ..:.::o:o:,cooooCo"oo:o:&#x000A; ` . . ..:.:cocoooo"'o:o:::'&#x000A; .` . ..::ccccoc"'o:o:o:::'&#x000A; :.:. ,c:cccc"':.:.:.:.:.'&#x000A; ..:.:"'`::::c:"'..:.:.:.:.:.' http://www.chris.com/ASCII/&#x000A; ...:.'.:.::::"' . . . . .'&#x000A; .. . ....:."' ` . . . ''&#x000A; . . . ...."'&#x000A; .. . ."' -hrr-&#x000A; .&#x000A;&#x000A;&#x000A; It's a planet!&#x000A;%strong This shouldn't be bold!
</pre>
<strong>This should!</strong>
<textarea>
___ ___ ___ ___ &#x000A; /\__\ /\ \ /\__\ /\__\&#x000A; /:/ / /::\ \ /::| | /:/ /&#x000A; /:/__/ /:/\:\ \ /:|:| | /:/ / &#x000A; /::\ \ ___ /::\~\:\ \ /:/|:|__|__ /:/ / &#x000A; /:/\:\ /\__\ /:/\:\ \:\__\ /:/ |::::\__\ /:/__/ &#x000A; \/__\:\/:/ / \/__\:\/:/ / \/__/~~/:/ / \:\ \ &#x000A; \::/ / \::/ / /:/ / \:\ \ &#x000A; /:/ / /:/ / /:/ / \:\ \ &#x000A; /:/ / /:/ / /:/ / \:\__\&#x000A; \/__/ \/__/ \/__/ \/__/&#x000A;&#x000A; Many&#x000A; thanks&#x000A; to&#x000A; http://www.network-science.de/ascii/&#x000A;
___ ___ ___ ___ &#x000A; /\__\ /\ \ /\__\ /\__\&#x000A; /:/ / /::\ \ /::| | /:/ /&#x000A; /:/__/ /:/\:\ \ /:|:| | /:/ / &#x000A; /::\ \ ___ /::\~\:\ \ /:/|:|__|__ /:/ / &#x000A; /:/\:\ /\__\ /:/\:\ \:\__\ /:/ |::::\__\ /:/__/ &#x000A; \/__\:\/:/ / \/__\:\/:/ / \/__/~~/:/ / \:\ \ &#x000A; \::/ / \::/ / /:/ / \:\ \ &#x000A; /:/ / /:/ / /:/ / \:\ \ &#x000A; /:/ / /:/ / /:/ / \:\__\&#x000A; \/__/ \/__/ \/__/ \/__/&#x000A;&#x000A; Many&#x000A; thanks&#x000A; to&#x000A; http://www.network-science.de/ascii/
<strong>indeed!</strong>
</textarea>
</div>
@ -86,9 +86,9 @@
13
</div>
<pre>
__ ______ __ ______&#x000A;.----.| |--.|__ |.----.| |--..--------.| __ |&#x000A;| __|| ||__ || __|| < | || __ |&#x000A;|____||__|__||______||____||__|__||__|__|__||______|&#x000A;
__ ______ __ ______&#x000A;.----.| |--.|__ |.----.| |--..--------.| __ |&#x000A;| __|| ||__ || __|| < | || __ |&#x000A;|____||__|__||______||____||__|__||__|__|__||______|
</pre>
<pre>
foo&#x000A;
foo
bar
</pre>