annotations 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -1,6 +1,4 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in annotations.gemspec
4
- gemspec
5
-
6
- # TODO: Test me
4
+ gemspec
data/README.md CHANGED
@@ -2,18 +2,20 @@
2
2
 
3
3
  Extracts and displays annotations from source code comments like these:
4
4
 
5
- class MyModel
6
- def find(id)
7
- # TODO: Find the thing
8
- end
5
+ ```ruby
6
+ class MyModel
7
+ def find(id)
8
+ # TODO: Find the thing
9
9
  end
10
+ end
11
+ ```
10
12
 
11
13
  The output looks like this:
12
14
 
13
- ./lib/my_model.rb:
14
- * [ 17] [TODO] Find the thing
15
+ ./lib/my_model.rb:
16
+ * [ 17] [TODO] Find the thing
15
17
 
16
- If this looks familiar from Rails, it's because Annotations is derived/forked from the annotations code in Rails 3.2.1, now extracted into its own gem so it can be used in non-Rails (or even non-Ruby) projects.
18
+ Annotations is a standalone library derived from the notes tasks in Rails 3.2.1, extracted into its own gem so it can be used in non-Rails (or even non-Ruby) projects.
17
19
 
18
20
  Annotations looks for TODO, FIXME, and OPTIMIZE comments in the following kinds of source code files:
19
21
 
@@ -70,12 +72,12 @@ Annotations::RakeTask.new
70
72
 
71
73
  This will add the following tasks:
72
74
 
73
- $ bundle exec rake -T notes
74
- rake notes # Enumerate all annotations
75
- rake notes:custom[annotation] # Enumerate a custom annotation
76
- rake notes:fixme # Enumerate all FIXME annotations
77
- rake notes:optimize # Enumerate all OPTIMIZE annotations
78
- rake notes:todo # Enumerate all TODO annotations
75
+ $ bundle exec rake -T notes
76
+ rake notes # Enumerate all annotations
77
+ rake notes:custom[annotation] # Enumerate a custom annotation
78
+ rake notes:fixme # Enumerate all FIXME annotations
79
+ rake notes:optimize # Enumerate all OPTIMIZE annotations
80
+ rake notes:todo # Enumerate all TODO annotations
79
81
 
80
82
  If you want to name the tasks something other than "notes", just pass the name you want to use into `RakeTask.new`:
81
83
 
@@ -87,12 +89,22 @@ You can also set the default tag list when defining the task, using this block s
87
89
 
88
90
  ```ruby
89
91
  Annotations::RakeTask.new do |t|
90
- # This will add an additional 'WTF' annotation; it will be included in
92
+ # This will add an additional 'WTF' annotation; it will be included in
91
93
  # `rake notes`, and a `rake notes:wtf` task will be added
92
94
  t.tags = [:fixme, :optimize, :todo, :wtf]
93
95
  end
94
96
  ```
95
97
 
98
+ Once your `Rakefile` is set up, run the tasks to view your notes:
99
+
100
+ rake notes
101
+
102
+ ### Runtime options
103
+
104
+ **Filter by file extension:** Only display annotations for certain kinds of files. (Thanks for Gabriel Schammah for contributing this feature.)
105
+
106
+ rake notes:todo ext=js,rb,coffee
107
+
96
108
  ## Roadmap
97
109
 
98
110
  * Ability to set/limit the search path(s) for annotations (currently set to '.')
@@ -14,7 +14,6 @@ module Annotations
14
14
  # start with the tag optionally followed by a colon. Everything up to the end
15
15
  # of the line (or closing ERB comment tag) is considered to be their text.
16
16
  class Extractor
17
- # TODO: Test me
18
17
  class Annotation < Struct.new(:line, :tag, :text)
19
18
 
20
19
  # Returns a representation of the annotation that looks like this:
@@ -25,7 +24,7 @@ module Annotations
25
24
  # Otherwise the string contains just line and text.
26
25
  def to_s(options={})
27
26
  s = "[%3d] " % line
28
- s << "[#{tag}] " if options[:tag]
27
+ s << "[#{tag}] " if options[:show_tag]
29
28
  s << text
30
29
  end
31
30
  end
@@ -37,14 +36,15 @@ module Annotations
37
36
  #
38
37
  # This class method is the single entry point for the rake tasks.
39
38
  def self.enumerate(tag, options={})
40
- extractor = new(tag)
39
+ extractor = new(tag, options)
41
40
  extractor.display(extractor.find, options)
42
41
  end
43
42
 
44
43
  attr_reader :tag
45
44
 
46
- def initialize(tag)
45
+ def initialize(tag, options)
47
46
  @tag = tag
47
+ @extensions = options[:extensions]
48
48
  end
49
49
 
50
50
  # Returns a hash that maps filenames under +dirs+ (recursively) to arrays
@@ -63,13 +63,13 @@ module Annotations
63
63
  def find_in(dir)
64
64
  results = {}
65
65
 
66
- Dir.glob("#{dir}/*") do |item|
67
- next if File.basename(item)[0] == ?.
66
+ pattern = "#{dir}/**/*"
67
+ pattern += ".{#{@extensions}}" if @extensions
68
68
 
69
- if File.directory?(item)
70
- results.update(find_in(item))
71
- # Ruby source code
72
- elsif item =~ /\.(ru|builder|coffee|(r(?:b|xml|js)))$/
69
+ Dir.glob(pattern) do |item|
70
+ next if File.basename(item)[0] == ?. or File.directory?(item)
71
+
72
+ if item =~ /\.(ru|builder|coffee|(r(?:b|xml|js)))$/
73
73
  results.update(extract_annotations_from(item, /#\s*(#{tag}):?\s*(.*)$/))
74
74
  # Other Ruby source files (Rake, Bundler)
75
75
  elsif item =~ /(Rakefile|Gemfile|Guardfile)$/
@@ -111,4 +111,4 @@ module Annotations
111
111
  end
112
112
  end
113
113
  end
114
- end
114
+ end
@@ -10,7 +10,8 @@ module Annotations
10
10
  def initialize(name = :notes)
11
11
  @name = name
12
12
  @tags = [:optimize, :fixme, :todo]
13
- yield self
13
+ @extensions = ENV["ext"]
14
+ yield self if block_given?
14
15
  define
15
16
  end
16
17
 
@@ -22,24 +23,24 @@ module Annotations
22
23
  def define
23
24
  desc "Enumerate all annotations"
24
25
  task name do
25
- Annotations::Extractor.enumerate(tags_to_pattern, :tag => true)
26
+ Annotations::Extractor.enumerate(tags_to_pattern, :show_tag => true, :extensions => @extensions)
26
27
  end
27
28
 
28
29
  namespace name do
29
30
  tags.each do |tagname|
30
31
  desc "Enumerate all #{tagname.to_s.upcase} annotations"
31
32
  task tagname.to_sym do
32
- Annotations::Extractor.enumerate(tagname.to_s.upcase, :tag => true)
33
+ Annotations::Extractor.enumerate(tagname.to_s.upcase, :show_tag => true, :extensions => @extensions)
33
34
  end
34
35
  end
35
36
 
36
37
  desc "Enumerate a custom annotation, specify with ANNOTATION=CUSTOM"
37
38
  task :custom, :annotation do |annotation|
38
39
  puts annotation
39
- SourceAnnotationExtractor.enumerate ENV['ANNOTATION']
40
+ Annotations::Extractor.enumerate(ENV['ANNOTATION'], :extensions => @extensions)
40
41
  end
41
42
  end
42
43
  end
43
44
 
44
45
  end
45
- end
46
+ end
@@ -1,3 +1,3 @@
1
1
  module Annotations
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: annotations
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-05-02 00:00:00.000000000 Z
12
+ date: 2012-06-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
16
- requirement: &70138368469980 !ruby/object:Gem::Requirement
16
+ requirement: &70222080962560 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,7 +21,7 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70138368469980
24
+ version_requirements: *70222080962560
25
25
  description: Source code annotations, extracted from Rails.
26
26
  email:
27
27
  - ddemaree@gmail.com
@@ -51,12 +51,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
51
51
  - - ! '>='
52
52
  - !ruby/object:Gem::Version
53
53
  version: '0'
54
+ segments:
55
+ - 0
56
+ hash: -2817081159239259207
54
57
  required_rubygems_version: !ruby/object:Gem::Requirement
55
58
  none: false
56
59
  requirements:
57
60
  - - ! '>='
58
61
  - !ruby/object:Gem::Version
59
62
  version: '0'
63
+ segments:
64
+ - 0
65
+ hash: -2817081159239259207
60
66
  requirements: []
61
67
  rubyforge_project:
62
68
  rubygems_version: 1.8.11