diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2015-08-19 20:17:35 -0300 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2015-08-19 20:17:35 -0300 |
commit | 3ee7c5706fb81fda6cb138b3288a5039388e0b92 (patch) | |
tree | 00601be017b3d737c5ab142dc3710144651e5ca5 /railties | |
parent | f454ad37ed46e14eb535eb3305d2c3183a5d52f7 (diff) | |
parent | d0e0fbafb205f96444d889c8654f18a9ee0bb328 (diff) | |
download | rails-3ee7c5706fb81fda6cb138b3288a5039388e0b92.tar.gz rails-3ee7c5706fb81fda6cb138b3288a5039388e0b92.tar.bz2 rails-3ee7c5706fb81fda6cb138b3288a5039388e0b92.zip |
Merge pull request #21132 from Andreis13/sprockets-4
Migrate to Sprockets 4.
Diffstat (limited to 'railties')
7 files changed, 59 insertions, 18 deletions
diff --git a/railties/lib/rails/generators/app_base.rb b/railties/lib/rails/generators/app_base.rb index 249fe96772..a5fdfdcf2f 100644 --- a/railties/lib/rails/generators/app_base.rb +++ b/railties/lib/rails/generators/app_base.rb @@ -209,12 +209,16 @@ module Rails [ GemfileEntry.path('rails', Rails::Generators::RAILS_DEV_PATH), GemfileEntry.github('sprockets-rails', 'rails/sprockets-rails'), + GemfileEntry.github('sprockets', 'rails/sprockets'), + GemfileEntry.github('sass-rails', 'rails/sass-rails'), GemfileEntry.github('arel', 'rails/arel') ] elsif options.edge? [ GemfileEntry.github('rails', 'rails/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') ] else @@ -255,8 +259,6 @@ module Rails return [] if options[:skip_sprockets] gems = [] - gems << GemfileEntry.version('sass-rails', '~> 5.0', - 'Use SCSS for stylesheets') gems << GemfileEntry.version('uglifier', '>= 1.3.0', diff --git a/railties/lib/rails/generators/rails/app/templates/app/assets/manifest.js.tt b/railties/lib/rails/generators/rails/app/templates/app/assets/manifest.js.tt new file mode 100644 index 0000000000..3325553f57 --- /dev/null +++ b/railties/lib/rails/generators/rails/app/templates/app/assets/manifest.js.tt @@ -0,0 +1,8 @@ + +<% unless options.api? -%> +//= link_tree ./images +<% end -%> +<% unless options.skip_javascript -%> +//= link ./javascripts/application.js +<% end -%> +//= link ./stylesheets/application.css diff --git a/railties/lib/rails/generators/rails/plugin/plugin_generator.rb b/railties/lib/rails/generators/rails/plugin/plugin_generator.rb index 0e1326ce4f..8fea30189e 100644 --- a/railties/lib/rails/generators/rails/plugin/plugin_generator.rb +++ b/railties/lib/rails/generators/rails/plugin/plugin_generator.rb @@ -104,8 +104,9 @@ task default: :test end def test_dummy_assets - 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/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/dummy_manifest.js", "#{dummy_path}/app/assets/manifest.js", force: true end def test_dummy_clean @@ -122,6 +123,10 @@ task default: :test end end + def assets_manifest + template "rails/engine_manifest.js", "app/assets/#{underscored_name}_manifest.js" + end + def stylesheets if mountable? copy_file "rails/stylesheets.css", @@ -220,6 +225,10 @@ task default: :test build(:lib) end + def create_assets_manifest_file + build(:assets_manifest) unless api? + end + def create_public_stylesheets_files build(:stylesheets) unless api? end diff --git a/railties/lib/rails/generators/rails/plugin/templates/rails/dummy_manifest.js b/railties/lib/rails/generators/rails/plugin/templates/rails/dummy_manifest.js new file mode 100644 index 0000000000..ace695a811 --- /dev/null +++ b/railties/lib/rails/generators/rails/plugin/templates/rails/dummy_manifest.js @@ -0,0 +1,11 @@ + +<% 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 -%> diff --git a/railties/lib/rails/generators/rails/plugin/templates/rails/engine_manifest.js b/railties/lib/rails/generators/rails/plugin/templates/rails/engine_manifest.js new file mode 100644 index 0000000000..f8ef26982a --- /dev/null +++ b/railties/lib/rails/generators/rails/plugin/templates/rails/engine_manifest.js @@ -0,0 +1,6 @@ +<% if mountable? -%> +<% unless options.skip_javascript -%> +//= link ./javascripts/<%= namespaced_name %>/application.js +<% end -%> +//= link ./stylesheets/<%= namespaced_name %>/application.css +<% end -%> diff --git a/railties/test/application/asset_debugging_test.rb b/railties/test/application/asset_debugging_test.rb index 36ab8109a7..fef65adda2 100644 --- a/railties/test/application/asset_debugging_test.rb +++ b/railties/test/application/asset_debugging_test.rb @@ -48,7 +48,7 @@ module ApplicationTests assert_no_match(/<script src="\/assets\/xmlhr-([0-z]+)\.js"><\/script>/, last_response.body) 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" ENV["RAILS_ENV"] = "production" @@ -57,8 +57,7 @@ module ApplicationTests class ::PostsController < ActionController::Base ; end 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\/xmlhr(\.self)?-([0-z]+)\.js\?body=1"><\/script>/, last_response.body) + assert_match(/<script src="\/assets\/application(\.debug)?-([0-z]+)\.js"><\/script>/, last_response.body) end end end diff --git a/railties/test/application/assets_test.rb b/railties/test/application/assets_test.rb index ba2c27d8e8..ddcd51f3fc 100644 --- a/railties/test/application/assets_test.rb +++ b/railties/test/application/assets_test.rb @@ -72,6 +72,7 @@ module ApplicationTests end 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/foo/application.js", "alert();" @@ -87,6 +88,7 @@ module ApplicationTests end 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/foo/application.js", "alert();" app_file "app/controllers/users_controller.rb", <<-eoruby @@ -178,8 +180,11 @@ module ApplicationTests end 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_env_config 'production', 'config.assets.precompile += [ "another.js" ]' + add_to_config 'config.assets.precompile = [ "something_manifest.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/another.js.erb', 'alert();' @@ -190,14 +195,14 @@ module ApplicationTests assert_file_exists("#{app_path}/public/assets/another-*.js") 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_env_config "production", "config.assets.compile = true" ENV["RAILS_ENV"] = "production" require "#{app_path}/config/environment" - assert_equal Sprockets::Index, Rails.application.assets.class + assert_equal Sprockets::CachedEnvironment, Rails.application.assets.class end test "precompile creates a manifest file with all the assets listed" do @@ -246,7 +251,7 @@ module ApplicationTests 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/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" precompile!('RAILS_ENV=test') @@ -258,7 +263,7 @@ module ApplicationTests test "precompile shouldn't use the digests present in manifest.json" do 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" precompile! @@ -277,7 +282,7 @@ module ApplicationTests 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/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" precompile! @@ -289,7 +294,8 @@ module ApplicationTests test "precompile should handle utf8 filenames" do filename = "レイルズ.png" 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! @@ -394,7 +400,7 @@ module ApplicationTests app_file "app/assets/javascripts/xmlhr.js.erb", "<%= Post.name %>" 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 test "initialization on the assets group should set assets_dir" do @@ -439,9 +445,9 @@ module ApplicationTests class ::PostsController < ActionController::Base; end 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'} - 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 test "asset urls should be protocol-relative if no request is in scope" do |