Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Allow nested hashes for "data" property in tag helper #787

Merged
merged 6 commits into from

2 participants

Alexandros Giouzenis Davide D'Agostino
Alexandros Giouzenis

e.g. :data => {:dojo => {:type => xxx, :props => yyy}}

Alexandros Giouzenis agios Allow nested hash hierarchies for "data" option
e.g. :data => {:dojo => {:type => xxx, :props => yyy}}
25eb60d
Davide D'Agostino
Owner

Can you add some test?

Thank you man!

Alexandros Giouzenis

Tests added, sorry I could not get around it sooner

Davide D'Agostino
Owner

@nesquena can you review this and merge for 10.6?

Davide D'Agostino DAddYE merged commit 8173344 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 14, 2012
  1. Alexandros Giouzenis

    Allow nested hash hierarchies for "data" option

    agios authored
    e.g. :data => {:dojo => {:type => xxx, :props => yyy}}
Commits on Mar 7, 2012
  1. Alexandros Giouzenis
  2. Alexandros Giouzenis

    Merge remote-tracking branch 'upstream/master'

    agios authored
    Conflicts:
    	padrino-helpers/test/test_tag_helpers.rb
  3. Alexandros Giouzenis

    Added necessary requires

    agios authored
  4. Alexandros Giouzenis
  5. Alexandros Giouzenis
This page is out of date. Refresh to see the latest.
6 Rakefile
View
@@ -92,7 +92,11 @@ task :test do
# Omit the padrino metagem since no tests there
GEM_PATHS[0..-2].each do |g|
# Hardcode the 'cd' into the command and do not use Dir.chdir because this causes random tests to fail
- sh "cd #{File.join(ROOT, g)} && #{Gem.ruby} -S rake test"
+ begin
+ sh "cd #{File.join(ROOT, g)} && #{Gem.ruby} -S rake test"
+ rescue RuntimeError
+ #Don't stop tests if one fails
+ end
end
end
4 padrino-helpers/lib/padrino-helpers/tag_helpers.rb
View
@@ -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
3  padrino-helpers/test/test_number_helpers.rb
View
@@ -1,3 +1,6 @@
+require File.expand_path(File.dirname(__FILE__) + '/helper')
+require File.expand_path(File.dirname(__FILE__) + '/fixtures/markup_app/app')
+
describe "NumberHelpers" do
include Padrino::Helpers::NumberHelpers
5 padrino-helpers/test/test_tag_helpers.rb
View
@@ -26,6 +26,11 @@ def app
assert_has_tag(:a, 'data-remote' => 'true', 'data-method' => 'post') { actual_html }
end
+ should "support nested data attributes" do
+ actual_html = tag(:div, :data => {:dojo => {:type => 'dijit.form.TextBox', :props => 'readOnly: true'}})
+ assert_has_tag(:div, 'data-dojo-type' => 'dijit.form.TextBox', 'data-dojo-props' => 'readOnly: true') { actual_html }
+ end
+
should "support open tags" do
actual_html = tag(:p, { :class => 'demo' }, true)
assert_equal "<p class=\"demo\">", actual_html
Something went wrong with that request. Please try again.