aboutsummaryrefslogtreecommitdiffstats
path: root/railties/lib
diff options
context:
space:
mode:
authorRick Olson <technoweenie@gmail.com>2007-09-28 17:02:40 +0000
committerRick Olson <technoweenie@gmail.com>2007-09-28 17:02:40 +0000
commit8c33359ce8531df65a03c21631232024c0868bf8 (patch)
tree14f1b7de7b6df377cd70119c153b16e5b519d230 /railties/lib
parent82ff27766d3edc3fb1d0d043841e9c3cd277744f (diff)
downloadrails-8c33359ce8531df65a03c21631232024c0868bf8.tar.gz
rails-8c33359ce8531df65a03c21631232024c0868bf8.tar.bz2
rails-8c33359ce8531df65a03c21631232024c0868bf8.zip
Moved the SourceAnnotationExtractor to a separate file in case libraries try to load the rails rake tasks twice. rspec_on_rails, I'm looking at you. [Rick]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7672 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'railties/lib')
-rw-r--r--railties/lib/source_annotation_extractor.rb62
-rw-r--r--railties/lib/tasks/annotations.rake63
2 files changed, 63 insertions, 62 deletions
diff --git a/railties/lib/source_annotation_extractor.rb b/railties/lib/source_annotation_extractor.rb
new file mode 100644
index 0000000000..8844226536
--- /dev/null
+++ b/railties/lib/source_annotation_extractor.rb
@@ -0,0 +1,62 @@
+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 =~ /\.(builder|(r(?:b|xml|js)))$/
+ results.update(extract_annotations_from(item, /#\s*(#{tag}):?\s*(.*)$/))
+ elsif item =~ /\.(rhtml|erb)$/
+ 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 \ No newline at end of file
diff --git a/railties/lib/tasks/annotations.rake b/railties/lib/tasks/annotations.rake
index 80fe202588..ea6046670f 100644
--- a/railties/lib/tasks/annotations.rake
+++ b/railties/lib/tasks/annotations.rake
@@ -1,65 +1,4 @@
-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 =~ /\.(builder|(r(?:b|xml|js)))$/
- results.update(extract_annotations_from(item, /#\s*(#{tag}):?\s*(.*)$/))
- elsif item =~ /\.(rhtml|erb)$/
- 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
+require 'source_annotation_extractor'
desc "Enumerate all annotations"
task :notes do