mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
[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.
This commit is contained in:
parent
4106245530
commit
c690b7124d
11 changed files with 30 additions and 10 deletions
|
@ -4,7 +4,6 @@ require "action_dispatch/railtie"
|
|||
require "action_view/railtie"
|
||||
require "abstract_controller/railties/routes_helpers"
|
||||
require "action_controller/railties/paths"
|
||||
require "sprockets/railtie"
|
||||
|
||||
module ActionController
|
||||
class Railtie < Rails::Railtie
|
||||
|
|
|
@ -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 @@ module Sprockets
|
|||
|
||||
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
|
||||
|
|
|
@ -8,6 +8,8 @@
|
|||
|
||||
*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
Normal file → Executable file
0
railties/bin/rails
Normal file → Executable file
|
@ -6,6 +6,7 @@ require "rails"
|
|||
action_mailer
|
||||
active_resource
|
||||
rails/test_unit
|
||||
sprockets
|
||||
).each do |framework|
|
||||
begin
|
||||
require "#{framework}/railtie"
|
||||
|
|
|
@ -37,6 +37,9 @@ module Rails
|
|||
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 @@ module Rails
|
|||
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)
|
||||
|
|
|
@ -8,6 +8,7 @@ require 'rails/all'
|
|||
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 @@ module <%= app_const_base %>
|
|||
# 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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -3,7 +3,6 @@ $VERBOSE = nil
|
|||
# Load Rails rakefile extensions
|
||||
%w(
|
||||
annotations
|
||||
assets
|
||||
documentation
|
||||
framework
|
||||
log
|
||||
|
|
|
@ -48,11 +48,12 @@ class AppGeneratorTest < Rails::Generators::TestCase
|
|||
::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
|
||||
|
@ -180,15 +181,20 @@ class AppGeneratorTest < Rails::Generators::TestCase
|
|||
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
|
||||
|
|
Loading…
Reference in a new issue