diff --git a/lib/sinatra/static_assets.rb b/lib/sinatra/static_assets.rb index a44cd06..86f1ffc 100644 --- a/lib/sinatra/static_assets.rb +++ b/lib/sinatra/static_assets.rb @@ -14,7 +14,7 @@ module Sinatra # The default value of +closed+ option is +false+. # def image_tag(source, options = {}) - options[:src] = url_for(source) + options[:src] = source_url(source) tag("img", options) end @@ -59,12 +59,12 @@ module Sinatra def stylesheet_tag(source, options = {}) tag("link", { :type => "text/css", :charset => "utf-8", :media => "screen", :rel => "stylesheet", - :href => url_for(source) }.merge(options)) + :href => source_url(source) }.merge(options)) end def javascript_tag(source, options = {}) tag("script", { :type => "text/javascript", :charset => "utf-8", - :src => url_for(source) }.merge(options)) do + :src => source_url(source) }.merge(options)) do end end @@ -73,6 +73,19 @@ module Sinatra [a, opts] end + def source_url(source) + source_url_timestamp url_for(source) + end + + def source_url_timestamp(url) + full_url = "#{Sinatra::Application.root}/public#{url}" + if File.exists? full_url + timestamp = File.mtime(full_url).to_i + "#{url}?#{timestamp}" + else + url + end + end end def self.registered(app) diff --git a/sinatra-static-assets.gemspec b/sinatra-static-assets.gemspec index 9251061..33f5069 100644 --- a/sinatra-static-assets.gemspec +++ b/sinatra-static-assets.gemspec @@ -4,7 +4,7 @@ # -*- encoding: utf-8 -*- Gem::Specification.new do |s| - s.name = %q{sinatra-static-assets} + s.name = %q{r7-sinatra-static-assets} s.version = "0.5.2" s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= @@ -69,7 +69,7 @@ Gem::Specification.new do |s| s.homepage = %q{http://github.com/wbzyl/sinatra-static-assets} s.rdoc_options = ["--charset=UTF-8"] s.require_paths = ["lib"] - s.rubyforge_project = %q{sinatra-static-assets} + s.rubyforge_project = %q{r7-sinatra-static-assets} s.rubygems_version = %q{1.3.6} s.summary = %q{Sinatra extension providing helper methods to output tags for static assetgemspec.} s.test_files = [