dnote 1.1.4 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. data/HISTORY +29 -0
  2. data/bin/dnote +2 -2
  3. data/lib/dnote.rb +2 -3
  4. data/lib/dnote/format.rb +26 -69
  5. data/lib/dnote/note.rb +57 -0
  6. data/lib/dnote/notes.rb +158 -97
  7. data/lib/dnote/session.rb +277 -0
  8. data/lib/dnote/templates/html.erb +4 -4
  9. data/lib/dnote/templates/html/file.erb +40 -0
  10. data/lib/dnote/templates/html/label.erb +41 -0
  11. data/lib/dnote/templates/html/list.erb +33 -0
  12. data/lib/dnote/templates/json.erb +8 -0
  13. data/lib/dnote/templates/json/file.erb +8 -0
  14. data/lib/dnote/templates/json/label.erb +8 -0
  15. data/lib/dnote/templates/json/list.erb +8 -0
  16. data/lib/dnote/templates/md.erb +18 -0
  17. data/lib/dnote/templates/md/file.erb +13 -0
  18. data/lib/dnote/templates/md/label.erb +18 -0
  19. data/lib/dnote/templates/md/list.erb +9 -0
  20. data/lib/dnote/templates/rdoc.erb +3 -3
  21. data/lib/dnote/templates/rdoc/file.erb +9 -0
  22. data/lib/dnote/templates/rdoc/label.erb +11 -0
  23. data/lib/dnote/templates/rdoc/list.erb +6 -0
  24. data/lib/dnote/templates/soap.erb +4 -0
  25. data/lib/dnote/templates/soap/file.erb +4 -0
  26. data/lib/dnote/templates/soap/label.erb +4 -0
  27. data/lib/dnote/templates/soap/list.erb +4 -0
  28. data/lib/dnote/templates/text.erb +11 -0
  29. data/lib/dnote/templates/text/file.erb +10 -0
  30. data/lib/dnote/templates/text/label.erb +11 -0
  31. data/lib/dnote/templates/text/list.erb +7 -0
  32. data/lib/dnote/templates/xml.erb +6 -6
  33. data/lib/dnote/templates/xml/file.erb +15 -0
  34. data/lib/dnote/templates/xml/label.erb +15 -0
  35. data/lib/dnote/templates/xml/list.erb +6 -0
  36. data/lib/dnote/templates/xoxo.erb +4 -0
  37. data/lib/dnote/templates/xoxo/file.erb +4 -0
  38. data/lib/dnote/templates/xoxo/label.erb +4 -0
  39. data/lib/dnote/templates/xoxo/list.erb +6 -0
  40. data/lib/dnote/templates/yaml.erb +1 -0
  41. data/lib/dnote/templates/yaml/file.erb +1 -0
  42. data/lib/dnote/templates/yaml/label.erb +1 -0
  43. data/lib/dnote/templates/yaml/list.erb +1 -0
  44. data/lib/plugins/syckle/dnote.rb +35 -8
  45. data/meta/version +1 -1
  46. data/test/cases/notes_case.rb +20 -31
  47. metadata +44 -14
  48. data/MANIFEST +0 -33
  49. data/lib/dnote/command.rb +0 -134
  50. data/lib/dnote/site.rb +0 -140
  51. data/lib/dnote/templates/gnu.erb +0 -8
  52. data/lib/dnote/templates/markdown.erb +0 -17
@@ -0,0 +1,277 @@
1
+ module DNote
2
+
3
+ require 'dnote/notes'
4
+ require 'dnote/format'
5
+
6
+ # User session which is used by commandline interface.
7
+ #
8
+ # By making this a class it makes it easy for external
9
+ # libraries to use this library just as if they were
10
+ # calling the commandline, but without the need to shellout.
11
+ #
12
+ class Session
13
+
14
+ # Directory relative to this script. This is used
15
+ # to lookup the available format templates.
16
+ DIR = File.dirname(__FILE__)
17
+
18
+ # Default format.
19
+ DEFAULT_FORMAT = "text"
20
+
21
+ # Default title.
22
+ DEFAULT_TITLE = "Developer's Notes"
23
+
24
+ # Paths to include.
25
+ attr_accessor :paths
26
+
27
+ # Paths to exclude (match by pathname).
28
+ attr_accessor :exclude
29
+
30
+ # Paths to ignore (match by basename).
31
+ attr_accessor :ignore
32
+
33
+ # Labels to lookup.
34
+ # By default these are TODO, FIXME and OPTIMIZE.
35
+ attr_accessor :labels
36
+
37
+ # Selected labels can optionally do without the colon.
38
+ attr_accessor :colon
39
+
40
+ # Output format.
41
+ attr_accessor :format
42
+
43
+ # If custom format, specify template file.
44
+ attr_accessor :template
45
+
46
+ # Some format put a title at the top of the output.
47
+ # The default is "Developer's Notes".
48
+ attr_accessor :title
49
+
50
+ # Output to a file instead of STDOUT.
51
+ attr_accessor :output
52
+
53
+ # If output path given, don't actually write to disk.
54
+ attr_accessor :dryrun
55
+
56
+ private
57
+
58
+ # New Session.
59
+ def initialize(options={})
60
+ options ||= {}
61
+ initialize_defaults
62
+ options.each{ |k,v| __send__("#{k}=", v) }
63
+ yield(self) if block_given?
64
+ end
65
+
66
+ # Set default values for attributes.
67
+ def initialize_defaults
68
+ @paths = []
69
+ @labels = []
70
+ @exclude = []
71
+ @ignore = []
72
+ @format = DEFAULT_FORMAT
73
+ @title = DEFAULT_TITLE
74
+ @dryrun = false
75
+ end
76
+
77
+ public
78
+
79
+ # Set exclude list ensuring that the value is an array.
80
+ def exclude=(list)
81
+ @exclude = [list].flatten.compact
82
+ end
83
+
84
+ # Set ignore list ensuring that the value is an array.
85
+ def ignore=(list)
86
+ @ignore = [list].flatten.compact
87
+ end
88
+
89
+ # Run session.
90
+ def run
91
+ notes = Notes.new(files, :labels=>labels, :colon=>colon)
92
+ formatter = Format.new(notes) do |f|
93
+ f.format = format
94
+ f.template = template
95
+ f.title = title
96
+ f.output = output
97
+ end
98
+ formatter.render
99
+ end
100
+
101
+ # Collect path globs and remove exclusions.
102
+ # This method uses #paths, #exclude and #ignore to
103
+ # compile the list of files.
104
+ def files
105
+ list = [paths].flatten.compact
106
+ list = ['**/*.rb'] if list.empty?
107
+ list = glob(list)
108
+ list = list - glob(exclude)
109
+ list.reject do |path|
110
+ path.split('/').any?{ |part| ignore.any?{ |ig| File.fnmatch?(ig, part) } }
111
+ end
112
+ end
113
+
114
+ # Collect the file glob of each path given. If
115
+ # a path is a directory, inclue all content.
116
+ def glob(paths)
117
+ paths.map do |path|
118
+ if File.directory?(path)
119
+ Dir.glob(File.join(path, '**/*'))
120
+ else
121
+ Dir.glob(path)
122
+ end
123
+ end.flatten.uniq
124
+ end
125
+
126
+ # Set special labels.
127
+ #def labels=(labels)
128
+ # @labels = (
129
+ # case labels
130
+ # when String
131
+ # labels.split(/[:;,]/)
132
+ # else
133
+ # labels = [labels].flatten.compact.uniq.map{ |s| s.to_s }
134
+ # end
135
+ # )
136
+ #end
137
+
138
+ # Commandline interface.
139
+ def self.main(*argv)
140
+ require 'optparse'
141
+
142
+ session = Session.new
143
+
144
+ opts = OptionParser.new do |opt|
145
+
146
+ opt.banner = "DNote v#{DNote::VERSION}"
147
+
148
+ opt.separator(" ")
149
+ opt.separator("USAGE:\n dnote [OPTIONS] path1 [path2 ...]")
150
+
151
+ opt.separator(" ")
152
+ opt.separator("OUTPUT FORMAT: (choose one)")
153
+
154
+ #opt.on("--default", "Plain text format (default)") do
155
+ # session.format = 'label'
156
+ #end
157
+
158
+ #opt.on("--yaml", "YAML serialization format") do
159
+ # session.format = 'yaml'
160
+ #end
161
+
162
+ #opt.on("--json", "JSON serialization format") do
163
+ # session.format = 'json'
164
+ #end
165
+
166
+ #opt.on("--soap", "SOAP XML envelope format") do
167
+ # session.format = 'soap'
168
+ #end
169
+
170
+ #opt.on("--xoxo", "XOXO microformat format") do
171
+ # session.format = 'xoxo'
172
+ #end
173
+
174
+ #opt.on("--xml", "XML markup format") do
175
+ # session.format = 'xml'
176
+ #end
177
+
178
+ #opt.on("--html", "HTML markup format") do
179
+ # session.format = 'html'
180
+ #end
181
+
182
+ #opt.on("--rdoc", "rdoc comment format") do
183
+ # session.format = 'rdoc'
184
+ #end
185
+
186
+ #opt.on("--markdown", "markdown wiki format") do
187
+ # session.format = 'md'
188
+ #end
189
+
190
+ opt.on("--format", "-f NAME", "select a format [text]") do |format|
191
+ session.format = format
192
+ end
193
+
194
+ opt.on("--custom", "-c FILE", "use a custom ERB template") do |file|
195
+ session.format = 'custom'
196
+ session.template = file
197
+ end
198
+
199
+ opt.on("--file", "shortcut for text/file format") do
200
+ session.format = 'text/file'
201
+ end
202
+
203
+ opt.on("--list", "shortcut for text/list format") do
204
+ session.format = 'text/list'
205
+ end
206
+
207
+ opt.separator(" ")
208
+ opt.separator("OTHER OPTIONS:")
209
+
210
+ opt.on("--label", "-l LABEL", "labels to collect") do |lbl|
211
+ session.labels.concat(lbl.split(':'))
212
+ end
213
+
214
+ opt.on("--[no-]colon", "match labels with/without colon suffix") do |val|
215
+ session.colon = val
216
+ end
217
+
218
+ opt.on("--exclude", "-x PATH", "exclude file or directory") do |path|
219
+ session.exclude << path
220
+ end
221
+
222
+ opt.on("--ignore", "-i NAME", "ignore based on any part of the pathname") do |name|
223
+ session.ignore << name
224
+ end
225
+
226
+ opt.on("--title", "-t TITLE", "title to use in header") do |title|
227
+ session.title = title
228
+ end
229
+
230
+ opt.on("--output", "-o PATH", "name of file or directory") do |path|
231
+ session.output = path
232
+ end
233
+
234
+ opt.on("--dryrun", "-n", "do not actually write to disk") do
235
+ session.dryrun = true
236
+ end
237
+
238
+ opt.on("--debug", "debug mode") do
239
+ $DEBUG = true
240
+ $VERBOSE = true
241
+ end
242
+
243
+ opt.separator(" ")
244
+ opt.separator("COMMAND OPTIONS:")
245
+
246
+ opt.on_tail('--templates', "-T", "list available format templates") do
247
+ tdir = File.join(DIR, 'templates')
248
+ tfiles = Dir[File.join(tdir, '**/*.erb')]
249
+ tnames = tfiles.map{ |tname| tname.sub(tdir+'/', '').chomp('.erb') }
250
+ groups = tnames.group_by{ |tname| tname.split('/').first }
251
+ groups.sort.each do |(type, names)|
252
+ puts ("%-18s " * names.size) % names.sort
253
+ end
254
+ exit
255
+ end
256
+
257
+ opt.on_tail('--help', '-h', "show this help information") do
258
+ puts opt
259
+ exit
260
+ end
261
+ end
262
+
263
+ begin
264
+ opts.parse!(argv)
265
+ session.paths.replace(argv)
266
+ session.run
267
+ rescue => err
268
+ raise err if $DEBUG
269
+ puts err
270
+ exit 1
271
+ end
272
+ end
273
+
274
+ end
275
+
276
+ end
277
+
@@ -22,14 +22,14 @@
22
22
  <div class="main">
23
23
  <h1><%= title %></h1>
24
24
  <div class="notes">
25
- <% notes.each do |label, per_file| %>
25
+ <% notes.by_label_file.each do |label, per_file| %>
26
26
  <h2><%= label %></h2>
27
27
  <ol class="set <%= label.downcase %>">
28
28
  <% per_file.each do |file, line_notes| %>
29
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>
30
+ <% line_notes.sort!{ |a,b| a.line <=> b.line } %>
31
+ <% line_notes.each do |note| %>
32
+ <li class="note <%= label.downcase %>" ref="<%= note.line %>"><%= h note.text %> <sup><%= note.line %></sup></li>
33
33
  <% end %>
34
34
  </ol></li>
35
35
  <% end %>
@@ -0,0 +1,40 @@
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.by_file_label.each do |file, per_label| %>
26
+ <h2><a href="<%= file %>"><%= file %></a></h2>
27
+ <ol class="file">
28
+ <% per_label.each do |label, lnotes| %>
29
+ <li><h3><%= label %></h3><ol class="label">
30
+ <% lnotes.each do |note| %>
31
+ <li class="note <%= label.downcase %>" ref="<%= note.line %>"><%= h note.textline %> <sup><%= note.line %></sup></li>
32
+ <% end %>
33
+ </ol></li>
34
+ <% end %>
35
+ </ol>
36
+ <% end %>
37
+ </div>
38
+ </div>
39
+ </body>
40
+ </html>
@@ -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.by_label_file.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.line <=> b.line } %>
31
+ <% line_notes.each do |note| %>
32
+ <li class="note <%= label.downcase %>" ref="<%= note.line %>"><%= h note.text %> <sup><%= note.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,33 @@
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
+ <ol>
26
+ <% notes.each do |note| %>
27
+ <li class="note <%= note.label.downcase %>" ref="<%= note.line %>"><%= note.label %>: <%= h note.text %> <sup><%= note.file %>: <%= note.line %></sup></li>
28
+ <% end %>
29
+ </ol>
30
+ </div>
31
+ </div>
32
+ </body>
33
+ </html>
@@ -0,0 +1,8 @@
1
+ <%=
2
+ begin
3
+ require 'json'
4
+ rescue LoadError
5
+ require 'json_pure'
6
+ end
7
+ notes.map{ |n| n.to_h_raw }.to_json
8
+ %>
@@ -0,0 +1,8 @@
1
+ <%=
2
+ begin
3
+ require 'json'
4
+ rescue LoadError
5
+ require 'json_pure'
6
+ end
7
+ notes.by_file.to_json
8
+ %>
@@ -0,0 +1,8 @@
1
+ <%=
2
+ begin
3
+ require 'json'
4
+ rescue LoadError
5
+ require 'json_pure'
6
+ end
7
+ notes.by_label.to_json
8
+ %>
@@ -0,0 +1,8 @@
1
+ <%=
2
+ begin
3
+ require 'json'
4
+ rescue LoadError
5
+ require 'json_pure'
6
+ end
7
+ notes.map{ |n| n.to_h_raw }.to_json
8
+ %>