Added tabulation-management methods too Haml::Helpers.

git-svn-id: svn://hamptoncatlin.com/haml/branches/edge@129 7063305b-7217-0410-af8c-cdc13e5119b9
This commit is contained in:
nex3 2006-11-08 03:27:37 +00:00
parent 35207a6340
commit 758aee4653
4 changed files with 44 additions and 0 deletions

View File

@ -30,5 +30,24 @@ module Haml
def list_of(array) # :yields: item
(array.collect { |i| "<li>#{yield(i)}</li>" }).join("\n")
end
# Increments the tabulation modifier of the buffer. This is the
# number of tabs the buffer automatically adds to the lines of the
# template.
def tab_up(i = 1)
buffer.tabulation += i
end
# Decrements the tabulation modifier of the buffer. This is the
# number of tabs the buffer automatically adds to the lines of the
# template.
def tab_down(i = 1)
buffer.tabulation -= i
end
# Gets a reference to the current Haml::Buffer object.
def buffer # :nodoc:
@haml_stack[-1]
end
end
end

View File

@ -6,6 +6,10 @@ require File.dirname(__FILE__) + '/../lib/haml/helpers'
class HelperTest < Test::Unit::TestCase
include Haml::Helpers
def render(text, options = {})
Haml::Engine.new(text, options).to_html
end
def test_flatten
assert_equal(flatten("FooBar"), "FooBar")
@ -21,4 +25,12 @@ class HelperTest < Test::Unit::TestCase
assert_equal("<li>1</li>\n<li>2</li>", (list_of([1, 2]) { |i| i.to_s}))
assert_equal("<li>1</li>", (list_of([[1]]) { |i| i.first}))
end
def test_buffer_access
assert(render("= buffer") =~ /#<Haml::Buffer:0x[a-z0-9]+>/)
end
def test_tabs
assert_equal(render("foo\n- tab_up\nbar\n- tab_down\nbaz"), "foo\n bar\nbaz\n")
end
end

View File

@ -23,3 +23,9 @@
man.
</p>
</div>
<p>foo</p>
<p>
reeeeeeeeeeeeeeeeeeeeeeeeeeeeeeally loooooooooooooooooong
</p>
<p>baz</p>
<p>boom</p>

View File

@ -8,3 +8,10 @@
man.
- 3.times do
= foo
%p foo
- tab_up
%p reeeeeeeeeeeeeeeeeeeeeeeeeeeeeeally loooooooooooooooooong
- tab_down
%p baz
- buffer.tabulation = 10
%p boom