Created
January 10, 2010 02:05
-
-
Save path/273287 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 'erb' | |
vendored_codecleaner_path = Dir["#{RAILS_ROOT}/vendor/gems/code-cleaner*"].first | |
options = { | |
:path => File.join(vendored_codecleaner_path, "bin"), | |
:whitelist => '\.(rb|rake|task|html|js)$', | |
:blacklist => '(/vendor/|/gems/|schema.rb)', | |
:force => false | |
} | |
namespace :codecleaner do | |
desc "Install git pre-commit hook for automatically removing trailing whitespace" | |
task "git:install" do | |
if !options[:force] && File.size?(".git/hooks/pre-commit") | |
abort "You must remove .git/hooks/pre-commit first!" | |
else | |
begin | |
puts "Installing .git/hooks/pre-commit ..." | |
source = File.join(vendored_codecleaner_path, "support", "pre-commit.erb") | |
File.open(".git/hooks/pre-commit", "w") do |file| | |
file.puts(ERB.new(File.read(source)).result(binding)) | |
end | |
File.chmod(0755, ".git/hooks/pre-commit") | |
rescue Errno::ENOENT | |
abort "You have to run git init first!" | |
end | |
end | |
end | |
desc "Overwrites existing git pre-commit hook if it exists" | |
task "git:install:force" do | |
options[:force] = true | |
Rake::Task['codecleaner:git:install'].execute | |
end | |
desc "Remove trailing whitespace and convert tabs to spaces" | |
task "clean" do | |
`WHITELIST='#{options[:whitelist]}' BLACKLIST='#{options[:blacklist]}' #{options[:path]}/code-cleaner #{RAILS_ROOT}` | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment