aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCarlos Antonio da Silva <carlosantoniodasilva@gmail.com>2012-01-12 20:06:34 -0200
committerCarlos Antonio da Silva <carlosantoniodasilva@gmail.com>2012-01-12 20:06:34 -0200
commit4be6544cbc4e7e9e4e0a4b9712d34a2744ce9c16 (patch)
treedee8607a16555acd99c1a4cd541f90ff238ee351
parent4e33fbebf84055170917d471c8368b042917c59c (diff)
downloadrails-4be6544cbc4e7e9e4e0a4b9712d34a2744ce9c16.tar.gz
rails-4be6544cbc4e7e9e4e0a4b9712d34a2744ce9c16.tar.bz2
rails-4be6544cbc4e7e9e4e0a4b9712d34a2744ce9c16.zip
Split tag options helper in smaller methods
-rw-r--r--actionpack/lib/action_view/helpers/tag_helper.rb30
1 files changed, 21 insertions, 9 deletions
diff --git a/actionpack/lib/action_view/helpers/tag_helper.rb b/actionpack/lib/action_view/helpers/tag_helper.rb
index 93a3c40683..4b5d97efe8 100644
--- a/actionpack/lib/action_view/helpers/tag_helper.rb
+++ b/actionpack/lib/action_view/helpers/tag_helper.rb
@@ -134,23 +134,35 @@ module ActionView
options.each_pair do |key, value|
if key.to_s == 'data' && value.is_a?(Hash)
value.each do |k, v|
- if !v.is_a?(String) && !v.is_a?(Symbol)
- v = v.to_json
- end
- v = ERB::Util.html_escape(v) if escape
- attrs << %(data-#{k.to_s.dasherize}="#{v}")
+ attrs << data_tag_option(k, v, escape)
end
elsif BOOLEAN_ATTRIBUTES.include?(key)
- attrs << %(#{key}="#{key}") if value
+ attrs << boolean_tag_option(key, value) if value
elsif !value.nil?
- final_value = value.is_a?(Array) ? value.join(" ") : value
- final_value = ERB::Util.html_escape(final_value) if escape
- attrs << %(#{key}="#{final_value}")
+ attrs << tag_option(key, value, escape)
end
end
" #{attrs.sort * ' '}".html_safe unless attrs.empty?
end
end
+
+ def data_tag_option(k, v, escape)
+ if !v.is_a?(String) && !v.is_a?(Symbol)
+ v = v.to_json
+ end
+ v = ERB::Util.html_escape(v) if escape
+ %(data-#{k.to_s.dasherize}="#{v}")
+ end
+
+ def boolean_tag_option(key, value)
+ %(#{key}="#{key}")
+ end
+
+ def tag_option(key, value, escape)
+ final_value = value.is_a?(Array) ? value.join(" ") : value
+ final_value = ERB::Util.html_escape(final_value) if escape
+ %(#{key}="#{final_value}")
+ end
end
end
end