2 module AssetPackageHelper
4 def javascript_include_merged(*sources)
5 options = sources.last.is_a?(Hash) ? sources.pop.stringify_keys : { }
7 if sources.include?(:defaults)
8 sources = sources[0..(sources.index(:defaults))] +
9 ['prototype', 'effects', 'dragdrop', 'controls'] +
10 (File.exists?("#{RAILS_ROOT}/public/javascripts/application.js") ? ['application'] : []) +
11 sources[(sources.index(:defaults) + 1)..sources.length]
12 sources.delete(:defaults)
15 sources.collect!{|s| s.to_s}
16 sources = #(RAILS_ENV == "production" ?
17 AssetPackage.targets_from_sources("javascripts", sources) #:
18 #AssetPackage.sources_from_targets("javascripts", sources))
20 sources.collect {|source| javascript_include_tag(source, options) }.join("\n")
23 def stylesheet_link_merged(*sources)
24 options = sources.last.is_a?(Hash) ? sources.pop.stringify_keys : { }
26 sources.collect!{|s| s.to_s}
27 sources = (RAILS_ENV == "production" ?
28 AssetPackage.targets_from_sources("stylesheets", sources) :
29 AssetPackage.sources_from_targets("stylesheets", sources))
31 sources.collect { |source|
32 source = stylesheet_path(source)
33 tag("link", { "rel" => "Stylesheet", "type" => "text/css", "media" => "screen", "href" => source }.merge(options))
38 # rewrite compute_public_path to allow us to not include the query string timestamp
39 # used by ActionView::Helpers::AssetTagHelper
40 def compute_public_path(source, dir, ext, add_asset_id=true)
42 source << ".#{ext}" if File.extname(source).blank?
43 unless source =~ %r{^[-a-z]+://}
44 source = "/#{dir}/#{source}" unless source[0] == ?/
45 asset_id = rails_asset_id(source)
46 source << '?' + asset_id if defined?(RAILS_ROOT) and add_asset_id and not asset_id.blank?
47 source = "#{ActionController::Base.asset_host}#{@controller.request.relative_url_root}#{source}"
52 # rewrite javascript path function to not include query string timestamp
53 def javascript_path(source)
54 compute_public_path(source, 'javascripts', 'js', false)
57 # rewrite stylesheet path function to not include query string timestamp
58 def stylesheet_path(source)
59 compute_public_path(source, 'stylesheets', 'css', false)