Provide initialize_on_precompile which, when set to false, does not initialize the app for precompilation. Defaults to true.
This commit is contained in:
parent
1efe41dc36
commit
753424079e
|
@ -54,7 +54,11 @@ namespace :assets do
|
||||||
end
|
end
|
||||||
|
|
||||||
task :environment do
|
task :environment do
|
||||||
Rails.application.initialize!(:assets)
|
if Rails.application.config.assets.initialize_on_precompile
|
||||||
Sprockets::Bootstrap.new(Rails.application).run
|
Rake::Task["environment"].invoke
|
||||||
|
else
|
||||||
|
Rails.application.initialize!(:assets)
|
||||||
|
Sprockets::Bootstrap.new(Rails.application).run
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -17,7 +17,8 @@
|
||||||
|
|
||||||
* Add jquery-rails to Gemfile of plugins, test/dummy app needs it. Closes #3091. [Santiago Pastorino]
|
* Add jquery-rails to Gemfile of plugins, test/dummy app needs it. Closes #3091. [Santiago Pastorino]
|
||||||
|
|
||||||
* `rake assets:precompile` loads the application but does not initialize it.
|
* Add config.assets.initialize_on_precompile which, when set to false, forces
|
||||||
|
`rake assets:precompile` to load the application but does not initialize it.
|
||||||
|
|
||||||
To the app developer, this means configuration add in
|
To the app developer, this means configuration add in
|
||||||
config/initializers/* will not be executed.
|
config/initializers/* will not be executed.
|
||||||
|
|
|
@ -37,19 +37,20 @@ module Rails
|
||||||
@cache_store = [ :file_store, "#{root}/tmp/cache/" ]
|
@cache_store = [ :file_store, "#{root}/tmp/cache/" ]
|
||||||
|
|
||||||
@assets = ActiveSupport::OrderedOptions.new
|
@assets = ActiveSupport::OrderedOptions.new
|
||||||
@assets.enabled = false
|
@assets.enabled = false
|
||||||
@assets.paths = []
|
@assets.paths = []
|
||||||
@assets.precompile = [ Proc.new{ |path| !File.extname(path).in?(['.js', '.css']) },
|
@assets.precompile = [ Proc.new{ |path| !File.extname(path).in?(['.js', '.css']) },
|
||||||
/(?:\/|\\|\A)application\.(css|js)$/ ]
|
/(?:\/|\\|\A)application\.(css|js)$/ ]
|
||||||
@assets.prefix = "/assets"
|
@assets.prefix = "/assets"
|
||||||
@assets.version = ''
|
@assets.version = ''
|
||||||
@assets.debug = false
|
@assets.debug = false
|
||||||
@assets.compile = true
|
@assets.compile = true
|
||||||
@assets.digest = false
|
@assets.digest = false
|
||||||
@assets.manifest = nil
|
@assets.manifest = nil
|
||||||
@assets.cache_store = [ :file_store, "#{root}/tmp/cache/assets/" ]
|
@assets.cache_store = [ :file_store, "#{root}/tmp/cache/assets/" ]
|
||||||
@assets.js_compressor = nil
|
@assets.js_compressor = nil
|
||||||
@assets.css_compressor = nil
|
@assets.css_compressor = nil
|
||||||
|
@assets.initialize_on_precompile = true
|
||||||
end
|
end
|
||||||
|
|
||||||
def compiled_asset_path
|
def compiled_asset_path
|
||||||
|
|
|
@ -395,7 +395,30 @@ module ApplicationTests
|
||||||
assert_match(/<script src="\/assets\/xmlhr-([0-z]+)\.js\?body=1" type="text\/javascript"><\/script>/, last_response.body)
|
assert_match(/<script src="\/assets\/xmlhr-([0-z]+)\.js\?body=1" type="text\/javascript"><\/script>/, last_response.body)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "assets can access model information when precompiling" do
|
||||||
|
app_file "app/models/post.rb", "class Post; end"
|
||||||
|
app_file "app/assets/javascripts/application.js", "//= require_tree ."
|
||||||
|
app_file "app/assets/javascripts/xmlhr.js.erb", "<%= Post.name %>"
|
||||||
|
|
||||||
|
add_to_config "config.assets.digest = false"
|
||||||
|
precompile!
|
||||||
|
assert_equal "Post;\n", File.read("#{app_path}/public/assets/application.js")
|
||||||
|
end
|
||||||
|
|
||||||
|
test "assets can't access model information when precompiling if not initializing the app" do
|
||||||
|
app_file "app/models/post.rb", "class Post; end"
|
||||||
|
app_file "app/assets/javascripts/application.js", "//= require_tree ."
|
||||||
|
app_file "app/assets/javascripts/xmlhr.js.erb", "<%= defined?(Post) || :NoPost %>"
|
||||||
|
|
||||||
|
add_to_config "config.assets.digest = false"
|
||||||
|
add_to_config "config.assets.initialize_on_precompile = false"
|
||||||
|
|
||||||
|
precompile!
|
||||||
|
assert_equal "NoPost;\n", File.read("#{app_path}/public/assets/application.js")
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def app_with_assets_in_view
|
def app_with_assets_in_view
|
||||||
app_file "app/assets/javascripts/application.js", "//= require_tree ."
|
app_file "app/assets/javascripts/application.js", "//= require_tree ."
|
||||||
app_file "app/assets/javascripts/xmlhr.js", "function f1() { alert(); }"
|
app_file "app/assets/javascripts/xmlhr.js", "function f1() { alert(); }"
|
||||||
|
|
Loading…
Reference in New Issue