Added three helpers to help deal with the too much whitespace.

git-svn-id: svn://hamptoncatlin.com/haml/branches/edge@163 7063305b-7217-0410-af8c-cdc13e5119b9
This commit is contained in:
nex3 2006-11-20 07:03:31 +00:00
parent 899c06c1c0
commit 0daa563fca
3 changed files with 70 additions and 0 deletions

View File

@ -60,6 +60,65 @@ module Haml
buffer.tabulation -= i
end
# Surrounds the given block of Haml code with the given characters,
# with no whitespace in between.
# For example,
#
# = surround '(', ')' do
# %a{:href => "food"} chicken
#
# makes
#
# (<a href='food'>chicken</a>)
#
# and
#
# = surround '*' do
# %strong angry
#
# makes
#
# *<strong>angry</strong>*
#
def surround(front, back = nil, &block)
back ||= front
output = capture_haml(&block)
"#{front}#{output.chomp}#{back}\n"
end
# Prepends the given character to the beginning of the Haml block,
# with no whitespace between.
# For example:
#
# = precede '*' do
# %span.small Not really
#
# compiles to
#
# *<span class='small'>Not really</span>
#
def precede(char, &block)
"#{char}#{capture_haml(&block).chomp}\n"
end
# Appends the given character to the end of the Haml block,
# with no whitespace between.
# For example:
#
# click
# = succeed '.' do
# %a{:href=>"thing"} here
#
# compiles to
#
# click
# <a href='thing'>here</a>.
#
def succeed(char, &block)
"#{capture_haml(&block).chomp}#{char}\n"
end
# Captures the result of the given block of Haml code,
# gets rid of the excess indentation,
# and returns it as a string.

View File

@ -35,7 +35,11 @@
<!-- Invisible -->
</div>
</div>
(<strong>parentheses!</strong>)
</div>
*<span class='small'>Not really</span>
click
<a href='thing'>here</a>.
<p>baz</p>
<p>boom</p>
foo

View File

@ -19,6 +19,13 @@
%h1 Big!
%p Small
/ Invisible
= surround '(', ')' do
%strong parentheses!
= precede '*' do
%span.small Not really
click
= succeed '.' do
%a{:href=>"thing"} here
%p baz
- buffer.tabulation = 10
%p boom