Skip to content

Instantly share code, notes, and snippets.

@gilles
Created February 22, 2011 19:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gilles/839251 to your computer and use it in GitHub Desktop.
Save gilles/839251 to your computer and use it in GitHub Desktop.
A pre-commit hook to check if jammit needs to be run
#!/usr/bin/env ruby
#
# A pre-commit hook to test if jammit needs to be run
# In case you don't like on the fly stuff
#
require 'rubygems'
require 'jammit'
def check_assets(config)
Jammit.load_configuration(config)
[:javascripts, :stylesheets].each do |type|
Jammit.configuration[type].each do |key, globs|
if !check_group(type, key, globs)
$stderr.puts "run jammit"
exit 1
end
end
end
end
def check_group(type, key, globs)
case type
when :js, :javascripts
ext = '.js'
when :css, :stylesheets
ext = '.css'
else
raise ArgumentError "Invalid type"
end
asset_path = File.join('public', Jammit.package_path, "#{key}#{ext}")
if !File.exists?(asset_path)
$stderr.puts "asset #{asset_path} missing"
return false
end
mtime = File.mtime(asset_path)
globs.each do |g|
Dir.glob(g) do |filename|
if File.mtime(filename) > mtime
$stderr.puts "#{filename} newer then #{asset_path}"
return false
end
end
end
true
end
check_assets(Jammit::DEFAULT_CONFIG_PATH)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment