From cfcef34bb54bce0cda77da4ae99774fa501ab713 Mon Sep 17 00:00:00 2001 From: Stephen Celis & Xavier Noria Date: Mon, 18 Oct 2010 21:01:57 -0500 Subject: [PATCH] Additional documentation for data-* attributes. Signed-off-by: Xavier Noria --- .../lib/action_view/helpers/tag_helper.rb | 27 ++++++++++++------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/actionpack/lib/action_view/helpers/tag_helper.rb b/actionpack/lib/action_view/helpers/tag_helper.rb index 7dd3a27a5d..2f29c8f0e6 100644 --- a/actionpack/lib/action_view/helpers/tag_helper.rb +++ b/actionpack/lib/action_view/helpers/tag_helper.rb @@ -24,13 +24,20 @@ module ActionView # escaping. # # ==== Options - # Use +true+ with boolean attributes that can render with no value (like - # +disabled+ and +readonly+). + # Use +true+ with boolean attributes that can render with no value, like + # +disabled+ and +readonly+. # - # HTML5 data-* attributes can be set with a single +data+ key and a hash - # value of sub-attributes. Sub-attribute keys will be dasherized. + # HTML5 data-* attributes can be set with a single +data+ key + # pointing to a hash of sub-attributes. # - # You can use symbols or strings for the attribute names. + # Sub-attribute keys may be strings or symbols. To play nicely with + # JavaScript conventions +dataset+ they will be dasherized so that a key + # +user_id+ would render as data-user-id and thus accessed as + # dataset.userId. + # + # Values are encoded to JSON, with the exception of strings and symbols. + # This may come in handy when using jQuery's HTML5-aware .data() + # from 1.4.3. # # ==== Examples # tag("br") @@ -39,17 +46,17 @@ module ActionView # tag("br", nil, true) # # =>
# - # tag("input", { :type => 'text', :disabled => true }) + # tag("input", :type => 'text', :disabled => true) # # => # - # tag("img", { :src => "open & shut.png" }) + # tag("img", :src => "open & shut.png") # # => # - # tag("img", { :src => "open & shut.png" }, false, false) + # tag("img", {:src => "open & shut.png"}, false, false) # # => # - # tag("div", { :data => { :name => 'Stephen', :city_state => %w(Chicago IL) } }) - # # =>
+ # tag("div", :data => {:name => 'Stephen', :city_state => %w(Chicago IL)}) + # # =>
def tag(name, options = nil, open = false, escape = true) "<#{name}#{tag_options(options, escape) if options}#{open ? ">" : " />"}".html_safe end