Skip to content

Commit 7b71ac4

Browse files
author
Matthew Loberg
committed
Add source and config options to page command
Update the page command to use the correct Jekyll source from config or command line option.
1 parent d7bb9af commit 7b71ac4

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed

lib/jekyll/commands/page.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ def self.options
1616
[
1717
['extension', '-x EXTENSION', '--extension EXTENSION', 'Specify the file extension'],
1818
['layout', '-l LAYOUT', '--layout LAYOUT', "Specify the page layout"],
19-
['force', '-f', '--force', 'Overwrite a page if it already exists']
19+
['force', '-f', '--force', 'Overwrite a page if it already exists'],
20+
['config', '--config CONFIG_FILE[,CONFIG_FILE2,...]', Array, 'Custom configuration file'],
21+
['source', '-s', '--source SOURCE', 'Custom source directory'],
2022
]
2123
end
2224

@@ -26,7 +28,7 @@ def self.process(args = [], options = {})
2628

2729
page = PageFileInfo.new params
2830

29-
Compose::FileCreator.new(page, params.force?).create!
31+
Compose::FileCreator.new(page, params.force?, params.source).create!
3032
end
3133

3234
class PageArgParser < Compose::ArgParser

spec/page_spec.rb

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,37 @@
6363
expect(File.read(path)).to match(/layout: page/)
6464
end
6565
end
66+
67+
context 'when a configuration file exists' do
68+
let(:config) { source_dir('_config.yml') }
69+
let(:path) { Pathname.new(source_dir).join('site', filename) }
70+
71+
before(:each) do
72+
File.open(config, 'w') do |f|
73+
f.write(%{
74+
source: site
75+
})
76+
end
77+
end
78+
79+
after(:each) do
80+
FileUtils.rm(config)
81+
end
82+
83+
it 'should use source directory set by config' do
84+
expect(path).not_to exist
85+
capture_stdout { described_class.process(args) }
86+
expect(path).to exist
87+
end
88+
end
89+
90+
context 'when source option is set' do
91+
let(:path) { Pathname.new(source_dir).join('site', filename) }
92+
93+
it 'should use source directory set by command line option' do
94+
expect(path).not_to exist
95+
capture_stdout { described_class.process(args, 'source' => 'site') }
96+
expect(path).to exist
97+
end
98+
end
6699
end

0 commit comments

Comments
 (0)