Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Access tag attributes via tag[key] in addition to tag.attr[key] (Davi…

…d Chelimsky and Corey Haines)
  • Loading branch information...
commit 5c717b3983982ab153fc2c62fc5452698f0d6475 1 parent a395113
@dchelimsky authored
Showing with 11 additions and 0 deletions.
  1. +5 −0 lib/radius.rb
  2. +6 −0 test/radius_test.rb
View
5 lib/radius.rb
@@ -210,6 +210,11 @@ def missing!
def render(tag, attributes = {}, &block)
@context.render_tag(tag, attributes, &block)
end
+
+ # Shortcut for accessing tag.attr[key]
+ def [](key)
+ attr[key]
+ end
end
#
View
6 test/radius_test.rb
@@ -197,6 +197,12 @@ def test_parse_tag__binding_render_tag
define_tag('hello') { |tag| tag.render('test', tag.attr) }
assert_parse_output 'Hello John!', '<r:hello name="John" />'
end
+
+ def test_accessing_tag_attributes_through_tag_indexer
+ define_tag('test') { |tag| "Hello #{tag['name']}!" }
+ assert_parse_output 'Hello John!', '<r:test name="John" />'
+ end
+
def test_parse_tag__binding_render_tag_with_block
define_tag('test') { |tag| "Hello #{tag.expand}!" }
define_tag('hello') { |tag| tag.render('test') { tag.expand } }
Please sign in to comment.
Something went wrong with that request. Please try again.