Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[IMPORTANT] Make "sprockets/railtie" require explicit.

This makes "sprockets/railtie" explicit. This means that sprockets will
be loaded when you require "rails/all". If you are not using requiring
"rails/all", you need to manually load it with all other framework
railties.

In order to be complete, this commit also adds --skip-sprockets to
the rails generator.
  • Loading branch information...
commit fe6e890f637d85f503cdc39b3bac7942b84c5231 1 parent 0b794f9
José Valim josevalim authored
1  actionpack/lib/action_controller/railtie.rb
View
@@ -4,7 +4,6 @@
require "action_view/railtie"
require "abstract_controller/railties/routes_helpers"
require "action_controller/railties/paths"
-require "sprockets/railtie"
module ActionController
class Railtie < Rails::Railtie
0  railties/lib/rails/tasks/assets.rake → actionpack/lib/sprockets/assets.rake
View
File renamed without changes
5 actionpack/lib/sprockets/railtie.rb
View
@@ -1,6 +1,7 @@
module Sprockets
autoload :Helpers, "sprockets/helpers"
+ # TODO: Get rid of config.assets.enabled
class Railtie < ::Rails::Railtie
def self.using_coffee?
require 'coffee-script'
@@ -11,6 +12,10 @@ def self.using_coffee?
config.app_generators.javascript_engine :coffee if using_coffee?
+ rake_tasks do
+ load "sprockets/assets.rake"
+ end
+
# Configure ActionController to use sprockets.
initializer "sprockets.set_configs", :after => "action_controller.set_configs" do |app|
ActiveSupport.on_load(:action_controller) do
2  railties/CHANGELOG
View
@@ -1,5 +1,7 @@
*Rails 3.1.0 (unreleased)*
+* Make sprockets/railtie require explicit and add --skip-sprockets to app generator [José Valim]
+
* Added Rails.groups that automatically handles Rails.env and ENV["RAILS_GROUPS"] [José Valim]
* The new rake task assets:clean removes precompiled assets. [fxn]
0  railties/bin/rails 100644 → 100755
View
File mode changed
1  railties/lib/rails/all.rb
View
@@ -6,6 +6,7 @@
action_mailer
active_resource
rails/test_unit
+ sprockets
).each do |framework|
begin
require "#{framework}/railtie"
5 railties/lib/rails/generators/app_base.rb
View
@@ -37,6 +37,9 @@ def self.add_shared_options_for(name)
class_option :skip_active_record, :type => :boolean, :aliases => "-O", :default => false,
:desc => "Skip Active Record files"
+ class_option :skip_sprockets, :type => :boolean, :aliases => "-S", :default => false,
+ :desc => "Skip Sprockets files"
+
class_option :database, :type => :string, :aliases => "-d", :default => "sqlite3",
:desc => "Preconfigure for selected database (options: #{DATABASES.join('/')})"
@@ -124,7 +127,7 @@ def database_gemfile_entry
end
def include_all_railties?
- !options[:skip_active_record] && !options[:skip_test_unit]
+ !options[:skip_active_record] && !options[:skip_test_unit] && !options[:skip_sprockets]
end
def comment_if(value)
3  railties/lib/rails/generators/rails/app/templates/config/application.rb
View
@@ -8,6 +8,7 @@
require "action_controller/railtie"
require "action_mailer/railtie"
require "active_resource/railtie"
+<%= comment_if :skip_sprockets %> require "sprockets/railtie"
<%= comment_if :skip_test_unit %> require "rails/test_unit/railtie"
<% end -%>
@@ -46,7 +47,9 @@ class Application < Rails::Application
# Configure sensitive parameters which will be filtered from the log file.
config.filter_parameters += [:password]
+ <% unless options.skip_sprockets? %>
# Enable the asset pipeline
config.assets.enabled = true
+ <% end %>
end
end
8 railties/lib/rails/generators/rails/plugin_new/templates/rails/application.rb
View
@@ -1,13 +1,15 @@
require File.expand_path('../boot', __FILE__)
-<% unless options[:skip_active_record] -%>
+<% if include_all_railties? -%>
require 'rails/all'
<% else -%>
-# require "active_record/railtie"
+# Pick the frameworks you want:
+<%= comment_if :skip_active_record %>require "active_record/railtie"
require "action_controller/railtie"
require "action_mailer/railtie"
require "active_resource/railtie"
-require "rails/test_unit/railtie"
+<%= comment_if :skip_sprockets %> require "sprockets/railtie"
+<%= comment_if :skip_test_unit %> require "rails/test_unit/railtie"
<% end -%>
Bundler.require
1  railties/lib/rails/tasks.rb
View
@@ -3,7 +3,6 @@
# Load Rails rakefile extensions
%w(
annotations
- assets
documentation
framework
log
14 railties/test/generators/app_generator_test.rb
View
@@ -48,11 +48,12 @@ def default_files
::DEFAULT_APP_FILES
end
- def test_application_controller_and_layout_files
+ def test_assets
run_generator
assert_file "app/views/layouts/application.html.erb", /stylesheet_link_tag\s+"application"/
assert_file "app/views/layouts/application.html.erb", /javascript_include_tag\s+"application"/
assert_file "app/assets/stylesheets/application.css"
+ assert_file "config/application.rb", /config\.assets\.enabled = true/
end
def test_invalid_application_name_raises_an_error
@@ -157,15 +158,20 @@ def test_config_jdbcpostgresql_database
def test_generator_if_skip_active_record_is_given
run_generator [destination_root, "--skip-active-record"]
assert_no_file "config/database.yml"
+ assert_file "config/application.rb", /#\s+require\s+["']active_record\/railtie["']/
assert_file "test/test_helper.rb" do |helper_content|
assert_no_match(/fixtures :all/, helper_content)
end
assert_file "test/performance/browsing_test.rb"
end
- def test_active_record_is_removed_from_frameworks_if_skip_active_record_is_given
- run_generator [destination_root, "--skip-active-record"]
- assert_file "config/application.rb", /#\s+require\s+["']active_record\/railtie["']/
+ def test_generator_if_skip_active_record_is_given
+ run_generator [destination_root, "--skip-sprockets"]
+ assert_file "config/application.rb" do |content|
+ assert_match(/#\s+require\s+["']sprockets\/railtie["']/, content)
+ assert_no_match(/config\.assets\.enabled = true/, content)
+ end
+ assert_file "test/performance/browsing_test.rb"
end
def test_creation_of_a_test_directory
Please sign in to comment.
Something went wrong with that request. Please try again.