aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_view/helpers/tag_helper.rb
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2005-09-20 07:54:55 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2005-09-20 07:54:55 +0000
commit7f26415d3c0e4101ce1569a499470e8a32dbfede (patch)
treebd1b1db0161dea64945daca530acbf3d09e13cc9 /actionpack/lib/action_view/helpers/tag_helper.rb
parent47292cdef7fe9ca21c749c7fe594457ee1c81de6 (diff)
downloadrails-7f26415d3c0e4101ce1569a499470e8a32dbfede.tar.gz
rails-7f26415d3c0e4101ce1569a499470e8a32dbfede.tar.bz2
rails-7f26415d3c0e4101ce1569a499470e8a32dbfede.zip
Optimized tag_options to not sort keys, which is no longer necessary when assert_dom_equal and friend is available #1995 [skae]. Added assert_dom_equal and assert_dom_not_equal to compare tags generated by the helpers in an order-indifferent manner #1995 [skae]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2271 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack/lib/action_view/helpers/tag_helper.rb')
-rw-r--r--actionpack/lib/action_view/helpers/tag_helper.rb19
1 files changed, 9 insertions, 10 deletions
diff --git a/actionpack/lib/action_view/helpers/tag_helper.rb b/actionpack/lib/action_view/helpers/tag_helper.rb
index 40fd72d23f..8b2d2c3a5a 100644
--- a/actionpack/lib/action_view/helpers/tag_helper.rb
+++ b/actionpack/lib/action_view/helpers/tag_helper.rb
@@ -10,27 +10,26 @@ module ActionView
# Examples:
# * <tt>tag("br") => <br /></tt>
# * <tt>tag("input", { "type" => "text"}) => <input type="text" /></tt>
- def tag(name, options = {}, open = false)
- "<#{name}#{tag_options(options)}" + (open ? ">" : " />")
+ def tag(name, options = nil, open = false)
+ "<#{name}#{tag_options(options.stringify_keys) if options}" + (open ? ">" : " />")
end
# Examples:
# * <tt>content_tag("p", "Hello world!") => <p>Hello world!</p></tt>
# * <tt>content_tag("div", content_tag("p", "Hello world!"), "class" => "strong") => </tt>
# <tt><div class="strong"><p>Hello world!</p></div></tt>
- def content_tag(name, content, options = {})
- "<#{name}#{tag_options(options)}>#{content}</#{name}>"
+ def content_tag(name, content, options = nil)
+ "<#{name}#{tag_options(options.stringify_keys) if options}>#{content}</#{name}>"
end
private
def tag_options(options)
- cleaned_options = options.reject { |key, value| value.nil? }
- unless cleaned_options.empty?
- " " + cleaned_options.symbolize_keys.map { |key, value|
- %(#{key}="#{html_escape(value.to_s)}")
- }.sort.join(" ")
+ if options
+ options.inject("") do |html_str, (key, value)|
+ value.nil? ? html_str : html_str << %( #{key}="#{html_escape(value)}")
+ end
end
end
end
end
-end \ No newline at end of file
+end