Created
September 29, 2009 18:47
-
-
Save indirect/197146 to your computer and use it in GitHub Desktop.
rake tasks to fix whitespace
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
def find_and_replace_in_source_files(find, replace) | |
extensions = %w[.rhtml .rxml .erb .builder .rb .css .js .rake] | |
files = Dir["**/*"] | |
files.each do |file_name| | |
next if (file_name =~ /^vendor/) || !extensions.include?(File.extname(file_name)) | |
text = File.open(file_name, 'r'){ |file| file.read } | |
changed = text.gsub!(find, replace) | |
File.open(file_name, 'w'){|file| file.write(changed)} if changed | |
end | |
end | |
namespace :source do | |
desc "Replace all tabs in source code files with two spaces" | |
task :detab do | |
find_and_replace_in_source_files("\t", " ") | |
end | |
desc "Remove trailing whitespace on the ends of lines" | |
task :detrail do | |
find_and_replace_in_source_files(/ +$/, '') | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment