Skip to content

Instantly share code, notes, and snippets.

@jszmajda
Created January 14, 2010 17:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jszmajda/277348 to your computer and use it in GitHub Desktop.
Save jszmajda/277348 to your computer and use it in GitHub Desktop.
# in lib/asset_tag_helper_ext.rb
module ActionView
module Helpers
module AssetTagHelper
alias :orig_javascript_include_tag :javascript_include_tag
def javascript_include_tag(*sources)
options = sources.extract_options!.stringify_keys
rkey = '__scripts'
request[rkey] ||= []
scripts = request[rkey]
ok = []
sources.each do |src|
if !scripts.include?(src.to_s)
scripts << src.to_s
ok << src
end
end
request[rkey] = scripts
orig_javascript_include_tag(ok, options)
end
alias :orig_stylesheet_link_tag :stylesheet_link_tag
def stylesheet_link_tag(*sources)
options = sources.extract_options!.stringify_keys
rkey = '__styles'
request[rkey] ||= []
styles = request[rkey]
ok = []
sources.each do |src|
if !styles.include?(src.to_s)
styles << src.to_s
ok << src
end
end
request[rkey] = styles
orig_stylesheet_link_tag(ok, options)
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment