Skip to content

Commit d20fb11

Browse files
author
Matthew Loberg
committed
Add source and config options to unpublish command
Update Unpublish command to allow custom Jekyll source.
1 parent 9103444 commit d20fb11

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

lib/jekyll/commands/unpublish.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ def self.init_with_program(prog)
66
c.syntax 'unpublish POST_PATH'
77
c.description 'Moves a post back into the _drafts directory'
88

9+
c.option 'config', '--config CONFIG_FILE[,CONFIG_FILE2,...]', Array, 'Custom configuration file'
10+
c.option 'source', '-s', '--source SOURCE', 'Custom source directory'
11+
912
c.action do |args, options|
1013
process(args, options)
1114
end
@@ -18,7 +21,7 @@ def self.process(args = [], options = {})
1821

1922
movement = PostMovementInfo.new params
2023

21-
mover = PostMover.new movement
24+
mover = PostMover.new movement, params.source
2225
mover.move
2326
end
2427

spec/unpublish_spec.rb

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,42 @@
5757
}).to raise_error("There was no post found at '#{weird_path}'.")
5858
end
5959

60+
context 'when a configuration file exists' do
61+
let(:config) { source_dir('_config.yml') }
62+
let(:drafts_dir) { Pathname.new(source_dir('site', '_drafts')) }
63+
let(:posts_dir) { Pathname.new(source_dir('site', '_posts')) }
64+
65+
before(:each) do
66+
File.open(config, 'w') do |f|
67+
f.write(%{
68+
source: site
69+
})
70+
end
71+
end
72+
73+
after(:each) do
74+
FileUtils.rm(config)
75+
end
76+
77+
it 'should use source directory set by config' do
78+
expect(post_path).to exist
79+
expect(draft_path).not_to exist
80+
capture_stdout { described_class.process(args) }
81+
expect(post_path).not_to exist
82+
expect(draft_path).to exist
83+
end
84+
end
85+
86+
context 'when source option is set' do
87+
let(:drafts_dir) { Pathname.new(source_dir('site', '_drafts')) }
88+
let(:posts_dir) { Pathname.new(source_dir('site', '_posts')) }
89+
90+
it 'should use source directory set by command line option' do
91+
expect(post_path).to exist
92+
expect(draft_path).not_to exist
93+
capture_stdout { described_class.process(args, 'source' => 'site') }
94+
expect(post_path).not_to exist
95+
expect(draft_path).to exist
96+
end
97+
end
6098
end

0 commit comments

Comments
 (0)