mirror of https://github.com/rails/rails
Remove more potential clashes with asset methods and resource routes. Closes #9928 [gbuesing]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7976 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
parent
3facc8578b
commit
62fd6532e5
|
@ -1,5 +1,7 @@
|
|||
*SVN*
|
||||
|
||||
* Make sure resource routes don't clash with internal helpers like javascript_path, image_path etc. #9928 [gbuesing]
|
||||
|
||||
* caches_page uses a single after_filter instead of one per action. #9891 [lifofifo]
|
||||
|
||||
* Update Prototype to 1.6.0_rc1 and script.aculo.us to 1.8.0 preview 0. [sam, madrobby]
|
||||
|
|
|
@ -90,6 +90,7 @@ module ActionView
|
|||
def javascript_path(source)
|
||||
compute_public_path(source, 'javascripts', 'js')
|
||||
end
|
||||
alias_method :path_to_javascript, :javascript_path # aliased to avoid conflicts with a javascript_path named route
|
||||
|
||||
JAVASCRIPT_DEFAULT_SOURCES = ['prototype', 'effects', 'dragdrop', 'controls'] unless const_defined?(:JAVASCRIPT_DEFAULT_SOURCES)
|
||||
@@javascript_default_sources = JAVASCRIPT_DEFAULT_SOURCES.dup
|
||||
|
@ -190,11 +191,11 @@ module ActionView
|
|||
end
|
||||
|
||||
content_tag("script", "", {
|
||||
"type" => Mime::JS, "src" => javascript_path(joined_javascript_name)
|
||||
"type" => Mime::JS, "src" => path_to_javascript(joined_javascript_name)
|
||||
}.merge(options))
|
||||
else
|
||||
expand_javascript_sources(sources).collect do |source|
|
||||
content_tag("script", "", { "type" => Mime::JS, "src" => javascript_path(source) }.merge(options))
|
||||
content_tag("script", "", { "type" => Mime::JS, "src" => path_to_javascript(source) }.merge(options))
|
||||
end.join("\n")
|
||||
end
|
||||
end
|
||||
|
@ -225,6 +226,7 @@ module ActionView
|
|||
def stylesheet_path(source)
|
||||
compute_public_path(source, 'stylesheets', 'css')
|
||||
end
|
||||
alias_method :path_to_stylesheet, :stylesheet_path # aliased to avoid conflicts with a stylesheet_path named route
|
||||
|
||||
# Returns a stylesheet link tag for the sources specified as arguments. If
|
||||
# you don't specify an extension, .css will be appended automatically.
|
||||
|
@ -300,14 +302,14 @@ module ActionView
|
|||
|
||||
tag("link", {
|
||||
"rel" => "stylesheet", "type" => Mime::CSS, "media" => "screen",
|
||||
"href" => html_escape(stylesheet_path(joined_stylesheet_name))
|
||||
"href" => html_escape(path_to_stylesheet(joined_stylesheet_name))
|
||||
}.merge(options), false, false)
|
||||
else
|
||||
options.delete("cache")
|
||||
|
||||
expand_stylesheet_sources(sources).collect do |source|
|
||||
tag("link", {
|
||||
"rel" => "stylesheet", "type" => Mime::CSS, "media" => "screen", "href" => html_escape(stylesheet_path(source))
|
||||
"rel" => "stylesheet", "type" => Mime::CSS, "media" => "screen", "href" => html_escape(path_to_stylesheet(source))
|
||||
}.merge(options), false, false)
|
||||
end.join("\n")
|
||||
end
|
||||
|
|
|
@ -70,6 +70,12 @@ class AssetTagHelperTest < Test::Unit::TestCase
|
|||
%(javascript_path("/super/xmlhr.js")) => %(/super/xmlhr.js)
|
||||
}
|
||||
|
||||
PathToJavascriptToTag = {
|
||||
%(path_to_javascript("xmlhr")) => %(/javascripts/xmlhr.js),
|
||||
%(path_to_javascript("super/xmlhr")) => %(/javascripts/super/xmlhr.js),
|
||||
%(path_to_javascript("/super/xmlhr.js")) => %(/super/xmlhr.js)
|
||||
}
|
||||
|
||||
JavascriptIncludeToTag = {
|
||||
%(javascript_include_tag("xmlhr")) => %(<script src="/javascripts/xmlhr.js" type="text/javascript"></script>),
|
||||
%(javascript_include_tag("xmlhr.js")) => %(<script src="/javascripts/xmlhr.js" type="text/javascript"></script>),
|
||||
|
@ -88,6 +94,13 @@ class AssetTagHelperTest < Test::Unit::TestCase
|
|||
%(stylesheet_path('/dir/file.rcss')) => %(/dir/file.rcss)
|
||||
}
|
||||
|
||||
PathToStyleToTag = {
|
||||
%(path_to_stylesheet("style")) => %(/stylesheets/style.css),
|
||||
%(path_to_stylesheet("style.css")) => %(/stylesheets/style.css),
|
||||
%(path_to_stylesheet('dir/file')) => %(/stylesheets/dir/file.css),
|
||||
%(path_to_stylesheet('/dir/file.rcss')) => %(/dir/file.rcss)
|
||||
}
|
||||
|
||||
StyleLinkToTag = {
|
||||
%(stylesheet_link_tag("style")) => %(<link href="/stylesheets/style.css" media="screen" rel="stylesheet" type="text/css" />),
|
||||
%(stylesheet_link_tag("style.css")) => %(<link href="/stylesheets/style.css" media="screen" rel="stylesheet" type="text/css" />),
|
||||
|
@ -107,6 +120,13 @@ class AssetTagHelperTest < Test::Unit::TestCase
|
|||
%(image_path("/dir/xml.png")) => %(/dir/xml.png)
|
||||
}
|
||||
|
||||
PathToImageToTag = {
|
||||
%(path_to_image("xml")) => %(/images/xml),
|
||||
%(path_to_image("xml.png")) => %(/images/xml.png),
|
||||
%(path_to_image("dir/xml.png")) => %(/images/dir/xml.png),
|
||||
%(path_to_image("/dir/xml.png")) => %(/dir/xml.png)
|
||||
}
|
||||
|
||||
ImageLinkToTag = {
|
||||
%(image_tag("xml.png")) => %(<img alt="Xml" src="/images/xml.png" />),
|
||||
%(image_tag("rss.gif", :alt => "rss syndication")) => %(<img alt="rss syndication" src="/images/rss.gif" />),
|
||||
|
@ -127,6 +147,10 @@ class AssetTagHelperTest < Test::Unit::TestCase
|
|||
JavascriptPathToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) }
|
||||
end
|
||||
|
||||
def test_path_to_javascript_alias_for_javascript_path
|
||||
PathToJavascriptToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) }
|
||||
end
|
||||
|
||||
def test_javascript_include_tag
|
||||
ENV["RAILS_ASSET_ID"] = ""
|
||||
JavascriptIncludeToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) }
|
||||
|
@ -149,6 +173,10 @@ class AssetTagHelperTest < Test::Unit::TestCase
|
|||
StylePathToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) }
|
||||
end
|
||||
|
||||
def test_path_to_stylesheet_alias_for_stylesheet_path
|
||||
PathToStyleToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) }
|
||||
end
|
||||
|
||||
def test_stylesheet_link_tag
|
||||
ENV["RAILS_ASSET_ID"] = ""
|
||||
StyleLinkToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) }
|
||||
|
@ -159,7 +187,7 @@ class AssetTagHelperTest < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
def test_path_to_image_alias_for_image_path
|
||||
ImagePathToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) }
|
||||
PathToImageToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) }
|
||||
end
|
||||
|
||||
def test_image_tag
|
||||
|
|
Loading…
Reference in New Issue