Merge pull request #863 from mojombo/accept-custom-config
Accept custom configuration
This commit is contained in:
commit
d091cfe3fc
|
@ -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'
|
||||
|
|
|
@ -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 <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)
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue