standup_md 0.1.3 → 0.3.2

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.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/Gemfile.lock +7 -1
  4. data/README.md +182 -98
  5. data/Rakefile +11 -28
  6. data/bin/standup +1 -1
  7. data/doc/README_md.html +183 -78
  8. data/doc/StandupMD.html +83 -1248
  9. data/doc/StandupMD/Cli.html +124 -474
  10. data/doc/StandupMD/Cli/Helpers.html +167 -0
  11. data/doc/StandupMD/Config.html +230 -0
  12. data/doc/StandupMD/Config/Cli.html +355 -0
  13. data/doc/StandupMD/Config/Entry.html +284 -0
  14. data/doc/StandupMD/Config/EntryList.html +197 -0
  15. data/doc/StandupMD/Config/File.html +609 -0
  16. data/doc/StandupMD/Entry.html +478 -0
  17. data/doc/StandupMD/EntryList.html +759 -0
  18. data/doc/StandupMD/File.html +614 -0
  19. data/doc/created.rid +15 -8
  20. data/doc/index.html +189 -79
  21. data/doc/js/navigation.js.gz +0 -0
  22. data/doc/js/search_index.js +1 -1
  23. data/doc/js/search_index.js.gz +0 -0
  24. data/doc/js/searcher.js.gz +0 -0
  25. data/doc/table_of_contents.html +153 -263
  26. data/lib/standup_md.rb +29 -508
  27. data/lib/standup_md/cli.rb +63 -242
  28. data/lib/standup_md/cli/helpers.rb +165 -0
  29. data/lib/standup_md/config.rb +45 -0
  30. data/lib/standup_md/config/cli.rb +106 -0
  31. data/lib/standup_md/config/entry.rb +61 -0
  32. data/lib/standup_md/config/entry_list.rb +26 -0
  33. data/lib/standup_md/config/file.rb +199 -0
  34. data/lib/standup_md/entry.rb +121 -0
  35. data/lib/standup_md/entry_list.rb +166 -0
  36. data/lib/standup_md/file.rb +183 -0
  37. data/lib/standup_md/file/helpers.rb +62 -0
  38. data/lib/standup_md/version.rb +5 -5
  39. data/standup_md.gemspec +1 -0
  40. metadata +35 -5
  41. data/doc/TestCli.html +0 -792
  42. data/doc/TestHelper.html +0 -282
  43. data/doc/TestStandupMD.html +0 -1354
@@ -1,30 +1,50 @@
1
- require 'json'
2
- require 'yaml'
1
+ # frozen_string_literal: true
2
+
3
3
  require 'optparse'
4
- require_relative '../standup_md'
4
+ require_relative 'cli/helpers'
5
+
6
+ module StandupMD
5
7
 
6
- class StandupMD
7
8
  ##
8
9
  # Class for handing the command-line interface.
9
10
  class Cli
11
+ include Helpers
12
+
13
+ ##
14
+ # Access to the class's configuration.
15
+ #
16
+ # @return [StandupMD::Config::Cli]
17
+ def self.config
18
+ @config ||= StandupMD.config.cli
19
+ end
10
20
 
11
21
  ##
12
- # The user's preference file.
13
- PREFERENCE_FILE =
14
- File.expand_path(File.join(ENV['HOME'], '.standup_md.yml')).freeze
22
+ # Prints output if +verbose+ is true.
23
+ #
24
+ # @return [nil]
25
+ def self.echo(msg)
26
+ puts msg if config.verbose
27
+ end
15
28
 
16
29
  ##
17
30
  # Creates an instance of +StandupMD+ and runs what the user requested.
18
31
  def self.execute(options = [])
19
32
  exe = new(options)
20
- exe.append_to_previous_entry_tasks if exe.should_append?
21
33
 
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?
34
+ exe.write_file if config.write
35
+ if config.print
36
+ exe.print(exe.entry)
37
+ elsif config.edit
38
+ exe.edit
39
+ end
26
40
  end
27
41
 
42
+ ##
43
+ # The entry searched for, usually today.
44
+ #
45
+ # @return [StandupMD::Entry]
46
+ attr_reader :entry
47
+
28
48
  ##
29
49
  # Arguments passed at runtime.
30
50
  #
@@ -32,110 +52,54 @@ class StandupMD
32
52
  attr_reader :options
33
53
 
34
54
  ##
35
- # Preferences after reading config file and parsing ARGV.
55
+ # The file loaded.
36
56
  #
37
- # @return [Array]
38
- attr_reader :preferences
57
+ # @return [StandupMD::File]
58
+ attr_reader :file
39
59
 
40
60
  ##
41
61
  # Constructor. Sets defaults.
42
62
  #
43
63
  # @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
64
+ def initialize(options = [], load_config = true)
65
+ @config = self.class.config
66
+ @preference_file_loaded = false
67
+ @options = options
68
+ load_preferences if load_config
69
+ set_preferences(options)
70
+ @file = StandupMD::File.find_by_date(@config.date)
71
+ @file.load
72
+ @entry = set_entry(@file)
54
73
  end
55
74
 
56
75
  ##
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.
76
+ # Load the preference file.
111
77
  #
112
78
  # @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
79
+ def load_preferences
80
+ if ::File.exist?(@config.preference_file)
81
+ ::StandupMD.load_config_file(@config.preference_file)
82
+ @preference_file_loaded = true
83
+ else
84
+ echo "Preference file #{@config.preference_file} does not exist."
118
85
  end
119
- echo ' ...as json'
120
- entry = {standup.header => standup.current_entry}.to_json
121
- puts entry
122
86
  end
123
87
 
124
88
  ##
125
- # Appends entries passed at runtime to existing previous entries.
89
+ # Has the preference file been loaded?
126
90
  #
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)
91
+ # @return boolean
92
+ def preference_file_loaded?
93
+ @preference_file_loaded
132
94
  end
133
95
 
134
96
  ##
135
97
  # Opens the file in an editor. Abandons the script.
98
+ #
99
+ # @return [nil]
136
100
  def edit
137
- echo " Opening file in #{editor}"
138
- exec("#{editor} #{standup.file}")
101
+ echo "Opening file in #{@config.editor}"
102
+ exec("#{@config.editor} #{file.name}")
139
103
  end
140
104
 
141
105
  ##
@@ -143,159 +107,16 @@ class StandupMD
143
107
  #
144
108
  # @return [Boolean] true if file was written
145
109
  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
110
+ echo "Writing file #{file.name}"
111
+ file.write
172
112
  end
173
113
 
174
114
  ##
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.
115
+ # Quick access to Cli.echo.
217
116
  #
218
117
  # @return [nil]
219
118
  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)
119
+ self.class.echo(msg)
299
120
  end
300
121
  end
301
122
  end
@@ -0,0 +1,165 @@
1
+ # frozen_string_literal: true
2
+
3
+ module StandupMD
4
+ class Cli
5
+
6
+ ##
7
+ # Module responsible for reading and writing standup files.
8
+ module Helpers
9
+
10
+ ##
11
+ # Print an entry to the command line.
12
+ #
13
+ # @param [StandupMD::Entry] entry
14
+ #
15
+ # @return [nil]
16
+ def print(entry)
17
+ if entry.nil?
18
+ puts "No record found for #{StandupMD.config.cli.date}"
19
+ return
20
+ end
21
+ puts '#' * StandupMD.config.file.header_depth + ' ' + entry.date.strftime(StandupMD.config.file.header_date_format)
22
+ StandupMD.config.file.sub_header_order.each do |attr|
23
+ tasks = entry.send(attr)
24
+ next if !tasks || tasks.empty?
25
+ puts '#' * StandupMD.config.file.sub_header_depth + ' ' + StandupMD.config.file.send("#{attr}_header").capitalize
26
+ tasks.each { |task| puts StandupMD.config.file.bullet_character + ' ' + task }
27
+ end
28
+ puts
29
+ end
30
+
31
+ private
32
+
33
+ ##
34
+ # Parses options passed at runtime and concatenates them with the options
35
+ # in the user's preferences file. Reveal source to see options.
36
+ #
37
+ # @return [Hash]
38
+ def set_preferences(options)
39
+ OptionParser.new do |opts|
40
+ opts.banner = 'The Standup Doctor'
41
+ opts.version = "[StandupMD] #{::StandupMD::VERSION}"
42
+ opts.on(
43
+ '--current ARRAY', Array,
44
+ "List of current entry's tasks"
45
+ ) { |v| StandupMD.config.entry.current = v }
46
+
47
+ opts.on(
48
+ '--previous ARRAY', Array,
49
+ "List of precious entry's tasks"
50
+ ) { |v| StandupMD.config.entry.previous = v }
51
+
52
+ opts.on(
53
+ '--impediments ARRAY', Array,
54
+ 'List of impediments for current entry'
55
+ ) { |v| StandupMD.config.entry.impediments = v }
56
+
57
+ opts.on(
58
+ '--notes ARRAY', Array,
59
+ 'List of notes for current entry'
60
+ ) { |v| StandupMD.config.entry.notes = v }
61
+
62
+ opts.on(
63
+ '--sub-header-order ARRAY', Array,
64
+ 'The order of the sub-headers when writing the file'
65
+ ) { |v| StandupMD.config.file.sub_header_order = v }
66
+
67
+ opts.on(
68
+ '-f', '--file-name-format STRING',
69
+ 'Date-formattable string to use for standup file name'
70
+ ) { |v| StandupMD.config.file.name_format = v }
71
+
72
+ opts.on(
73
+ '-E', '--editor EDITOR',
74
+ 'Editor to use for opening standup files'
75
+ ) { |v| StandupMD.config.cli.editor = v }
76
+
77
+ opts.on(
78
+ '-d', '--directory DIRECTORY',
79
+ 'The directories where standup files are located'
80
+ ) { |v| StandupMD.config.file.directory = v }
81
+
82
+ opts.on(
83
+ '-w', '--[no-]write',
84
+ "Write current entry if it doesn't exist. Default is true"
85
+ ) { |v| StandupMD.config.cli.write = v }
86
+
87
+ opts.on(
88
+ '-a', '--[no-]auto-fill-previous',
89
+ "Auto-generate 'previous' tasks for new entries. Default is true"
90
+ ) { |v| StandupMD.config.cli.auto_fill_previous = v }
91
+
92
+ opts.on(
93
+ '-e', '--[no-]edit',
94
+ 'Open the file in the editor. Default is true'
95
+ ) { |v| StandupMD.config.cli.edit = v }
96
+
97
+ opts.on(
98
+ '-v', '--[no-]verbose',
99
+ 'Verbose output. Default is false.'
100
+ ) { |v| StandupMD.config.cli.verbose = v }
101
+
102
+ opts.on(
103
+ '-p', '--print [DATE]',
104
+ 'Print current entry.',
105
+ 'If DATE is passed, will print entry for DATE, if it exists.',
106
+ 'DATE must be in the same format as file-name-format',
107
+ ) do |v|
108
+ StandupMD.config.cli.print = true
109
+ StandupMD.config.cli.date =
110
+ v.nil? ? Date.today : Date.strptime(v, StandupMD.config.file.header_date_format)
111
+ end
112
+ end.parse!(options)
113
+ end
114
+
115
+ ##
116
+ # The entry for today.
117
+ #
118
+ # @return [StandupMD::Entry]
119
+ def set_entry(file)
120
+ entry = file.entries.find(StandupMD.config.cli.date)
121
+ if entry.nil? && StandupMD.config.cli.date == Date.today
122
+ previous_entry = set_previous_entry(file)
123
+ entry = StandupMD::Entry.new(
124
+ StandupMD.config.cli.date,
125
+ StandupMD.config.entry.current,
126
+ previous_entry,
127
+ StandupMD.config.entry.impediments,
128
+ StandupMD.config.entry.notes
129
+ )
130
+ file.entries << entry
131
+ end
132
+ entry
133
+ end
134
+
135
+ ##
136
+ # The "previous" entries.
137
+ #
138
+ # @return [Array]
139
+ def set_previous_entry(file)
140
+ return [] unless StandupMD.config.cli.auto_fill_previous
141
+ return prev_entry(prev_file.load.entries) if file.new? && prev_file
142
+ prev_entry(file.entries)
143
+ end
144
+
145
+ ##
146
+ # The previous entry.
147
+ #
148
+ # @param [StandupMD::EntryList] entries
149
+ #
150
+ # @return [StandupMD::Entry]
151
+ def prev_entry(entries)
152
+ return [] if entries.empty?
153
+ entries.last.current
154
+ end
155
+
156
+ ##
157
+ # The previous month's file.
158
+ #
159
+ # @return [StandupMD::File]
160
+ def prev_file
161
+ StandupMD::File.find_by_date(Date.today.prev_month)
162
+ end
163
+ end
164
+ end
165
+ end