public
Description: PLEASE CHECK http://github.com/lifo/docrails/wikis
Homepage: http://weblog.rubyonrails.org/2008/5/2/help-improve-rails-documentation-on-git-branch
Clone URL: git://github.com/lifo/docrails.git
Search Repo:
documented the source annotation extractor
fxn (author)
Sat May 10 17:54:02 -0700 2008
commit  80bba28a1a56a0cafeb0fc94659905e88129bc31
tree    15e070c92f62ef583b953d2c92183cf006716683
parent  e6823bb1650d9b0fea58bd2d355f388961a408b3
...
1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
 
 
 
 
 
 
 
3
4
5
...
7
8
9
 
 
 
 
 
 
10
11
12
13
...
18
19
20
 
 
 
 
21
22
23
24
 
 
 
 
25
26
27
...
40
41
42
 
 
 
43
44
45
...
50
51
52
 
 
53
54
55
...
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
...
29
30
31
32
33
34
35
36
37
38
39
40
41
...
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
...
76
77
78
79
80
81
82
83
84
...
89
90
91
92
93
94
95
96
0
@@ -1,5 +1,27 @@
0
 class SourceAnnotationExtractor
0
+
0
+ # Implements the logic behind the rake tasks for annotations like
0
+ #
0
+ # rake notes
0
+ # rake notes:optimize
0
+ #
0
+ # and friends. See <tt>rake -T notes</tt> and <tt>railties/lib/tasks/annotations.rake</tt>.
0
+ #
0
+ # Annotation objects are triplets <tt>:line</tt>, <tt>:tag</tt>, <tt>:text</tt> that
0
+ # represent the line where the annotation lives, its tag, and its text. Note
0
+ # the filename is not stored.
0
+ #
0
+ # Annotations are looked for in comments and modulus whitespace they have to
0
+ # start with the tag optionally followed by a colon. Everything up to the end
0
+ # of the line (or closing ERb comment tag) is considered to be their text.
0
   class Annotation < Struct.new(:line, :tag, :text)
0
+
0
+ # Returns a representation of the annotation that looks like this:
0
+ #
0
+ # [126] [TODO] This algorithm is simple and clearly correct, make it faster.
0
+ #
0
+ # If +options+ has a flag <tt>:tag</tt> the tag is shown as in the example above.
0
+ # Otherwise the string contains just line and text.
0
     def to_s(options={})
0
       s = "[%3d] " % line
0
       s << "[#{tag}] " if options[:tag]
0
@@ -7,6 +29,12 @@
0
     end
0
   end
0
 
0
+ # Prints all annotations with tag +tag+ under the root directories +app+, +lib+,
0
+ # and +test+ (recursively). Only filenames with extension +.builder+, +.rb+,
0
+ # +.rxml+, +.rjs+, +.rhtml+, or +.erb+ are taken into account. The +options+
0
+ # hash is passed to each annotation's +to_s+.
0
+ #
0
+ # This class method is the single entry point for the rake tasks.
0
   def self.enumerate(tag, options={})
0
     extractor = new(tag)
0
     extractor.display(extractor.find, options)
0
0
@@ -18,10 +46,18 @@
0
     @tag = tag
0
   end
0
 
0
+ # Returns a hash that maps filenames under +dirs+ (recursively) to arrays
0
+ # with their annotations. Only files with annotations are included, and only
0
+ # those with extension +.builder+, +.rb+, +.rxml+, +.rjs+, +.rhtml+, and +.erb+
0
+ # are taken into account.
0
   def find(dirs=%w(app lib test))
0
     dirs.inject({}) { |h, dir| h.update(find_in(dir)) }
0
   end
0
 
0
+ # Returns a hash that maps filenames under +dir+ (recursively) to arrays
0
+ # with their annotations. Only files with annotations are included, and only
0
+ # those with extension +.builder+, +.rb+, +.rxml+, +.rjs+, +.rhtml+, and +.erb+
0
+ # are taken into account.
0
   def find_in(dir)
0
     results = {}
0
 
0
@@ -40,6 +76,9 @@
0
     results
0
   end
0
 
0
+ # If +file+ is the filename of a file that contains annotations this method returns
0
+ # a hash with a single entry that maps +file+ to an array of its annotations.
0
+ # Otherwise it returns an empty hash.
0
   def extract_annotations_from(file, pattern)
0
     lineno = 0
0
     result = File.readlines(file).inject([]) do |list, line|
0
@@ -50,6 +89,8 @@
0
     result.empty? ? {} : { file => result }
0
   end
0
 
0
+ # Prints the mapping from filenames to annotations in +results+ ordered by filename.
0
+ # The +options+ hash is passed to each annotation's +to_s+.
0
   def display(results, options={})
0
     results.keys.sort.each do |file|
0
       puts "#{file}:"

Comments

    No one has commented yet.