Added tests & documentation for the extended square brackets syntax

This commit is contained in:
Stefano Cobianchi 2008-04-10 12:37:22 +02:00
parent 15332d55ce
commit edd2d48241
2 changed files with 12 additions and 2 deletions

View File

@ -221,6 +221,8 @@ $LOAD_PATH << dir unless $LOAD_PATH.include?(dir)
# and the id is set to the object's class, followed by its id.
# Because the id of an object is normally an obscure implementation detail,
# this is most useful for elements that represent instances of Models.
# Additionally, the second argument (if present) will be used as a prefix for
# both the id and class attributes.
# For example:
#
# # file: app/controllers/users_controller.rb
@ -231,13 +233,13 @@ $LOAD_PATH << dir unless $LOAD_PATH.include?(dir)
#
# -# file: app/views/users/show.haml
#
# %div[@user]
# %div[@user, :greeting]
# %bar[290]/
# Hello!
#
# is compiled to:
#
# <div class="crazy_user" id="crazy_user_15">
# <div class="greeting_crazy_user" id="greeting_crazy_user_15">
# <bar class="fixnum" id="fixnum_581" />
# Hello!
# </div>

View File

@ -234,6 +234,14 @@ class EngineTest < Test::Unit::TestCase
foo[0] = Struct.new('Foo', :id).new
assert_equal("<p class='struct_foo' id='struct_foo_new'>New User]</p>\n",
render("%p[foo[0]] New User]", :locals => {:foo => foo}))
assert_equal("<p class='prefix_struct_foo' id='prefix_struct_foo_new'>New User]</p>\n",
render("%p[foo[0], :prefix] New User]", :locals => {:foo => foo}))
foo[0].id = 1
assert_equal("<p class='struct_foo' id='struct_foo_1'>New User]</p>\n",
render("%p[foo[0]] New User]", :locals => {:foo => foo}))
assert_equal("<p class='prefix_struct_foo' id='prefix_struct_foo_1'>New User]</p>\n",
render("%p[foo[0], :prefix] New User]", :locals => {:foo => foo}))
end
def test_empty_attrs