lib/sinatra/assetpack/class_methods.rb in sinatra-assetpack-0.1.7 vs lib/sinatra/assetpack/class_methods.rb in sinatra-assetpack-0.2.0
- old
+ new
@@ -22,10 +22,14 @@
# Add routes for the compressed versions
def add_compressed_routes!
assets.packages.each do |name, package|
get package.route_regex do
+ if defined?(settings.assets.app.clear_tilt_cache) && settings.assets.app.clear_tilt_cache
+ AssetPack.clear_tilt_cache!(@template_cache, settings.assets.app)
+ end
+
mtime, contents = @template_cache.fetch(package.path) {
[ package.mtime, package.minify ]
}
content_type package.type
@@ -40,23 +44,35 @@
def add_individual_routes!
assets.served.each do |path, from|
get %r{#{"^/#{path}/".squeeze('/')}(.*)$} do |file|
fmt = File.extname(file)[1..-1]
+ if file =~ /(.*)\.([a-f0-9]{32})\.(.*)/
+ clean_file = "#{$1}.#{$3}"
+ requested_hash = $2
+ else
+ clean_file = file
+ end
+
# Sanity checks
pass unless AssetPack.supported_formats.include?(fmt)
- fn = asset_path_for(file, from) or pass
- pass if settings.assets.ignored?("#{path}/#{file}")
+ fn = asset_path_for(clean_file, from) or pass
+ pass if settings.assets.ignored?("#{path}/#{clean_file}")
+
# Send headers
content_type fmt.to_sym
last_modified File.mtime(fn).to_i
assets_expires
format = File.extname(fn)[1..-1]
+ if defined?(settings.assets.app.clear_tilt_cache) && settings.assets.app.clear_tilt_cache
+ AssetPack.clear_tilt_cache!(@template_cache, settings.assets.app)
+ end
+
if AssetPack.supported_formats.include?(format)
# Static file
if fmt == 'css'
# Matching static file format
pass unless fmt == File.extname(fn)[1..-1]
@@ -75,10 +91,9 @@
out
}
end
end
end
-
end
end
end
end