From 628c31b353706877322e7613702d1bd4a59e3514 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Tue, 22 Mar 2011 15:43:40 -0500 Subject: Add sprockets md5s to asset tags --- .../helpers/asset_tag_helpers/javascript_tag_helpers.rb | 10 ++++++++++ .../helpers/asset_tag_helpers/stylesheet_tag_helpers.rb | 10 ++++++++++ 2 files changed, 20 insertions(+) (limited to 'actionpack') diff --git a/actionpack/lib/action_view/helpers/asset_tag_helpers/javascript_tag_helpers.rb b/actionpack/lib/action_view/helpers/asset_tag_helpers/javascript_tag_helpers.rb index 82bbfcc7d2..2187887b49 100644 --- a/actionpack/lib/action_view/helpers/asset_tag_helpers/javascript_tag_helpers.rb +++ b/actionpack/lib/action_view/helpers/asset_tag_helpers/javascript_tag_helpers.rb @@ -173,6 +173,16 @@ module ActionView # # javascript_include_tag :all, :cache => true, :recursive => true def javascript_include_tag(*sources) + if config.perform_caching + sources = sources.map do |source| + if source =~ /^\/assets\/(.+)/ + "/assets/#{Rails.application.assets.url($1)}" + else + source + end + end + end + @javascript_include ||= JavascriptIncludeTag.new(config, asset_paths) @javascript_include.include_tag(*sources) end diff --git a/actionpack/lib/action_view/helpers/asset_tag_helpers/stylesheet_tag_helpers.rb b/actionpack/lib/action_view/helpers/asset_tag_helpers/stylesheet_tag_helpers.rb index a48c87b49a..b9f49f37b4 100644 --- a/actionpack/lib/action_view/helpers/asset_tag_helpers/stylesheet_tag_helpers.rb +++ b/actionpack/lib/action_view/helpers/asset_tag_helpers/stylesheet_tag_helpers.rb @@ -136,6 +136,16 @@ module ActionView # stylesheet_link_tag :all, :concat => true # def stylesheet_link_tag(*sources) + if config.perform_caching + sources = sources.map do |source| + if source =~ /^\/assets\/(.+)/ + "/assets/#{Rails.application.assets.url($1)}" + else + source + end + end + end + @stylesheet_include ||= StylesheetIncludeTag.new(config, asset_paths) @stylesheet_include.include_tag(*sources) end -- cgit v1.2.3 From 41cc6430650d0e90e892e0bd9a29ddcefd8a9c64 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Mon, 28 Mar 2011 13:54:58 -0500 Subject: Remove sprockets exception from main asset helpers --- .../helpers/asset_tag_helpers/javascript_tag_helpers.rb | 10 ---------- .../helpers/asset_tag_helpers/stylesheet_tag_helpers.rb | 10 ---------- 2 files changed, 20 deletions(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_view/helpers/asset_tag_helpers/javascript_tag_helpers.rb b/actionpack/lib/action_view/helpers/asset_tag_helpers/javascript_tag_helpers.rb index 2187887b49..82bbfcc7d2 100644 --- a/actionpack/lib/action_view/helpers/asset_tag_helpers/javascript_tag_helpers.rb +++ b/actionpack/lib/action_view/helpers/asset_tag_helpers/javascript_tag_helpers.rb @@ -173,16 +173,6 @@ module ActionView # # javascript_include_tag :all, :cache => true, :recursive => true def javascript_include_tag(*sources) - if config.perform_caching - sources = sources.map do |source| - if source =~ /^\/assets\/(.+)/ - "/assets/#{Rails.application.assets.url($1)}" - else - source - end - end - end - @javascript_include ||= JavascriptIncludeTag.new(config, asset_paths) @javascript_include.include_tag(*sources) end diff --git a/actionpack/lib/action_view/helpers/asset_tag_helpers/stylesheet_tag_helpers.rb b/actionpack/lib/action_view/helpers/asset_tag_helpers/stylesheet_tag_helpers.rb index b9f49f37b4..a48c87b49a 100644 --- a/actionpack/lib/action_view/helpers/asset_tag_helpers/stylesheet_tag_helpers.rb +++ b/actionpack/lib/action_view/helpers/asset_tag_helpers/stylesheet_tag_helpers.rb @@ -136,16 +136,6 @@ module ActionView # stylesheet_link_tag :all, :concat => true # def stylesheet_link_tag(*sources) - if config.perform_caching - sources = sources.map do |source| - if source =~ /^\/assets\/(.+)/ - "/assets/#{Rails.application.assets.url($1)}" - else - source - end - end - end - @stylesheet_include ||= StylesheetIncludeTag.new(config, asset_paths) @stylesheet_include.include_tag(*sources) end -- cgit v1.2.3 From 9cb264555dbc630ff5e44d96b0d70061856f568c Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Mon, 28 Mar 2011 15:19:34 -0500 Subject: Add SprocketsHelper --- actionpack/lib/action_view/helpers.rb | 2 + .../lib/action_view/helpers/sprockets_helper.rb | 77 ++++++++++++++++++++++ 2 files changed, 79 insertions(+) create mode 100644 actionpack/lib/action_view/helpers/sprockets_helper.rb (limited to 'actionpack') diff --git a/actionpack/lib/action_view/helpers.rb b/actionpack/lib/action_view/helpers.rb index d338ce616a..cb1ab64121 100644 --- a/actionpack/lib/action_view/helpers.rb +++ b/actionpack/lib/action_view/helpers.rb @@ -22,6 +22,7 @@ module ActionView #:nodoc: autoload :RecordTagHelper autoload :SanitizeHelper autoload :ScriptaculousHelper + autoload :SprocketsHelper autoload :TagHelper autoload :TextHelper autoload :TranslationHelper @@ -52,6 +53,7 @@ module ActionView #:nodoc: include RecordTagHelper include SanitizeHelper include ScriptaculousHelper + include SprocketsHelper include TagHelper include TextHelper include TranslationHelper diff --git a/actionpack/lib/action_view/helpers/sprockets_helper.rb b/actionpack/lib/action_view/helpers/sprockets_helper.rb new file mode 100644 index 0000000000..4abc09e9a5 --- /dev/null +++ b/actionpack/lib/action_view/helpers/sprockets_helper.rb @@ -0,0 +1,77 @@ +require 'uri' + +module ActionView + module Helpers + module SprocketsHelper + def sprockets_javascript_path(source) + compute_sprockets_path source, 'javascripts', 'js' + end + + def sprockets_javascript_include_tag(source, options = {}) + options = { + 'type' => "application/javascript", + 'src' => sprockets_javascript_path(source) + }.merge(options.stringify_keys) + + content_tag 'script', "", options + end + + def sprockets_stylesheet_path(source) + compute_sprockets_path source, 'stylesheets', 'css' + end + + def sprockets_stylesheet_link_tag(source, options = {}) + options = { + 'rel' => "stylesheet", + 'type' => "text/css", + 'media' => "screen", + 'href' => sprockets_stylesheet_path(source) + }.merge(options.stringify_keys) + + tag 'link', options + end + + private + def compute_sprockets_path(source, dir, default_ext) + return source if URI.parse(source).host + + # Add /javscripts to relative paths + if source[0] != ?/ + source = "/#{dir}/#{source}" + end + + # Add default extension if there isn't one + if default_ext && File.extname(source).empty? + source = "#{source}.#{default_ext}" + end + + # Fingerprint url + source = Rails.application.assets.url(source) + + host = compute_asset_host(source) + + if controller.respond_to?(:request) && host && URI.parse(host).host.nil? + host = "#{controller.request.protocol}#{host}" + end + + "#{host}#{source}" + end + + def compute_asset_host(source) + if host = config.asset_host + if host.is_a?(Proc) || host.respond_to?(:call) + case host.is_a?(Proc) ? host.arity : host.method(:call).arity + when 2 + request = controller.respond_to?(:request) && controller.request + host.call(source, request) + else + host.call(source) + end + else + (host =~ /%d/) ? host % (source.hash % 4) : host + end + end + end + end + end +end -- cgit v1.2.3 From 3b4e1a91590b27f6f874927dc51f6f1755ae9f19 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Mon, 28 Mar 2011 15:58:29 -0500 Subject: Update sprockets path generation method --- actionpack/lib/action_view/helpers/sprockets_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_view/helpers/sprockets_helper.rb b/actionpack/lib/action_view/helpers/sprockets_helper.rb index 4abc09e9a5..bfc396fad5 100644 --- a/actionpack/lib/action_view/helpers/sprockets_helper.rb +++ b/actionpack/lib/action_view/helpers/sprockets_helper.rb @@ -46,7 +46,7 @@ module ActionView end # Fingerprint url - source = Rails.application.assets.url(source) + source = Rails.application.assets.path(source) host = compute_asset_host(source) -- cgit v1.2.3 From 1af295fc9a6772e587e438254cfe354e6da0fa19 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Tue, 29 Mar 2011 15:42:31 -0500 Subject: Tests for SprocketsHelper --- .../lib/action_view/helpers/sprockets_helper.rb | 16 ++-- .../app/assets/javascripts/application.js | 0 .../sprockets/app/assets/javascripts/dir/xmlhr.js | 0 .../sprockets/app/assets/javascripts/xmlhr.js | 0 .../app/assets/stylesheets/application.css | 0 .../sprockets/app/assets/stylesheets/dir/style.css | 0 .../sprockets/app/assets/stylesheets/style.css | 0 actionpack/test/template/sprockets_helper_test.rb | 93 ++++++++++++++++++++++ 8 files changed, 104 insertions(+), 5 deletions(-) create mode 100644 actionpack/test/fixtures/sprockets/app/assets/javascripts/application.js create mode 100644 actionpack/test/fixtures/sprockets/app/assets/javascripts/dir/xmlhr.js create mode 100644 actionpack/test/fixtures/sprockets/app/assets/javascripts/xmlhr.js create mode 100644 actionpack/test/fixtures/sprockets/app/assets/stylesheets/application.css create mode 100644 actionpack/test/fixtures/sprockets/app/assets/stylesheets/dir/style.css create mode 100644 actionpack/test/fixtures/sprockets/app/assets/stylesheets/style.css create mode 100644 actionpack/test/template/sprockets_helper_test.rb (limited to 'actionpack') diff --git a/actionpack/lib/action_view/helpers/sprockets_helper.rb b/actionpack/lib/action_view/helpers/sprockets_helper.rb index bfc396fad5..f6f4f06d6e 100644 --- a/actionpack/lib/action_view/helpers/sprockets_helper.rb +++ b/actionpack/lib/action_view/helpers/sprockets_helper.rb @@ -9,7 +9,7 @@ module ActionView def sprockets_javascript_include_tag(source, options = {}) options = { - 'type' => "application/javascript", + 'type' => "text/javascript", 'src' => sprockets_javascript_path(source) }.merge(options.stringify_keys) @@ -33,6 +33,8 @@ module ActionView private def compute_sprockets_path(source, dir, default_ext) + source = source.to_s + return source if URI.parse(source).host # Add /javscripts to relative paths @@ -46,15 +48,15 @@ module ActionView end # Fingerprint url - source = Rails.application.assets.path(source) + source = assets.path(source) host = compute_asset_host(source) - if controller.respond_to?(:request) && host && URI.parse(host).host.nil? - host = "#{controller.request.protocol}#{host}" + if controller.respond_to?(:request) && host && URI.parse(host).host + source = "#{controller.request.protocol}#{host}#{source}" end - "#{host}#{source}" + source end def compute_asset_host(source) @@ -72,6 +74,10 @@ module ActionView end end end + + def assets + Rails.application.assets + end end end end diff --git a/actionpack/test/fixtures/sprockets/app/assets/javascripts/application.js b/actionpack/test/fixtures/sprockets/app/assets/javascripts/application.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/actionpack/test/fixtures/sprockets/app/assets/javascripts/dir/xmlhr.js b/actionpack/test/fixtures/sprockets/app/assets/javascripts/dir/xmlhr.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/actionpack/test/fixtures/sprockets/app/assets/javascripts/xmlhr.js b/actionpack/test/fixtures/sprockets/app/assets/javascripts/xmlhr.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/actionpack/test/fixtures/sprockets/app/assets/stylesheets/application.css b/actionpack/test/fixtures/sprockets/app/assets/stylesheets/application.css new file mode 100644 index 0000000000..e69de29bb2 diff --git a/actionpack/test/fixtures/sprockets/app/assets/stylesheets/dir/style.css b/actionpack/test/fixtures/sprockets/app/assets/stylesheets/dir/style.css new file mode 100644 index 0000000000..e69de29bb2 diff --git a/actionpack/test/fixtures/sprockets/app/assets/stylesheets/style.css b/actionpack/test/fixtures/sprockets/app/assets/stylesheets/style.css new file mode 100644 index 0000000000..e69de29bb2 diff --git a/actionpack/test/template/sprockets_helper_test.rb b/actionpack/test/template/sprockets_helper_test.rb new file mode 100644 index 0000000000..f6fd4f5bb4 --- /dev/null +++ b/actionpack/test/template/sprockets_helper_test.rb @@ -0,0 +1,93 @@ +require 'abstract_unit' +require 'sprockets' + +class SprocketsHelperTest < ActionView::TestCase + tests ActionView::Helpers::SprocketsHelper + + attr_accessor :assets + + def setup + super + + @controller = BasicController.new + + @request = Class.new do + def protocol() 'http://' end + def ssl?() false end + def host_with_port() 'localhost' end + end.new + + @controller.request = @request + + @assets = Sprockets::Environment.new + @assets.paths << FIXTURES.join("sprockets/app/assets") + end + + def url_for(*args) + "http://www.example.com" + end + + test "javascript path" do + assert_equal "/javascripts/application-d41d8cd98f00b204e9800998ecf8427e.js", + sprockets_javascript_path(:application) + + assert_equal "/javascripts/xmlhr-d41d8cd98f00b204e9800998ecf8427e.js", + sprockets_javascript_path("xmlhr") + assert_equal "/javascripts/dir/xmlhr-d41d8cd98f00b204e9800998ecf8427e.js", + sprockets_javascript_path("dir/xmlhr.js") + + assert_equal "/dir/xmlhr.js", + sprockets_javascript_path("/dir/xmlhr") + + assert_equal "http://www.railsapplication.com/js/xmlhr", + sprockets_javascript_path("http://www.railsapplication.com/js/xmlhr") + assert_equal "http://www.railsapplication.com/js/xmlhr.js", + sprockets_javascript_path("http://www.railsapplication.com/js/xmlhr.js") + end + + test "javascript include tag" do + assert_equal '', + sprockets_javascript_include_tag(:application) + + assert_equal '', + sprockets_javascript_include_tag("xmlhr") + assert_equal '', + sprockets_javascript_include_tag("xmlhr.js") + assert_equal '', + sprockets_javascript_include_tag("http://www.railsapplication.com/xmlhr") + end + + test "stylesheet path" do + assert_equal "/stylesheets/application-d41d8cd98f00b204e9800998ecf8427e.css", + sprockets_stylesheet_path(:application) + + assert_equal "/stylesheets/style-d41d8cd98f00b204e9800998ecf8427e.css", + sprockets_stylesheet_path("style") + assert_equal "/stylesheets/dir/style-d41d8cd98f00b204e9800998ecf8427e.css", + sprockets_stylesheet_path("dir/style.css") + assert_equal "/dir/style.css", + sprockets_stylesheet_path("/dir/style.css") + + assert_equal "http://www.railsapplication.com/css/style", + sprockets_stylesheet_path("http://www.railsapplication.com/css/style") + assert_equal "http://www.railsapplication.com/css/style.css", + sprockets_stylesheet_path("http://www.railsapplication.com/css/style.css") + end + + test "stylesheet link tag" do + assert_equal '', + sprockets_stylesheet_link_tag(:application) + + assert_equal '', + sprockets_stylesheet_link_tag("style") + assert_equal '', + sprockets_stylesheet_link_tag("style.css") + + assert_equal '', + sprockets_stylesheet_link_tag("http://www.railsapplication.com/style.css") + assert_equal '', + sprockets_stylesheet_link_tag("style", :media => "all") + assert_equal '', + sprockets_stylesheet_link_tag("style", :media => "print") + end +end -- cgit v1.2.3 From 375443a9c5eb28279d66f5a53677856e9a39d93f Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Tue, 29 Mar 2011 15:53:28 -0500 Subject: Use sprockets helpers if config.use_sprockets is set --- .../helpers/asset_tag_helpers/javascript_tag_helpers.rb | 14 +++++++++++--- .../helpers/asset_tag_helpers/stylesheet_tag_helpers.rb | 14 +++++++++++--- 2 files changed, 22 insertions(+), 6 deletions(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_view/helpers/asset_tag_helpers/javascript_tag_helpers.rb b/actionpack/lib/action_view/helpers/asset_tag_helpers/javascript_tag_helpers.rb index 82bbfcc7d2..ed95f1c018 100644 --- a/actionpack/lib/action_view/helpers/asset_tag_helpers/javascript_tag_helpers.rb +++ b/actionpack/lib/action_view/helpers/asset_tag_helpers/javascript_tag_helpers.rb @@ -86,7 +86,11 @@ module ActionView # javascript_path "http://www.railsapplication.com/js/xmlhr" # => http://www.railsapplication.com/js/xmlhr # javascript_path "http://www.railsapplication.com/js/xmlhr.js" # => http://www.railsapplication.com/js/xmlhr.js def javascript_path(source) - asset_paths.compute_public_path(source, 'javascripts', 'js') + if config.use_sprockets + sprockets_javascript_path(source) + else + asset_paths.compute_public_path(source, 'javascripts', 'js') + end end alias_method :path_to_javascript, :javascript_path # aliased to avoid conflicts with a javascript_path named route @@ -173,8 +177,12 @@ module ActionView # # javascript_include_tag :all, :cache => true, :recursive => true def javascript_include_tag(*sources) - @javascript_include ||= JavascriptIncludeTag.new(config, asset_paths) - @javascript_include.include_tag(*sources) + if config.use_sprockets + sprockets_javascript_include_tag(*sources) + else + @javascript_include ||= JavascriptIncludeTag.new(config, asset_paths) + @javascript_include.include_tag(*sources) + end end end diff --git a/actionpack/lib/action_view/helpers/asset_tag_helpers/stylesheet_tag_helpers.rb b/actionpack/lib/action_view/helpers/asset_tag_helpers/stylesheet_tag_helpers.rb index a48c87b49a..a994afb65e 100644 --- a/actionpack/lib/action_view/helpers/asset_tag_helpers/stylesheet_tag_helpers.rb +++ b/actionpack/lib/action_view/helpers/asset_tag_helpers/stylesheet_tag_helpers.rb @@ -63,7 +63,11 @@ module ActionView # stylesheet_path "http://www.railsapplication.com/css/style" # => http://www.railsapplication.com/css/style # stylesheet_path "http://www.railsapplication.com/css/style.css" # => http://www.railsapplication.com/css/style.css def stylesheet_path(source) - asset_paths.compute_public_path(source, 'stylesheets', 'css') + if config.use_sprockets + sprockets_stylesheet_path(source) + else + asset_paths.compute_public_path(source, 'stylesheets', 'css') + end end alias_method :path_to_stylesheet, :stylesheet_path # aliased to avoid conflicts with a stylesheet_path named route @@ -136,8 +140,12 @@ module ActionView # stylesheet_link_tag :all, :concat => true # def stylesheet_link_tag(*sources) - @stylesheet_include ||= StylesheetIncludeTag.new(config, asset_paths) - @stylesheet_include.include_tag(*sources) + if config.use_sprockets + sprockets_stylesheet_link_tag(*sources) + else + @stylesheet_include ||= StylesheetIncludeTag.new(config, asset_paths) + @stylesheet_include.include_tag(*sources) + end end end -- cgit v1.2.3 From bed7a1acc46c9b211b7feaa21cc10395283392ab Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Tue, 29 Mar 2011 16:17:49 -0500 Subject: Copy use_sprockets config --- actionpack/lib/abstract_controller/asset_paths.rb | 4 ++-- actionpack/lib/action_controller/railtie.rb | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) (limited to 'actionpack') diff --git a/actionpack/lib/abstract_controller/asset_paths.rb b/actionpack/lib/abstract_controller/asset_paths.rb index 9ca2fb742f..ad14cd6d87 100644 --- a/actionpack/lib/abstract_controller/asset_paths.rb +++ b/actionpack/lib/abstract_controller/asset_paths.rb @@ -3,7 +3,7 @@ module AbstractController extend ActiveSupport::Concern included do - config_accessor :asset_host, :asset_path, :assets_dir, :javascripts_dir, :stylesheets_dir + config_accessor :asset_host, :asset_path, :assets_dir, :javascripts_dir, :stylesheets_dir, :use_sprockets end end -end \ No newline at end of file +end diff --git a/actionpack/lib/action_controller/railtie.rb b/actionpack/lib/action_controller/railtie.rb index f0c29825ba..0f87295d47 100644 --- a/actionpack/lib/action_controller/railtie.rb +++ b/actionpack/lib/action_controller/railtie.rb @@ -21,6 +21,7 @@ module ActionController paths = app.config.paths options = app.config.action_controller + options.use_sprockets ||= app.config.use_sprockets options.assets_dir ||= paths["public"].first options.javascripts_dir ||= paths["public/javascripts"].first options.stylesheets_dir ||= paths["public/stylesheets"].first -- cgit v1.2.3 From a5f547cc7937fe1c75ea741b5432e89f7539cb2b Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Tue, 29 Mar 2011 17:27:49 -0500 Subject: Only add fingerprints if perform_caching is on --- actionpack/lib/action_view/helpers/sprockets_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_view/helpers/sprockets_helper.rb b/actionpack/lib/action_view/helpers/sprockets_helper.rb index f6f4f06d6e..9fd5f6759c 100644 --- a/actionpack/lib/action_view/helpers/sprockets_helper.rb +++ b/actionpack/lib/action_view/helpers/sprockets_helper.rb @@ -48,7 +48,7 @@ module ActionView end # Fingerprint url - source = assets.path(source) + source = assets.path(source, config.perform_caching) host = compute_asset_host(source) -- cgit v1.2.3 From db3e310d6b327b2b58cfbc0318abd3b4ddca5e30 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Tue, 29 Mar 2011 18:05:23 -0500 Subject: Change back to /assets prefix --- actionpack/lib/action_view/helpers/sprockets_helper.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_view/helpers/sprockets_helper.rb b/actionpack/lib/action_view/helpers/sprockets_helper.rb index 9fd5f6759c..4f19f4bb21 100644 --- a/actionpack/lib/action_view/helpers/sprockets_helper.rb +++ b/actionpack/lib/action_view/helpers/sprockets_helper.rb @@ -4,7 +4,7 @@ module ActionView module Helpers module SprocketsHelper def sprockets_javascript_path(source) - compute_sprockets_path source, 'javascripts', 'js' + compute_sprockets_path source, 'assets', 'js' end def sprockets_javascript_include_tag(source, options = {}) @@ -17,7 +17,7 @@ module ActionView end def sprockets_stylesheet_path(source) - compute_sprockets_path source, 'stylesheets', 'css' + compute_sprockets_path source, 'assets', 'css' end def sprockets_stylesheet_link_tag(source, options = {}) -- cgit v1.2.3 From 651d371a247b0c473fb35a62076e480d95d84a35 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Tue, 29 Mar 2011 21:23:05 -0500 Subject: Rename option to config.asset_pipeline --- actionpack/lib/action_controller/railtie.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_controller/railtie.rb b/actionpack/lib/action_controller/railtie.rb index 0f87295d47..175b7744d7 100644 --- a/actionpack/lib/action_controller/railtie.rb +++ b/actionpack/lib/action_controller/railtie.rb @@ -21,7 +21,7 @@ module ActionController paths = app.config.paths options = app.config.action_controller - options.use_sprockets ||= app.config.use_sprockets + options.use_sprockets ||= app.config.asset_pipeline options.assets_dir ||= paths["public"].first options.javascripts_dir ||= paths["public/javascripts"].first options.stylesheets_dir ||= paths["public/stylesheets"].first -- cgit v1.2.3 From 77d8f7a4b71d7f52a7ba6f8bc7f7f6f6ac9b81e0 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Tue, 29 Mar 2011 21:40:24 -0500 Subject: Seperate asset directories --- .../lib/action_view/helpers/sprockets_helper.rb | 4 ++- .../app/assets/javascripts/application.js | 0 .../sprockets/app/assets/javascripts/dir/xmlhr.js | 0 .../sprockets/app/assets/javascripts/xmlhr.js | 0 .../app/assets/stylesheets/application.css | 0 .../sprockets/app/assets/stylesheets/dir/style.css | 0 .../sprockets/app/assets/stylesheets/style.css | 0 .../sprockets/app/javascripts/application.js | 0 .../sprockets/app/javascripts/dir/xmlhr.js | 0 .../fixtures/sprockets/app/javascripts/xmlhr.js | 0 .../sprockets/app/stylesheets/application.css | 0 .../sprockets/app/stylesheets/dir/style.css | 0 .../fixtures/sprockets/app/stylesheets/style.css | 0 actionpack/test/template/sprockets_helper_test.rb | 33 ++++++++++++---------- 14 files changed, 21 insertions(+), 16 deletions(-) delete mode 100644 actionpack/test/fixtures/sprockets/app/assets/javascripts/application.js delete mode 100644 actionpack/test/fixtures/sprockets/app/assets/javascripts/dir/xmlhr.js delete mode 100644 actionpack/test/fixtures/sprockets/app/assets/javascripts/xmlhr.js delete mode 100644 actionpack/test/fixtures/sprockets/app/assets/stylesheets/application.css delete mode 100644 actionpack/test/fixtures/sprockets/app/assets/stylesheets/dir/style.css delete mode 100644 actionpack/test/fixtures/sprockets/app/assets/stylesheets/style.css create mode 100644 actionpack/test/fixtures/sprockets/app/javascripts/application.js create mode 100644 actionpack/test/fixtures/sprockets/app/javascripts/dir/xmlhr.js create mode 100644 actionpack/test/fixtures/sprockets/app/javascripts/xmlhr.js create mode 100644 actionpack/test/fixtures/sprockets/app/stylesheets/application.css create mode 100644 actionpack/test/fixtures/sprockets/app/stylesheets/dir/style.css create mode 100644 actionpack/test/fixtures/sprockets/app/stylesheets/style.css (limited to 'actionpack') diff --git a/actionpack/lib/action_view/helpers/sprockets_helper.rb b/actionpack/lib/action_view/helpers/sprockets_helper.rb index 4f19f4bb21..408a2030ab 100644 --- a/actionpack/lib/action_view/helpers/sprockets_helper.rb +++ b/actionpack/lib/action_view/helpers/sprockets_helper.rb @@ -48,7 +48,9 @@ module ActionView end # Fingerprint url - source = assets.path(source, config.perform_caching) + if source =~ /^\/#{dir}\/(.+)/ + source = assets.path($1, config.perform_caching, dir) + end host = compute_asset_host(source) diff --git a/actionpack/test/fixtures/sprockets/app/assets/javascripts/application.js b/actionpack/test/fixtures/sprockets/app/assets/javascripts/application.js deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/actionpack/test/fixtures/sprockets/app/assets/javascripts/dir/xmlhr.js b/actionpack/test/fixtures/sprockets/app/assets/javascripts/dir/xmlhr.js deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/actionpack/test/fixtures/sprockets/app/assets/javascripts/xmlhr.js b/actionpack/test/fixtures/sprockets/app/assets/javascripts/xmlhr.js deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/actionpack/test/fixtures/sprockets/app/assets/stylesheets/application.css b/actionpack/test/fixtures/sprockets/app/assets/stylesheets/application.css deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/actionpack/test/fixtures/sprockets/app/assets/stylesheets/dir/style.css b/actionpack/test/fixtures/sprockets/app/assets/stylesheets/dir/style.css deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/actionpack/test/fixtures/sprockets/app/assets/stylesheets/style.css b/actionpack/test/fixtures/sprockets/app/assets/stylesheets/style.css deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/actionpack/test/fixtures/sprockets/app/javascripts/application.js b/actionpack/test/fixtures/sprockets/app/javascripts/application.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/actionpack/test/fixtures/sprockets/app/javascripts/dir/xmlhr.js b/actionpack/test/fixtures/sprockets/app/javascripts/dir/xmlhr.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/actionpack/test/fixtures/sprockets/app/javascripts/xmlhr.js b/actionpack/test/fixtures/sprockets/app/javascripts/xmlhr.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/actionpack/test/fixtures/sprockets/app/stylesheets/application.css b/actionpack/test/fixtures/sprockets/app/stylesheets/application.css new file mode 100644 index 0000000000..e69de29bb2 diff --git a/actionpack/test/fixtures/sprockets/app/stylesheets/dir/style.css b/actionpack/test/fixtures/sprockets/app/stylesheets/dir/style.css new file mode 100644 index 0000000000..e69de29bb2 diff --git a/actionpack/test/fixtures/sprockets/app/stylesheets/style.css b/actionpack/test/fixtures/sprockets/app/stylesheets/style.css new file mode 100644 index 0000000000..e69de29bb2 diff --git a/actionpack/test/template/sprockets_helper_test.rb b/actionpack/test/template/sprockets_helper_test.rb index f6fd4f5bb4..67aee86d02 100644 --- a/actionpack/test/template/sprockets_helper_test.rb +++ b/actionpack/test/template/sprockets_helper_test.rb @@ -20,7 +20,10 @@ class SprocketsHelperTest < ActionView::TestCase @controller.request = @request @assets = Sprockets::Environment.new - @assets.paths << FIXTURES.join("sprockets/app/assets") + @assets.paths << FIXTURES.join("sprockets/app/javascripts") + @assets.paths << FIXTURES.join("sprockets/app/stylesheets") + + config.perform_caching = true end def url_for(*args) @@ -28,12 +31,12 @@ class SprocketsHelperTest < ActionView::TestCase end test "javascript path" do - assert_equal "/javascripts/application-d41d8cd98f00b204e9800998ecf8427e.js", + assert_equal "/assets/application-d41d8cd98f00b204e9800998ecf8427e.js", sprockets_javascript_path(:application) - assert_equal "/javascripts/xmlhr-d41d8cd98f00b204e9800998ecf8427e.js", + assert_equal "/assets/xmlhr-d41d8cd98f00b204e9800998ecf8427e.js", sprockets_javascript_path("xmlhr") - assert_equal "/javascripts/dir/xmlhr-d41d8cd98f00b204e9800998ecf8427e.js", + assert_equal "/assets/dir/xmlhr-d41d8cd98f00b204e9800998ecf8427e.js", sprockets_javascript_path("dir/xmlhr.js") assert_equal "/dir/xmlhr.js", @@ -46,24 +49,24 @@ class SprocketsHelperTest < ActionView::TestCase end test "javascript include tag" do - assert_equal '', + assert_equal '', sprockets_javascript_include_tag(:application) - assert_equal '', + assert_equal '', sprockets_javascript_include_tag("xmlhr") - assert_equal '', + assert_equal '', sprockets_javascript_include_tag("xmlhr.js") assert_equal '', sprockets_javascript_include_tag("http://www.railsapplication.com/xmlhr") end test "stylesheet path" do - assert_equal "/stylesheets/application-d41d8cd98f00b204e9800998ecf8427e.css", + assert_equal "/assets/application-d41d8cd98f00b204e9800998ecf8427e.css", sprockets_stylesheet_path(:application) - assert_equal "/stylesheets/style-d41d8cd98f00b204e9800998ecf8427e.css", + assert_equal "/assets/style-d41d8cd98f00b204e9800998ecf8427e.css", sprockets_stylesheet_path("style") - assert_equal "/stylesheets/dir/style-d41d8cd98f00b204e9800998ecf8427e.css", + assert_equal "/assets/dir/style-d41d8cd98f00b204e9800998ecf8427e.css", sprockets_stylesheet_path("dir/style.css") assert_equal "/dir/style.css", sprockets_stylesheet_path("/dir/style.css") @@ -75,19 +78,19 @@ class SprocketsHelperTest < ActionView::TestCase end test "stylesheet link tag" do - assert_equal '', + assert_equal '', sprockets_stylesheet_link_tag(:application) - assert_equal '', + assert_equal '', sprockets_stylesheet_link_tag("style") - assert_equal '', + assert_equal '', sprockets_stylesheet_link_tag("style.css") assert_equal '', sprockets_stylesheet_link_tag("http://www.railsapplication.com/style.css") - assert_equal '', + assert_equal '', sprockets_stylesheet_link_tag("style", :media => "all") - assert_equal '', + assert_equal '', sprockets_stylesheet_link_tag("style", :media => "print") end end -- cgit v1.2.3 From 28fee29e383258c38649e20dc9508188010020c8 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Wed, 30 Mar 2011 21:56:15 -0500 Subject: Unify sprockets config options --- actionpack/lib/action_controller/railtie.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_controller/railtie.rb b/actionpack/lib/action_controller/railtie.rb index 175b7744d7..0dd13fa9bf 100644 --- a/actionpack/lib/action_controller/railtie.rb +++ b/actionpack/lib/action_controller/railtie.rb @@ -21,7 +21,7 @@ module ActionController paths = app.config.paths options = app.config.action_controller - options.use_sprockets ||= app.config.asset_pipeline + options.use_sprockets ||= app.config.assets.enabled options.assets_dir ||= paths["public"].first options.javascripts_dir ||= paths["public/javascripts"].first options.stylesheets_dir ||= paths["public/stylesheets"].first -- cgit v1.2.3