aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/sprockets/helpers/rails_helper.rb
diff options
context:
space:
mode:
authorwycats <wycats@gmail.com>2011-05-23 16:07:16 -0700
committerwycats <wycats@gmail.com>2011-05-23 16:45:26 -0700
commit4b7902949022d1293ad71e8c25e64635b143ae89 (patch)
tree16b0f04e164582629c84a9f9a16281de4c3fa206 /actionpack/lib/sprockets/helpers/rails_helper.rb
parent5ec23b95ba7d5a00d20f6ec59f75c34a2ac73b5d (diff)
downloadrails-4b7902949022d1293ad71e8c25e64635b143ae89.tar.gz
rails-4b7902949022d1293ad71e8c25e64635b143ae89.tar.bz2
rails-4b7902949022d1293ad71e8c25e64635b143ae89.zip
Start moving some logic from being embedded in AV into the Rails Sprockets extensions
Diffstat (limited to 'actionpack/lib/sprockets/helpers/rails_helper.rb')
-rw-r--r--actionpack/lib/sprockets/helpers/rails_helper.rb51
1 files changed, 51 insertions, 0 deletions
diff --git a/actionpack/lib/sprockets/helpers/rails_helper.rb b/actionpack/lib/sprockets/helpers/rails_helper.rb
new file mode 100644
index 0000000000..3a49c347fb
--- /dev/null
+++ b/actionpack/lib/sprockets/helpers/rails_helper.rb
@@ -0,0 +1,51 @@
+module Sprockets
+ module Helpers
+ 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
+
+ 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)
+ source = rewrite_extension(source, nil, ext)
+ assets[source]
+ end
+
+ def rewrite_asset_path(source, dir)
+ if source[0] == ?/
+ source
+ else
+ assets.path(source, performing_caching?, dir)
+ end
+ end
+
+ def rewrite_extension(source, dir, ext)
+ if ext && File.extname(source).empty?
+ "#{source}.#{ext}"
+ else
+ source
+ end
+ end
+
+ def assets
+ Rails.application.assets
+ end
+
+ # When included in Sprockets::Context, we need to ask the top-level config as the controller is not available
+ def performing_caching?
+ @config ? @config.perform_caching : Rails.application.config.action_controller.perform_caching
+ end
+ end
+ end
+ end
+end