Accept multiple config files from command line
Parse config as if it can contain multiple references to config files. This allows you to pass in multiple config files from the command line Helps with issues #514 and #703
This commit is contained in:
parent
8446d6e8ad
commit
df1efeff25
|
@ -136,13 +136,19 @@ 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?
|
||||
# If config is a list of space separate config files
|
||||
config_files = config_files.split(' ')
|
||||
|
||||
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"
|
||||
|
|
|
@ -46,10 +46,20 @@ class TestConfiguration < Test::Unit::TestCase
|
|||
assert_equal Jekyll::DEFAULTS.deep_merge({ "baseurl" => "http://wahoo.dev" }), Jekyll.configuration({ "config" => @paths[:other] })
|
||||
end
|
||||
|
||||
should "load default config if path passed is empty" do
|
||||
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]}")
|
||||
assert_equal Jekyll::DEFAULTS, Jekyll.configuration({ "config" => @paths[:empty] })
|
||||
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