Skip to content

Instantly share code, notes, and snippets.

@jcasimir
Created July 20, 2011 17:34
Show Gist options
  • Save jcasimir/1095448 to your computer and use it in GitHub Desktop.
Save jcasimir/1095448 to your computer and use it in GitHub Desktop.
Using Rake to keep track of my pending/to-do items while writing
FILE_SEARCH_PATTERN = "tutorials/**/*.{markdown, textile}"
MARKERS = {"todo" => :red, "pending" => :green}
COLORIZE = true
MARKERS.keys.each do |marker|
desc "Pull out #{marker.upcase} lines"
task marker do
print_lines_containing(marker)
end
end
task :default => [:todo]
desc "Pull out all marked lines"
task :all do
print_lines_containing(MARKERS.keys)
end
def print_lines_containing(*keywords)
Dir.glob(FILE_SEARCH_PATTERN) do |filename|
filename_printed = false
File.open(filename).lines.each do |line|
if line.downcase.match(/.*\[(#{keywords.join("|")})+.*\].*/)
unless filename_printed
puts "\n" + filename.underline
filename_printed = true
end
puts line.chomp.send(MARKERS[$1.downcase])
end
end
end
puts ""
end
class String
def red; colorize(self, "\e[1m\e[31m"); end
def yellow; colorize(self, "\e[1m\e[33m"); end
def green; colorize(self, "\e[1m\e[32m"); end
def underline; colorize(self, "\e[1m\e[4m"); end
def colorize(text, color_code)
COLORIZE ? "#{color_code}#{text}\e[0m" : text
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment