Permalink
Browse files

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
  • Loading branch information...
1 parent 8446d6e commit df1efeff25e60c3b7852fe92f7109e4b2d5f1aa9 @voidfiles committed Apr 10, 2013
Showing with 23 additions and 7 deletions.
  1. +11 −5 lib/jekyll.rb
  2. +12 −2 test/test_configuration.rb
View
@@ -136,13 +136,19 @@ def self.configuration(override)
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"
View
@@ -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

0 comments on commit df1efef

Please sign in to comment.