提交 e484d4ae 编写于 作者: D Denis Odorcic 提交者: José Valim

Made asset_tag_helper use config.perform_caching instead of ActionController::Base.perform_caching

Signed-off-by: NJosé Valim <jose.valim@gmail.com>
上级 b8f7ba29
......@@ -242,12 +242,12 @@ def javascript_path(source)
# == Caching multiple javascripts into one
#
# You can also cache multiple javascripts into one file, which requires less HTTP connections to download and can better be
# compressed by gzip (leading to faster transfers). Caching will only happen if ActionController::Base.perform_caching
# compressed by gzip (leading to faster transfers). Caching will only happen if config.perform_caching
# is set to <tt>true</tt> (which is the case by default for the Rails production environment, but not for the development
# environment).
#
# ==== Examples
# javascript_include_tag :all, :cache => true # when ActionController::Base.perform_caching is false =>
# javascript_include_tag :all, :cache => true # when config.perform_caching is false =>
# <script type="text/javascript" src="/javascripts/prototype.js"></script>
# <script type="text/javascript" src="/javascripts/effects.js"></script>
# ...
......@@ -255,15 +255,15 @@ def javascript_path(source)
# <script type="text/javascript" src="/javascripts/shop.js"></script>
# <script type="text/javascript" src="/javascripts/checkout.js"></script>
#
# javascript_include_tag :all, :cache => true # when ActionController::Base.perform_caching is true =>
# javascript_include_tag :all, :cache => true # when config.perform_caching is true =>
# <script type="text/javascript" src="/javascripts/all.js"></script>
#
# javascript_include_tag "prototype", "cart", "checkout", :cache => "shop" # when ActionController::Base.perform_caching is false =>
# javascript_include_tag "prototype", "cart", "checkout", :cache => "shop" # when config.perform_caching is false =>
# <script type="text/javascript" src="/javascripts/prototype.js"></script>
# <script type="text/javascript" src="/javascripts/cart.js"></script>
# <script type="text/javascript" src="/javascripts/checkout.js"></script>
#
# javascript_include_tag "prototype", "cart", "checkout", :cache => "shop" # when ActionController::Base.perform_caching is true =>
# javascript_include_tag "prototype", "cart", "checkout", :cache => "shop" # when config.perform_caching is true =>
# <script type="text/javascript" src="/javascripts/shop.js"></script>
#
# The <tt>:recursive</tt> option is also available for caching:
......@@ -275,11 +275,11 @@ def javascript_include_tag(*sources)
cache = concat || options.delete("cache")
recursive = options.delete("recursive")
if concat || (ActionController::Base.perform_caching && cache)
if concat || (config.perform_caching && cache)
joined_javascript_name = (cache == true ? "all" : cache) + ".js"
joined_javascript_path = File.join(joined_javascript_name[/^#{File::SEPARATOR}/] ? config.assets_dir : config.javascripts_dir, joined_javascript_name)
unless ActionController::Base.perform_caching && File.exists?(joined_javascript_path)
unless config.perform_caching && File.exists?(joined_javascript_path)
write_asset_file_contents(joined_javascript_path, compute_javascript_paths(sources, recursive))
end
javascript_src_tag(joined_javascript_name, options)
......@@ -390,25 +390,25 @@ def stylesheet_path(source)
# == Caching multiple stylesheets into one
#
# You can also cache multiple stylesheets into one file, which requires less HTTP connections and can better be
# compressed by gzip (leading to faster transfers). Caching will only happen if ActionController::Base.perform_caching
# compressed by gzip (leading to faster transfers). Caching will only happen if config.perform_caching
# is set to true (which is the case by default for the Rails production environment, but not for the development
# environment). Examples:
#
# ==== Examples
# stylesheet_link_tag :all, :cache => true # when ActionController::Base.perform_caching is false =>
# stylesheet_link_tag :all, :cache => true # when config.perform_caching is false =>
# <link href="/stylesheets/style1.css" media="screen" rel="stylesheet" type="text/css" />
# <link href="/stylesheets/styleB.css" media="screen" rel="stylesheet" type="text/css" />
# <link href="/stylesheets/styleX2.css" media="screen" rel="stylesheet" type="text/css" />
#
# stylesheet_link_tag :all, :cache => true # when ActionController::Base.perform_caching is true =>
# stylesheet_link_tag :all, :cache => true # when config.perform_caching is true =>
# <link href="/stylesheets/all.css" media="screen" rel="stylesheet" type="text/css" />
#
# stylesheet_link_tag "shop", "cart", "checkout", :cache => "payment" # when ActionController::Base.perform_caching is false =>
# stylesheet_link_tag "shop", "cart", "checkout", :cache => "payment" # when config.perform_caching is false =>
# <link href="/stylesheets/shop.css" media="screen" rel="stylesheet" type="text/css" />
# <link href="/stylesheets/cart.css" media="screen" rel="stylesheet" type="text/css" />
# <link href="/stylesheets/checkout.css" media="screen" rel="stylesheet" type="text/css" />
#
# stylesheet_link_tag "shop", "cart", "checkout", :cache => "payment" # when ActionController::Base.perform_caching is true =>
# stylesheet_link_tag "shop", "cart", "checkout", :cache => "payment" # when config.perform_caching is true =>
# <link href="/stylesheets/payment.css" media="screen" rel="stylesheet" type="text/css" />
#
# The <tt>:recursive</tt> option is also available for caching:
......@@ -426,11 +426,11 @@ def stylesheet_link_tag(*sources)
cache = concat || options.delete("cache")
recursive = options.delete("recursive")
if concat || (ActionController::Base.perform_caching && cache)
if concat || (config.perform_caching && cache)
joined_stylesheet_name = (cache == true ? "all" : cache) + ".css"
joined_stylesheet_path = File.join(joined_stylesheet_name[/^#{File::SEPARATOR}/] ? config.assets_dir : config.stylesheets_dir, joined_stylesheet_name)
unless ActionController::Base.perform_caching && File.exists?(joined_stylesheet_path)
unless config.perform_caching && File.exists?(joined_stylesheet_path)
write_asset_file_contents(joined_stylesheet_path, compute_stylesheet_paths(sources, recursive))
end
stylesheet_tag(joined_stylesheet_name, options)
......
......@@ -50,7 +50,7 @@ def host_with_port() 'localhost' end
end
def teardown
ActionController::Base.perform_caching = false
config.perform_caching = false
ENV.delete('RAILS_ASSET_ID')
end
......@@ -422,7 +422,7 @@ def test_caching_image_path_with_caching_and_proc_asset_host_using_request
def test_caching_javascript_include_tag_when_caching_on
ENV["RAILS_ASSET_ID"] = ""
@controller.config.asset_host = 'http://a0.example.com'
ActionController::Base.perform_caching = true
config.perform_caching = true
assert_dom_equal(
%(<script src="http://a0.example.com/javascripts/all.js" type="text/javascript"></script>),
......@@ -454,7 +454,7 @@ def test_caching_javascript_include_tag_when_caching_on
def test_caching_javascript_include_tag_when_caching_on_with_proc_asset_host
ENV['RAILS_ASSET_ID'] = ''
@controller.config.asset_host = Proc.new { |source| "http://a#{source.length}.example.com" }
ActionController::Base.perform_caching = true
config.perform_caching = true
assert_equal '/javascripts/scripts.js'.length, 23
assert_dom_equal(
......@@ -477,7 +477,7 @@ def test_caching_javascript_include_tag_when_caching_on_with_2_argument_proc_ass
"#{request.protocol}assets#{source.length}.example.com"
end
}
ActionController::Base.perform_caching = true
config.perform_caching = true
assert_equal '/javascripts/vanilla.js'.length, 23
assert_dom_equal(
......@@ -517,7 +517,7 @@ def call(source, request)
end
end.new
ActionController::Base.perform_caching = true
config.perform_caching = true
assert_equal '/javascripts/vanilla.js'.length, 23
assert_dom_equal(
......@@ -548,7 +548,7 @@ def ssl?() true end
def test_caching_javascript_include_tag_when_caching_on_and_using_subdirectory
ENV["RAILS_ASSET_ID"] = ""
@controller.config.asset_host = 'http://a%d.example.com'
ActionController::Base.perform_caching = true
config.perform_caching = true
hash = '/javascripts/cache/money.js'.hash % 4
assert_dom_equal(
......@@ -564,7 +564,7 @@ def test_caching_javascript_include_tag_when_caching_on_and_using_subdirectory
def test_caching_javascript_include_tag_with_all_and_recursive_puts_defaults_at_the_start_of_the_file
ENV["RAILS_ASSET_ID"] = ""
@controller.config.asset_host = 'http://a0.example.com'
ActionController::Base.perform_caching = true
config.perform_caching = true
assert_dom_equal(
%(<script src="http://a0.example.com/javascripts/combined.js" type="text/javascript"></script>),
......@@ -585,7 +585,7 @@ def test_caching_javascript_include_tag_with_all_and_recursive_puts_defaults_at_
def test_caching_javascript_include_tag_with_all_puts_defaults_at_the_start_of_the_file
ENV["RAILS_ASSET_ID"] = ""
@controller.config.asset_host = 'http://a0.example.com'
ActionController::Base.perform_caching = true
config.perform_caching = true
assert_dom_equal(
%(<script src="http://a0.example.com/javascripts/combined.js" type="text/javascript"></script>),
......@@ -606,7 +606,7 @@ def test_caching_javascript_include_tag_with_all_puts_defaults_at_the_start_of_t
def test_caching_javascript_include_tag_with_relative_url_root
ENV["RAILS_ASSET_ID"] = ""
@controller.config.relative_url_root = "/collaboration/hieraki"
ActionController::Base.perform_caching = true
config.perform_caching = true
assert_dom_equal(
%(<script src="/collaboration/hieraki/javascripts/all.js" type="text/javascript"></script>),
......@@ -629,7 +629,7 @@ def test_caching_javascript_include_tag_with_relative_url_root
def test_caching_javascript_include_tag_when_caching_off
ENV["RAILS_ASSET_ID"] = ""
ActionController::Base.perform_caching = false
config.perform_caching = false
assert_dom_equal(
%(<script src="/javascripts/prototype.js" type="text/javascript"></script>\n<script src="/javascripts/effects.js" type="text/javascript"></script>\n<script src="/javascripts/dragdrop.js" type="text/javascript"></script>\n<script src="/javascripts/controls.js" type="text/javascript"></script>\n<script src="/javascripts/application.js" type="text/javascript"></script>\n<script src="/javascripts/bank.js" type="text/javascript"></script>\n<script src="/javascripts/robber.js" type="text/javascript"></script>\n<script src="/javascripts/version.1.0.js" type="text/javascript"></script>),
......@@ -658,7 +658,7 @@ def test_caching_javascript_include_tag_when_caching_off
def test_caching_javascript_include_tag_when_caching_on_and_missing_javascript_file
ENV["RAILS_ASSET_ID"] = ""
ActionController::Base.perform_caching = true
config.perform_caching = true
assert_raise(Errno::ENOENT) {
javascript_include_tag('bank', 'robber', 'missing_security_guard', :cache => true)
......@@ -675,7 +675,7 @@ def test_caching_javascript_include_tag_when_caching_on_and_missing_javascript_f
def test_caching_javascript_include_tag_when_caching_off_and_missing_javascript_file
ENV["RAILS_ASSET_ID"] = ""
ActionController::Base.perform_caching = false
config.perform_caching = false
assert_raise(Errno::ENOENT) {
javascript_include_tag('bank', 'robber', 'missing_security_guard', :cache => true)
......@@ -693,7 +693,7 @@ def test_caching_javascript_include_tag_when_caching_off_and_missing_javascript_
def test_caching_stylesheet_link_tag_when_caching_on
ENV["RAILS_ASSET_ID"] = ""
@controller.config.asset_host = 'http://a0.example.com'
ActionController::Base.perform_caching = true
config.perform_caching = true
assert_dom_equal(
%(<link href="http://a0.example.com/stylesheets/all.css" media="screen" rel="stylesheet" type="text/css" />),
......@@ -760,7 +760,7 @@ def test_concat_stylesheet_link_tag_when_caching_off
def test_caching_stylesheet_link_tag_when_caching_on_and_missing_css_file
ENV["RAILS_ASSET_ID"] = ""
ActionController::Base.perform_caching = true
config.perform_caching = true
assert_raise(Errno::ENOENT) {
stylesheet_link_tag('bank', 'robber', 'missing_security_guard', :cache => true)
......@@ -781,7 +781,7 @@ def test_caching_stylesheet_link_tag_when_caching_on_and_missing_css_file
def test_caching_stylesheet_link_tag_when_caching_off_and_missing_css_file
ENV["RAILS_ASSET_ID"] = ""
ActionController::Base.perform_caching = false
config.perform_caching = false
assert_raise(Errno::ENOENT) {
stylesheet_link_tag('bank', 'robber', 'missing_security_guard', :cache => true)
......@@ -803,7 +803,7 @@ def test_caching_stylesheet_link_tag_when_caching_off_and_missing_css_file
def test_caching_stylesheet_link_tag_when_caching_on_with_proc_asset_host
ENV["RAILS_ASSET_ID"] = ""
@controller.config.asset_host = Proc.new { |source| "http://a#{source.length}.example.com" }
ActionController::Base.perform_caching = true
config.perform_caching = true
assert_equal '/stylesheets/styles.css'.length, 23
assert_dom_equal(
......@@ -820,7 +820,7 @@ def test_caching_stylesheet_link_tag_when_caching_on_with_proc_asset_host
def test_caching_stylesheet_link_tag_with_relative_url_root
ENV["RAILS_ASSET_ID"] = ""
@controller.config.relative_url_root = "/collaboration/hieraki"
ActionController::Base.perform_caching = true
config.perform_caching = true
assert_dom_equal(
%(<link href="/collaboration/hieraki/stylesheets/all.css" media="screen" rel="stylesheet" type="text/css" />),
......@@ -845,7 +845,7 @@ def test_caching_stylesheet_link_tag_with_relative_url_root
def test_caching_stylesheet_include_tag_when_caching_off
ENV["RAILS_ASSET_ID"] = ""
ActionController::Base.perform_caching = false
config.perform_caching = false
assert_dom_equal(
%(<link href="/stylesheets/bank.css" media="screen" rel="stylesheet" type="text/css" />\n<link href="/stylesheets/robber.css" media="screen" rel="stylesheet" type="text/css" />\n<link href="/stylesheets/version.1.0.css" media="screen" rel="stylesheet" type="text/css" />),
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册