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:
parent
899c06c1c0
commit
0daa563fca
|
@ -60,6 +60,65 @@ module Haml
|
||||||
buffer.tabulation -= i
|
buffer.tabulation -= i
|
||||||
end
|
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,
|
# Captures the result of the given block of Haml code,
|
||||||
# gets rid of the excess indentation,
|
# gets rid of the excess indentation,
|
||||||
# and returns it as a string.
|
# and returns it as a string.
|
||||||
|
|
|
@ -35,7 +35,11 @@
|
||||||
<!-- Invisible -->
|
<!-- Invisible -->
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
(<strong>parentheses!</strong>)
|
||||||
</div>
|
</div>
|
||||||
|
*<span class='small'>Not really</span>
|
||||||
|
click
|
||||||
|
<a href='thing'>here</a>.
|
||||||
<p>baz</p>
|
<p>baz</p>
|
||||||
<p>boom</p>
|
<p>boom</p>
|
||||||
foo
|
foo
|
||||||
|
|
|
@ -19,6 +19,13 @@
|
||||||
%h1 Big!
|
%h1 Big!
|
||||||
%p Small
|
%p Small
|
||||||
/ Invisible
|
/ Invisible
|
||||||
|
= surround '(', ')' do
|
||||||
|
%strong parentheses!
|
||||||
|
= precede '*' do
|
||||||
|
%span.small Not really
|
||||||
|
click
|
||||||
|
= succeed '.' do
|
||||||
|
%a{:href=>"thing"} here
|
||||||
%p baz
|
%p baz
|
||||||
- buffer.tabulation = 10
|
- buffer.tabulation = 10
|
||||||
%p boom
|
%p boom
|
||||||
|
|
Loading…
Reference in New Issue