Created
December 2, 2008 16:45
-
-
Save dstrelau/31165 to your computer and use it in GitHub Desktop.
This file contains 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: source | |
class Source < Thor | |
class Clean < Thor | |
desc "whitespace", "Clean trailing whitespace." | |
method_options :extension => :optional | |
def whitespace | |
Dir.glob("./**/*#{options[:extension]}").each do |file| | |
next unless File.file?(file) | |
cleaned = [] | |
File.open(file) do |f| | |
f.readlines.inject(cleaned) do |cleaned, line| | |
cleaned << if line =~ /^\s+$/ then "\n" else line.sub(/[ ]+$/, '') end | |
end | |
end | |
File.open(file, 'w') {|f| f.write(cleaned) } | |
end | |
end # def whitespace | |
end # class Clean | |
end # class Source |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment