Merge pull request #4052 from Crunch09/process-empty-config-files
Merge pull request 4052
This commit is contained in:
commit
92adfd0e46
|
@ -110,7 +110,7 @@ module Jekyll
|
||||||
Jekyll::External.require_with_graceful_fail('toml') unless defined?(TOML)
|
Jekyll::External.require_with_graceful_fail('toml') unless defined?(TOML)
|
||||||
TOML.load_file(filename)
|
TOML.load_file(filename)
|
||||||
when /\.ya?ml/i
|
when /\.ya?ml/i
|
||||||
SafeYAML.load_file(filename)
|
SafeYAML.load_file(filename) || {}
|
||||||
else
|
else
|
||||||
raise ArgumentError, "No parser for '#{filename}' is available. Use a .toml or .y(a)ml file instead."
|
raise ArgumentError, "No parser for '#{filename}' is available. Use a .toml or .y(a)ml file instead."
|
||||||
end
|
end
|
||||||
|
@ -145,7 +145,7 @@ module Jekyll
|
||||||
# Returns this configuration, overridden by the values in the file
|
# Returns this configuration, overridden by the values in the file
|
||||||
def read_config_file(file)
|
def read_config_file(file)
|
||||||
next_config = safe_load_file(file)
|
next_config = safe_load_file(file)
|
||||||
raise ArgumentError.new("Configuration file: (INVALID) #{file}".yellow) unless next_config.is_a?(Hash)
|
check_config_is_hash!(next_config, file)
|
||||||
Jekyll.logger.info "Configuration file:", file
|
Jekyll.logger.info "Configuration file:", file
|
||||||
next_config
|
next_config
|
||||||
rescue SystemCallError
|
rescue SystemCallError
|
||||||
|
@ -228,7 +228,8 @@ module Jekyll
|
||||||
end
|
end
|
||||||
|
|
||||||
%w[include exclude].each do |option|
|
%w[include exclude].each do |option|
|
||||||
if config.fetch(option, []).is_a?(String)
|
config[option] ||= []
|
||||||
|
if config[option].is_a?(String)
|
||||||
Jekyll::Deprecator.deprecation_message "The '#{option}' configuration option" +
|
Jekyll::Deprecator.deprecation_message "The '#{option}' configuration option" +
|
||||||
" must now be specified as an array, but you specified" +
|
" must now be specified as an array, but you specified" +
|
||||||
" a string. For now, we've treated the string you provided" +
|
" a string. For now, we've treated the string you provided" +
|
||||||
|
@ -292,6 +293,7 @@ module Jekyll
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def style_to_permalink(permalink_style)
|
def style_to_permalink(permalink_style)
|
||||||
case permalink_style.to_sym
|
case permalink_style.to_sym
|
||||||
when :pretty
|
when :pretty
|
||||||
|
@ -306,5 +308,17 @@ module Jekyll
|
||||||
permalink_style.to_s
|
permalink_style.to_s
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Private: Checks if a given config is a hash
|
||||||
|
#
|
||||||
|
# extracted_config - the value to check
|
||||||
|
# file - the file from which the config was extracted
|
||||||
|
#
|
||||||
|
# Raises an ArgumentError if given config is not a hash
|
||||||
|
def check_config_is_hash!(extracted_config, file)
|
||||||
|
unless extracted_config.is_a?(Hash)
|
||||||
|
raise ArgumentError.new("Configuration file: (INVALID) #{file}".yellow)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -59,6 +59,34 @@ class TestConfiguration < JekyllUnitTest
|
||||||
assert_equal %w[config/site.yml config/deploy.toml configuration.yml], @config.config_files(@multiple_files)
|
assert_equal %w[config/site.yml config/deploy.toml configuration.yml], @config.config_files(@multiple_files)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "#read_config_file" do
|
||||||
|
setup do
|
||||||
|
@config = Configuration[{"source" => source_dir('empty.yml')}]
|
||||||
|
end
|
||||||
|
|
||||||
|
should "not raise an error on empty files" do
|
||||||
|
allow(SafeYAML).to receive(:load_file).with('empty.yml').and_return(false)
|
||||||
|
Jekyll.logger.log_level = :warn
|
||||||
|
@config.read_config_file('empty.yml')
|
||||||
|
Jekyll.logger.log_level = :info
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "#read_config_files" do
|
||||||
|
setup do
|
||||||
|
@config = Configuration[{"source" => source_dir}]
|
||||||
|
end
|
||||||
|
|
||||||
|
should "continue to read config files if one is empty" do
|
||||||
|
allow(SafeYAML).to receive(:load_file).with('empty.yml').and_return(false)
|
||||||
|
allow(SafeYAML).to receive(:load_file).with('not_empty.yml').and_return({'foo' => 'bar', 'include' => '', 'exclude' => ''})
|
||||||
|
Jekyll.logger.log_level = :warn
|
||||||
|
read_config = @config.read_config_files(['empty.yml', 'not_empty.yml'])
|
||||||
|
Jekyll.logger.log_level = :info
|
||||||
|
assert_equal 'bar', read_config['foo']
|
||||||
|
end
|
||||||
|
end
|
||||||
context "#backwards_compatibilize" do
|
context "#backwards_compatibilize" do
|
||||||
setup do
|
setup do
|
||||||
@config = Configuration[{
|
@config = Configuration[{
|
||||||
|
|
Loading…
Reference in New Issue