Skip to content

Commit

Permalink
Drop a string conversion from the often-called tag_options helper
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremy committed Jun 7, 2008
1 parent 78a0cca commit 3f89b57
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions actionpack/lib/action_view/helpers/tag_helper.rb
@@ -1,5 +1,6 @@
require 'cgi'
require 'erb'
require 'set'

module ActionView
module Helpers #:nodoc:
Expand All @@ -8,7 +9,8 @@ module Helpers #:nodoc:
module TagHelper
include ERB::Util

BOOLEAN_ATTRIBUTES = Set.new(%w(disabled readonly multiple))
BOOLEAN_ATTRIBUTES = %w(disabled readonly multiple).to_set
BOOLEAN_ATTRIBUTES.merge(BOOLEAN_ATTRIBUTES.map(&:to_sym))

# Returns an empty HTML tag of type +name+ which by default is XHTML
# compliant. Set +open+ to true to create an open tag compatible
Expand Down Expand Up @@ -37,7 +39,7 @@ module TagHelper
# tag("img", { :src => "open & shut.png" }, false, false)
# # => <img src="open &amp; shut.png" />
def tag(name, options = nil, open = false, escape = true)
"<#{name}#{tag_options(options, escape) if options}" + (open ? ">" : " />")
"<#{name}#{tag_options(options, escape) if options}#{open ? ">" : " />"}"
end

# Returns an HTML block tag of type +name+ surrounding the +content+. Add
Expand Down Expand Up @@ -114,7 +116,6 @@ def tag_options(options, escape = true)
if escape
options.each do |key, value|
next unless value
key = key.to_s
value = BOOLEAN_ATTRIBUTES.include?(key) ? key : escape_once(value)
attrs << %(#{key}="#{value}")
end
Expand Down

0 comments on commit 3f89b57

Please sign in to comment.