From d01f7943debf08dee645990ddb0e00d59cf846bb Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Fri, 8 Apr 2016 10:00:03 -0700 Subject: [PATCH] Add Configuration.from & use in Jekyll.configuration. This process streamlines the creation of new configurations. Creating a new site will choke if not all the correct options are given. Configuration.from will ensure the overrides have all string keys and ensures all the common issues & defaults are in place so a Site can be created. A common use: config = Configuration.from({ 'permalink' => '/:title/' }) # etc site = Jekyll::Site.new(config) --- lib/jekyll.rb | 7 +++---- lib/jekyll/configuration.rb | 19 ++++++++++++++++++- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/lib/jekyll.rb b/lib/jekyll.rb index e9f4547b3..0d680842f 100644 --- a/lib/jekyll.rb +++ b/lib/jekyll.rb @@ -98,15 +98,14 @@ module Jekyll # list of option names and their defaults. # # Returns the final configuration Hash. - def configuration(override = {}) - config = Configuration[Configuration::DEFAULTS] - override = Configuration[override].stringify_keys + def configuration(override = Hash.new) + config = Configuration.new unless override.delete('skip_config_files') config = config.read_config_files(config.config_files(override)) end # Merge DEFAULTS < _config.yml < override - config = Utils.deep_merge_hashes(config, override).stringify_keys + config = Configuration.from Utils.deep_merge_hashes(config, override).stringify_keys set_timezone(config['timezone']) if config['timezone'] config diff --git a/lib/jekyll/configuration.rb b/lib/jekyll/configuration.rb index 4c36341d1..4af19a63f 100644 --- a/lib/jekyll/configuration.rb +++ b/lib/jekyll/configuration.rb @@ -74,6 +74,23 @@ module Jekyll } }].freeze + class << self + # Static: Produce a Configuration ready for use in a Site. + # It takes the input, fills in the defaults where values do not + # exist, and patches common issues including migrating options for + # backwards compatiblity. Except where a key or value is being fixed, + # the user configuration will override the defaults. + # + # user_config - a Hash or Configuration of overrides. + # + # Returns a Configuration filled with defaults and fixed for common + # problems and backwards-compatibility. + def from(user_config) + Utils.deep_merge_hashes(DEFAULTS, Configuration[user_config].stringify_keys). + fix_common_issues.backwards_compatibilize.add_default_collections + end + end + # Public: Turn all keys into string # # Return a copy of the hash where all its keys are strings @@ -237,7 +254,7 @@ module Jekyll " as a list of comma-separated values." config[option] = csv_to_array(config[option]) end - config[option].map!(&:to_s) + config[option].map!(&:to_s) if config[option] end if (config['kramdown'] || {}).key?('use_coderay')