Created
March 7, 2012 11:14
-
-
Save mitio/1992575 to your computer and use it in GitHub Desktop.
Where the Rails' asset pipeline searches for asset files and how the config.assets.precompile directive works
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Test the result of config.assets.precompile | |
# | |
# Check which files will be regarded as "manifests" and thus precompiled and be | |
# available for standalone use via the /assets/<asset> URL when in production. | |
# Execute this code in your Rails console. | |
# First, you'll probably be in development mode, so add here your | |
# additional production precompile patterns you want to test against. | |
precompile = Rails.configuration.assets.precompile + [/^.+\.css$/, 'active_admin.js'] | |
# Temporary hack so that we can test easily for procs too. | |
# Please don't let this get out of your development console :-) | |
class Proc; def ===(other); call(other); end; end | |
# Now run the check; the list you see printed is the list of *all* | |
# assets you can include individually while in production mode, e.g. via | |
# image_tag('name'), javascript_include_tag('name'), stylesheet_include_tag('name') etc. | |
Rails.application.assets.each_logical_path { |asset_path| puts asset_path if precompile.any? { |rule| rule === asset_path } }; nil |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Find out the list of assets available for packaging for your app. | |
# | |
# This one is important, because these path segments are used by the assets:precompile | |
# Rake task when preparing your manifest assets. The rules to match them can be found in | |
# production.rb, in the config.assets.precompile setting. | |
# | |
# Find out more details about this here: | |
# https://github.com/rails/rails/blob/v3.1.3/actionpack/lib/sprockets/static_compiler.rb#L18 | |
Rails.application.assets.each_logical_path { |asset_path| puts asset_path }; nil | |
# Or which paths are searched for assets: | |
Rails.application.assets.paths.each { |path| puts path }; nil |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment