mirror of
https://github.com/github/rails.git
synced 2026-04-26 03:00:59 -04:00
Create an :assets group in the Gemfile.
This group is required by default only on development and test (you can change it on config/application.rb). `rake assets:precompile` will automatically add the assets group to Rails.groups (and consequently Bundler.require) and should work transparently.
This commit is contained in:
@@ -164,7 +164,7 @@ module Rails
|
||||
end
|
||||
end
|
||||
|
||||
def gem_for_ruby_debugger
|
||||
def ruby_debugger_gemfile_entry
|
||||
if RUBY_VERSION < "1.9"
|
||||
"gem 'ruby-debug'"
|
||||
else
|
||||
@@ -172,7 +172,7 @@ module Rails
|
||||
end
|
||||
end
|
||||
|
||||
def gem_for_turn
|
||||
def turn_gemfile_entry
|
||||
unless RUBY_VERSION < "1.9.2" || options[:skip_test_unit]
|
||||
<<-GEMFILE.strip_heredoc
|
||||
group :test do
|
||||
@@ -183,7 +183,7 @@ module Rails
|
||||
end
|
||||
end
|
||||
|
||||
def gem_for_javascript
|
||||
def javascript_gemfile_entry
|
||||
"gem '#{options[:javascript]}-rails'" unless options[:skip_javascript]
|
||||
end
|
||||
|
||||
|
||||
@@ -5,13 +5,17 @@ source 'http://rubygems.org'
|
||||
<%= database_gemfile_entry -%>
|
||||
|
||||
<%= "gem 'jruby-openssl'\n" if defined?(JRUBY_VERSION) -%>
|
||||
# Asset template engines
|
||||
<%= "gem 'json'\n" if RUBY_VERSION < "1.9.2" -%>
|
||||
gem 'sass-rails', "~> 3.1.0.rc"
|
||||
gem 'coffee-script'
|
||||
gem 'uglifier'
|
||||
|
||||
<%= gem_for_javascript %>
|
||||
# Gems used only for assets and not required
|
||||
# in production environments by default.
|
||||
group :assets do
|
||||
gem 'sass-rails', "~> 3.1.0.rc"
|
||||
gem 'coffee-script'
|
||||
gem 'uglifier'
|
||||
end
|
||||
|
||||
<%= javascript_gemfile_entry %>
|
||||
|
||||
# Use unicorn as the web server
|
||||
# gem 'unicorn'
|
||||
@@ -20,6 +24,6 @@ gem 'uglifier'
|
||||
# gem 'capistrano'
|
||||
|
||||
# To use debugger
|
||||
# <%= gem_for_ruby_debugger %>
|
||||
# <%= ruby_debugger_gemfile_entry %>
|
||||
|
||||
<%= gem_for_turn -%>
|
||||
<%= turn_gemfile_entry -%>
|
||||
|
||||
@@ -11,9 +11,10 @@ require "active_resource/railtie"
|
||||
<%= comment_if :skip_test_unit %> require "rails/test_unit/railtie"
|
||||
<% end -%>
|
||||
|
||||
# If you have a Gemfile, require the gems listed there, including any gems
|
||||
# you've limited to :test, :development, or :production.
|
||||
Bundler.require(:default, Rails.env) if defined?(Bundler)
|
||||
# If you have a Gemfile, require the default gems, the ones in the
|
||||
# current environment and also include :assets gems if in development
|
||||
# or test environments.
|
||||
Bundler.require *Rails.groups(:assets => %w(development test)) if defined?(Bundler)
|
||||
|
||||
module <%= app_const_base %>
|
||||
class Application < Rails::Application
|
||||
|
||||
@@ -7,9 +7,8 @@ source "http://rubygems.org"
|
||||
<% end -%>
|
||||
|
||||
<% if mountable? -%>
|
||||
<%= gem_for_javascript -%>
|
||||
<%= javascript_gemfile_entry -%>
|
||||
<% end -%>
|
||||
|
||||
if RUBY_VERSION < '1.9'
|
||||
gem "ruby-debug", ">= 0.10.3"
|
||||
end
|
||||
# To use debugger
|
||||
# <%= ruby_debugger_gemfile_entry %>
|
||||
@@ -1,11 +1,16 @@
|
||||
namespace :assets do
|
||||
desc "Compile all the assets named in config.assets.precompile"
|
||||
task :precompile => :environment do
|
||||
# Give assets access to asset_path
|
||||
Sprockets::Helpers::RailsHelper
|
||||
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)
|
||||
assets = Rails.application.config.assets.precompile
|
||||
Rails.application.assets.precompile(*assets)
|
||||
end
|
||||
end
|
||||
|
||||
desc "Remove compiled assets"
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
require 'isolation/abstract_unit'
|
||||
require 'active_support/core_ext/kernel/reporting'
|
||||
require 'rack/test'
|
||||
|
||||
module ApplicationTests
|
||||
class RoutingTest < Test::Unit::TestCase
|
||||
class AssetsTest < Test::Unit::TestCase
|
||||
include ActiveSupport::Testing::Isolation
|
||||
include Rack::Test::Methods
|
||||
|
||||
@@ -34,6 +35,17 @@ module ApplicationTests
|
||||
assert_match "alert()", last_response.body
|
||||
end
|
||||
|
||||
test "assets are compiled properly" do
|
||||
app_file "app/assets/javascripts/application.js", "alert();"
|
||||
|
||||
capture(:stdout) do
|
||||
Dir.chdir(app_path){ `bundle exec rake assets:precompile` }
|
||||
end
|
||||
|
||||
file = Dir["#{app_path}/public/assets/application-*.js"][0]
|
||||
assert_equal "alert();\n", File.read(file)
|
||||
end
|
||||
|
||||
test "does not stream session cookies back" do
|
||||
app_file "app/assets/javascripts/demo.js.erb", "<%= :alert %>();"
|
||||
|
||||
|
||||
@@ -239,6 +239,10 @@ module TestHelpers
|
||||
end
|
||||
end
|
||||
|
||||
def remove_file(path)
|
||||
FileUtils.rm_rf "#{app_path}/#{path}"
|
||||
end
|
||||
|
||||
def controller(name, contents)
|
||||
app_file("app/controllers/#{name}_controller.rb", contents)
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user