Usability: Don't raise an exception when config is missing or invalid

This commit is contained in:
Joseph Wynn 2018-06-30 19:39:40 -07:00
parent b76e2d3365
commit c559bcced3
No known key found for this signature in database
GPG Key ID: F34B9E530F0D3AEE
4 changed files with 33 additions and 2 deletions

12
features/plugin.feature Normal file
View File

@ -0,0 +1,12 @@
Feature: General plugin usage
Scenario: No config at all
Given I have no configuration
When I run Jekyll
Then there should be no errors
Scenario: Config with empty responsive_image block
Given I have a responsive_image configuration with:
"""
"""
When I run Jekyll
Then there should be no errors

View File

@ -6,6 +6,10 @@ Then /^Jekyll should throw a "(.+)"$/ do |error_class|
assert_raise(Object.const_get(error_class)) { run_jekyll }
end
Then /^there should be no errors$/ do
# Implicit pass
end
Given /^I have copied my site to "(.+)"$/ do |path|
new_site_dir = File.join(TEST_DIR, path)
@ -16,6 +20,10 @@ Given /^I have copied my site to "(.+)"$/ do |path|
.each { |f| FileUtils.mv(f, new_site_dir) }
end
Given /^I have no configuration$/ do
write_file('_config.yml', '')
end
Given /^I have a configuration with:$/ do |config|
write_file('_config.yml', config)
end

View File

@ -17,8 +17,19 @@ module Jekyll
@site = site
end
def valid_config(config)
config.has_key?('responsive_image') && config['responsive_image'].is_a?(Hash)
end
def to_h
DEFAULTS.merge(@site.config['responsive_image'])
config = {}
if valid_config(@site.config)
config = @site.config['responsive_image']
end
DEFAULTS.merge(config)
.merge(site_source: @site.source, site_dest: @site.dest)
end
end

View File

@ -1,5 +1,5 @@
module Jekyll
module ResponsiveImage
VERSION = '1.5.1'.freeze
VERSION = '1.5.2'.freeze
end
end