Permalink
Browse files

Refactor and improve readability

  • Loading branch information...
1 parent 4be6544 commit 8bc065ee654b3917b9e058c92b649672cec5c2dd @carlosantoniodasilva carlosantoniodasilva committed Jan 12, 2012
Showing with 7 additions and 8 deletions.
  1. +7 −8 actionpack/lib/action_view/helpers/tag_helper.rb
@@ -125,7 +125,8 @@ def escape_once(html)
def content_tag_string(name, content, options, escape = true)
tag_options = tag_options(options, escape) if options
- "<#{name}#{tag_options}>#{escape ? ERB::Util.h(content) : content}</#{name}>".html_safe
+ content = ERB::Util.h(content) if escape
+ "<#{name}#{tag_options}>#{content}</#{name}>".html_safe
end
def tag_options(options, escape = true)
@@ -147,10 +148,8 @@ def tag_options(options, escape = true)
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
+ v = v.to_json if !v.is_a?(String) && !v.is_a?(Symbol)
+ v = ERB::Util.h(v) if escape
%(data-#{k.to_s.dasherize}="#{v}")
end
@@ -159,9 +158,9 @@ def boolean_tag_option(key, value)
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}")
+ value = value.join(" ") if value.is_a?(Array)
+ value = ERB::Util.h(value) if escape
+ %(#{key}="#{value}")
end
end
end

0 comments on commit 8bc065e

Please sign in to comment.