adding timestamp from file in full url

This commit is contained in:
Lucas Souza 2011-07-05 11:45:44 -03:00
parent 473eff9363
commit 06979f6fae
2 changed files with 18 additions and 5 deletions

View File

@ -14,7 +14,7 @@ module Sinatra
# The default value of +closed+ option is +false+. # The default value of +closed+ option is +false+.
# #
def image_tag(source, options = {}) def image_tag(source, options = {})
options[:src] = url_for(source) options[:src] = source_url(source)
tag("img", options) tag("img", options)
end end
@ -59,12 +59,12 @@ module Sinatra
def stylesheet_tag(source, options = {}) def stylesheet_tag(source, options = {})
tag("link", { :type => "text/css", tag("link", { :type => "text/css",
:charset => "utf-8", :media => "screen", :rel => "stylesheet", :charset => "utf-8", :media => "screen", :rel => "stylesheet",
:href => url_for(source) }.merge(options)) :href => source_url(source) }.merge(options))
end end
def javascript_tag(source, options = {}) def javascript_tag(source, options = {})
tag("script", { :type => "text/javascript", :charset => "utf-8", tag("script", { :type => "text/javascript", :charset => "utf-8",
:src => url_for(source) }.merge(options)) do :src => source_url(source) }.merge(options)) do
end end
end end
@ -73,6 +73,19 @@ module Sinatra
[a, opts] [a, opts]
end 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 end
def self.registered(app) def self.registered(app)

View File

@ -4,7 +4,7 @@
# -*- encoding: utf-8 -*- # -*- encoding: utf-8 -*-
Gem::Specification.new do |s| Gem::Specification.new do |s|
s.name = %q{sinatra-static-assets} s.name = %q{r7-sinatra-static-assets}
s.version = "0.5.2" s.version = "0.5.2"
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= 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.homepage = %q{http://github.com/wbzyl/sinatra-static-assets}
s.rdoc_options = ["--charset=UTF-8"] s.rdoc_options = ["--charset=UTF-8"]
s.require_paths = ["lib"] 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.rubygems_version = %q{1.3.6}
s.summary = %q{Sinatra extension providing helper methods to output tags for static assetgemspec.} s.summary = %q{Sinatra extension providing helper methods to output tags for static assetgemspec.}
s.test_files = [ s.test_files = [