Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #14689 from matthewd/asset_initializer

Move assets precompile (and version) to an initializer
Conflicts:
	railties/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt
  • Loading branch information...
commit 48e7203c0e3b52065173f0a83009066ae3dd106c 1 parent 176ce1d
Rafael Mendonça França rafaelfranca authored
8 guides/source/asset_pipeline.md
View
@@ -724,17 +724,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
4 railties/CHANGELOG.md
View
@@ -1,3 +1,7 @@
+* 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*
6 railties/lib/rails/generators/rails/app/app_generator.rb
View
@@ -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
3  railties/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt
View
@@ -33,8 +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'
+ # `config.assets.precompile` has moved to config/initializers/assets.rb
<%- end -%>
# Specifies the header that your server uses for sending files.
8 railties/lib/rails/generators/rails/app/templates/config/initializers/assets.rb.tt
View
@@ -0,0 +1,8 @@
+# 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 )
2  railties/test/generators/app_generator_test.rb
View
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.