Class: Jekyll::Configuration
- Inherits:
-
Hash
- Object
- Hash
- Jekyll::Configuration
- Defined in:
- lib/jekyll/configuration.rb
Constant Summary collapse
- DEFAULTS =
Default options. Overridden by values in _config.yml. Strings rather than symbols are used for compatibility with YAML.
Configuration[{ # Where things are 'source' => Dir.pwd, 'destination' => File.join(Dir.pwd, '_site'), 'plugins_dir' => '_plugins', 'layouts_dir' => '_layouts', 'data_dir' => '_data', 'includes_dir' => '_includes', 'collections' => {}, # Handling Reading 'safe' => false, 'include' => ['.htaccess']
Instance Method Summary collapse
- #add_default_collections ⇒ Object
-
#backwards_compatibilize ⇒ Object
Public: Ensure the proper options are set in the configuration to allow for backwards-compatibility with Jekyll pre-1.0.
-
#config_files(override) ⇒ Object
Public: Generate list of configuration files from the override.
-
#csv_to_array(csv) ⇒ Object
Public: Split a CSV string into an array containing its values.
- #fix_common_issues ⇒ Object
- #get_config_value_with_override(config_key, override) ⇒ Object
- #quiet(override = {}) ⇒ Object (also: #quiet?)
-
#read_config_file(file) ⇒ Object
Public: Read configuration and return merged Hash.
-
#read_config_files(files) ⇒ Object
Public: Read in a list of configuration files and merge with this hash.
- #renamed_key(old, new, config, allowed_values = nil) ⇒ Object
- #safe_load_file(filename) ⇒ Object
-
#source(override) ⇒ Object
Public: Directory of the Jekyll source folder.
-
#stringify_keys ⇒ Object
Public: Turn all keys into string.
- #verbose(override = {}) ⇒ Object (also: #verbose?)
Instance Method Details
#add_default_collections ⇒ Object
278 279 280 281 282 283 284 285 286 287 288 289 290 291 |
# File 'lib/jekyll/configuration.rb', line 278 def add_default_collections config = clone return config if config['collections'].nil? if config['collections'].is_a?(Array) config['collections'] = Hash[config['collections'].map{|c| [c, {}]}] end config['collections']['posts'] ||= {} config['collections']['posts']['output'] = true config['collections']['posts']['permalink'] = style_to_permalink(config['permalink']) config end |
#backwards_compatibilize ⇒ Object
Public: Ensure the proper options are set in the configuration to allow for backwards-compatibility with Jekyll pre-1.0
Returns the backwards-compatible configuration
205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 |
# File 'lib/jekyll/configuration.rb', line 205 def backwards_compatibilize config = clone # Provide backwards-compatibility if config.key?('auto') || config.key?('watch') Jekyll::Deprecator. "Auto-regeneration can no longer" + " be set from your configuration file(s). Use the"+ " --[no-]watch/-w command-line option instead." config.delete('auto') config.delete('watch') end if config.key? 'server' Jekyll::Deprecator. "The 'server' configuration option" + " is no longer accepted. Use the 'jekyll serve'" + " subcommand to serve your site with WEBrick." config.delete('server') 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. "The 'pygments' configuration option" + " has been renamed to 'highlighter'. Please update your" + " config file accordingly. The allowed values are 'rouge', " + "'pygments' or null." config['highlighter'] = 'pygments' if config['pygments'] config.delete('pygments') end %w[include exclude].each do |option| if config.fetch(option, []).is_a?(String) Jekyll::Deprecator. "The '#{option}' configuration option" + " must now be specified as an array, but you specified" + " a string. For now, we've treated the string you provided" + " as a list of comma-separated values." config[option] = csv_to_array(config[option]) end config[option].map!(&:to_s) end if (config['kramdown'] || {}).key?('use_coderay') Jekyll::Deprecator. "Please change 'use_coderay'" + " to 'enable_coderay' in your configuration file." config['kramdown']['use_coderay'] = config['kramdown'].delete('enable_coderay') end if config.fetch('markdown', 'kramdown').to_s.downcase.eql?("maruku") Jekyll.logger.abort_with "Error:", "You're using the 'maruku' " + "Markdown processor, which has been removed as of 3.0.0. " + "We recommend you switch to Kramdown. To do this, replace " + "`markdown: maruku` with `markdown: kramdown` in your " + "`_config.yml` file." end config end |
#config_files(override) ⇒ Object
Public: Generate list of configuration files from the override
override - the command-line options hash
Returns an Array of config files
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/jekyll/configuration.rb', line 132 def config_files(override) # Adjust verbosity quickly Jekyll.logger.adjust_verbosity(:quiet => quiet?(override), :verbose => verbose?(override)) # Get configuration from <source>/_config.yml or <source>/<config_file> config_files = override.delete('config') if config_files.to_s.empty? default = %w[yml yaml].find(Proc.new { 'yml' }) do |ext| File.exist?(Jekyll.sanitized_path(source(override), "_config.#{ext}")) end config_files = Jekyll.sanitized_path(source(override), "_config.#{default}") @default_config_file = true end config_files = [config_files] unless config_files.is_a? Array config_files end |
#csv_to_array(csv) ⇒ Object
Public: Split a CSV string into an array containing its values
csv - the string of comma-separated values
Returns an array of the values contained in the CSV
197 198 199 |
# File 'lib/jekyll/configuration.rb', line 197 def csv_to_array(csv) csv.split(",").map(&:strip) end |
#fix_common_issues ⇒ Object
266 267 268 269 270 271 272 273 274 275 276 |
# File 'lib/jekyll/configuration.rb', line 266 def fix_common_issues config = clone if config.key?('paginate') && (!config['paginate'].is_a?(Integer) || config['paginate'] < 1) Jekyll.logger.warn "Config Warning:", "The `paginate` key must be a" + " positive integer or nil. It's currently set to '#{config['paginate'].inspect}'." config['paginate'] = nil end config end |
#get_config_value_with_override(config_key, override) ⇒ Object
92 93 94 |
# File 'lib/jekyll/configuration.rb', line 92 def get_config_value_with_override(config_key, override) override[config_key] || self[config_key] || DEFAULTS[config_key] end |
#quiet(override = {}) ⇒ Object Also known as: quiet?
105 106 107 |
# File 'lib/jekyll/configuration.rb', line 105 def quiet(override = {}) get_config_value_with_override('quiet', override) end |
#read_config_file(file) ⇒ Object
Public: Read configuration and return merged Hash
file - the path to the YAML file to be read in
Returns this configuration, overridden by the values in the file
154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
# File 'lib/jekyll/configuration.rb', line 154 def read_config_file(file) next_config = safe_load_file(file) raise ArgumentError.new("Configuration file: (INVALID) #{file}".yellow) unless next_config.is_a?(Hash) Jekyll.logger.info "Configuration file:", file next_config rescue SystemCallError if @default_config_file Jekyll.logger.warn "Configuration file:", "none" {} else Jekyll.logger.error "Fatal:", "The configuration file '#{file}' could not be found." raise LoadError, "The Configuration file '#{file}' could not be found." end end |
#read_config_files(files) ⇒ Object
Public: Read in a list of configuration files and merge with this hash
files - the list of configuration file paths
Returns the full configuration, with the defaults overridden by the values in the configuration files
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 |
# File 'lib/jekyll/configuration.rb', line 175 def read_config_files(files) configuration = clone begin files.each do |config_file| new_config = read_config_file(config_file) configuration = Utils.deep_merge_hashes(configuration, new_config) end rescue ArgumentError => err Jekyll.logger.warn "WARNING:", "Error reading configuration. " + "Using defaults (and options)." $stderr.puts "#{err}" end configuration.fix_common_issues.backwards_compatibilize.add_default_collections end |
#renamed_key(old, new, config, allowed_values = nil) ⇒ Object
293 294 295 296 297 298 299 300 |
# File 'lib/jekyll/configuration.rb', line 293 def renamed_key(old, new, config, allowed_values = nil) if config.key?(old) Jekyll::Deprecator. "The '#{old}' configuration" + "option has been renamed to '#{new}'. Please update your config " + "file accordingly." config[new] = config.delete(old) end end |
#safe_load_file(filename) ⇒ Object
115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/jekyll/configuration.rb', line 115 def safe_load_file(filename) case File.extname(filename) when /\.toml/i Jekyll::External.require_with_graceful_fail('toml') unless defined?(TOML) TOML.load_file(filename) when /\.ya?ml/i SafeYAML.load_file(filename) else raise ArgumentError, "No parser for '#{filename}' is available. Use a .toml or .y(a)ml file instead." end end |
#source(override) ⇒ Object
Public: Directory of the Jekyll source folder
override - the command-line options hash
Returns the path to the Jekyll source directory
101 102 103 |
# File 'lib/jekyll/configuration.rb', line 101 def source(override) get_config_value_with_override('source', override) end |
#stringify_keys ⇒ Object
Public: Turn all keys into string
Return a copy of the hash where all its keys are strings
88 89 90 |
# File 'lib/jekyll/configuration.rb', line 88 def stringify_keys reduce({}) { |hsh,(k,v)| hsh.merge(k.to_s => v) } end |
#verbose(override = {}) ⇒ Object Also known as: verbose?
110 111 112 |
# File 'lib/jekyll/configuration.rb', line 110 def verbose(override = {}) get_config_value_with_override('verbose', override) end |