Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Accept multiple config files from command line #945

Merged
merged 3 commits into from

5 participants

@voidfiles

Parse config as if it can contain multiple references to config files.
This allows you to pass in multiple config files from the command line

Helps with issues #514 and #703

@voidfiles voidfiles Accept multiple config files from command line
Parse config as if it can contain multiple references to config files.
This allows you to pass in multiple config files from the command line

Helps with issues #514 and #703
df1efef
lib/jekyll.rb
@@ -136,13 +136,19 @@ def self.configuration(override)
source = override['source'] || Jekyll::DEFAULTS['source']
# 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?
+ config_files = override.delete('config')
+ config_files = File.join(source, "_config.yml") if config_files.to_s.empty?
+ # If config is a list of space separate config files
+ config_files = config_files.split(' ')
@parkr Owner
parkr added a note

I'm worried that this is no good in case someone has a space in their file path

@parkr Owner
parkr added a note

Look into commander accepting an Array instead of String like it does right now in bin/jekyll

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@voidfiles

I ran the tests in ruby 1.8.7 and it passes for me I am not sure how I can replicate the travis env.

@maul-esel

Passes for me as well. It's annoying that due to that SystemStackError you can't see what's actually wrong :unamused:

lib/jekyll.rb
@@ -136,13 +136,20 @@ def self.configuration(override)
source = override['source'] || Jekyll::DEFAULTS['source']
# 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?
+ config_files = override.delete('config')
+ config_files = File.join(source, "_config.yml") if config_files.to_s.empty?
+ if not config_files.is_a? Array
@parkr Owner
parkr added a note

please use !. @mojombo prefers to use the more C-like versions - no python allowed ;)

@parkr Owner
parkr added a note

better yet, use unless

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
test/test_configuration.rb
@@ -46,10 +46,20 @@ class TestConfiguration < Test::Unit::TestCase
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
+ should "load multiple config files" do
@parkr Owner
parkr added a note

wait. whyyyyy did you take my test?

I am not sure. I will change that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@voidfiles

funny, the tests passed this time.

@parkr
Owner

LGTM, will ask for another pair of eyes

@mattr-
Owner

:+1: :shipit:

@parkr parkr merged commit 17c1e23 into jekyll:master
@parkr parkr referenced this pull request from a commit
@parkr parkr Update history to reflect merge of #945 64aa31b
@benbalter
Owner

Are you able to replicate this behavior via command line? Can't get it to work. What am I doing wrong?

jekyll build --config _config.yml _config2.yml
Configuration file: _config.yml
...
@parkr
Owner

The option should probably be --config FILE1, FILE2, ... or something. It specifies Array though. Hm.

@benbalter
Owner

Tried:

  • --config foo bar
  • --config foo, bar
  • --config [foo, bar] (also with quotes)
  • --config foo --config bar

No such luck.

@voidfiles

--config FILE1,FILE2 no spaces, but I found some other problems as well. I have a patch I am about to push.

@voidfiles

Here is a pull request that updates the command line description to make it a better example of how to do it. Also multi config files just weren't working.

#973

@parkr parkr referenced this pull request from a commit
@parkr parkr Merge branch 'master' of github.com:mojombo/jekyll
* 'master' of github.com:mojombo/jekyll:
  Print deprecation warnings for 'server', 'watch' and 'auto' when loaded from files. Fixes #972
  Fixes multiple config loading. Closes #973. Rel: #945.
d33f45f
@netpoetica netpoetica referenced this pull request in dannygarcia/grunt-jekyll
Closed

No Async #21

@parkr parkr referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
@parkr parkr referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 10, 2013
  1. @voidfiles

    Accept multiple config files from command line

    voidfiles authored
    Parse config as if it can contain multiple references to config files.
    This allows you to pass in multiple config files from the command line
    
    Helps with issues #514 and #703
  2. @voidfiles
Commits on Apr 11, 2013
  1. @voidfiles
This page is out of date. Refresh to see the latest.
Showing with 30 additions and 7 deletions.
  1. +2 −2 bin/jekyll
  2. +12 −5 lib/jekyll.rb
  3. +16 −0 test/test_configuration.rb
View
4 bin/jekyll
@@ -44,7 +44,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 '--config [CONFIG_FILE]', Array, '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'
@@ -63,7 +63,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 '--config [CONFIG_FILE]', Array,'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
17 lib/jekyll.rb
@@ -136,13 +136,20 @@ def self.configuration(override)
source = override['source'] || Jekyll::DEFAULTS['source']
# 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?
+ config_files = override.delete('config')
+ config_files = File.join(source, "_config.yml") if config_files.to_s.empty?
+ unless config_files.is_a? Array
+ config_files = [config_files]
+ end
begin
- config = YAML.safe_load_file(config_file)
- raise "Configuration file: (INVALID) #{config_file}" if !config.is_a?(Hash)
- $stdout.puts "Configuration file: #{config_file}"
+ config = {}
+ config_files.each do |config_file|
+ next_config = YAML.safe_load_file(config_file)
+ raise "Configuration file: (INVALID) #{config_file}" if !next_config.is_a?(Hash)
+ $stdout.puts "Configuration file: #{config_file}"
+ config = config.deep_merge(next_config)
+ end
rescue SystemCallError
# Errno:ENOENT = file not found
$stderr.puts "Configuration file: none"
View
16 test/test_configuration.rb
@@ -51,5 +51,21 @@ class TestConfiguration < Test::Unit::TestCase
mock($stdout).puts("Configuration file: #{@paths[:default]}")
assert_equal Jekyll::DEFAULTS, Jekyll.configuration({ "config" => @paths[:empty] })
end
+
+ should "load multiple config files" do
+ mock(YAML).safe_load_file(@paths[:default]) { Hash.new }
+ mock(YAML).safe_load_file(@paths[:other]) { Hash.new }
+ mock($stdout).puts("Configuration file: #{@paths[:default]}")
+ mock($stdout).puts("Configuration file: #{@paths[:other]}")
+ assert_equal Jekyll::DEFAULTS, Jekyll.configuration({ "config" => [@paths[:default], @paths[:other]] })
+ end
+
+ should "load multiple config files and last config should win" do
+ mock(YAML).safe_load_file(@paths[:default]) { {"baseurl" => "http://example.dev"} }
+ mock(YAML).safe_load_file(@paths[:other]) { {"baseurl" => "http://wahoo.dev"} }
+ mock($stdout).puts("Configuration file: #{@paths[:default]}")
+ mock($stdout).puts("Configuration file: #{@paths[:other]}")
+ assert_equal Jekyll::DEFAULTS.deep_merge({ "baseurl" => "http://wahoo.dev" }), Jekyll.configuration({ "config" => [@paths[:default], @paths[:other]] })
+ end
end
end
Something went wrong with that request. Please try again.