mr_poole 0.2.2 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # Changelog
2
2
 
3
+ ### v0.3.0 (2013-09-22)
4
+
5
+ - Added --keep-draft and --keep-timestamp flags to publish command (thanks,
6
+ Steven Karas!)
7
+
3
8
  ### v0.2.2 (2013-09-22)
4
9
 
5
10
  - Bugfix so that poole works on ruby 1.9.3
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. (TODO: add flags for
80
- no-delete drafts, and no-update timestamp.) Also updates the date filed in the
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
- # eventually there will be options...not yet
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
 
@@ -66,7 +66,12 @@ module MrPoole
66
66
  end
67
67
 
68
68
  # Todo make this take a path instead?
69
- def publish(draftpath)
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
- l = line.sub(/^date:\s*$/, "date: #{date} #{time}\n")
86
- outfile.write(l)
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
@@ -1,3 +1,3 @@
1
1
  module MrPoole
2
- VERSION = '0.2.2'
2
+ VERSION = '0.3.0'
3
3
  end
data/lib/mr_poole.rb CHANGED
@@ -1,9 +1,8 @@
1
1
  require 'fileutils'
2
2
 
3
- require 'mr_poole/commands'
4
- require 'mr_poole/helper'
5
- require 'mr_poole/cli'
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 'spec_helper'
2
- require 'mr_poole'
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
@@ -1,7 +1,7 @@
1
1
  # encoding: UTF-8
2
-
3
- require 'spec_helper'
4
- require 'mr_poole'
2
+ require 'rspec/autorun'
3
+ require File.expand_path('../spec_helper', __FILE__)
4
+ require File.expand_path('../../lib/mr_poole', __FILE__)
5
5
 
6
6
  module MrPoole
7
7
  describe Commands do
data/spec/config_spec.rb CHANGED
@@ -1,5 +1,6 @@
1
- require 'spec_helper'
2
- require 'mr_poole'
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
  def write_config_file
5
6
  f = File.open('_config.yml', 'w')
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mr_poole
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: