1
0
Fork 0
mirror of https://github.com/haml/haml.git synced 2022-11-09 12:33:31 -05:00

A slight tweak to the behavior of capture_haml.

git-svn-id: svn://hamptoncatlin.com/haml/branches/edge@162 7063305b-7217-0410-af8c-cdc13e5119b9
This commit is contained in:
nex3 2006-11-20 06:46:44 +00:00
parent 53b68c335f
commit 899c06c1c0
3 changed files with 35 additions and 14 deletions

View file

@ -60,9 +60,12 @@ module Haml
buffer.tabulation -= i buffer.tabulation -= i
end end
# Captures the result of the given block of Haml code and returns # Captures the result of the given block of Haml code,
# them as a string. For example, after the following, # gets rid of the excess indentation,
# and returns it as a string.
# For example, after the following,
# #
# .foo
# - foo = capture_haml(13) do |a| # - foo = capture_haml(13) do |a|
# %p= a # %p= a
# #
@ -73,7 +76,19 @@ module Haml
block.call(*args) block.call(*args)
buffer_buffer.slice!(position..-1) captured = buffer_buffer.slice!(position..-1)
min_tabs = nil
captured.each do |line|
tabs = line.index(/[^ ]/)
min_tabs ||= tabs
min_tabs = min_tabs > tabs ? tabs : min_tabs
end
result = captured.map do |line|
line[min_tabs..-1]
end
result.to_s
end end
# Gets a reference to the current Haml::Buffer object. # Gets a reference to the current Haml::Buffer object.

View file

@ -27,11 +27,15 @@
<p> <p>
reeeeeeeeeeeeeeeeeeeeeeeeeeeeeeally loooooooooooooooooong reeeeeeeeeeeeeeeeeeeeeeeeeeeeeeally loooooooooooooooooong
</p> </p>
<div class='woah'>
<div id='funky'>
<div> <div>
<h1>Big!</h1> <h1>Big!</h1>
<p>Small</p> <p>Small</p>
<!-- Invisible --> <!-- Invisible -->
</div> </div>
</div>
</div>
<p>baz</p> <p>baz</p>
<p>boom</p> <p>boom</p>
foo foo

View file

@ -12,6 +12,8 @@
- tab_up - tab_up
%p reeeeeeeeeeeeeeeeeeeeeeeeeeeeeeally loooooooooooooooooong %p reeeeeeeeeeeeeeeeeeeeeeeeeeeeeeally loooooooooooooooooong
- tab_down - tab_down
.woah
#funky
= capture_haml do = capture_haml do
%div %div
%h1 Big! %h1 Big!