Merge pull request #945 from voidfiles/master
Accept multiple config files from command line
This commit is contained in:
commit
17c1e23203
|
@ -44,7 +44,7 @@ command :build do |c|
|
|||
c.syntax = 'jekyll build [options]'
|
||||
c.description = 'Build your site'
|
||||
|
||||
c.option '--config [CONFIG_FILE]', 'Custom configuration file'
|
||||
c.option '--config [CONFIG_FILE]', Array, 'Custom configuration file'
|
||||
c.option '--future', 'Publishes posts with a future date'
|
||||
c.option '--limit_posts MAX_POSTS', 'Limits the number of posts to parse and publish'
|
||||
c.option '-w', '--watch', 'Watch for changes and rebuild'
|
||||
|
@ -63,7 +63,7 @@ command :serve do |c|
|
|||
c.syntax = 'jekyll serve [options]'
|
||||
c.description = 'Serve your site locally'
|
||||
|
||||
c.option '--config [CONFIG_FILE]', 'Custom configuration file'
|
||||
c.option '--config [CONFIG_FILE]', Array,'Custom configuration file'
|
||||
c.option '--future', 'Publishes posts with a future date'
|
||||
c.option '--limit_posts MAX_POSTS', 'Limits the number of posts to parse and publish'
|
||||
c.option '-w', '--watch', 'Watch for changes and rebuild'
|
||||
|
|
|
@ -136,13 +136,20 @@ module Jekyll
|
|||
source = override['source'] || Jekyll::DEFAULTS['source']
|
||||
|
||||
# Get configuration from <source>/_config.yml or <source>/<config_file>
|
||||
config_file = override.delete('config')
|
||||
config_file = File.join(source, "_config.yml") if config_file.to_s.empty?
|
||||
config_files = override.delete('config')
|
||||
config_files = File.join(source, "_config.yml") if config_files.to_s.empty?
|
||||
unless config_files.is_a? Array
|
||||
config_files = [config_files]
|
||||
end
|
||||
|
||||
begin
|
||||
config = YAML.safe_load_file(config_file)
|
||||
raise "Configuration file: (INVALID) #{config_file}" if !config.is_a?(Hash)
|
||||
$stdout.puts "Configuration file: #{config_file}"
|
||||
config = {}
|
||||
config_files.each do |config_file|
|
||||
next_config = YAML.safe_load_file(config_file)
|
||||
raise "Configuration file: (INVALID) #{config_file}" if !next_config.is_a?(Hash)
|
||||
$stdout.puts "Configuration file: #{config_file}"
|
||||
config = config.deep_merge(next_config)
|
||||
end
|
||||
rescue SystemCallError
|
||||
# Errno:ENOENT = file not found
|
||||
$stderr.puts "Configuration file: none"
|
||||
|
|
|
@ -51,5 +51,21 @@ class TestConfiguration < Test::Unit::TestCase
|
|||
mock($stdout).puts("Configuration file: #{@paths[:default]}")
|
||||
assert_equal Jekyll::DEFAULTS, Jekyll.configuration({ "config" => @paths[:empty] })
|
||||
end
|
||||
|
||||
should "load multiple config files" do
|
||||
mock(YAML).safe_load_file(@paths[:default]) { Hash.new }
|
||||
mock(YAML).safe_load_file(@paths[:other]) { Hash.new }
|
||||
mock($stdout).puts("Configuration file: #{@paths[:default]}")
|
||||
mock($stdout).puts("Configuration file: #{@paths[:other]}")
|
||||
assert_equal Jekyll::DEFAULTS, Jekyll.configuration({ "config" => [@paths[:default], @paths[:other]] })
|
||||
end
|
||||
|
||||
should "load multiple config files and last config should win" do
|
||||
mock(YAML).safe_load_file(@paths[:default]) { {"baseurl" => "http://example.dev"} }
|
||||
mock(YAML).safe_load_file(@paths[:other]) { {"baseurl" => "http://wahoo.dev"} }
|
||||
mock($stdout).puts("Configuration file: #{@paths[:default]}")
|
||||
mock($stdout).puts("Configuration file: #{@paths[:other]}")
|
||||
assert_equal Jekyll::DEFAULTS.deep_merge({ "baseurl" => "http://wahoo.dev" }), Jekyll.configuration({ "config" => [@paths[:default], @paths[:other]] })
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue