Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Support for `--config [file]` option #561

Closed
wants to merge 3 commits into from

6 participants

@bfontaine

Hello there,
I'm making my blog with Jekyll, and I use two _config.yml files, one for local testing, and one for my website. I think it should be usefull if Jekyll has a --config [file] option which allow to give a different config filename.
For example: jekyll --config _local_config.yml.

@parkr
Owner

You might consider writing some tests for this.

@bfontaine

Ok, I added tests in commit 39d32c3.

@schreifels

For what it's worth, I could really use this!

@parkr
Owner

@mojombo, thoughts?

@fcy
fcy commented

I'd love this feature. My use case is that I want to have two configuration files for each of the languages I write in my blog.

@sl4mmy

I think this feature is a great idea.

Some sites hosted on GitHub Pages run Jekyll locally in unsafe mode in order to use plugins, and push static HTML up to GitHub Pages where Jekyll is run in safe mode. This feature would simplify setting up such workflows, especially on documentation projects with many contributors.

@sl4mmy

It looks like #725 is another attempt at adding this feature

@maul-esel

#863 has been merged. So I'd say this is done?

@sl4mmy sl4mmy referenced this pull request
Merged

Accept custom configuration #863

@sl4mmy

+1 @maul-esel

@parkr You can close this now since you merged #863.

@parkr parkr closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 51 additions and 2 deletions.
  1. +4 −0 bin/jekyll
  2. +7 −2 lib/jekyll.rb
  3. +40 −0 test/test_configuration.rb
View
4 bin/jekyll
@@ -50,6 +50,10 @@ opts = OptionParser.new do |opts|
end
+ opts.on("--config [FILE]", "Configuration file to use") do |config_file|
+ options['config_file'] = config_file
+ end
+
opts.on("--[no-]safe", "Safe mode (default unsafe)") do |safe|
options['safe'] = safe
end
View
9 lib/jekyll.rb
@@ -60,6 +60,8 @@ module Jekyll
'destination' => File.join(Dir.pwd, '_site'),
'plugins' => File.join(Dir.pwd, '_plugins'),
+ 'config_file' => '_config.yml',
+
'future' => true,
'lsi' => false,
'pygments' => false,
@@ -119,8 +121,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')
+ config_filename = override['config_file'] || Jekyll::DEFAULTS['config_file']
+
+ # Get configuration from <source>/<config_filename>
+ config_file = File.join(source, config_filename)
begin
config = YAML.load_file(config_file)
raise "Invalid configuration - #{config_file}" if !config.is_a?(Hash)
@@ -129,6 +133,7 @@ def self.configuration(override)
$stderr.puts "WARNING: Could not read configuration. " +
"Using defaults (and options)."
$stderr.puts "\t" + err.to_s
+ override.delete 'config_file' # bad config file, using default one
config = {}
end
View
40 test/test_configuration.rb
@@ -1,6 +1,7 @@
require 'helper'
class TestConfiguration < Test::Unit::TestCase
+
context "loading configuration" do
setup do
@path = File.join(Dir.pwd, '_config.yml')
@@ -26,4 +27,43 @@ class TestConfiguration < Test::Unit::TestCase
assert_equal Jekyll::DEFAULTS, Jekyll.configuration({})
end
end
+
+ context "loading configuration from a non-existent given file" do
+ setup do
+ @path = File.join(Dir.pwd, 'bad.yml')
+ end
+
+ should "fire warning if given file does not exist" do
+ mock(YAML).load_file(@path) { raise "No such file or directory - #{@path}" }
+ mock($stderr).puts("WARNING: Could not read configuration. Using defaults (and options).")
+ mock($stderr).puts("\tNo such file or directory - #{@path}")
+ assert_equal Jekyll::DEFAULTS, Jekyll.configuration({'config_file'=>'bad.yml'})
+ end
+ end
+
+ context "loading configuration from an existent given file" do
+ setup do
+ @path = File.join(Dir.pwd, '_myconfig.yml')
+ end
+
+ should "load configuration as hash" do
+ mock(YAML).load_file(@path) { { 'foo' => 'bar' } }
+ mock($stdout).puts("Configuration from #{@path}")
+ assert_equal Jekyll::DEFAULTS.merge({'config_file'=>'_myconfig.yml', 'foo'=>'bar'}),
+ Jekyll.configuration({'config_file'=>'_myconfig.yml'})
+ end
+ end
+
+ context "loading configuration from a bad given file" do
+ setup do
+ @path = File.join(Dir.pwd, '_array_config.yml')
+ end
+
+ should "fire warning with bad config" do
+ mock(YAML).load_file(@path) { ['foo', 'bar'] }
+ mock($stderr).puts("WARNING: Could not read configuration. Using defaults (and options).")
+ mock($stderr).puts("\tInvalid configuration - #{@path}")
+ assert_equal Jekyll::DEFAULTS, Jekyll.configuration({'config_file'=>'_array_config.yml'})
+ end
+ end
end
Something went wrong with that request. Please try again.