mirror of
https://github.com/haml/haml.git
synced 2022-11-09 12:33:31 -05:00
Added tests & documentation for the extended square brackets syntax
This commit is contained in:
parent
15332d55ce
commit
edd2d48241
2 changed files with 12 additions and 2 deletions
|
@ -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>
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue