提交 f612c2b0 编写于 作者: M Matthew Draper

Move assets precompile (and version) to an initializer

sprockets-rails 2.1 needs the precompile list to be available in all
environments.
上级 d8d0fcb0
......@@ -709,17 +709,17 @@ JS/CSS is excluded, as well as raw JS/CSS files; for example, `.coffee` and
`.scss` files are **not** automatically included as they compile to JS/CSS.
If you have other manifests or individual stylesheets and JavaScript files to
include, you can add them to the `precompile` array in `config/application.rb`:
include, you can add them to the `precompile` array in `config/initializers/assets.rb`:
```ruby
config.assets.precompile += ['admin.js', 'admin.css', 'swfObject.js']
Rails.application.config.assets.precompile += ['admin.js', 'admin.css', 'swfObject.js']
```
Or, you can opt to precompile all assets with something like this:
```ruby
# config/application.rb
config.assets.precompile << Proc.new do |path|
# config/initializers/assets.rb
Rails.application.config.assets.precompile << Proc.new do |path|
if path =~ /\.(css|js)\z/
full_path = Rails.application.assets.resolve(path).to_path
app_assets_path = Rails.root.join('app', 'assets').to_path
......
* Move configuration of asset precompile list and version to an initializer.
*Matthew Draper*
* Do not set the Rails environment to test by default when using test_unit Railtie.
*Konstantin Shabanov*
......
......@@ -231,6 +231,12 @@ def delete_js_folder_skipping_javascript
end
end
def delete_assets_initializer_skipping_sprockets
if options[:skip_sprockets]
remove_file 'config/initializers/assets.rb'
end
end
def finish_template
build(:leftovers)
end
......
......@@ -33,12 +33,7 @@ Rails.application.configure do
# Generate digests for assets URLs.
config.assets.digest = true
# Version of your assets, change this if you want to expire all your assets.
config.assets.version = '1.0'
# Precompile additional assets.
# application.js, application.css, and all non-JS/CSS in app/assets folder are already added.
# config.assets.precompile += %w( search.js )
# `config.assets.precompile` has moved to config/initializers/assets.rb
<%- end -%>
# Specifies the header that your server uses for sending files.
......
# Be sure to restart your server when you modify this file.
# Version of your assets, change this if you want to expire all your assets.
Rails.application.config.assets.version = '1.0'
# Precompile additional assets.
# application.js, application.css, and all non-JS/CSS in app/assets folder are already added.
# Rails.application.config.assets.precompile += %w( search.js )
......@@ -237,6 +237,7 @@ def test_generator_if_skip_action_view_is_given
def test_generator_if_skip_sprockets_is_given
run_generator [destination_root, "--skip-sprockets"]
assert_no_file "config/initializers/assets.rb"
assert_file "config/application.rb" do |content|
assert_match(/#\s+require\s+["']sprockets\/railtie["']/, content)
end
......@@ -252,7 +253,6 @@ def test_generator_if_skip_sprockets_is_given
assert_no_match(/config\.assets\.digest = true/, content)
assert_no_match(/config\.assets\.js_compressor = :uglifier/, content)
assert_no_match(/config\.assets\.css_compressor = :sass/, content)
assert_no_match(/config\.assets\.version = '1\.0'/, content)
end
end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册