Skip to content
This repository

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

Closed
wants to merge 3 commits into from

6 participants

Baptiste Fontaine Parker Moore Michael Schreifels Felipe Cypriano Kent R. Spillner maul.esel
Baptiste Fontaine

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.

Parker Moore
Owner
parkr commented May 24, 2012

You might consider writing some tests for this.

Baptiste Fontaine

Ok, I added tests in commit 39d32c3.

Michael Schreifels

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

Parker Moore
Owner
parkr commented June 28, 2012

@mojombo, thoughts?

Felipe Cypriano

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.

Kent R. Spillner

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.

Kent R. Spillner

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

Kent R. Spillner sl4mmy referenced this pull request January 02, 2013
Closed

Accept custom configs #725

maul.esel

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

Kent R. Spillner

+1 @maul-esel

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

Parker Moore parkr closed this March 17, 2013
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.
4  bin/jekyll
@@ -50,6 +50,10 @@ opts = OptionParser.new do |opts|
50 50
   end
51 51
   
52 52
 
  53
+  opts.on("--config [FILE]", "Configuration file to use") do |config_file|
  54
+      options['config_file'] = config_file
  55
+  end
  56
+
53 57
   opts.on("--[no-]safe", "Safe mode (default unsafe)") do |safe|
54 58
     options['safe'] = safe
55 59
   end
9  lib/jekyll.rb
@@ -60,6 +60,8 @@ module Jekyll
60 60
     'destination'  => File.join(Dir.pwd, '_site'),
61 61
     'plugins'      => File.join(Dir.pwd, '_plugins'),
62 62
 
  63
+    'config_file'  => '_config.yml',
  64
+
63 65
     'future'       => true,
64 66
     'lsi'          => false,
65 67
     'pygments'     => false,
@@ -119,8 +121,10 @@ def self.configuration(override)
119 121
     # then, we need to know where to look for _config.yml
120 122
     source = override['source'] || Jekyll::DEFAULTS['source']
121 123
 
122  
-    # Get configuration from <source>/_config.yml
123  
-    config_file = File.join(source, '_config.yml')
  124
+    config_filename = override['config_file'] || Jekyll::DEFAULTS['config_file']
  125
+
  126
+    # Get configuration from <source>/<config_filename>
  127
+    config_file = File.join(source, config_filename)
124 128
     begin
125 129
       config = YAML.load_file(config_file)
126 130
       raise "Invalid configuration - #{config_file}" if !config.is_a?(Hash)
@@ -129,6 +133,7 @@ def self.configuration(override)
129 133
       $stderr.puts "WARNING: Could not read configuration. " +
130 134
                    "Using defaults (and options)."
131 135
       $stderr.puts "\t" + err.to_s
  136
+      override.delete 'config_file' # bad config file, using default one
132 137
       config = {}
133 138
     end
134 139
 
40  test/test_configuration.rb
... ...
@@ -1,6 +1,7 @@
1 1
 require 'helper'
2 2
 
3 3
 class TestConfiguration < Test::Unit::TestCase
  4
+
4 5
   context "loading configuration" do
5 6
     setup do
6 7
       @path = File.join(Dir.pwd, '_config.yml')
@@ -26,4 +27,43 @@ class TestConfiguration < Test::Unit::TestCase
26 27
       assert_equal Jekyll::DEFAULTS, Jekyll.configuration({})
27 28
     end
28 29
   end
  30
+
  31
+  context "loading configuration from a non-existent given file" do
  32
+    setup do
  33
+      @path = File.join(Dir.pwd, 'bad.yml')
  34
+    end
  35
+
  36
+    should "fire warning if given file does not exist" do
  37
+      mock(YAML).load_file(@path) { raise "No such file or directory - #{@path}" }
  38
+      mock($stderr).puts("WARNING: Could not read configuration. Using defaults (and options).")
  39
+      mock($stderr).puts("\tNo such file or directory - #{@path}")
  40
+      assert_equal Jekyll::DEFAULTS, Jekyll.configuration({'config_file'=>'bad.yml'})
  41
+    end
  42
+  end
  43
+
  44
+  context "loading configuration from an existent given file" do
  45
+    setup do
  46
+      @path = File.join(Dir.pwd, '_myconfig.yml')
  47
+    end
  48
+
  49
+    should "load configuration as hash" do
  50
+      mock(YAML).load_file(@path) { { 'foo' => 'bar' } }
  51
+      mock($stdout).puts("Configuration from #{@path}")
  52
+      assert_equal Jekyll::DEFAULTS.merge({'config_file'=>'_myconfig.yml', 'foo'=>'bar'}),
  53
+                   Jekyll.configuration({'config_file'=>'_myconfig.yml'})
  54
+    end
  55
+  end
  56
+
  57
+  context "loading configuration from a bad given file" do
  58
+    setup do
  59
+      @path = File.join(Dir.pwd, '_array_config.yml')
  60
+    end
  61
+
  62
+    should "fire warning with bad config" do
  63
+      mock(YAML).load_file(@path) { ['foo', 'bar'] }
  64
+      mock($stderr).puts("WARNING: Could not read configuration. Using defaults (and options).")
  65
+      mock($stderr).puts("\tInvalid configuration - #{@path}")
  66
+      assert_equal Jekyll::DEFAULTS, Jekyll.configuration({'config_file'=>'_array_config.yml'})
  67
+    end
  68
+  end
29 69
 end
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.