Skip to content

Commit

Permalink
Merge pull request #2411 from ai/debug_assets_by_config
Browse files Browse the repository at this point in the history
Debug assets by config
  • Loading branch information
spastorino committed Aug 22, 2011
1 parent 2f20c6c commit b938b04
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 19 deletions.
10 changes: 6 additions & 4 deletions actionpack/lib/sprockets/helpers/rails_helper.rb
Expand Up @@ -70,10 +70,12 @@ def asset_path(source, default_ext = nil, body = false, protocol = nil)

private
def debug_assets?
Rails.env.development? || Rails.env.test? ||
params[:debug_assets] == '1' || params[:debug_assets] == 'true'
rescue NoMethodError
false
begin
params[:debug_assets] == '1' ||
params[:debug_assets] == 'true'
rescue NoMethodError
false
end || Rails.application.config.assets.debug
end

# Override to specify an alternative prefix for asset path generation.
Expand Down
20 changes: 6 additions & 14 deletions actionpack/test/template/sprockets_helper_test.rb
Expand Up @@ -144,8 +144,6 @@ def url_for(*args)
end

test "javascript include tag" do
Rails.env.stubs(:test?).returns(false)

assert_match %r{<script src="/assets/application-[0-9a-f]+.js" type="text/javascript"></script>},
javascript_include_tag(:application)

Expand All @@ -159,14 +157,12 @@ def url_for(*args)
assert_match %r{<script src=\"/assets/xmlhr-[0-9a-f]+.js" type=\"text/javascript\"></script>\n<script src=\"/assets/extra-[0-9a-f]+.js" type=\"text/javascript\"></script>},
javascript_include_tag("xmlhr", "extra")

Rails.env.stubs(:test?).returns(true)
assert_match %r{<script src="/assets/xmlhr-[0-9a-f]+.js\?body=1" type="text/javascript"></script>\n<script src="/assets/application-[0-9a-f]+.js\?body=1" type="text/javascript"></script>},
javascript_include_tag(:application, :debug => true)

@config.assets.debug = true
assert_match %r{<script src="/assets/xmlhr-[0-9a-f]+.js\?body=1" type="text/javascript"></script>\n<script src="/assets/application-[0-9a-f]+.js\?body=1" type="text/javascript"></script>},
javascript_include_tag(:application)

assert_match %r{<script src="/assets/application-[0-9a-f]+.js\" type="text/javascript"></script>},
javascript_include_tag(:application, :debug => false)

end

test "stylesheet path" do
Expand All @@ -183,8 +179,6 @@ def url_for(*args)
end

test "stylesheet link tag" do
Rails.env.stubs(:test?).returns(false)

assert_match %r{<link href="/assets/application-[0-9a-f]+.css" media="screen" rel="stylesheet" type="text/css" />},
stylesheet_link_tag(:application)

Expand All @@ -203,14 +197,12 @@ def url_for(*args)
assert_match %r{<link href="/assets/style-[0-9a-f]+.css" media="screen" rel="stylesheet" type="text/css" />\n<link href="/assets/extra-[0-9a-f]+.css" media="screen" rel="stylesheet" type="text/css" />},
stylesheet_link_tag("style", "extra")

Rails.env.stubs(:test?).returns(true)
assert_match %r{<link href="/assets/style-[0-9a-f]+.css\?body=1" media="screen" rel="stylesheet" type="text/css" />\n<link href="/assets/application-[0-9a-f]+.css\?body=1" media="screen" rel="stylesheet" type="text/css" />},
stylesheet_link_tag(:application, :debug => true)

@config.assets.debug = true
assert_match %r{<link href="/assets/style-[0-9a-f]+.css\?body=1" media="screen" rel="stylesheet" type="text/css" />\n<link href="/assets/application-[0-9a-f]+.css\?body=1" media="screen" rel="stylesheet" type="text/css" />},
stylesheet_link_tag(:application)

assert_match %r{<link href="/assets/application-[0-9a-f]+.css" media="screen" rel="stylesheet" type="text/css" />},
stylesheet_link_tag(:application, :debug => false)

end

test "alternate asset prefix" do
Expand Down
2 changes: 1 addition & 1 deletion railties/guides/source/asset_pipeline.textile
Expand Up @@ -226,7 +226,7 @@ If any of the files in the manifest have changed between requests, the server re

h4. Debugging Assets

You can put +?debug_assets=true+ or +?debug_assets=1+ at the end of a URL and Sprockets expands the lines which load the assets. For example, if you had an +app/assets/javascripts/application.js+ file containing these lines:
You can put +?debug_assets=true+ or +?debug_assets=1+ at the end of a URL or set +config.assets.debug+ and Sprockets expands the lines which load the assets. For example, if you had an +app/assets/javascripts/application.js+ file containing these lines:

<plain>
//= require "projects"
Expand Down
1 change: 1 addition & 0 deletions railties/lib/rails/application/configuration.rb
Expand Up @@ -38,6 +38,7 @@ def initialize(*)
@assets.precompile = [ /\w+\.(?!js|css).+/, /application.(css|js)$/ ]
@assets.prefix = "/assets"
@assets.version = ''
@assets.debug = false

@assets.cache_store = [ :file_store, "#{root}/tmp/cache/assets/" ]
@assets.js_compressor = nil
Expand Down
Expand Up @@ -24,4 +24,7 @@

# Do not compress assets
config.assets.compress = false

# Expands the lines which load the assets
config.assets.debug = true
end

0 comments on commit b938b04

Please sign in to comment.