aboutsummaryrefslogtreecommitdiffstats
path: root/railties
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2007-02-25 19:40:37 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2007-02-25 19:40:37 +0000
commitee2b5dda803d4da31b187eb592569692b4972417 (patch)
treef7c6795834a67e6290f182c9a04d8daeb3f833de /railties
parent23e24c5996c90e072b66a616ee0cbe066dd5c1a2 (diff)
downloadrails-ee2b5dda803d4da31b187eb592569692b4972417.tar.gz
rails-ee2b5dda803d4da31b187eb592569692b4972417.tar.bz2
rails-ee2b5dda803d4da31b187eb592569692b4972417.zip
Added source-annotations extractor tasks to rake [Jamis Buck]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6229 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'railties')
-rw-r--r--railties/CHANGELOG2
-rw-r--r--railties/lib/tasks/annotations.rake84
2 files changed, 86 insertions, 0 deletions
diff --git a/railties/CHANGELOG b/railties/CHANGELOG
index 8411c12b2c..ed6a4c56bb 100644
--- a/railties/CHANGELOG
+++ b/railties/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Added source-annotations extractor tasks to rake [Jamis Buck]. This allows you to add FIXME, OPTIMIZE, and TODO comments to your source code that can then be extracted in concert with rake notes (shows all), rake notes:fixme, rake notes:optimize and rake notes:todo.
+
* Added fixtures :all to test_helper.rb to assume that most people just want all their fixtures loaded all the time [DHH]
* Added config/initializers where all ruby files within it are automatically loaded after the Rails configuration is done, so you don't have to litter the environment.rb file with a ton of mixed stuff [DHH]
diff --git a/railties/lib/tasks/annotations.rake b/railties/lib/tasks/annotations.rake
new file mode 100644
index 0000000000..20ccad6d7b
--- /dev/null
+++ b/railties/lib/tasks/annotations.rake
@@ -0,0 +1,84 @@
+class SourceAnnotationExtractor
+ class Annotation < Struct.new(:line, :tag, :text)
+ def to_s(options={})
+ s = "[%3d] " % line
+ s << "[#{tag}] " if options[:tag]
+ s << text
+ end
+ end
+
+ def self.enumerate(tag, options={})
+ extractor = new(tag)
+ extractor.display(extractor.find, options)
+ end
+
+ attr_reader :tag
+
+ def initialize(tag)
+ @tag = tag
+ end
+
+ def find(dirs=%w(app lib test))
+ dirs.inject({}) { |h, dir| h.update(find_in(dir)) }
+ end
+
+ def find_in(dir)
+ results = {}
+
+ Dir.glob("#{dir}/*") do |item|
+ next if File.basename(item)[0] == ?.
+
+ if File.directory?(item)
+ results.update(find_in(item))
+ elsif item =~ /\.r(?:b|xml|js)$/
+ results.update(extract_annotations_from(item, /#\s*(#{tag}):?\s*(.*)$/))
+ elsif item =~ /\.rhtml$/
+ results.update(extract_annotations_from(item, /<%\s*#\s*(#{tag}):?\s*(.*?)\s*%>/))
+ end
+ end
+
+ results
+ end
+
+ def extract_annotations_from(file, pattern)
+ lineno = 0
+ result = File.readlines(file).inject([]) do |list, line|
+ lineno += 1
+ next list unless line =~ pattern
+ list << Annotation.new(lineno, $1, $2)
+ end
+ result.empty? ? {} : { file => result }
+ end
+
+ def display(results, options={})
+ results.keys.sort.each do |file|
+ puts "#{file}:"
+ results[file].each do |note|
+ puts " * #{note.to_s(options)}"
+ end
+ puts
+ end
+ end
+end
+
+desc "Enumerate all annotations"
+task :notes do
+ SourceAnnotationExtractor.enumerate "OPTIMIZE|FIXME|TODO", :tag => true
+end
+
+namespace :notes do
+ desc "Enumerate all OPTIMIZE annotations"
+ task :optimize do
+ SourceAnnotationExtractor.enumerate "OPTIMIZE"
+ end
+
+ desc "Enumerate all FIXME annotations"
+ task :fixme do
+ SourceAnnotationExtractor.enumerate "FIXME"
+ end
+
+ desc "Enumerate all TODO annotations"
+ task :todo do
+ SourceAnnotationExtractor.enumerate "TODO"
+ end
+end \ No newline at end of file