Skip to content
Browse files

Allow nested hash hierarchies for "data" option

e.g. :data => {:dojo => {:type => xxx, :props => yyy}}
  • Loading branch information...
1 parent d980b11 commit 25eb60de145794f7e2ff959b15733460907d5ff6 @agios agios committed Feb 14, 2012
Showing with 4 additions and 0 deletions.
  1. +4 −0 padrino-helpers/lib/padrino-helpers/tag_helpers.rb
View
4 padrino-helpers/lib/padrino-helpers/tag_helpers.rb
@@ -195,6 +195,10 @@ def tag_options(options)
options.each do |attribute, value|
next if value.nil? || value == false
if attribute == :data && value.is_a?(Hash)
+ while sub = value.detect{|k, v| v.is_a?(Hash)} do #Recurse through sub hashes
+ sub[1].each { |k, v| value["#{sub[0].to_s.dasherize}-#{k.to_s.dasherize}"] = v }
+ value.delete(sub[0])
+ end
value.each { |k, v| attributes << %[data-#{k.to_s.dasherize}="#{escape_value(v)}"] }
elsif BOOLEAN_ATTRIBUTES.include?(attribute)
attributes << attribute.to_s

0 comments on commit 25eb60d

Please sign in to comment.
Something went wrong with that request. Please try again.