Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Access custom config array throughout session #6200

Merged
merged 3 commits into from Aug 7, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/jekyll/configuration.rb
Expand Up @@ -155,7 +155,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 @@ -37,6 +37,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 @@ -354,7 +354,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 @@ -366,23 +369,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 @@ -397,7 +406,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 @@ -422,7 +433,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