diff options
Diffstat (limited to 'actionpack/lib')
-rw-r--r-- | actionpack/lib/action_view/helpers.rb | 2 | ||||
-rw-r--r-- | actionpack/lib/action_view/helpers/asset_tag_helper.rb | 18 | ||||
-rw-r--r-- | actionpack/lib/sprockets/helpers/rails_helper.rb (renamed from actionpack/lib/action_view/helpers/sprockets_helper.rb) | 55 | ||||
-rw-r--r-- | actionpack/lib/sprockets/railtie.rb | 2 |
4 files changed, 33 insertions, 44 deletions
diff --git a/actionpack/lib/action_view/helpers.rb b/actionpack/lib/action_view/helpers.rb index 78a68db282..262e0f1010 100644 --- a/actionpack/lib/action_view/helpers.rb +++ b/actionpack/lib/action_view/helpers.rb @@ -22,7 +22,6 @@ module ActionView #:nodoc: autoload :RecordTagHelper autoload :RenderingHelper autoload :SanitizeHelper - autoload :SprocketsHelper autoload :TagHelper autoload :TextHelper autoload :TranslationHelper @@ -53,7 +52,6 @@ module ActionView #:nodoc: include RecordTagHelper include RenderingHelper include SanitizeHelper - include SprocketsHelper include TagHelper include TextHelper include TranslationHelper diff --git a/actionpack/lib/action_view/helpers/asset_tag_helper.rb b/actionpack/lib/action_view/helpers/asset_tag_helper.rb index 9bc847a1ab..7970176d37 100644 --- a/actionpack/lib/action_view/helpers/asset_tag_helper.rb +++ b/actionpack/lib/action_view/helpers/asset_tag_helper.rb @@ -274,11 +274,7 @@ module ActionView # The alias +path_to_image+ is provided to avoid that. Rails uses the alias internally, and # plugin authors are encouraged to do so. def image_path(source) - if config.use_sprockets - asset_path(source) - else - asset_paths.compute_public_path(source, 'images') - end + asset_paths.compute_public_path(source, 'images') end alias_method :path_to_image, :image_path # aliased to avoid conflicts with an image_path named route @@ -293,11 +289,7 @@ module ActionView # video_path("/trailers/hd.avi") # => /trailers/hd.avi # video_path("http://www.example.com/vid/hd.avi") # => http://www.example.com/vid/hd.avi def video_path(source) - if config.use_sprockets - asset_path(source) - else - asset_paths.compute_public_path(source, 'videos') - end + asset_paths.compute_public_path(source, 'videos') end alias_method :path_to_video, :video_path # aliased to avoid conflicts with a video_path named route @@ -312,11 +304,7 @@ module ActionView # audio_path("/sounds/horse.wav") # => /sounds/horse.wav # audio_path("http://www.example.com/sounds/horse.wav") # => http://www.example.com/sounds/horse.wav def audio_path(source) - if config.use_sprockets - asset_path(source) - else - asset_paths.compute_public_path(source, 'audios') - end + asset_paths.compute_public_path(source, 'audios') end alias_method :path_to_audio, :audio_path # aliased to avoid conflicts with an audio_path named route diff --git a/actionpack/lib/action_view/helpers/sprockets_helper.rb b/actionpack/lib/sprockets/helpers/rails_helper.rb index e5d780225b..3b64be67d9 100644 --- a/actionpack/lib/action_view/helpers/sprockets_helper.rb +++ b/actionpack/lib/sprockets/helpers/rails_helper.rb @@ -1,27 +1,24 @@ -require 'uri' -require 'action_view/helpers/asset_paths' +require "action_view/helpers/asset_paths" +require "action_view/helpers/asset_tag_helper" -module ActionView +module Sprockets module Helpers - module SprocketsHelper - def debug_assets? - params[:debug_assets] == '1' || - params[:debug_assets] == 'true' - end - - def asset_path(source, default_ext = nil, body = false) - source = source.logical_path if source.respond_to?(:logical_path) - path = sprockets_asset_paths.compute_public_path(source, 'assets', default_ext, true) - body ? "#{path}?body=1" : path + module RailsHelper + def asset_paths + @asset_paths ||= begin + config = self.config if respond_to?(:config) + controller = self.controller if respond_to?(:controller) + RailsHelper::AssetPaths.new(config, controller) + end end - def sprockets_javascript_include_tag(source, options = {}) + def javascript_include_tag(source, options = {}) debug = options.key?(:debug) ? options.delete(:debug) : debug_assets? body = options.key?(:body) ? options.delete(:body) : false - if debug && asset = sprockets_asset_paths.asset_for(source, 'js') + if debug && asset = asset_paths.asset_for(source, 'js') asset.to_a.map { |dep| - sprockets_javascript_include_tag(dep, :debug => false, :body => true) + javascript_include_tag(dep, :debug => false, :body => true) }.join("\n").html_safe else options = { @@ -33,13 +30,13 @@ module ActionView end end - def sprockets_stylesheet_link_tag(source, options = {}) + def stylesheet_link_tag(source, options = {}) debug = options.key?(:debug) ? options.delete(:debug) : debug_assets? body = options.key?(:body) ? options.delete(:body) : false - if debug && asset = sprockets_asset_paths.asset_for(source, 'css') + if debug && asset = asset_paths.asset_for(source, 'css') asset.to_a.map { |dep| - sprockets_stylesheet_link_tag(dep, :debug => false, :body => true) + stylesheet_link_tag(dep, :debug => false, :body => true) }.join("\n").html_safe else options = { @@ -53,17 +50,23 @@ module ActionView end end - private + private + def debug_assets? + params[:debug_assets] == '1' || + params[:debug_assets] == 'true' + end - def sprockets_asset_paths - @sprockets_asset_paths ||= begin - config = self.config if respond_to?(:config) - controller = self.controller if respond_to?(:controller) - SprocketsHelper::AssetPaths.new(config, controller) - end + def asset_path(source, default_ext = nil, body = false) + source = source.logical_path if source.respond_to?(:logical_path) + path = asset_paths.compute_public_path(source, 'assets', default_ext, true) + body ? "#{path}?body=1" : path end class AssetPaths < ActionView::Helpers::AssetPaths #:nodoc: + def compute_public_path(source, dir, ext=nil, include_host=true) + super(source, 'assets', ext, include_host) + end + def asset_for(source, ext) source = source.to_s return nil if is_uri?(source) diff --git a/actionpack/lib/sprockets/railtie.rb b/actionpack/lib/sprockets/railtie.rb index 8cee3babe2..43ebf529e9 100644 --- a/actionpack/lib/sprockets/railtie.rb +++ b/actionpack/lib/sprockets/railtie.rb @@ -35,7 +35,7 @@ module Sprockets ActiveSupport.on_load(:action_view) do app.assets.context_class.instance_eval do - include ::ActionView::Helpers::SprocketsHelper + include ::Sprockets::Helpers::RailsHelper end end |