dnote 1.3.1 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/HISTORY CHANGED
@@ -1,5 +1,18 @@
1
1
  = RELEASE HISTORY
2
2
 
3
+ == 1.4.0 / 2010-06-26
4
+
5
+ This release adds auto-determination of marker based on file
6
+ extension. This mean DNote can now scan multiple file types
7
+ in a single pass. The supported type are fairly small at this
8
+ point, but will expand in the future. The fallback marker is '#'.
9
+ You can still force a particular marker using the --marker option.
10
+
11
+ Changes:
12
+
13
+ * Support for automatic markers.
14
+
15
+
3
16
  == 1.3.1 / 2010-06-11
4
17
 
5
18
  This release fixes a simple bug. Some version of Ruby do not have
data/VERSION CHANGED
@@ -1,5 +1,5 @@
1
1
  name : dnote
2
2
  major: 1
3
- minor: 3
4
- patch: 1
5
- date : 2010-06-11
3
+ minor: 4
4
+ patch: 0
5
+ date : 2010-06-26
@@ -9,8 +9,8 @@ module DNote
9
9
  # of any labeled comments. Labels are all-cap single word prefixes
10
10
  # to a comment ending in a colon.
11
11
  #
12
- # Special labels do require the colon. By default these are +TODO+,
13
- # +FIXME+, +OPTIMIZE+ and +DEPRECATE+.
12
+ # Special labels do not require the colon. By default these are
13
+ # +TODO+, +FIXME+, +OPTIMIZE+, +THINK+ and +DEPRECATE+.
14
14
  #
15
15
  #--
16
16
  # TODO: Add ability to read header notes. They often
@@ -23,7 +23,7 @@ module DNote
23
23
  DEFAULT_PATHS = ["**/*.rb"]
24
24
 
25
25
  # Default note labels to look for in source code. (NOT CURRENTLY USED!)
26
- DEFAULT_LABELS = ['TODO', 'FIXME', 'OPTIMIZE', 'DEPRECATE']
26
+ DEFAULT_LABELS = ['TODO', 'FIXME', 'OPTIMIZE', 'THINK', 'DEPRECATE']
27
27
 
28
28
  # Files to search for notes.
29
29
  attr_accessor :files
@@ -42,7 +42,8 @@ module DNote
42
42
  @files = [files].flatten
43
43
  @labels = [options[:labels] || DEFAULT_LABELS].flatten.compact
44
44
  @colon = options[:colon].nil? ? true : options[:colon]
45
- @marker = options[:marker] || '#'
45
+ @marker = options[:marker] #|| '#'
46
+ @remark = {}
46
47
  parse
47
48
  end
48
49
 
@@ -81,6 +82,7 @@ module DNote
81
82
  files.each do |fname|
82
83
  next unless File.file?(fname)
83
84
  #next unless fname =~ /\.rb$/ # TODO: should this be done?
85
+ mark = remark(fname)
84
86
  File.open(fname) do |f|
85
87
  lineno, save, text = 0, nil, nil
86
88
  while line = f.gets
@@ -94,14 +96,14 @@ module DNote
94
96
  else
95
97
  if text
96
98
  case line
97
- when /^\s*#{remark}+\s*$/, /(?!^\s*#{remark})/, /^\s*#{remark}[+][+]/
99
+ when /^\s*#{mark}+\s*$/, /(?!^\s*#{mark})/, /^\s*#{mark}[+][+]/
98
100
  text.strip!
99
101
  text = nil
100
102
  else
101
103
  if text[-1,1] == "\n"
102
- text << line.gsub(/^\s*#{remark}\s*/,'')
104
+ text << line.gsub(/^\s*#{mark}\s*/,'')
103
105
  else
104
- text << "\n" << line.gsub(/^\s*#{remark}\s*/,'')
106
+ text << "\n" << line.gsub(/^\s*#{mark}\s*/,'')
105
107
  end
106
108
  end
107
109
  end
@@ -126,7 +128,7 @@ module DNote
126
128
  def match_special(line, lineno, file)
127
129
  rec = nil
128
130
  labels.each do |label|
129
- if md = match_special_regex(label).match(line)
131
+ if md = match_special_regex(label, file).match(line)
130
132
  text = md[1]
131
133
  #rec = {'label'=>label,'file'=>file,'line'=>lineno,'note'=>text}
132
134
  rec = Note.new(file, label, lineno, text)
@@ -138,18 +140,19 @@ module DNote
138
140
  #--
139
141
  # TODO: ruby-1.9.1-p378 reports: `match': invalid byte sequence in UTF-8
140
142
  #++
141
- def match_special_regex(label)
143
+ def match_special_regex(label, file)
144
+ mark = remark(file)
142
145
  if colon
143
- /#{remark}\s*#{Regexp.escape(label)}[:]\s*(.*?)$/
146
+ /#{mark}\s*#{Regexp.escape(label)}[:]\s*(.*?)$/
144
147
  else
145
- /#{remark}\s*#{Regexp.escape(label)}[:]?\s*(.*?)$/
148
+ /#{mark}\s*#{Regexp.escape(label)}[:]?\s*(.*?)$/
146
149
  end
147
150
  end
148
151
 
149
152
  # Match notes that are labeled with a colon.
150
153
  def match_general(line, lineno, file)
151
154
  rec = nil
152
- if md = match_general_regex.match(line)
155
+ if md = match_general_regex(file).match(line)
153
156
  label, text = md[1], md[2]
154
157
  #rec = {'label'=>label,'file'=>file,'line'=>lineno,'note'=>text}
155
158
  rec = Note.new(file, label, lineno, text)
@@ -158,11 +161,12 @@ module DNote
158
161
  end
159
162
 
160
163
  #
161
- def match_general_regex
164
+ def match_general_regex(file)
165
+ mark = remark(file)
162
166
  if colon
163
- /#{remark}\s*([A-Z]+)[:]\s+(.*?)$/
167
+ /#{mark}\s*([A-Z]+)[:]\s+(.*?)$/
164
168
  else
165
- /#{remark}\s*([A-Z]+)[:]?\s+(.*?)$/
169
+ /#{mark}\s*([A-Z]+)[:]?\s+(.*?)$/
166
170
  end
167
171
  end
168
172
 
@@ -233,8 +237,31 @@ module DNote
233
237
  end
234
238
 
235
239
  #
236
- def remark
237
- @remark ||= Regexp.escape(marker)
240
+ def remark(file)
241
+ @remark[File.extname(file)] ||= (
242
+ mark = guess_marker(file)
243
+ Regexp.escape(mark)
244
+ )
245
+ end
246
+
247
+ # Guess marker based on file extension. Fallsback to '#'
248
+ # if the extension is unknown.
249
+ #
250
+ # TODO: Continue to add comment types.
251
+ def guess_marker(file)
252
+ return @marker if @marker # forced marker
253
+ case File.extname(file)
254
+ when '.js', '.c', 'cpp', '.css'
255
+ '//'
256
+ when '.bas'
257
+ "'"
258
+ when '.sql', '.ada'
259
+ '--'
260
+ when '.asm'
261
+ ';'
262
+ else
263
+ '#'
264
+ end
238
265
  end
239
266
 
240
267
  # Convert to array of hashes then to YAML.
@@ -76,7 +76,7 @@ module DNote
76
76
  @format = DEFAULT_FORMAT
77
77
  @title = DEFAULT_TITLE
78
78
  @dryrun = false
79
- @marker = '#'
79
+ @marker = nil
80
80
  end
81
81
 
82
82
  public
@@ -1,5 +1,5 @@
1
1
  name : dnote
2
2
  major: 1
3
- minor: 3
4
- patch: 1
5
- date : 2010-06-11
3
+ minor: 4
4
+ patch: 0
5
+ date : 2010-06-26
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dnote
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 7
4
5
  prerelease: false
5
6
  segments:
6
7
  - 1
7
- - 3
8
- - 1
9
- version: 1.3.1
8
+ - 4
9
+ - 0
10
+ version: 1.4.0
10
11
  platform: ruby
11
12
  authors:
12
13
  - Thomas Sawyer
@@ -14,16 +15,18 @@ autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []
16
17
 
17
- date: 2010-06-11 00:00:00 -04:00
18
+ date: 2010-06-26 00:00:00 -04:00
18
19
  default_executable:
19
20
  dependencies:
20
21
  - !ruby/object:Gem::Dependency
21
22
  name: syckle
22
23
  prerelease: false
23
24
  requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
24
26
  requirements:
25
27
  - - ">="
26
28
  - !ruby/object:Gem::Version
29
+ hash: 3
27
30
  segments:
28
31
  - 0
29
32
  version: "0"
@@ -33,9 +36,11 @@ dependencies:
33
36
  name: lemon
34
37
  prerelease: false
35
38
  requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
36
40
  requirements:
37
41
  - - ">="
38
42
  - !ruby/object:Gem::Version
43
+ hash: 3
39
44
  segments:
40
45
  - 0
41
46
  version: "0"
@@ -121,23 +126,27 @@ rdoc_options:
121
126
  require_paths:
122
127
  - lib
123
128
  required_ruby_version: !ruby/object:Gem::Requirement
129
+ none: false
124
130
  requirements:
125
131
  - - ">="
126
132
  - !ruby/object:Gem::Version
133
+ hash: 3
127
134
  segments:
128
135
  - 0
129
136
  version: "0"
130
137
  required_rubygems_version: !ruby/object:Gem::Requirement
138
+ none: false
131
139
  requirements:
132
140
  - - ">="
133
141
  - !ruby/object:Gem::Version
142
+ hash: 3
134
143
  segments:
135
144
  - 0
136
145
  version: "0"
137
146
  requirements: []
138
147
 
139
148
  rubyforge_project: dnote
140
- rubygems_version: 1.3.6
149
+ rubygems_version: 1.3.7
141
150
  signing_key:
142
151
  specification_version: 3
143
152
  summary: Extract developer's notes from source code