From 4be6544cbc4e7e9e4e0a4b9712d34a2744ce9c16 Mon Sep 17 00:00:00 2001 From: Carlos Antonio da Silva Date: Thu, 12 Jan 2012 20:06:34 -0200 Subject: Split tag options helper in smaller methods --- actionpack/lib/action_view/helpers/tag_helper.rb | 30 +++++++++++++++++------- 1 file 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 -- cgit v1.2.3