From 7e1100962ce8b95ef96f498d99ba89fa384d9543 Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Sat, 16 Mar 2013 14:44:49 +0100 Subject: [PATCH 1/3] Load in config from --config switch --- lib/jekyll.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/jekyll.rb b/lib/jekyll.rb index 493b8562..6e489264 100644 --- a/lib/jekyll.rb +++ b/lib/jekyll.rb @@ -129,8 +129,10 @@ module Jekyll # then, we need to know where to look for _config.yml source = override['source'] || Jekyll::DEFAULTS['source'] - # Get configuration from /_config.yml - config_file = File.join(source, '_config.yml') + # Get configuration from /_config.yml or / + config_file = override.delete('config') + config_file = File.join(source, "_config.yml") if config_file.to_s.empty? + begin config = YAML.safe_load_file(config_file) raise "Configuration file: (INVALID) #{config_file}" if !config.is_a?(Hash) From 9100967ebd0a4c4a767af50afd239572040e1816 Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Sat, 16 Mar 2013 14:46:26 +0100 Subject: [PATCH 2/3] Add unit tests for custom configuration. --- test/test_configuration.rb | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/test/test_configuration.rb b/test/test_configuration.rb index abaf6117..40b091de 100644 --- a/test/test_configuration.rb +++ b/test/test_configuration.rb @@ -25,4 +25,31 @@ class TestConfiguration < Test::Unit::TestCase assert_equal Jekyll::DEFAULTS, Jekyll.configuration({}) end end + context "loading config from external file" do + setup do + @paths = { + :default => File.join(Dir.pwd, '_config.yml'), + :other => File.join(Dir.pwd, '_config.live.yml'), + :empty => "" + } + end + + should "load default config if no config_file is set" do + mock(YAML).safe_load_file(@paths[:default]) { Hash.new } + mock($stdout).puts("Configuration file: #{@paths[:default]}") + assert_equal Jekyll::DEFAULTS, Jekyll.configuration({}) + end + + should "load different config if specified" do + mock(YAML).safe_load_file(@paths[:other]) { {"baseurl" => "http://wahoo.dev"} } + mock($stdout).puts("Configuration file: #{@paths[:other]}") + 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 + mock(YAML).safe_load_file(@paths[:default]) { Hash.new } + mock($stdout).puts("Configuration file: #{@paths[:default]}") + assert_equal Jekyll::DEFAULTS, Jekyll.configuration({ "config" => @paths[:empty] }) + end + end end From 7a57451962ea55716c4f3790e39cd350871a76d2 Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Sat, 16 Mar 2013 14:54:44 +0100 Subject: [PATCH 3/3] Add --config switch to build and serve commands. --- bin/jekyll | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bin/jekyll b/bin/jekyll index d135b952..1f3a9c8d 100755 --- a/bin/jekyll +++ b/bin/jekyll @@ -34,6 +34,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 '--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' @@ -52,6 +53,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 '--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'