Created
November 14, 2010 04:15
-
-
Save steveh/675902 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "digest/md5" | |
namespace :jammit do | |
desc "Lock packages to md5sum" | |
task :lock do | |
srcdir = File.join(Rails.root, "public", "packages") | |
dstdir = File.join(Rails.root, "public", "cache") | |
lockfile = File.join(Rails.root, "config", "assets.yml.lock") | |
locks = {} | |
Dir.new(srcdir).each do |file| | |
if file =~ /\.(css|js|gz)/ | |
hash = Digest::MD5.hexdigest(File.join(srcdir, file)) | |
locks[file] = hash | |
FileUtils.mkdir_p(File.join(dstdir, hash)) | |
File.symlink(File.join(srcdir, file), File.join(dstdir, hash, file)) | |
end | |
end | |
File.open(lockfile, "w") do |file| | |
file.puts locks.to_yaml | |
end | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Jammit | |
HASHES = YAML.load_file(File.join(Rails.root, "config", "assets.yml.lock")) || {} | |
def self.asset_url(package, extension, suffix=nil, mtime=nil) | |
file = filename(package, extension, suffix) | |
hash = HASHES[file] | |
"/cache/#{hash}/#{file}" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment