dnote 1.0 → 1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/HISTORY CHANGED
@@ -1,5 +1,23 @@
1
1
  = RELEASE HISTORY
2
2
 
3
+ == 1.1 / 2010-02-06
4
+
5
+ This relase primarily adjusts the way output it rendered
6
+ underthehood. Serialization formats are rendered as
7
+ before but markup formats now use Erb. In the process
8
+ two new serialization formats have been added: soap and xoxo.
9
+
10
+ Also, this release renames the lib/plugin directory to
11
+ lib/plugins (plural) per the new convention of the latest
12
+ Plugin gem. This only matters to Syckle users.
13
+
14
+ Changes:
15
+
16
+ * Add Soap and XOXO formats.
17
+ * Add actual --output option.
18
+ * Move lib/plugin to lib/plugins.
19
+
20
+
3
21
  == 1.0 / 2009-10-25
4
22
 
5
23
  This relase adds support for arbitrary note labels.
data/MANIFEST CHANGED
@@ -6,22 +6,26 @@ bin/dnote
6
6
  lib/dnote
7
7
  lib/dnote.rb
8
8
  lib/dnote/command.rb
9
+ lib/dnote/format.rb
9
10
  lib/dnote/notes.rb
10
11
  lib/dnote/site.rb
11
- lib/dnote/template
12
- lib/dnote/template/assets
13
- lib/dnote/template/assets/css
14
- lib/dnote/template/assets/img
15
- lib/dnote/template/index.html
12
+ lib/dnote/templates
13
+ lib/dnote/templates/gnu.erb
14
+ lib/dnote/templates/html.erb
15
+ lib/dnote/templates/markdown.erb
16
+ lib/dnote/templates/rdoc.erb
17
+ lib/dnote/templates/xml.erb
18
+ lib/plugins
19
+ lib/plugins/syckle
20
+ lib/plugins/syckle/dnote.rb
16
21
  meta/account
17
22
  meta/contact
18
- meta/loadpath
19
- meta/project
23
+ meta/name
20
24
  meta/released
21
25
  meta/repository
26
+ meta/suite
22
27
  meta/summary
23
28
  meta/title
24
29
  meta/version
25
- plug/syckle
26
- plug/syckle/services
27
- plug/syckle/services/dnote.rb
30
+ test/cases
31
+ test/cases/notes_case.rb
@@ -1,8 +1,8 @@
1
1
  = D'Note
2
2
 
3
3
  * home: http://proutils.github.com/dnote
4
- * source: http://github.com/proutils/dnote
5
4
  * forum: http://googlegroups.com/group/proutils
5
+ * source: http://github.com/proutils/dnote
6
6
 
7
7
 
8
8
  == DESCRIPTION
@@ -1,12 +1,32 @@
1
- require 'dnote/notes'
2
-
3
1
  module DNote
4
- VERSION = "1.0" #:till: VERSION = "<%= version %>"
2
+ VERSION = "1.1" #:till: VERSION = "<%= version %>"
3
+
4
+ require 'dnote/notes'
5
+
6
+ # NOTE: Toying with the idea of making DNote a class.
7
+
8
+ #attr :notes
9
+ #
10
+ #def initialize(paths, options={})
11
+ # labels = options[:labels] || options['labels']
12
+ # @notes = Notes.new(paths, labels)
13
+ #end
14
+ #
15
+ #
16
+ #def save(format, output, options)
17
+ # options = options.merge({ :format=>format, :output=>output })
18
+ # format = Format.new(notes, options)
19
+ # format.render
20
+ #end
21
+ #
22
+ #
23
+ #def display(format, options)
24
+ # options = options.merge({ :format=>format, :output=>nil })
25
+ # format = Format.new(@notes, options)
26
+ # format.render
27
+ #end
5
28
 
6
- def self.new(*args)
7
- Notes.new(*args)
8
- end
9
29
  end
10
30
 
11
- # TEST: This is a test of arbitraty note labels.
31
+ # TEST: This is a test of arbitraty labels.
12
32
 
@@ -3,6 +3,7 @@
3
3
  module DNote
4
4
  require 'optparse'
5
5
  require 'dnote'
6
+ require 'dnote/format'
6
7
 
7
8
  def self.run
8
9
  options = {}
@@ -15,28 +16,45 @@ module DNote
15
16
  opt.separator(" ")
16
17
  opt.separator("OUTPUT FORMAT: (choose one)")
17
18
 
18
- opt.on("--rdoc", "RDoc comment format") do |format|
19
- format = 'rdoc'
19
+ opt.on("--gnu", "Plain text format (default)") do
20
+ options[:format] = 'gnu'
20
21
  end
21
22
 
22
- opt.on("--markdown", "Markdown wiki format") do |format|
23
- format = 'markdown'
23
+ opt.on("--rdoc", "RDoc comment format") do
24
+ options[:format] = 'rdoc'
24
25
  end
25
26
 
26
- opt.on("--xml", "XML markup format") do |format|
27
- format = 'xml'
27
+ opt.on("--markdown", "Markdown wiki format") do
28
+ options[:format] = 'markdown'
28
29
  end
29
30
 
30
- opt.on("--html", "HTML markup format") do |format|
31
- format = 'html'
31
+ opt.on("--soap", "SOAP XML envelope format") do
32
+ options[:format] = 'soap'
32
33
  end
33
34
 
34
- opt.on("--yaml", "YAML serialization format") do |format|
35
- format = 'yaml'
35
+ opt.on("--xoxo", "XOXO microformat format") do
36
+ options[:format] = 'xoxo'
36
37
  end
37
38
 
38
- opt.on("--json", "JSON serialization format") do |format|
39
- format = 'json'
39
+ opt.on("--xml", "XML markup format") do
40
+ options[:format] = 'xml'
41
+ end
42
+
43
+ opt.on("--html", "HTML markup format") do
44
+ options[:format] = 'html'
45
+ end
46
+
47
+ opt.on("--yaml", "YAML serialization format") do
48
+ options[:format] = 'yaml'
49
+ end
50
+
51
+ opt.on("--json", "JSON serialization format") do
52
+ options[:format] = 'json'
53
+ end
54
+
55
+ opt.on("--template", "-t FILE", "Use a custom Erb template") do |file|
56
+ options[:format] = 'custom'
57
+ options[:template] = file
40
58
  end
41
59
 
42
60
  opt.separator(" ")
@@ -51,9 +69,9 @@ module DNote
51
69
  options[:title] = title
52
70
  end
53
71
 
54
- #opt.on("--output", "-o [FILE]", "name of file to store output (w/o extension)") do |out|
55
- # options[:output] = out
56
- #end
72
+ opt.on("--output", "-o [PATH]", "name of file or directory") do |path|
73
+ options[:output] = path
74
+ end
57
75
 
58
76
  opt.separator(" ")
59
77
  opt.separator("STANDARD OPTIONS:")
@@ -74,10 +92,9 @@ module DNote
74
92
  # options[:noharm] = true
75
93
  #end
76
94
 
77
- #opt.on("--dryrun", "noharm and verbose modes combined") do
78
- # options[:verbose] = true
79
- # options[:noharm] = true
80
- #end
95
+ opt.on("--dryrun", "-n", "do not actually write to disk") do
96
+ options[:dryrun] = true
97
+ end
81
98
 
82
99
  #opt.on("--trace", "debug and verbose modes combined") do
83
100
  # $DEBUG = true
@@ -91,11 +108,27 @@ module DNote
91
108
 
92
109
  end
93
110
 
94
- opts.parse!
111
+ begin
112
+ opts.parse!
113
+ rescue => err
114
+ puts err
115
+ exit 1
116
+ end
95
117
 
96
118
  paths = ARGV.dup
97
- dnote = DNote.new(paths, options)
98
- dnote.display(format)
119
+ paths = ['**/*.rb'] if paths.empty?
120
+
121
+ notes = Notes.new(paths, options[:labels])
122
+ format = Format.new(notes, options)
123
+ format.render
124
+
125
+ # NOTE: If DNote were a class.
126
+
127
+ #if output
128
+ # dnote.save(format, output)
129
+ #else
130
+ # dnote.display(format)
131
+ #end
99
132
  end
100
133
 
101
134
  end
@@ -0,0 +1,213 @@
1
+ module DNote
2
+
3
+ # = Notes Formatter
4
+ #
5
+ #--
6
+ # TODO: Need good CSS file.
7
+ #
8
+ # TODO: Need XSL?
9
+ #++
10
+ class Format
11
+
12
+ require 'fileutils'
13
+ require 'erb'
14
+ require 'rexml/text'
15
+
16
+ #DEFAULT_OUTPUT_DIR = "log/dnote"
17
+
18
+ EXTENSIONS = { 'soap'=>'xml', 'xoxo'=>'xml' }
19
+
20
+ #
21
+ attr :notes
22
+
23
+ #
24
+ attr_accessor :format
25
+
26
+ #
27
+ attr_accessor :output
28
+
29
+ #
30
+ attr_accessor :template
31
+
32
+ #
33
+ attr_accessor :title
34
+
35
+ #
36
+ attr_accessor :dryrun
37
+
38
+ #
39
+ def initialize(notes, options={})
40
+ @notes = notes
41
+ @format = :gnu
42
+ @title = "Developer's Notes"
43
+ options.each do |k,v|
44
+ __send__("#{k}=", v) if v
45
+ end
46
+ end
47
+
48
+ #
49
+ def render
50
+ if notes.empty?
51
+ $stderr << "No #{notes.labels.join(', ')} notes.\n"
52
+ else
53
+ raise ArgumentError unless respond_to?("render_#{format}")
54
+ __send__("render_#{format}")
55
+ end
56
+ end
57
+
58
+ # S E R I A L I Z A T I O N
59
+
60
+ def render_yaml
61
+ result = notes.to_yaml
62
+ publish(result)
63
+ end
64
+
65
+ def render_json
66
+ result = notes.to_json
67
+ publish(result)
68
+ end
69
+
70
+ # M L M A R K U P
71
+
72
+ def render_soap
73
+ result = notes.to_soap
74
+ publish(result)
75
+ end
76
+
77
+ def render_xoxo
78
+ result = notes.to_xoxo
79
+ publish(result)
80
+ end
81
+
82
+ def render_xml
83
+ template = File.join(File.dirname(__FILE__), 'templates/xml.erb')
84
+ result = erb(template)
85
+ publish(result)
86
+ end
87
+
88
+ def render_html
89
+ template = File.join(File.dirname(__FILE__), 'templates/html.erb')
90
+ result = erb(template)
91
+ publish(result)
92
+ end
93
+
94
+ def render_index
95
+ template = File.join(File.dirname(__FILE__), 'templates/html.erb')
96
+ result = erb(template)
97
+ publish(result, 'index.html')
98
+ end
99
+
100
+ # W I K I M A R K U P
101
+
102
+ def render_gnu
103
+ template = File.join(File.dirname(__FILE__), 'templates/gnu.erb')
104
+ result = erb(template)
105
+ publish(result)
106
+ end
107
+
108
+ def render_rdoc
109
+ template = File.join(File.dirname(__FILE__), 'templates/rdoc.erb')
110
+ result = erb(template)
111
+ publish(result)
112
+ end
113
+
114
+ def render_markdown
115
+ template = File.join(File.dirname(__FILE__), 'templates/markdown.erb')
116
+ result = erb(template)
117
+ publish(result)
118
+ end
119
+
120
+ # C U S T O M T E M P L A T E
121
+
122
+ def render_custom
123
+ result = erb(template)
124
+ publish(result)
125
+ end
126
+
127
+ private
128
+
129
+ #
130
+ def erb(file)
131
+ scope = ErbScope.new(:notes=>notes, :title=>title)
132
+ scope.render(file)
133
+ end
134
+
135
+ #
136
+ def publish(result, fname=nil)
137
+ if output
138
+ write(result, fname)
139
+ else
140
+ puts(result)
141
+ end
142
+ $stderr << "\n(" + notes.counts.map{|l,n| "#{n} #{l}s"}.join(', ') + ")\n"
143
+ end
144
+
145
+ #
146
+ def write(result, fname=nil)
147
+ if output.end_with?('/') || File.directory?(output)
148
+ ext = EXTENSIONS[format] || format
149
+ file = File.join(output, fname || "notes.#{ext}")
150
+ else
151
+ file = output
152
+ end
153
+ if dryrun?
154
+ puts "mkdir: #{File.dirname(file)}"
155
+ puts "write: #{file}"
156
+ else
157
+ dir = File.dirname(file)
158
+ fu.mkdir(dir) unless File.exist?(dir)
159
+ File.open(file, 'w'){ |f| f << result }
160
+ end
161
+ return file
162
+ end
163
+
164
+ #
165
+ def dryrun?
166
+ @dryrun
167
+ end
168
+
169
+ #
170
+ def debug?
171
+ $DEBUG
172
+ end
173
+
174
+ #
175
+ def fu
176
+ @fu ||= (
177
+ if dryrun? and debug?
178
+ FileUtils::DryRun
179
+ elsif dryrun?
180
+ FileUtils::Noop
181
+ elsif debug?
182
+ FileUtils::Verbose
183
+ else
184
+ FileUtils
185
+ end
186
+ )
187
+ end
188
+
189
+ #
190
+ class ErbScope
191
+ #
192
+ def initialize(data={})
193
+ @data = data
194
+ end
195
+ #
196
+ def render(file)
197
+ erb = ERB.new(File.read(file), nil, '<>')
198
+ erb.result(binding)
199
+ end
200
+ #
201
+ def h(string)
202
+ REXML::Text.normalize(string)
203
+ end
204
+ #
205
+ def method_missing(s, *a)
206
+ @data[s.to_sym]
207
+ end
208
+ end
209
+
210
+ end
211
+
212
+ end
213
+
@@ -1,35 +1,29 @@
1
- require 'rexml/text'
2
1
  require 'pathname'
3
- require 'erb'
4
2
 
5
3
  module DNote
6
4
 
7
5
  # = Developer Notes
8
6
  #
9
- # This class goes through you source files and compiles
10
- # an list of any labeled comments. Labels are single word
11
- # prefixes to a comment ending in a colon.
7
+ # This class goes through you source files and compiles a list
8
+ # of any labeled comments. Labels are single word prefixes to
9
+ # a comment ending in a colon.
12
10
  #
13
- # By default the labels supported are TODO, FIXME, OPTIMIZE and DEPRECATE.
11
+ # By default the labels supported are TODO, FIXME, OPTIMIZE
12
+ # and DEPRECATE.
14
13
  #
15
- # Output is a set of files in XML and RDoc's simple
16
- # markup format.
17
- #
18
- # TODO: Add ability to read header notes. They oftern
14
+ #--
15
+ # TODO: Add ability to read header notes. They often
19
16
  # have a outline format, rather then the single line.
20
- #
21
- # TODO: Need good CSS file.
22
- #
23
- # TODO: Need XSL?
24
- #
17
+ #++
25
18
  class Notes
19
+ include Enumerable
20
+
21
+ # Default paths (all ruby scripts).
22
+ DEFAULT_PATHS = ["**/*.rb"]
26
23
 
27
24
  # Default note labels to look for in source code.
28
25
  DEFAULT_LABELS = ['TODO', 'FIXME', 'OPTIMIZE', 'DEPRECATE']
29
26
 
30
- #
31
- attr_accessor :title
32
-
33
27
  # Paths to search.
34
28
  attr_accessor :paths
35
29
 
@@ -37,23 +31,12 @@ module DNote
37
31
  attr_accessor :labels
38
32
 
39
33
  #
40
- def initialize(paths, options={})
41
- initialize_defaults
42
- options.each do |k, v|
43
- __send__("#{k}=", v)
44
- end
45
- #@paths = ['**/*.rb'] if @paths.empty?
34
+ def initialize(paths, labels=nil)
35
+ @paths = [paths || DEFAULT_PATHS ].flatten
36
+ @labels = [labels || DEFAULT_LABELS].flatten
46
37
  parse
47
38
  end
48
39
 
49
- #
50
- def initialize_defaults
51
- @labels = DEFAULT_LABELS
52
- @paths = ["**/*.rb"]
53
- @title = "Developer's Notes"
54
- @format = "rdoc"
55
- end
56
-
57
40
  #
58
41
  def notes
59
42
  @notes
@@ -64,51 +47,14 @@ module DNote
64
47
  @counts
65
48
  end
66
49
 
67
- # Scans source code for developer notes and writes them to
68
- # well organized files.
69
50
  #
70
- def display(format)
71
- #paths = self.paths
72
- #output = self.output
73
-
74
- #parse
75
-
76
- #paths = paths.to_list
77
-
78
- #labels = labels.split(',') if String === labels
79
- #labels = [labels].flatten.compact
80
-
81
- #records, counts = extract(labels, loadpath)
82
- #records = organize(records)
83
-
84
- #case format.to_s
85
- #when 'rdoc', 'txt', 'text'
86
- # text = format_rd(records)
87
- #else
88
- # text = format_xml(records)
89
- #end
90
-
91
- if notes.empty?
92
- $stderr << "No #{labels.join(', ')} notes.\n"
93
- else
94
- #temp = templates.find{ |f| /#{format}$/ =~ f }
95
- #erb = ERB.new(File.read(temp))
96
- #text = erb.result(binding)
97
-
98
- text = __send__("to_#{format}")
51
+ def each(&block)
52
+ notes.each(&block)
53
+ end
99
54
 
100
- #if output
101
- # #templates.each do |template|
102
- # #text = format_notes(notes, format)
103
- # file = write(txt, format)
104
- # #file = file #Pathname.new(file).relative_path_from(Pathname.pwd) #project.root
105
- # puts "Updated #{file}"
106
- # #end
107
- #else
108
- puts text
109
- #end
110
- $stderr << "\n(" + counts.map{|l,n| "#{n} #{l}s"}.join(', ') + ")\n"
111
- end
55
+ #
56
+ def empty?
57
+ notes.empty?
112
58
  end
113
59
 
114
60
  #
@@ -118,7 +64,7 @@ module DNote
118
64
  when String
119
65
  labels.split(/[:;,]/)
120
66
  else
121
- labels = [labels].flatten.compact.uniq
67
+ labels = [labels].flatten.compact.uniq.map{ |s| s.to_s }
122
68
  end
123
69
  )
124
70
  end
@@ -164,7 +110,7 @@ module DNote
164
110
  #
165
111
  def files
166
112
  @files ||= (
167
- self.paths.map do |path|
113
+ [self.paths].flatten.map do |path|
168
114
  if File.directory?(path)
169
115
  Dir.glob(File.join(path, '**/*'))
170
116
  else
@@ -219,107 +165,6 @@ module DNote
219
165
  __send__("to_#{format}")
220
166
  end
221
167
 
222
- # Format notes in RDoc format.
223
- #
224
- def to_rdoc
225
- out = []
226
- out << "= Development Notes"
227
- notes.each do |label, per_file|
228
- out << %[\n== #{label}]
229
- per_file.each do |file, line_notes|
230
- out << %[\n=== file://#{file}\n]
231
- line_notes.sort!{ |a,b| a[0] <=> b[0] }
232
- line_notes.each do |line, note|
233
- out << %[* #{note} (#{line})]
234
- end
235
- end
236
- end
237
- return out.join("\n")
238
- end
239
-
240
- # Format notes in RDoc format.
241
- #
242
- def to_markdown
243
- out = []
244
- out << "# Development Notes"
245
- notes.each do |label, per_file|
246
- out << %[\n## #{label}]
247
- per_file.each do |file, line_notes|
248
- out << %[\n### file://#{file}\n]
249
- line_notes.sort!{ |a,b| a[0] <=> b[0] }
250
- line_notes.each do |line, note|
251
- out << %[* #{note} (#{line})]
252
- end
253
- end
254
- end
255
- return out.join("\n")
256
- end
257
-
258
- # Format notes in XML format.
259
- #
260
- def to_xml
261
- xml = []
262
- xml << "<notes>"
263
- notes.each do |label, per_file|
264
- xml << %[<set label="#{label}">]
265
- per_file.each do |file, line_notes|
266
- xml << %[<file src="#{file}">]
267
- line_notes.sort!{ |a,b| a[0] <=> b[0] }
268
- line_notes.each do |line, note|
269
- note = REXML::Text.normalize(note)
270
- xml << %[<note line="#{line}" type="#{label}">#{note}</note>]
271
- end
272
- xml << %[</file>]
273
- end
274
- xml << %[</set>]
275
- end
276
- xml << "</notes>"
277
- return xml.join("\n")
278
- end
279
-
280
- # HTML format.
281
- #
282
- def to_html
283
- html = []
284
- html << %[<html>]
285
- html << %[<head>]
286
- html << %[<title><%= title %></title>]
287
- html << %[<style>]
288
- html << HTML_CSS
289
- html << %[</style>]
290
- html << %[</head>]
291
- html << %[<body>]
292
- html << %[<div class="main">]
293
- html << %[<h1><%= title %></h1>]
294
- html << to_html_list
295
- html << %[</div>]
296
- html << %[</boby>]
297
- html << %[</html>]
298
- html.join("\n")
299
- end
300
-
301
- #
302
- def to_html_list
303
- html = []
304
- html << %[<div class="notes">]
305
- notes.each do |label, per_file|
306
- html << %[<h2>#{label}</h2>]
307
- html << %[<ol class="set #{label.downcase}">]
308
- per_file.each do |file, line_notes|
309
- html << %[<li><h3><a href="#{file}">#{file}</a></h3><ol class="file" href="#{file}">]
310
- line_notes.sort!{ |a,b| a[0] <=> b[0] }
311
- line_notes.each do |line, note|
312
- note = REXML::Text.normalize(note)
313
- html << %[<li class="note #{label.downcase}" ref="#{line}">#{note} <sup>#{line}</sup></li>]
314
- end
315
- html << %[</ol></li>]
316
- end
317
- html << %[</ol>]
318
- end
319
- html << %[</div>]
320
- html.join("\n")
321
- end
322
-
323
168
  #
324
169
  def to_yaml
325
170
  require 'yaml'
@@ -328,68 +173,27 @@ module DNote
328
173
 
329
174
  #
330
175
  def to_json
331
- require 'json' # TODO: fallback to json_pure
176
+ begin
177
+ require 'json'
178
+ rescue LoadError
179
+ require 'json_pure'
180
+ end
332
181
  notes.to_json
333
182
  end
334
183
 
335
- HTML_CSS = <<-HERE
336
- body { margin: 0; padding: 0; }
337
- .main { width: 800px; margin: 0 auto; border: 1px solid #ccc; padding: 0 20px 20px 20px; }
338
- h1 { margin: 25px 0; }
339
- h2,h3,h4 { margin: 5px 0; padding: 0; color: 880044; }
340
- h3 { color: 004488; }
341
- h4 { color: 888844; }
342
- ul { margin: 0; padding: 0; text-align: left; }
343
- li { margin: 0; padding: 0; text-align: left; }
344
- HERE
184
+ # Soap envelope XML.
185
+ def to_soap
186
+ require 'soap/marshal'
187
+ SOAP::Marshal.marshal(notes)
188
+ end
189
+
190
+ # XOXO microformat.
191
+ def to_xoxo
192
+ require 'xoxo'
193
+ notes.to_xoxo
194
+ end
345
195
 
346
196
  end
347
197
 
348
198
  end
349
199
 
350
- # out = ''
351
- #
352
- # case format
353
- # when 'yaml'
354
- # out << records.to_yaml
355
- # when 'list'
356
- # records.each do |record|
357
- # out << "* #{record['note']}\n"
358
- # end
359
- # else #when 'rdoc'
360
- # labels.each do |label|
361
- # recs = records.select{ |r| r['label'] == label }
362
- # next if recs.empty?
363
- # out << "\n= #{label}\n"
364
- # last_file = nil
365
- # recs.sort!{ |a,b| a['file'] <=> b['file'] }
366
- # recs.each do |record|
367
- # if last_file != record['file']
368
- # out << "\n"
369
- # last_file = record['file']
370
- # out << "file://#{record['file']}\n"
371
- # end
372
- # out << "* #{record['note'].rstrip} (#{record['line']})\n"
373
- # end
374
- # end
375
- # out << "\n---\n"
376
- # out << counts.collect{|l,n| "#{n} #{l}s"}.join(' ')
377
- # out << "\n"
378
- # end
379
-
380
- # # List TODO notes. Same as notes --label=TODO.
381
- #
382
- # def todo( options={} )
383
- # options = options.to_openhash
384
- # options.label = 'TODO'
385
- # notes(options)
386
- # end
387
- #
388
- # # List FIXME notes. Same as notes --label=FIXME.
389
- #
390
- # def fixme( options={} )
391
- # options = options.to_openhash
392
- # options.label = 'FIXME'
393
- # notes(options)
394
- # end
395
-
@@ -4,13 +4,13 @@ module DNote
4
4
 
5
5
  # Site class is used to build a "pretty" output set.
6
6
  # The template files are saved to the +output+ directory.
7
- # Additional +formats+ can be saved the the directory
7
+ # Additional +formats+ can be saved to the directory
8
8
  # as well.
9
9
 
10
10
  class Site
11
11
 
12
- # Default output directory is +dnote/+.
13
- DEFAULT_OUTPUT = Pathname.new('dnote')
12
+ # Default output directory is +log/dnote/+.
13
+ DEFAULT_OUTPUT = Pathname.new('log/dnote')
14
14
 
15
15
  # Title to use in any headers.
16
16
  attr_accessor :title
@@ -18,17 +18,19 @@ module DNote
18
18
  # Directory to save output.
19
19
  attr_accessor :output
20
20
 
21
- # Additional Formats to supply besided the html (xml, rdoc, markdown, etc.)
21
+ # Additional Formats to supply besides the html (xml, rdoc, markdown, etc.)
22
22
  attr_accessor :formats
23
23
 
24
24
  # Notes object.
25
25
  attr_reader :notes
26
26
 
27
27
  def initialize(paths, options)
28
- self.title = options[:title]
28
+ initialize_defaults
29
29
 
30
- self.output = options.delete(:output)
31
- self.formats = options.delete(:formats)
30
+ self.title = options[:title] if options[:title]
31
+
32
+ self.output = options.delete(:output) if options[:output]
33
+ self.formats = options.delete(:formats) if options[:formats]
32
34
 
33
35
  @notes = Notes.new(paths, options)
34
36
  end
@@ -37,7 +39,7 @@ module DNote
37
39
  def initialize_defaults
38
40
  @output = DEFAULT_OUTPUT
39
41
  @title = "Development Notes"
40
- @formats = []
42
+ @formats = ['html']
41
43
  end
42
44
 
43
45
  #
@@ -50,19 +52,27 @@ module DNote
50
52
  def document
51
53
  fu.mkdir_p(output)
52
54
 
53
- # copy the whole template directory over
54
- fu.cp_r("#{__DIR__}/template/", "#{output}/")
55
-
56
- # (re)write the erb templates
57
- templates.each do |temp|
58
- erb = ERB.new(File.read(temp))
59
- text = erb.result(binding)
60
- file = File.basename(temp)
61
- write(file, text)
62
- end
63
-
64
55
  # produce requested additional formats
65
56
  formats.each do |format|
57
+ =begin
58
+ tdir = tempdir(format)
59
+
60
+ # copy non-erb files
61
+ files = Dir.entries(tdir) - ['.', '..']
62
+ files = files.reject{ |file| File.extname(file) == '.erb' }
63
+ files.each do |file|
64
+ dest = File.dirname(file).sub(tdir, '')
65
+ fu.cp_r(File.join(tdir, file), output)
66
+ end
67
+
68
+ # write the erb templates
69
+ templates(format).each do |temp|
70
+ file = File.join(tdir, temp)
71
+ erb = ERB.new(File.read(file))
72
+ text = erb.result(binding)
73
+ write(temp.chomp('.erb'), text)
74
+ end
75
+ =end
66
76
  text = notes.to(format)
67
77
  write("notes.#{format}", text)
68
78
  end
@@ -85,10 +95,17 @@ module DNote
85
95
  end
86
96
 
87
97
  #
88
- def templates
89
- @templates ||= (
90
- Dir[File.join(File.dirname(__FILE__), 'template/*')].select{ |f| File.file?(f) }
91
- )
98
+ tempdir(format)
99
+ "#{__DIR__}/templates/#{format}"
100
+ end
101
+
102
+ # TODO: Don't use chdir.
103
+ def templates(format)
104
+ temps = []
105
+ Dir.chdir(tempdir(format)) do
106
+ temps = Dir['**/*.erb']
107
+ end
108
+ temps
92
109
  end
93
110
 
94
111
  # Save file to output.
@@ -0,0 +1,8 @@
1
+ <%= title %>
2
+
3
+ <% notes.each do |label, per_file| %>
4
+ <%= label %>:
5
+ <% per_file.each do |file, line_notes| %>
6
+ <% line_notes.sort!{ |a,b| a[0] <=> b[0] } %><% line_notes.each do |line, note| %>
7
+ * <%= note %> (<%= file %>:<%= line %>)
8
+ <% end; end; end %>
@@ -0,0 +1,41 @@
1
+ <html>
2
+ <head>
3
+ <title><%= title %></title>
4
+ <style>
5
+ body { margin: 0; padding: 0; }
6
+ .main {
7
+ width: 800px;
8
+ margin: 0 auto;
9
+ border: 1px solid #ccc;
10
+ padding: 0 20px 20px 20px;
11
+ }
12
+ h1 { margin: 25px 0; }
13
+ h2,h3,h4 { margin: 5px 0; padding: 0; color: 880044; }
14
+ h3 { color: 004488; }
15
+ h4 { color: 888844; }
16
+ ul { margin: 0; padding: 0; text-align: left; }
17
+ li { margin: 0; padding: 0; text-align: left; }
18
+ </style>
19
+ <link rel="stylesheet" href="notes.css" type="text/css">
20
+ </head>
21
+ <body>
22
+ <div class="main">
23
+ <h1><%= title %></h1>
24
+ <div class="notes">
25
+ <% notes.each do |label, per_file| %>
26
+ <h2><%= label %></h2>
27
+ <ol class="set <%= label.downcase %>">
28
+ <% per_file.each do |file, line_notes| %>
29
+ <li><h3><a href="<%= file %>"><%= file %></a></h3><ol class="file" href="<%= file %>">
30
+ <% line_notes.sort!{ |a,b| a[0] <=> b[0] } %>
31
+ <% line_notes.each do |line, note| %>
32
+ <li class="note <%= label.downcase %>" ref="<%= line %>"><%= h note %> <sup><%= line %></sup></li>
33
+ <% end %>
34
+ </ol></li>
35
+ <% end %>
36
+ </ol>
37
+ <% end %>
38
+ </div>
39
+ </div>
40
+ </body>
41
+ </html>
@@ -0,0 +1,11 @@
1
+ # <%= title %><% notes.each do |label, per_file| %>
2
+
3
+ ## <%= label %>
4
+ <% per_file.each do |file, line_notes| %>
5
+
6
+ ### file://<%= file %>
7
+
8
+ <% line_notes.sort!{ |a,b| a[0] <=> b[0] } %><% line_notes.each do |line, note| %>
9
+ * <%= note %> (<%= line %>)
10
+ <% end; end; end %>
11
+
@@ -0,0 +1,11 @@
1
+ = <%= title %><% notes.each do |label, per_file| %>
2
+
3
+ == <%= label %>
4
+ <% per_file.each do |file, line_notes| %>
5
+
6
+ === file://<%= file %>
7
+
8
+ <% line_notes.sort!{ |a,b| a[0] <=> b[0] } %><% line_notes.each do |line, note| %>
9
+ * <%= note %> (<%= line %>)
10
+ <% end; end; end %>
11
+
@@ -0,0 +1,15 @@
1
+ <?xml version="1.0" ?>
2
+ <notes>
3
+ <% notes.each do |label, per_file| %>
4
+ <set label="<%= label %>">
5
+ <% per_file.each do |file, line_notes| %>
6
+ <file src="<%= file %>">
7
+ <% line_notes.sort!{ |a,b| a[0] <=> b[0] } %>
8
+ <% line_notes.each do |line, note| %>
9
+ <note line="<%= line %>" type="<%= label %>"><%= h note %></note>
10
+ <% end %>
11
+ </file>
12
+ <% end %>
13
+ </set>
14
+ <% end %>
15
+ </notes>
@@ -26,7 +26,8 @@ module Syckle::Plugins
26
26
  # not that this is necessary, but ...
27
27
  available do |project|
28
28
  begin
29
- require 'dnote/site'
29
+ require 'dnote'
30
+ require 'dnote/format'
30
31
  true
31
32
  rescue LoadError
32
33
  false
@@ -35,11 +36,11 @@ module Syckle::Plugins
35
36
 
36
37
  # autorun if log/notes exists
37
38
  autorun do |project|
38
- (project.log + 'notes').exist?
39
+ (project.log + 'dnote').exist?
39
40
  end
40
41
 
41
42
  # Default note labels to looked for in source code.
42
- DEFAULT_LABELS = ['TODO', 'FIXME', 'OPTIMIZE', 'DEPRECATE']
43
+ #DEFAULT_LABELS = ['TODO', 'FIXME', 'OPTIMIZE', 'DEPRECATE']
43
44
 
44
45
  # Paths to search.
45
46
  attr_accessor :files
@@ -47,51 +48,71 @@ module Syckle::Plugins
47
48
  # Labels to document. Defaults are: TODO, FIXME, OPTIMIZE and DEPRECATE.
48
49
  attr_accessor :labels
49
50
 
50
- # Directory to save output. Defaults to <tt>dnote/</tt> under project
51
- # log directory.
51
+ # Output directory to save notes file. Defaults to <tt>dnote/</tt> under
52
+ # the project log directory (eg. <tt>log/dnote/</tt>).
52
53
  attr_accessor :output
53
54
 
54
55
  # Formats (xml, html, rdoc).
55
56
  attr_accessor :formats
56
57
 
58
+ # Title to use if temaplte can use it.
59
+ attr_accessor :title
60
+
57
61
  #
58
62
  def output=(path)
59
63
  @output = Pathname.new(path)
60
64
  end
61
65
 
62
66
  #
63
- def dnote
64
- @dnote ||= ::DNote::Site.new(files, :labels=>labels, :formats=>formats, :output=>output)
65
- end
67
+ #def dnote
68
+ # @dnote ||= ::DNote::Site.new(files, :labels=>labels, :formats=>formats, :output=>output)
69
+ #end
66
70
 
67
71
  # Generate notes documents.
72
+ #--
73
+ # TODO: Is #trial? correct?
74
+ #++
68
75
  def document
69
- $NOOP = noop? # TODO:
70
- dnote.document
71
- #mkdir_p(output)
72
- #file = output + "index.html"
73
- #File.open(file, 'w'){ |f| f << dnote.to_html }
74
- report "Updated #{output.to_s.sub(Dir.pwd+'/','')}"
76
+ notes = ::DNote::Notes.new(files, labels)
77
+ [formats].flatten.each do |format|
78
+ if format == 'index'
79
+ format = 'html'
80
+ output = File.join(self.output, 'index.html')
81
+ end
82
+ format = ::DNote::Format.new(notes, :format=>format, :output=>output.to_s, :title=>title, :dryrun=>trial?)
83
+ format.render
84
+ report "Updated #{output.to_s.sub(Dir.pwd+'/','')}" unless trial?
85
+ end
75
86
  end
76
87
 
77
- # Mark notes documents as out-of-date.
88
+ # Reset output directory, marking it as out-of-date.
78
89
  def reset
79
- #dnote.reset
90
+ if File.directory?(output)
91
+ File.utime(0,0,output) unless $NOOP
92
+ puts "Marked #{output}"
93
+ end
80
94
  end
81
95
 
82
- # Remove notes directory.
96
+ # Remove output files.
83
97
  def clean
84
- #dnote.clean
98
+ if File.directory?(output)
99
+ formats.each do |format|
100
+ ext = ::DNote::Format::EXTENSIONS[format] || format
101
+ file = (output + "notes.#{ext}").to_s
102
+ rm(file)
103
+ report "Removed #{output}"
104
+ end
105
+ end
85
106
  end
86
107
 
87
108
  private
88
109
 
89
- # TODO: maybe files default of **/*.rb is better?
110
+ #
90
111
  def initialize_defaults
91
- @files = metadata.loadpath || 'lib'
112
+ @files = "**/*.rb"
92
113
  @output = project.log + 'dnote'
93
- @formats = []
94
- @labels = DEFAULT_LABELS
114
+ @formats = ['index']
115
+ @labels = nil #DEFAULT_LABELS
95
116
  end
96
117
 
97
118
  end
File without changes
@@ -1 +1 @@
1
- 2009-10-06
1
+ 2010-02-06
@@ -0,0 +1 @@
1
+ proutils
@@ -1 +1 @@
1
- 1.0
1
+ 1.1
@@ -0,0 +1,55 @@
1
+ require 'dnote/notes'
2
+
3
+ Case DNote::Notes do
4
+
5
+ Concern "Full coverage of DNote::Notes class."
6
+
7
+ Unit :paths
8
+
9
+ Unit :labels => 'returns the list of labels' do
10
+ notes = DNote::Notes.new([])
11
+ notes.labels.assert == DNote::Notes::DEFAULT_LABELS
12
+ end
13
+
14
+ Unit :labels= => 'changes the list of labels' do
15
+ notes = DNote::Notes.new([])
16
+ notes.labels = [:CHOICE]
17
+ notes.labels.assert == ['CHOICE']
18
+ end
19
+
20
+ Unit :paths => 'returns the paths attribute' do
21
+ notes = DNote::Notes.new(["example1.rb"])
22
+ notes.assert.paths == ["example1.rb"]
23
+ notes = DNote::Notes.new([], :paths => ["example2.rb"])
24
+ notes.assert.paths == ["example2.rb"]
25
+ end
26
+
27
+ Unit :paths= => 'changes the paths attribute' do
28
+ notes = DNote::Notes.new([])
29
+ notes.paths = ["example1.rb"]
30
+ notes.assert.paths == ["example1.rb"]
31
+ end
32
+
33
+ Unit :files
34
+
35
+ Unit :match_arbitrary => '' do
36
+ notes = DNote::Notes.new([])
37
+ line, lineno, file = "# TODO: Do something or another!", 1, "foo.rb"
38
+ rec = notes.match_arbitrary(line, lineno, file)
39
+ rec.assert == {'label'=>"TODO",'file'=>file,'line'=>lineno,'note'=>"Do something or another!"}
40
+ end
41
+
42
+ Unit :match_common
43
+ Unit :to_xml
44
+ Unit :notes
45
+ Unit :to
46
+ Unit :initialize_defaults
47
+ Unit :parse
48
+ Unit :to_yaml
49
+ Unit :to_json
50
+ Unit :counts
51
+ Unit :organize
52
+ Unit :display
53
+
54
+ end
55
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dnote
3
3
  version: !ruby/object:Gem::Version
4
- version: "1.0"
4
+ version: "1.1"
5
5
  platform: ruby
6
6
  authors: []
7
7
 
@@ -9,21 +9,18 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-10-25 00:00:00 -04:00
12
+ date: 2010-02-06 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
16
16
  description: ""
17
- email: http://googlegroups.com/group/proutils
17
+ email:
18
18
  executables:
19
19
  - dnote
20
20
  extensions: []
21
21
 
22
- extra_rdoc_files:
23
- - MANIFEST
24
- - LICENSE
25
- - README.rdoc
26
- - HISTORY
22
+ extra_rdoc_files: []
23
+
27
24
  files:
28
25
  - HISTORY
29
26
  - LICENSE
@@ -32,19 +29,25 @@ files:
32
29
  - bin/dnote
33
30
  - lib/dnote.rb
34
31
  - lib/dnote/command.rb
32
+ - lib/dnote/format.rb
35
33
  - lib/dnote/notes.rb
36
34
  - lib/dnote/site.rb
37
- - lib/dnote/template/index.html
35
+ - lib/dnote/templates/gnu.erb
36
+ - lib/dnote/templates/html.erb
37
+ - lib/dnote/templates/markdown.erb
38
+ - lib/dnote/templates/rdoc.erb
39
+ - lib/dnote/templates/xml.erb
40
+ - lib/plugins/syckle/dnote.rb
38
41
  - meta/account
39
42
  - meta/contact
40
- - meta/loadpath
41
- - meta/project
43
+ - meta/name
42
44
  - meta/released
43
45
  - meta/repository
46
+ - meta/suite
44
47
  - meta/summary
45
48
  - meta/title
46
49
  - meta/version
47
- - plug/syckle/services/dnote.rb
50
+ - test/cases/notes_case.rb
48
51
  has_rdoc: true
49
52
  homepage:
50
53
  licenses: []
@@ -55,7 +58,6 @@ rdoc_options:
55
58
  - D'Note API
56
59
  require_paths:
57
60
  - lib
58
- - plug
59
61
  required_ruby_version: !ruby/object:Gem::Requirement
60
62
  requirements:
61
63
  - - ">="
@@ -1,32 +0,0 @@
1
- <html>
2
- <head>
3
- <title><%= title %></title>
4
- <style>
5
- body { margin: 0; padding: 0; }
6
- .main {
7
- width: 800px;
8
- margin: 0 auto;
9
- border: 1px solid #ccc;
10
- padding: 0 20px 20px 20px;
11
- }
12
- h1 { margin: 25px 0; }
13
- h2,h3,h4 { margin: 5px 0; padding: 0; color: 880044; }
14
- h3 { color: 004488; }
15
- h4 { color: 888844; }
16
- ul { margin: 0; padding: 0; text-align: left; }
17
- li { margin: 0; padding: 0; text-align: left; }
18
- </style>
19
- </head>
20
- <body>
21
-
22
- <div class="main">
23
-
24
- <h1><%= title %></h1>
25
-
26
- <%= notes.to_html_list %>
27
-
28
- </div>
29
-
30
- </boby>
31
- </html>
32
-
@@ -1,2 +0,0 @@
1
- lib
2
- plug