standup_md 0.0.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. checksums.yaml +7 -0
  2. data/.github/workflows/ruby.yml +24 -0
  3. data/.gitignore +1 -0
  4. data/Gemfile +10 -0
  5. data/Gemfile.lock +23 -0
  6. data/LICENSE +21 -0
  7. data/README.md +252 -0
  8. data/Rakefile +36 -0
  9. data/_config.yml +1 -0
  10. data/bin/standup +5 -0
  11. data/doc/README_md.html +290 -0
  12. data/doc/StandupMD/Cli.html +898 -0
  13. data/doc/StandupMD.html +1453 -0
  14. data/doc/TestHelper.html +282 -0
  15. data/doc/TestStandupMD.html +1938 -0
  16. data/doc/created.rid +8 -0
  17. data/doc/css/fonts.css +167 -0
  18. data/doc/css/rdoc.css +611 -0
  19. data/doc/fonts/Lato-Light.ttf +0 -0
  20. data/doc/fonts/Lato-LightItalic.ttf +0 -0
  21. data/doc/fonts/Lato-Regular.ttf +0 -0
  22. data/doc/fonts/Lato-RegularItalic.ttf +0 -0
  23. data/doc/fonts/SourceCodePro-Bold.ttf +0 -0
  24. data/doc/fonts/SourceCodePro-Regular.ttf +0 -0
  25. data/doc/images/add.png +0 -0
  26. data/doc/images/arrow_up.png +0 -0
  27. data/doc/images/brick.png +0 -0
  28. data/doc/images/brick_link.png +0 -0
  29. data/doc/images/bug.png +0 -0
  30. data/doc/images/bullet_black.png +0 -0
  31. data/doc/images/bullet_toggle_minus.png +0 -0
  32. data/doc/images/bullet_toggle_plus.png +0 -0
  33. data/doc/images/date.png +0 -0
  34. data/doc/images/delete.png +0 -0
  35. data/doc/images/find.png +0 -0
  36. data/doc/images/loadingAnimation.gif +0 -0
  37. data/doc/images/macFFBgHack.png +0 -0
  38. data/doc/images/package.png +0 -0
  39. data/doc/images/page_green.png +0 -0
  40. data/doc/images/page_white_text.png +0 -0
  41. data/doc/images/page_white_width.png +0 -0
  42. data/doc/images/plugin.png +0 -0
  43. data/doc/images/ruby.png +0 -0
  44. data/doc/images/tag_blue.png +0 -0
  45. data/doc/images/tag_green.png +0 -0
  46. data/doc/images/transparent.png +0 -0
  47. data/doc/images/wrench.png +0 -0
  48. data/doc/images/wrench_orange.png +0 -0
  49. data/doc/images/zoom.png +0 -0
  50. data/doc/index.html +286 -0
  51. data/doc/js/darkfish.js +84 -0
  52. data/doc/js/navigation.js +105 -0
  53. data/doc/js/navigation.js.gz +0 -0
  54. data/doc/js/search.js +110 -0
  55. data/doc/js/search_index.js +1 -0
  56. data/doc/js/search_index.js.gz +0 -0
  57. data/doc/js/searcher.js +229 -0
  58. data/doc/js/searcher.js.gz +0 -0
  59. data/doc/table_of_contents.html +551 -0
  60. data/lib/standup_md/cli.rb +301 -0
  61. data/lib/standup_md/version.rb +9 -0
  62. data/lib/standup_md.rb +530 -0
  63. data/standup_md.gemspec +36 -0
  64. metadata +108 -0
@@ -0,0 +1,301 @@
1
+ require 'json'
2
+ require 'yaml'
3
+ require 'optparse'
4
+ require_relative '../standup_md'
5
+
6
+ class StandupMD
7
+ ##
8
+ # Class for handing the command-line interface.
9
+ class CLI
10
+
11
+ ##
12
+ # The user's preference file.
13
+ PREFERENCE_FILE =
14
+ File.expand_path(File.join(ENV['HOME'], '.standup_md.yml')).freeze
15
+
16
+ ##
17
+ # Creates an instance of +StandupMD+ and runs what the user requested.
18
+ def self.execute(options = [])
19
+ exe = new(options)
20
+ exe.append_to_previous_entry_tasks if exe.should_append?
21
+
22
+ exe.print_current_entry if exe.print_current_entry?
23
+ exe.print_all_entries if exe.print_all_entries?
24
+ exe.write_file if exe.write?
25
+ exe.edit if exe.edit?
26
+ end
27
+
28
+ ##
29
+ # Arguments passed at runtime.
30
+ #
31
+ # @return [Array] ARGV
32
+ attr_reader :options
33
+
34
+ ##
35
+ # Preferences after reading config file and parsing ARGV.
36
+ #
37
+ # @return [Array] ARGV
38
+ attr_reader :preferences
39
+
40
+ ##
41
+ # Constructor. Sets defaults.
42
+ #
43
+ # @param [Array] options
44
+ def initialize(options)
45
+ @edit = true
46
+ @write = true
47
+ @append_previous = true
48
+ @print_current_entry = false
49
+ @json = false
50
+ @verbose = false
51
+ @print_all_entries = false
52
+ @options = options
53
+ @preferences = get_preferences
54
+ end
55
+
56
+ ##
57
+ # Sets up an instance of +StandupMD+ and passes all user preferences.
58
+ #
59
+ # @return [StandupMD]
60
+ def standup
61
+ @standup ||= ::StandupMD.new do |s|
62
+ echo 'Runtime options:'
63
+ preferences.each do |k, v|
64
+ echo " #{k} = #{v}"
65
+ s.send("#{k}=", v)
66
+ end
67
+ end.load
68
+ end
69
+
70
+ ##
71
+ # Tries to determine the editor, first by checking if the user has one set
72
+ # in their preferences. If not, the +VISUAL+ and +EDITOR+ environmental
73
+ # variables are checked. If none of the above are set, defaults to +vim+.
74
+ #
75
+ # @return [String] The editor
76
+ def editor
77
+ @editor ||=
78
+ if preferences.key?('editor')
79
+ echo "Editor set to [#{preferences.key('editor')}] via preferences"
80
+ preferences.delete('editor')
81
+ elsif ENV['VISUAL']
82
+ echo "Editor set to [#{ENV['VISUAL']}] (ENV['VISUAL'])"
83
+ ENV['VISUAL']
84
+ elsif ENV['EDITOR']
85
+ echo "Editor set to [#{ENV['EDITOR']}] (ENV['EDITOR'])"
86
+ ENV['EDITOR']
87
+ else
88
+ echo "Editor set to [vim] (default)"
89
+ 'vim'
90
+ end
91
+ end
92
+
93
+ ##
94
+ # Prints all entries to the command line.
95
+ #
96
+ # @return [nil]
97
+ def print_all_entries
98
+ echo 'Display all entries'
99
+ unless json?
100
+ standup.all_entries.keys.reverse.each do |head|
101
+ print_entry(head, standup.all_entries[head])
102
+ end
103
+ return
104
+ end
105
+ echo ' ...as json'
106
+ puts standup.all_entries.to_json
107
+ end
108
+
109
+ ##
110
+ # Prints the current entry to the command line.
111
+ #
112
+ # @return [nil]
113
+ def print_current_entry
114
+ echo 'Print current entry'
115
+ unless json?
116
+ print_entry(standup.header, standup.current_entry)
117
+ return
118
+ end
119
+ echo ' ...as json'
120
+ entry = {standup.header => standup.current_entry}.to_json
121
+ puts entry
122
+ end
123
+
124
+ ##
125
+ # Appends entries passed at runtime to existing previous entries.
126
+ #
127
+ # @return [Hash]
128
+ def append_to_previous_entry_tasks
129
+ echo 'Appending previous entry tasks'
130
+ additions = preferences.delete('previous_entry_tasks')
131
+ standup.previous_entry_tasks.concat(additions)
132
+ end
133
+
134
+ ##
135
+ # Opens the file in an editor. Abandons the script.
136
+ def edit
137
+ echo " Opening file in #{editor}"
138
+ exec("#{editor} #{standup.file}")
139
+ end
140
+
141
+ ##
142
+ # Writes entries to the file.
143
+ #
144
+ # @return [Boolean] true if file was written
145
+ def write_file
146
+ echo ' Writing file'
147
+ standup.write
148
+ end
149
+
150
+ ##
151
+ # Should current entry be printed? If true, disables editing.
152
+ #
153
+ # @return [Boolean] Default is false
154
+ def print_current_entry?
155
+ @print_current_entry
156
+ end
157
+
158
+ ##
159
+ # If printing an entry, should it be printed as json?
160
+ #
161
+ # @return [Boolean] Default is false
162
+ def json?
163
+ @json
164
+ end
165
+
166
+ ##
167
+ # Should all entries be printed? If true, disables editing.
168
+ #
169
+ # @return [Boolean] Default is false
170
+ def print_all_entries?
171
+ @print_all_entries
172
+ end
173
+
174
+ ##
175
+ # Should debug info be printed?
176
+ #
177
+ # @return [Boolean] Default is false
178
+ def verbose?
179
+ @verbose
180
+ end
181
+
182
+ ##
183
+ # Should the file be written?
184
+ #
185
+ # @return [Boolean] Default is true
186
+ def write?
187
+ @write
188
+ end
189
+
190
+ ##
191
+ # Should the standup file be opened in the editor?
192
+ #
193
+ # @return [Boolean] Default is true
194
+ def edit?
195
+ @edit
196
+ end
197
+
198
+ ##
199
+ # Should `previous_entry_tasks` be appended? If false,
200
+ # +previous_entry_tasks+ will be overwritten.
201
+ #
202
+ # @return [Boolean] Default is true
203
+ def append_previous?
204
+ @append_previous
205
+ end
206
+
207
+ ##
208
+ # Did the user pass +previous_entry_tasks+, and should we append?
209
+ #
210
+ # @return [Boolean]
211
+ def should_append?
212
+ preferences.key?('previous_entry_tasks') && append_previous?
213
+ end
214
+
215
+ ##
216
+ # Prints output if +verbose+ is true.
217
+ #
218
+ # @return [nil]
219
+ def echo(msg)
220
+ puts msg if verbose?
221
+ end
222
+
223
+ private
224
+
225
+ ##
226
+ # Prints entries to the command line as markdown.
227
+ def print_entry(head, s_heads) # :nodoc:
228
+ puts '#' * standup.header_depth + ' ' + head
229
+ s_heads.each do |s_head, tasks|
230
+ puts '#' * standup.sub_header_depth + ' ' + s_head
231
+ tasks.each { |task| puts standup.bullet_character + ' ' + task }
232
+ end
233
+ puts
234
+ end
235
+
236
+ ##
237
+ # Parses options passed at runtime and concatenates them with the options in
238
+ # the user's preferences file. Reveal source to see options.
239
+ #
240
+ # @return [Hash]
241
+ def get_preferences # :nodoc:
242
+ prefs = {}
243
+
244
+ OptionParser.new do |opts|
245
+ opts.banner = 'The Standup Doctor'
246
+ opts.version = ::StandupMD::VERSION
247
+ opts.on('--current-entry-tasks=ARRAY', Array, "List of current entry's tasks") do |v|
248
+ prefs['current_entry_tasks'] = v
249
+ end
250
+ opts.on('--previous-entry-tasks=ARRAY', Array, "List of precious entry's tasks") do |v|
251
+ prefs['previous_entry_tasks'] = v
252
+ end
253
+ opts.on('--impediments=ARRAY', Array, 'List of impediments for current entry') do |v|
254
+ prefs['impediments'] = v
255
+ end
256
+ opts.on('--notes=ARRAY', Array, 'List of notes for current entry') do |v|
257
+ prefs['notes'] = v
258
+ end
259
+ opts.on('--sub-header-order=ARRAY', Array, 'The order of the sub-headers when writing the file') do |v|
260
+ prefs['sub_header_order'] = v
261
+ end
262
+ opts.on('--[no-]append-previous', 'Append previous tasks? Default is true') do |v|
263
+ @append_previous = v
264
+ end
265
+ opts.on('-f', '--file-name-format=STRING', 'Date-formattable string to use for standup file name') do |v|
266
+ prefs['file_name_format'] = v
267
+ end
268
+ opts.on('-e', '--editor=EDITOR', 'Editor to use for opening standup files') do |v|
269
+ prefs['editor'] = v
270
+ end
271
+ opts.on('-d', '--directory=DIRECTORY', 'The directories where standup files are located') do |v|
272
+ prefs['directory'] = v
273
+ end
274
+ opts.on('--[no-]write', "Write current entry if it doesn't exist. Default is true") do |v|
275
+ @write = v
276
+ end
277
+ opts.on('--[no-]edit', 'Open the file in the editor. Default is true') do |v|
278
+ @edit = v
279
+ end
280
+ opts.on('-j', '--[no-]json', 'Print output as formatted json. Default is false.') do |v|
281
+ @json = v
282
+ end
283
+ opts.on('-v', '--[no-]verbose', 'Verbose output. Default is false.') do |v|
284
+ @verbose = v
285
+ end
286
+ opts.on('-c', '--current', 'Print current entry. Disables editing and writing') do |v|
287
+ @print_current_entry = v
288
+ @edit = false
289
+ @write = false
290
+ end
291
+ opts.on('-a', '--all', 'Print all previous entries. Disables editing and writing') do |v|
292
+ @print_all_entries = v
293
+ @edit = false
294
+ @write = false
295
+ end
296
+ end.parse!(options)
297
+
298
+ (File.file?(PREFERENCE_FILE) ? YAML.load_file(PREFERENCE_FILE) : {}).merge(prefs)
299
+ end
300
+ end
301
+ end
@@ -0,0 +1,9 @@
1
+ class StandupMD
2
+ ##
3
+ # The gem verision
4
+ #
5
+ # @example
6
+ # StandupMD::VERSION
7
+ # # => '0.9.0'
8
+ VERSION = '0.0.10'
9
+ end