Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Accept custom configuration #863

Merged
merged 3 commits into from

3 participants

This page is out of date. Refresh to see the latest.
Showing with 33 additions and 2 deletions.
  1. +2 −0  bin/jekyll
  2. +4 −2 lib/jekyll.rb
  3. +27 −0 test/test_configuration.rb
View
2  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'
View
6 lib/jekyll.rb
@@ -129,8 +129,10 @@ def self.configuration(override)
# then, we need to know where to look for _config.yml
source = override['source'] || Jekyll::DEFAULTS['source']
- # Get configuration from <source>/_config.yml
- config_file = File.join(source, '_config.yml')
+ # 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?
+
begin
config = YAML.safe_load_file(config_file)
raise "Configuration file: (INVALID) #{config_file}" if !config.is_a?(Hash)
View
27 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
Something went wrong with that request. Please try again.