提交 d0e0fbaf 编写于 作者: A Andrei Istratii

Migrate to Sprockets 4.

上级 f454ad37
...@@ -20,8 +20,9 @@ gem 'turbolinks' ...@@ -20,8 +20,9 @@ gem 'turbolinks'
gem 'arel', github: 'rails/arel', branch: 'master' gem 'arel', github: 'rails/arel', branch: 'master'
gem 'mail', github: 'mikel/mail' gem 'mail', github: 'mikel/mail'
gem 'sprockets', '~> 3.0.0.rc.1' gem 'sprockets', github: 'rails/sprockets', branch: 'master'
gem 'sprockets-rails', github: 'rails/sprockets-rails', branch: 'master' gem 'sprockets-rails', github: 'rails/sprockets-rails', branch: 'master'
gem 'sass-rails', github: 'rails/sass-rails', branch: 'master'
# require: false so bcrypt is loaded only when has_secure_password is used. # require: false so bcrypt is loaded only when has_secure_password is used.
# This is to avoid ActiveModel (and by extension the entire framework) # This is to avoid ActiveModel (and by extension the entire framework)
...@@ -31,6 +32,7 @@ gem 'bcrypt', '~> 3.1.10', require: false ...@@ -31,6 +32,7 @@ gem 'bcrypt', '~> 3.1.10', require: false
# This needs to be with require false to avoid # This needs to be with require false to avoid
# it being automatically loaded by sprockets # it being automatically loaded by sprockets
gem 'uglifier', '>= 1.3.0', require: false gem 'uglifier', '>= 1.3.0', require: false
gem 'sass', '>= 3.3', require: false
group :doc do group :doc do
gem 'sdoc', '~> 0.4.0' gem 'sdoc', '~> 0.4.0'
......
...@@ -49,6 +49,17 @@ GIT ...@@ -49,6 +49,17 @@ GIT
railties (>= 4.2.0) railties (>= 4.2.0)
thor (>= 0.14, < 2.0) thor (>= 0.14, < 2.0)
GIT
remote: git://github.com/rails/sass-rails.git
revision: 805cb17722b8a13ff00dffe20283a6ba2c9a45dc
branch: master
specs:
sass-rails (6.0.0)
railties (>= 4.0.0, < 5.0)
sass (~> 3.3)
sprockets (>= 4.0)
sprockets-rails (< 4.0)
GIT GIT
remote: git://github.com/rails/sprockets-rails.git remote: git://github.com/rails/sprockets-rails.git
revision: ad4a43bd1bb19c86a8bf94a2ad5e477686161490 revision: ad4a43bd1bb19c86a8bf94a2ad5e477686161490
...@@ -59,6 +70,14 @@ GIT ...@@ -59,6 +70,14 @@ GIT
activesupport (>= 4.0) activesupport (>= 4.0)
sprockets (>= 3.0.0) sprockets (>= 3.0.0)
GIT
remote: git://github.com/rails/sprockets.git
revision: de057b4f13deb2bb5e8684cd06b9b687f5d09792
branch: master
specs:
sprockets (4.0.0)
rack (~> 1.0)
PATH PATH
remote: . remote: .
specs: specs:
...@@ -215,6 +234,7 @@ GEM ...@@ -215,6 +234,7 @@ GEM
resque (~> 1.25) resque (~> 1.25)
rufus-scheduler (~> 3.0) rufus-scheduler (~> 3.0)
rufus-scheduler (3.1.3) rufus-scheduler (3.1.3)
sass (3.4.16)
sdoc (0.4.1) sdoc (0.4.1)
json (~> 1.7, >= 1.7.7) json (~> 1.7, >= 1.7.7)
rdoc (~> 4.0) rdoc (~> 4.0)
...@@ -237,8 +257,6 @@ GEM ...@@ -237,8 +257,6 @@ GEM
serverengine (~> 1.5.5) serverengine (~> 1.5.5)
thor thor
thread (~> 0.1.7) thread (~> 0.1.7)
sprockets (3.0.3)
rack (~> 1.0)
sqlite3 (1.3.10) sqlite3 (1.3.10)
stackprof (0.2.7) stackprof (0.2.7)
sucker_punch (1.5.0) sucker_punch (1.5.0)
...@@ -303,11 +321,13 @@ DEPENDENCIES ...@@ -303,11 +321,13 @@ DEPENDENCIES
redcarpet (~> 3.2.3) redcarpet (~> 3.2.3)
resque resque
resque-scheduler resque-scheduler
sass (>= 3.3)
sass-rails!
sdoc (~> 0.4.0) sdoc (~> 0.4.0)
sequel sequel
sidekiq sidekiq
sneakers sneakers
sprockets (~> 3.0.0.rc.1) sprockets!
sprockets-rails! sprockets-rails!
sqlite3 (~> 1.3.6) sqlite3 (~> 1.3.6)
stackprof stackprof
......
...@@ -209,12 +209,16 @@ def rails_gemfile_entry ...@@ -209,12 +209,16 @@ def rails_gemfile_entry
[ [
GemfileEntry.path('rails', Rails::Generators::RAILS_DEV_PATH), GemfileEntry.path('rails', Rails::Generators::RAILS_DEV_PATH),
GemfileEntry.github('sprockets-rails', 'rails/sprockets-rails'), GemfileEntry.github('sprockets-rails', 'rails/sprockets-rails'),
GemfileEntry.github('sprockets', 'rails/sprockets'),
GemfileEntry.github('sass-rails', 'rails/sass-rails'),
GemfileEntry.github('arel', 'rails/arel') GemfileEntry.github('arel', 'rails/arel')
] ]
elsif options.edge? elsif options.edge?
[ [
GemfileEntry.github('rails', 'rails/rails'), GemfileEntry.github('rails', 'rails/rails'),
GemfileEntry.github('sprockets-rails', 'rails/sprockets-rails'), GemfileEntry.github('sprockets-rails', 'rails/sprockets-rails'),
GemfileEntry.github('sprockets', 'rails/sprockets'),
GemfileEntry.github('sass-rails', 'rails/sass-rails'),
GemfileEntry.github('arel', 'rails/arel') GemfileEntry.github('arel', 'rails/arel')
] ]
else else
...@@ -255,8 +259,6 @@ def assets_gemfile_entry ...@@ -255,8 +259,6 @@ def assets_gemfile_entry
return [] if options[:skip_sprockets] return [] if options[:skip_sprockets]
gems = [] gems = []
gems << GemfileEntry.version('sass-rails', '~> 5.0',
'Use SCSS for stylesheets')
gems << GemfileEntry.version('uglifier', gems << GemfileEntry.version('uglifier',
'>= 1.3.0', '>= 1.3.0',
......
<% unless options.api? -%>
//= link_tree ./images
<% end -%>
<% unless options.skip_javascript -%>
//= link ./javascripts/application.js
<% end -%>
//= link ./stylesheets/application.css
...@@ -104,8 +104,9 @@ def test_dummy_config ...@@ -104,8 +104,9 @@ def test_dummy_config
end end
def test_dummy_assets def test_dummy_assets
template "rails/javascripts.js", "#{dummy_path}/app/assets/javascripts/application.js", force: true template "rails/javascripts.js", "#{dummy_path}/app/assets/javascripts/application.js", force: true
template "rails/stylesheets.css", "#{dummy_path}/app/assets/stylesheets/application.css", force: true template "rails/stylesheets.css", "#{dummy_path}/app/assets/stylesheets/application.css", force: true
template "rails/dummy_manifest.js", "#{dummy_path}/app/assets/manifest.js", force: true
end end
def test_dummy_clean def test_dummy_clean
...@@ -122,6 +123,10 @@ def test_dummy_clean ...@@ -122,6 +123,10 @@ def test_dummy_clean
end end
end end
def assets_manifest
template "rails/engine_manifest.js", "app/assets/#{underscored_name}_manifest.js"
end
def stylesheets def stylesheets
if mountable? if mountable?
copy_file "rails/stylesheets.css", copy_file "rails/stylesheets.css",
...@@ -220,6 +225,10 @@ def create_lib_files ...@@ -220,6 +225,10 @@ def create_lib_files
build(:lib) build(:lib)
end end
def create_assets_manifest_file
build(:assets_manifest) unless api?
end
def create_public_stylesheets_files def create_public_stylesheets_files
build(:stylesheets) unless api? build(:stylesheets) unless api?
end end
......
<% unless api? -%>
//= link_tree ./images
<% end -%>
<% unless options.skip_javascript -%>
//= link ./javascripts/application.js
<% end -%>
//= link ./stylesheets/application.css
<% if mountable? && !api? -%>
//= link <%= underscored_name %>_manifest.js
<% end -%>
<% if mountable? -%>
<% unless options.skip_javascript -%>
//= link ./javascripts/<%= namespaced_name %>/application.js
<% end -%>
//= link ./stylesheets/<%= namespaced_name %>/application.css
<% end -%>
...@@ -48,7 +48,7 @@ class ::PostsController < ActionController::Base ; end ...@@ -48,7 +48,7 @@ class ::PostsController < ActionController::Base ; end
assert_no_match(/<script src="\/assets\/xmlhr-([0-z]+)\.js"><\/script>/, last_response.body) assert_no_match(/<script src="\/assets\/xmlhr-([0-z]+)\.js"><\/script>/, last_response.body)
end end
test "assets aren't concatenated when compile is true is on and debug_assets params is true" do test "assets are served with sourcemaps when compile is true and debug_assets params is true" do
add_to_env_config "production", "config.assets.compile = true" add_to_env_config "production", "config.assets.compile = true"
ENV["RAILS_ENV"] = "production" ENV["RAILS_ENV"] = "production"
...@@ -57,8 +57,7 @@ class ::PostsController < ActionController::Base ; end ...@@ -57,8 +57,7 @@ class ::PostsController < ActionController::Base ; end
class ::PostsController < ActionController::Base ; end class ::PostsController < ActionController::Base ; end
get '/posts?debug_assets=true' get '/posts?debug_assets=true'
assert_match(/<script src="\/assets\/application(\.self)?-([0-z]+)\.js\?body=1"><\/script>/, last_response.body) assert_match(/<script src="\/assets\/application(\.debug)?-([0-z]+)\.js"><\/script>/, last_response.body)
assert_match(/<script src="\/assets\/xmlhr(\.self)?-([0-z]+)\.js\?body=1"><\/script>/, last_response.body)
end end
end end
end end
...@@ -72,6 +72,7 @@ def assert_no_file_exists(filename) ...@@ -72,6 +72,7 @@ def assert_no_file_exists(filename)
end end
test "precompile creates the file, gives it the original asset's content and run in production as default" do test "precompile creates the file, gives it the original asset's content and run in production as default" do
app_file "app/assets/manifest.js", "//= link_tree ./javascripts"
app_file "app/assets/javascripts/application.js", "alert();" app_file "app/assets/javascripts/application.js", "alert();"
app_file "app/assets/javascripts/foo/application.js", "alert();" app_file "app/assets/javascripts/foo/application.js", "alert();"
...@@ -87,6 +88,7 @@ def assert_no_file_exists(filename) ...@@ -87,6 +88,7 @@ def assert_no_file_exists(filename)
end end
def test_precompile_does_not_hit_the_database def test_precompile_does_not_hit_the_database
app_file "app/assets/manifest.js", "//= link_tree ./javascripts"
app_file "app/assets/javascripts/application.js", "alert();" app_file "app/assets/javascripts/application.js", "alert();"
app_file "app/assets/javascripts/foo/application.js", "alert();" app_file "app/assets/javascripts/foo/application.js", "alert();"
app_file "app/controllers/users_controller.rb", <<-eoruby app_file "app/controllers/users_controller.rb", <<-eoruby
...@@ -178,8 +180,11 @@ class User < ActiveRecord::Base; raise 'should not be reached'; end ...@@ -178,8 +180,11 @@ class User < ActiveRecord::Base; raise 'should not be reached'; end
end end
test 'precompile use assets defined in app config and reassigned in app env config' do test 'precompile use assets defined in app config and reassigned in app env config' do
add_to_config 'config.assets.precompile = [ "something.js" ]' add_to_config 'config.assets.precompile = [ "something_manifest.js" ]'
add_to_env_config 'production', 'config.assets.precompile += [ "another.js" ]' add_to_env_config 'production', 'config.assets.precompile += [ "another_manifest.js" ]'
app_file 'app/assets/something_manifest.js', '//= link ./javascripts/something.js'
app_file 'app/assets/another_manifest.js', '//= link ./javascripts/another.js'
app_file 'app/assets/javascripts/something.js.erb', 'alert();' app_file 'app/assets/javascripts/something.js.erb', 'alert();'
app_file 'app/assets/javascripts/another.js.erb', 'alert();' app_file 'app/assets/javascripts/another.js.erb', 'alert();'
...@@ -190,14 +195,14 @@ class User < ActiveRecord::Base; raise 'should not be reached'; end ...@@ -190,14 +195,14 @@ class User < ActiveRecord::Base; raise 'should not be reached'; end
assert_file_exists("#{app_path}/public/assets/another-*.js") assert_file_exists("#{app_path}/public/assets/another-*.js")
end end
test "asset pipeline should use a Sprockets::Index when config.assets.digest is true" do test "asset pipeline should use a Sprockets::CachedEnvironment when config.assets.digest is true" do
add_to_config "config.action_controller.perform_caching = false" add_to_config "config.action_controller.perform_caching = false"
add_to_env_config "production", "config.assets.compile = true" add_to_env_config "production", "config.assets.compile = true"
ENV["RAILS_ENV"] = "production" ENV["RAILS_ENV"] = "production"
require "#{app_path}/config/environment" require "#{app_path}/config/environment"
assert_equal Sprockets::Index, Rails.application.assets.class assert_equal Sprockets::CachedEnvironment, Rails.application.assets.class
end end
test "precompile creates a manifest file with all the assets listed" do test "precompile creates a manifest file with all the assets listed" do
...@@ -246,7 +251,7 @@ class User < ActiveRecord::Base; raise 'should not be reached'; end ...@@ -246,7 +251,7 @@ class User < ActiveRecord::Base; raise 'should not be reached'; end
test "precompile properly refers files referenced with asset_path and runs in the provided RAILS_ENV" do test "precompile properly refers files referenced with asset_path and runs in the provided RAILS_ENV" do
app_file "app/assets/images/rails.png", "notactuallyapng" app_file "app/assets/images/rails.png", "notactuallyapng"
app_file "app/assets/stylesheets/application.css.erb", "<%= asset_path('rails.png') %>" app_file "app/assets/stylesheets/application.css.erb", "p { background-image: url(<%= asset_path('rails.png') %>) }"
add_to_env_config "test", "config.assets.digest = true" add_to_env_config "test", "config.assets.digest = true"
precompile!('RAILS_ENV=test') precompile!('RAILS_ENV=test')
...@@ -258,7 +263,7 @@ class User < ActiveRecord::Base; raise 'should not be reached'; end ...@@ -258,7 +263,7 @@ class User < ActiveRecord::Base; raise 'should not be reached'; end
test "precompile shouldn't use the digests present in manifest.json" do test "precompile shouldn't use the digests present in manifest.json" do
app_file "app/assets/images/rails.png", "notactuallyapng" app_file "app/assets/images/rails.png", "notactuallyapng"
app_file "app/assets/stylesheets/application.css.erb", "p { url: <%= asset_path('rails.png') %> }" app_file "app/assets/stylesheets/application.css.erb", "p { background-image: url(<%= asset_path('rails.png') %>) }"
ENV["RAILS_ENV"] = "production" ENV["RAILS_ENV"] = "production"
precompile! precompile!
...@@ -277,7 +282,7 @@ class User < ActiveRecord::Base; raise 'should not be reached'; end ...@@ -277,7 +282,7 @@ class User < ActiveRecord::Base; raise 'should not be reached'; end
test "precompile appends the md5 hash to files referenced with asset_path and run in production with digest true" do test "precompile appends the md5 hash to files referenced with asset_path and run in production with digest true" do
app_file "app/assets/images/rails.png", "notactuallyapng" app_file "app/assets/images/rails.png", "notactuallyapng"
app_file "app/assets/stylesheets/application.css.erb", "<%= asset_path('rails.png') %>" app_file "app/assets/stylesheets/application.css.erb", "p { background-image: url(<%= asset_path('rails.png') %>) }"
ENV["RAILS_ENV"] = "production" ENV["RAILS_ENV"] = "production"
precompile! precompile!
...@@ -289,7 +294,8 @@ class User < ActiveRecord::Base; raise 'should not be reached'; end ...@@ -289,7 +294,8 @@ class User < ActiveRecord::Base; raise 'should not be reached'; end
test "precompile should handle utf8 filenames" do test "precompile should handle utf8 filenames" do
filename = "レイルズ.png" filename = "レイルズ.png"
app_file "app/assets/images/#{filename}", "not an image really" app_file "app/assets/images/#{filename}", "not an image really"
add_to_config "config.assets.precompile = [ /\.png$/, /application.(css|js)$/ ]" app_file "app/assets/manifest.js", "//= link_tree ./images"
add_to_config "config.assets.precompile = %w(manifest.js)"
precompile! precompile!
...@@ -394,7 +400,7 @@ class ::PostsController < ActionController::Base ; end ...@@ -394,7 +400,7 @@ class ::PostsController < ActionController::Base ; end
app_file "app/assets/javascripts/xmlhr.js.erb", "<%= Post.name %>" app_file "app/assets/javascripts/xmlhr.js.erb", "<%= Post.name %>"
precompile! precompile!
assert_equal "Post;\n", File.read(Dir["#{app_path}/public/assets/application-*.js"].first) assert_equal "Post\n;\n", File.read(Dir["#{app_path}/public/assets/application-*.js"].first)
end end
test "initialization on the assets group should set assets_dir" do test "initialization on the assets group should set assets_dir" do
...@@ -439,9 +445,9 @@ class ::PostsController < ActionController::Base ; end ...@@ -439,9 +445,9 @@ class ::PostsController < ActionController::Base ; end
class ::PostsController < ActionController::Base; end class ::PostsController < ActionController::Base; end
get '/posts', {}, {'HTTPS'=>'off'} get '/posts', {}, {'HTTPS'=>'off'}
assert_match('src="http://example.com/assets/application.self.js', last_response.body) assert_match('src="http://example.com/assets/application.debug.js', last_response.body)
get '/posts', {}, {'HTTPS'=>'on'} get '/posts', {}, {'HTTPS'=>'on'}
assert_match('src="https://example.com/assets/application.self.js', last_response.body) assert_match('src="https://example.com/assets/application.debug.js', last_response.body)
end end
test "asset urls should be protocol-relative if no request is in scope" do test "asset urls should be protocol-relative if no request is in scope" do
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册