diff options
Diffstat (limited to 'railties')
-rw-r--r-- | railties/CHANGELOG | 2 | ||||
-rwxr-xr-x[-rw-r--r--] | railties/bin/rails | 0 | ||||
-rw-r--r-- | railties/lib/rails/all.rb | 1 | ||||
-rw-r--r-- | railties/lib/rails/generators/app_base.rb | 5 | ||||
-rw-r--r-- | railties/lib/rails/generators/rails/app/templates/config/application.rb | 3 | ||||
-rw-r--r-- | railties/lib/rails/generators/rails/plugin_new/templates/rails/application.rb | 8 | ||||
-rw-r--r-- | railties/lib/rails/tasks.rb | 1 | ||||
-rw-r--r-- | railties/lib/rails/tasks/assets.rake | 26 | ||||
-rw-r--r-- | railties/test/generators/app_generator_test.rb | 14 |
9 files changed, 25 insertions, 35 deletions
diff --git a/railties/CHANGELOG b/railties/CHANGELOG index e8b4a32056..a9b4deb551 100644 --- a/railties/CHANGELOG +++ b/railties/CHANGELOG @@ -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] diff --git a/railties/bin/rails b/railties/bin/rails index a7d6938e0d..a7d6938e0d 100644..100755 --- a/railties/bin/rails +++ b/railties/bin/rails diff --git a/railties/lib/rails/all.rb b/railties/lib/rails/all.rb index 82775b7e3b..01ceb80972 100644 --- a/railties/lib/rails/all.rb +++ b/railties/lib/rails/all.rb @@ -6,6 +6,7 @@ require "rails" action_mailer active_resource rails/test_unit + sprockets ).each do |framework| begin require "#{framework}/railtie" diff --git a/railties/lib/rails/generators/app_base.rb b/railties/lib/rails/generators/app_base.rb index 378eceb4c3..c8847f0159 100644 --- a/railties/lib/rails/generators/app_base.rb +++ b/railties/lib/rails/generators/app_base.rb @@ -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) diff --git a/railties/lib/rails/generators/rails/app/templates/config/application.rb b/railties/lib/rails/generators/rails/app/templates/config/application.rb index 7f623a7af9..eaa31e7386 100644 --- a/railties/lib/rails/generators/rails/app/templates/config/application.rb +++ b/railties/lib/rails/generators/rails/app/templates/config/application.rb @@ -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 diff --git a/railties/lib/rails/generators/rails/plugin_new/templates/rails/application.rb b/railties/lib/rails/generators/rails/plugin_new/templates/rails/application.rb index 8b68280a5e..4864ead960 100644 --- a/railties/lib/rails/generators/rails/plugin_new/templates/rails/application.rb +++ b/railties/lib/rails/generators/rails/plugin_new/templates/rails/application.rb @@ -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 diff --git a/railties/lib/rails/tasks.rb b/railties/lib/rails/tasks.rb index 166d518f7c..9807000578 100644 --- a/railties/lib/rails/tasks.rb +++ b/railties/lib/rails/tasks.rb @@ -3,7 +3,6 @@ $VERBOSE = nil # Load Rails rakefile extensions %w( annotations - assets documentation framework log diff --git a/railties/lib/rails/tasks/assets.rake b/railties/lib/rails/tasks/assets.rake deleted file mode 100644 index 0236350576..0000000000 --- a/railties/lib/rails/tasks/assets.rake +++ /dev/null @@ -1,26 +0,0 @@ -namespace :assets do - desc "Compile all the assets named in config.assets.precompile" - task :precompile do - if ENV["RAILS_GROUPS"].to_s.empty? - ENV["RAILS_GROUPS"] = "assets" - Kernel.exec $0, *ARGV - else - Rake::Task["environment"].invoke - Sprockets::Helpers::RailsHelper - - assets = Rails.application.config.assets.precompile - Rails.application.assets.precompile(*assets) - end - end - - desc "Remove compiled assets" - task :clean => :environment do - assets = Rails.application.config.assets - public_asset_path = Rails.public_path + assets.prefix - file_list = FileList.new("#{public_asset_path}/**/*") - file_list.each do |file| - rm_rf file - rm_rf "#{file}.gz" - end - end -end diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb index eb60674a03..81f0bf5e82 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -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 |