# Appends a modification timestamp to the url of assets that are output using any of the AssetTagHelper methods. # # For example: # image_tag('smiley.jpg') # => # # For background as to why this may be required: # http://overstimulate.com/articles/2005/09/08/web-apps-ajax-distribution-problem # $Id$ # $URL$ module AssetTimestampingPlugin #:nodoc: module ActionView module Helpers module AssetTagHelper def self.included(base) base.send(:include, InstanceMethods) base.class_eval do alias :compute_public_path_without_timestamp :compute_public_path alias :compute_public_path :timestamped_compute_public_path end end module InstanceMethods #:nodoc: private def timestamped_compute_public_path(source, dir, ext) public_path = compute_public_path_without_timestamp(source,dir,ext) if not source.include?('?') file_paths = ["#{RAILS_ROOT}/public/#{dir}/#{source}", "#{RAILS_ROOT}/public/#{dir}/#{source}.#{ext}"] for path in file_paths if File.exists?(path) return public_path << '?' + File.stat(path).mtime.to_i.to_s end end end public_path end end end end end end