From 399606c54447b5c4853981ae52cf40c30195c3be Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Sun, 16 Aug 2015 13:30:39 -0400 Subject: [PATCH] Unify renaming of configuration options to a single method. /cc #3782. --- lib/jekyll/configuration.rb | 48 ++++++++++--------------------------- 1 file changed, 13 insertions(+), 35 deletions(-) diff --git a/lib/jekyll/configuration.rb b/lib/jekyll/configuration.rb index 68dd9faf..6cf54193 100644 --- a/lib/jekyll/configuration.rb +++ b/lib/jekyll/configuration.rb @@ -220,14 +220,10 @@ module Jekyll config.delete('server') end - if config.key? 'server_port' - Jekyll::Deprecator.deprecation_message "The 'server_port' configuration option" + - " has been renamed to 'port'. Please update your config" + - " file accordingly." - # copy but don't overwrite: - config['port'] = config['server_port'] unless config.key?('port') - config.delete('server_port') - end + renamed_key 'server_port', 'port', config + renamed_key 'plugins', 'plugins_dir', config + renamed_key 'layouts', 'layouts_dir', config + renamed_key 'data_source', 'data_dir', config if config.key? 'pygments' Jekyll::Deprecator.deprecation_message "The 'pygments' configuration option" + @@ -264,33 +260,6 @@ module Jekyll "`_config.yml` file." end - if config.key? 'plugins' - Jekyll::Deprecator.deprecation_message "The 'plugins'" + - " configuration option has been renamed to 'plugins_dir'." + - " Please update your config file accordingly." - # copy but don't overwrite: - config['plugins_dir'] = config['plugins'] unless config.key?('plugins_dir') - config.delete('plugins') - end - - if config.key? 'layouts' - Jekyll::Deprecator.deprecation_message "The 'layouts'" + - " configuration option has been renamed to 'layouts_dir'." + - " Please update your config file accordingly." - # copy but don't overwrite: - config['layouts_dir'] = config['layouts'] unless config.key?('layouts_dir') - config.delete('layouts') - end - - if config.key? 'data_source' - Jekyll::Deprecator.deprecation_message "The 'data_source'" + - " configuration option has been renamed to 'data_dir'." + - " Please update your config file accordingly." - # copy but don't overwrite: - config['data_dir'] = config['data_source'] unless config.key?('data_dir') - config.delete('data_source') - end - config end @@ -305,5 +274,14 @@ module Jekyll config end + + def renamed_key(old, new, config, allowed_values = nil) + if config.key?(old) + Jekyll::Deprecator.deprecation_message "The '#{old}' configuration" + + "option has been renamed to '#{new}'. Please update your config " + + "file accordingly." + config[new] = config.delete(old) + end + end end end