Skip to content

Commit

Permalink
Access custom config array throughout session (#6200)
Browse files Browse the repository at this point in the history
Merge pull request 6200
  • Loading branch information
ashmaroli authored and jekyllbot committed Aug 7, 2017
1 parent adde251 commit c8eee7f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
2 changes: 1 addition & 1 deletion lib/jekyll/configuration.rb
Expand Up @@ -156,7 +156,7 @@ def config_files(override)
)

# Get configuration from <source>/_config.yml or <source>/<config_file>
config_files = override.delete("config")
config_files = override["config"]
if config_files.to_s.empty?
default = %w(yml yaml).find(-> { "yml" }) do |ext|
File.exist?(Jekyll.sanitized_path(source(override), "_config.#{ext}"))
Expand Down
3 changes: 3 additions & 0 deletions lib/jekyll/drops/site_drop.rb
Expand Up @@ -38,6 +38,9 @@ def collections
@site_collections ||= @obj.collections.values.sort_by(&:label).map(&:to_liquid)
end

# return nil for `{{ site.config }}` even if --config was passed via CLI
def config; end

private
def_delegator :@obj, :config, :fallback_data
end
Expand Down
28 changes: 21 additions & 7 deletions test/test_configuration.rb
Expand Up @@ -356,7 +356,10 @@ class TestConfiguration < JekyllUnitTest
.and_return({ "baseurl" => "http://example.com" })
allow($stdout).to receive(:puts).with("Configuration file: #{@paths[:other]}")
assert_equal \
site_configuration({ "baseurl" => "http://example.com" }),
site_configuration({
"baseurl" => "http://example.com",
"config" => @paths[:other],
}),
Jekyll.configuration(test_config.merge({ "config" => @paths[:other] }))
end

Expand All @@ -368,23 +371,29 @@ class TestConfiguration < JekyllUnitTest
.and_return({ "baseurl" => "http://example.com" })
allow($stdout).to receive(:puts).with("Configuration file: #{@paths[:other]}")
assert_equal \
site_configuration({ "baseurl" => "http://example.com" }),
site_configuration({
"baseurl" => "http://example.com",
"config" => @paths[:other],
}),
Jekyll.configuration(test_config.merge({ :config => @paths[:other] }))
end

should "load default config if path passed is empty" do
allow(SafeYAML).to receive(:load_file).with(@paths[:default]).and_return({})
allow($stdout).to receive(:puts).with("Configuration file: #{@paths[:default]}")
assert_equal \
site_configuration,
site_configuration({ "config" => [@paths[:empty]] }),
Jekyll.configuration(test_config.merge({ "config" => [@paths[:empty]] }))
end

should "successfully load a TOML file" do
Jekyll.logger.log_level = :warn
assert_equal \
site_configuration({ "baseurl" => "/you-beautiful-blog-you",
"title" => "My magnificent site, wut", }),
site_configuration({
"baseurl" => "/you-beautiful-blog-you",
"title" => "My magnificent site, wut",
"config" => [@paths[:toml]],
}),
Jekyll.configuration(test_config.merge({ "config" => [@paths[:toml]] }))
Jekyll.logger.log_level = :info
end
Expand All @@ -399,7 +408,9 @@ class TestConfiguration < JekyllUnitTest
allow($stdout).to receive(:puts).with("Configuration file: #{@paths[:other]}")
allow($stdout).to receive(:puts).with("Configuration file: #{@paths[:toml]}")
assert_equal(
site_configuration,
site_configuration({
"config" => [@paths[:default], @paths[:other], @paths[:toml]],
}),
Jekyll.configuration(
test_config.merge(
{ "config" => [@paths[:default], @paths[:other], @paths[:toml]] }
Expand All @@ -424,7 +435,10 @@ class TestConfiguration < JekyllUnitTest
.to receive(:puts)
.with("Configuration file: #{@paths[:other]}")
assert_equal \
site_configuration({ "baseurl" => "http://example.com" }),
site_configuration({
"baseurl" => "http://example.com",
"config" => [@paths[:default], @paths[:other]],
}),
Jekyll.configuration(
test_config.merge({ "config" => [@paths[:default], @paths[:other]] })
)
Expand Down

0 comments on commit c8eee7f

Please sign in to comment.