mr_poole 0.2.2 → 0.3.0
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/CHANGES.md +5 -0
- data/README.md +2 -3
- data/lib/mr_poole/cli.rb +7 -2
- data/lib/mr_poole/commands.rb +9 -4
- data/lib/mr_poole/version.rb +1 -1
- data/lib/mr_poole.rb +3 -4
- data/spec/cli_spec.rb +19 -2
- data/spec/command_spec.rb +3 -3
- data/spec/config_spec.rb +3 -2
- metadata +1 -1
data/CHANGES.md
CHANGED
data/README.md
CHANGED
@@ -76,9 +76,8 @@ The life, universe, and everything.
|
|
76
76
|
```
|
77
77
|
|
78
78
|
A call to `poole publish` will generate a file named
|
79
|
-
`_posts/yyyy-mm-dd-test_draft.md` and delete the draft.
|
80
|
-
|
81
|
-
header with a date, and HH:MM, producing this file:
|
79
|
+
`_posts/yyyy-mm-dd-test_draft.md` and delete the draft. Also updates the date
|
80
|
+
filed in the header with a date, and HH:MM, producing this file:
|
82
81
|
|
83
82
|
```
|
84
83
|
---
|
data/lib/mr_poole/cli.rb
CHANGED
@@ -46,13 +46,18 @@ module MrPoole
|
|
46
46
|
def handle_publish
|
47
47
|
options = OpenStruct.new
|
48
48
|
opt_parser = OptionParser.new do |opts|
|
49
|
-
|
49
|
+
opts.on('-d', '--keep-draft', "Keep the draft post") do |d|
|
50
|
+
options.keep_draft = d
|
51
|
+
end
|
52
|
+
opts.on('-t', '--keep-timestamp', "Keep the existing timestamp") do |t|
|
53
|
+
options.keep_timestamp = t
|
54
|
+
end
|
50
55
|
end
|
51
56
|
opt_parser.parse! @params
|
52
57
|
|
53
58
|
path = @params.first
|
54
59
|
@helper.publish_usage unless path
|
55
|
-
fn = @commands.publish(path)
|
60
|
+
fn = @commands.publish(path, options)
|
56
61
|
puts fn
|
57
62
|
end
|
58
63
|
|
data/lib/mr_poole/commands.rb
CHANGED
@@ -66,7 +66,12 @@ module MrPoole
|
|
66
66
|
end
|
67
67
|
|
68
68
|
# Todo make this take a path instead?
|
69
|
-
|
69
|
+
#
|
70
|
+
# @param draftpath [String] path to the draft
|
71
|
+
# @option options :keep_draft [Boolean] if true, keep the draft file
|
72
|
+
# @option options :keep_timestamp [Boolean] if true, don't change the timestamp
|
73
|
+
def publish(draftpath, opts = {})
|
74
|
+
opts = @helper.ensure_open_struct(opts)
|
70
75
|
tail = File.basename(draftpath)
|
71
76
|
|
72
77
|
begin
|
@@ -82,13 +87,13 @@ module MrPoole
|
|
82
87
|
outfile = File.open(outpath, "w")
|
83
88
|
|
84
89
|
infile.each_line do |line|
|
85
|
-
|
86
|
-
outfile.write(
|
90
|
+
line.sub!(/^date:\s*$/, "date: #{date} #{time}\n") unless opts.keep_timestamp
|
91
|
+
outfile.write(line)
|
87
92
|
end
|
88
93
|
|
89
94
|
infile.close
|
90
95
|
outfile.close
|
91
|
-
FileUtils.rm(draftpath)
|
96
|
+
FileUtils.rm(draftpath) unless opts.keep_draft
|
92
97
|
|
93
98
|
outpath
|
94
99
|
end
|
data/lib/mr_poole/version.rb
CHANGED
data/lib/mr_poole.rb
CHANGED
@@ -1,9 +1,8 @@
|
|
1
1
|
require 'fileutils'
|
2
2
|
|
3
|
-
|
4
|
-
require
|
5
|
-
|
6
|
-
require 'mr_poole/config'
|
3
|
+
%w{ commands helper cli config }.each do |lib|
|
4
|
+
require File.expand_path("../mr_poole/#{lib}", __FILE__)
|
5
|
+
end
|
7
6
|
|
8
7
|
module MrPoole
|
9
8
|
end
|
data/spec/cli_spec.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
|
-
require '
|
2
|
-
require '
|
1
|
+
require 'rspec/autorun'
|
2
|
+
require File.expand_path('../spec_helper', __FILE__)
|
3
|
+
require File.expand_path('../../lib/mr_poole', __FILE__)
|
3
4
|
|
4
5
|
module MrPoole
|
5
6
|
describe CLI do
|
@@ -232,6 +233,22 @@ module MrPoole
|
|
232
233
|
end
|
233
234
|
end # context exit message
|
234
235
|
|
236
|
+
context 'keep draft post' do
|
237
|
+
it 'should keep draft post if called with --keep-draft' do
|
238
|
+
argv = ['publish', '--keep-draft', d_path]
|
239
|
+
poole_no_stdout(argv).call
|
240
|
+
expect(File.exists?(d_path)).to be(true)
|
241
|
+
end
|
242
|
+
end
|
243
|
+
|
244
|
+
context 'keep timestamp' do
|
245
|
+
it 'should keep the timestamp if called with --keep-timestamp' do
|
246
|
+
argv = ['publish', '--keep-timestamp', d_path]
|
247
|
+
new_file = poole_no_stdout(argv).call.chomp
|
248
|
+
content = File.open(new_file, "r").read
|
249
|
+
expect(content).to match(/^date:$/)
|
250
|
+
end
|
251
|
+
end
|
235
252
|
end
|
236
253
|
|
237
254
|
describe "action 'unpublish'" do
|
data/spec/command_spec.rb
CHANGED
data/spec/config_spec.rb
CHANGED