My favorites | Sign in
Project Home Downloads Wiki Issues Source
READ-ONLY: This project has been archived. For more information see this post.
Search
for
  Advanced search   Search tips   Subscriptions

Issue 80 attachment: substruct_extract_annotations.patch (3.2 KB)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
Index: /home/edmundo/workspace_aptana/substruct_trunk/vendor/plugins/substruct/lib/substruct_annotation_extractor.rb
===================================================================
--- /home/edmundo/workspace_aptana/substruct_trunk/vendor/plugins/substruct/lib/substruct_annotation_extractor.rb (revision 0)
+++ /home/edmundo/workspace_aptana/substruct_trunk/vendor/plugins/substruct/lib/substruct_annotation_extractor.rb (revision 0)
@@ -0,0 +1,62 @@
+class SubstructAnnotationExtractor
+ 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("vendor/plugins/substruct/#{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
Index: /home/edmundo/workspace_aptana/substruct_trunk/vendor/plugins/substruct/tasks/substruct.rake
===================================================================
--- /home/edmundo/workspace_aptana/substruct_trunk/vendor/plugins/substruct/tasks/substruct.rake (revision 78)
+++ /home/edmundo/workspace_aptana/substruct_trunk/vendor/plugins/substruct/tasks/substruct.rake (working copy)
@@ -310,6 +310,33 @@

end # test namespace

+
+ # Annotations =======================================================
+
+ require "#{RAILS_ROOT}/vendor/plugins/substruct/lib/substruct_annotation_extractor.rb"
+
+ desc "Enumerate all annotations"
+ task :notes do
+ SubstructAnnotationExtractor.enumerate "OPTIMIZE|FIXME|TODO", :tag => true
+ end
+
+ namespace :notes do
+ desc "Enumerate all OPTIMIZE annotations"
+ task :optimize do
+ SubstructAnnotationExtractor.enumerate "OPTIMIZE"
+ end
+
+ desc "Enumerate all FIXME annotations"
+ task :fixme do
+ SubstructAnnotationExtractor.enumerate "FIXME"
+ end
+
+ desc "Enumerate all TODO annotations"
+ task :todo do
+ SubstructAnnotationExtractor.enumerate "TODO"
+ end
+ end # notes namespace
+
end # substruct namespace

def check_installed_gem(gem_name)

Powered by Google Project Hosting