Access custom config array throughout session (#6200)
Merge pull request 6200
This commit is contained in:
parent
adde25120c
commit
c8eee7ffcb
|
@ -156,7 +156,7 @@ module Jekyll
|
||||||
)
|
)
|
||||||
|
|
||||||
# Get configuration from <source>/_config.yml or <source>/<config_file>
|
# 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?
|
if config_files.to_s.empty?
|
||||||
default = %w(yml yaml).find(-> { "yml" }) do |ext|
|
default = %w(yml yaml).find(-> { "yml" }) do |ext|
|
||||||
File.exist?(Jekyll.sanitized_path(source(override), "_config.#{ext}"))
|
File.exist?(Jekyll.sanitized_path(source(override), "_config.#{ext}"))
|
||||||
|
|
|
@ -38,6 +38,9 @@ module Jekyll
|
||||||
@site_collections ||= @obj.collections.values.sort_by(&:label).map(&:to_liquid)
|
@site_collections ||= @obj.collections.values.sort_by(&:label).map(&:to_liquid)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# return nil for `{{ site.config }}` even if --config was passed via CLI
|
||||||
|
def config; end
|
||||||
|
|
||||||
private
|
private
|
||||||
def_delegator :@obj, :config, :fallback_data
|
def_delegator :@obj, :config, :fallback_data
|
||||||
end
|
end
|
||||||
|
|
|
@ -356,7 +356,10 @@ class TestConfiguration < JekyllUnitTest
|
||||||
.and_return({ "baseurl" => "http://example.com" })
|
.and_return({ "baseurl" => "http://example.com" })
|
||||||
allow($stdout).to receive(:puts).with("Configuration file: #{@paths[:other]}")
|
allow($stdout).to receive(:puts).with("Configuration file: #{@paths[:other]}")
|
||||||
assert_equal \
|
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] }))
|
Jekyll.configuration(test_config.merge({ "config" => @paths[:other] }))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -368,7 +371,10 @@ class TestConfiguration < JekyllUnitTest
|
||||||
.and_return({ "baseurl" => "http://example.com" })
|
.and_return({ "baseurl" => "http://example.com" })
|
||||||
allow($stdout).to receive(:puts).with("Configuration file: #{@paths[:other]}")
|
allow($stdout).to receive(:puts).with("Configuration file: #{@paths[:other]}")
|
||||||
assert_equal \
|
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] }))
|
Jekyll.configuration(test_config.merge({ :config => @paths[:other] }))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -376,15 +382,18 @@ class TestConfiguration < JekyllUnitTest
|
||||||
allow(SafeYAML).to receive(:load_file).with(@paths[:default]).and_return({})
|
allow(SafeYAML).to receive(:load_file).with(@paths[:default]).and_return({})
|
||||||
allow($stdout).to receive(:puts).with("Configuration file: #{@paths[:default]}")
|
allow($stdout).to receive(:puts).with("Configuration file: #{@paths[:default]}")
|
||||||
assert_equal \
|
assert_equal \
|
||||||
site_configuration,
|
site_configuration({ "config" => [@paths[:empty]] }),
|
||||||
Jekyll.configuration(test_config.merge({ "config" => [@paths[:empty]] }))
|
Jekyll.configuration(test_config.merge({ "config" => [@paths[:empty]] }))
|
||||||
end
|
end
|
||||||
|
|
||||||
should "successfully load a TOML file" do
|
should "successfully load a TOML file" do
|
||||||
Jekyll.logger.log_level = :warn
|
Jekyll.logger.log_level = :warn
|
||||||
assert_equal \
|
assert_equal \
|
||||||
site_configuration({ "baseurl" => "/you-beautiful-blog-you",
|
site_configuration({
|
||||||
"title" => "My magnificent site, wut", }),
|
"baseurl" => "/you-beautiful-blog-you",
|
||||||
|
"title" => "My magnificent site, wut",
|
||||||
|
"config" => [@paths[:toml]],
|
||||||
|
}),
|
||||||
Jekyll.configuration(test_config.merge({ "config" => [@paths[:toml]] }))
|
Jekyll.configuration(test_config.merge({ "config" => [@paths[:toml]] }))
|
||||||
Jekyll.logger.log_level = :info
|
Jekyll.logger.log_level = :info
|
||||||
end
|
end
|
||||||
|
@ -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[:other]}")
|
||||||
allow($stdout).to receive(:puts).with("Configuration file: #{@paths[:toml]}")
|
allow($stdout).to receive(:puts).with("Configuration file: #{@paths[:toml]}")
|
||||||
assert_equal(
|
assert_equal(
|
||||||
site_configuration,
|
site_configuration({
|
||||||
|
"config" => [@paths[:default], @paths[:other], @paths[:toml]],
|
||||||
|
}),
|
||||||
Jekyll.configuration(
|
Jekyll.configuration(
|
||||||
test_config.merge(
|
test_config.merge(
|
||||||
{ "config" => [@paths[:default], @paths[:other], @paths[:toml]] }
|
{ "config" => [@paths[:default], @paths[:other], @paths[:toml]] }
|
||||||
|
@ -424,7 +435,10 @@ class TestConfiguration < JekyllUnitTest
|
||||||
.to receive(:puts)
|
.to receive(:puts)
|
||||||
.with("Configuration file: #{@paths[:other]}")
|
.with("Configuration file: #{@paths[:other]}")
|
||||||
assert_equal \
|
assert_equal \
|
||||||
site_configuration({ "baseurl" => "http://example.com" }),
|
site_configuration({
|
||||||
|
"baseurl" => "http://example.com",
|
||||||
|
"config" => [@paths[:default], @paths[:other]],
|
||||||
|
}),
|
||||||
Jekyll.configuration(
|
Jekyll.configuration(
|
||||||
test_config.merge({ "config" => [@paths[:default], @paths[:other]] })
|
test_config.merge({ "config" => [@paths[:default], @paths[:other]] })
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue