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)
			
			
This commit is contained in:
		
							parent
							
								
									fab092fcec
								
							
						
					
					
						commit
						d01f7943de
					
				|  | @ -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 | ||||
|  |  | |||
|  | @ -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') | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue