From 76f947edf755f57ec721b412c6cef9a9c2c8f4b5 Mon Sep 17 00:00:00 2001 From: wycats Date: Mon, 23 May 2011 16:29:20 -0700 Subject: Move javascript/css helpers into the Sprockets helper and just have them override the old behavior --- actionpack/lib/sprockets/helpers/rails_helper.rb | 44 ++++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'actionpack/lib/sprockets/helpers') diff --git a/actionpack/lib/sprockets/helpers/rails_helper.rb b/actionpack/lib/sprockets/helpers/rails_helper.rb index 3a49c347fb..5f2854995f 100644 --- a/actionpack/lib/sprockets/helpers/rails_helper.rb +++ b/actionpack/lib/sprockets/helpers/rails_helper.rb @@ -9,6 +9,50 @@ module Sprockets end 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 + + 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 = asset_paths.asset_for(source, 'js') + asset.to_a.map { |dep| + javascript_include_tag(dep, :debug => false, :body => true) + }.join("\n").html_safe + else + options = { + 'type' => "text/javascript", + 'src' => asset_path(source, 'js', body) + }.merge(options.stringify_keys) + + content_tag 'script', "", options + end + end + + 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 = asset_paths.asset_for(source, 'css') + asset.to_a.map { |dep| + stylesheet_link_tag(dep, :debug => false, :body => true) + }.join("\n").html_safe + else + options = { + 'rel' => "stylesheet", + 'type' => "text/css", + 'media' => "screen", + 'href' => asset_path(source, 'css', body) + }.merge(options.stringify_keys) + + tag 'link', options + 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) -- cgit v1.2.3