Permalink
Browse files

Split tag options helper in smaller methods

  • Loading branch information...
1 parent 4e33fbe commit 4be6544cbc4e7e9e4e0a4b9712d34a2744ce9c16 @carlosantoniodasilva carlosantoniodasilva committed Jan 12, 2012
Showing with 21 additions and 9 deletions.
  1. +21 −9 actionpack/lib/action_view/helpers/tag_helper.rb
@@ -134,23 +134,35 @@ def tag_options(options, escape = true)
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

0 comments on commit 4be6544

Please sign in to comment.