Skip to content

Commit

Permalink
Merge pull request jekyll#5024 from ayastreb/configuration
Browse files Browse the repository at this point in the history
Merge pull request 5024
  • Loading branch information
jekyllbot authored Jun 24, 2016
2 parents 5312e85 + 14e8570 commit 205acb0
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 64 deletions.
1 change: 0 additions & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ AllCops:
- lib/**/*.rb
Exclude:
- lib/jekyll/collection.rb
- lib/jekyll/configuration.rb
- lib/jekyll/convertible.rb
- lib/jekyll/document.rb
- lib/jekyll/renderer.rb
Expand Down
152 changes: 89 additions & 63 deletions lib/jekyll/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ class << self
# 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.add_default_collections
Utils.deep_merge_hashes(DEFAULTS, Configuration[user_config].stringify_keys)
.fix_common_issues.add_default_collections
end
end

Expand Down Expand Up @@ -123,10 +123,10 @@ def verbose(override = {})

def safe_load_file(filename)
case File.extname(filename)
when /\.toml/i
when %r!\.toml!i
Jekyll::External.require_with_graceful_fail("toml") unless defined?(TOML)
TOML.load_file(filename)
when /\.ya?ml/i
when %r!\.ya?ml!i
SafeYAML.load_file(filename) || {}
else
raise ArgumentError, "No parser for '#{filename}' is available.
Expand Down Expand Up @@ -191,7 +191,7 @@ def read_config_files(files)

begin
files.each do |config_file|
next if config_file.nil? or config_file.empty?
next if config_file.nil? || config_file.empty?
new_config = read_config_file(config_file)
configuration = Utils.deep_merge_hashes(configuration, new_config)
end
Expand Down Expand Up @@ -220,60 +220,18 @@ def csv_to_array(csv)
def backwards_compatibilize
config = clone
# Provide backwards-compatibility
if config.key?("auto") || config.key?("watch")
Jekyll::Deprecator.deprecation_message "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.deprecation_message "The 'server' configuration option" \
" is no longer accepted. Use the 'jekyll serve'" \
" subcommand to serve your site with WEBrick."
config.delete("server")
end
check_auto(config)
check_server(config)

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" \
" 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[option].is_a?(String)
Jekyll::Deprecator.deprecation_message "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) if config[option]
end

if (config["kramdown"] || {}).key?("use_coderay")
Jekyll::Deprecator.deprecation_message "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.casecmp("maruku") == 0
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
check_pygments(config)
check_include_exclude(config)
check_coderay(config)
check_maruku(config)

config
end
Expand All @@ -296,19 +254,19 @@ def add_default_collections
config = clone

# It defaults to `{}`, so this is only if someone sets it to null manually.
return config if config['collections'].nil?
return config if config["collections"].nil?

# Ensure we have a hash.
if config['collections'].is_a?(Array)
config['collections'] = Hash[config['collections'].map { |c| [c, {}] }]
if config["collections"].is_a?(Array)
config["collections"] = Hash[config["collections"].map { |c| [c, {}] }]
end

config['collections'] = Utils.deep_merge_hashes(
{ 'posts' => {} }, config['collections']
config["collections"] = Utils.deep_merge_hashes(
{ "posts" => {} }, config["collections"]
).tap do |collections|
collections['posts']['output'] = true
if config['permalink']
collections['posts']['permalink'] ||= style_to_permalink(config['permalink'])
collections["posts"]["output"] = true
if config["permalink"]
collections["posts"]["permalink"] ||= style_to_permalink(config["permalink"])
end
end

Expand All @@ -325,7 +283,6 @@ def renamed_key(old, new, config, _ = nil)
end

private

def style_to_permalink(permalink_style)
case permalink_style.to_sym
when :pretty
Expand All @@ -347,9 +304,78 @@ def style_to_permalink(permalink_style)
# file - the file from which the config was extracted
#
# Raises an ArgumentError if given config is not a hash
private
def check_config_is_hash!(extracted_config, file)
unless extracted_config.is_a?(Hash)
raise ArgumentError.new("Configuration file: (INVALID) #{file}".yellow)
raise ArgumentError, "Configuration file: (INVALID) #{file}".yellow
end
end

private
def check_auto(config)
if config.key?("auto") || config.key?("watch")
Jekyll::Deprecator.deprecation_message "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
end

private
def check_server(config)
if config.key?("server")
Jekyll::Deprecator.deprecation_message "The 'server' configuration option" \
" is no longer accepted. Use the 'jekyll serve'" \
" subcommand to serve your site with WEBrick."
config.delete("server")
end
end

private
def check_pygments(config)
if config.key?("pygments")
Jekyll::Deprecator.deprecation_message "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
end

private
def check_include_exclude(config)
%w(include exclude).each do |option|
if config[option].is_a?(String)
Jekyll::Deprecator.deprecation_message "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) if config[option]
end
end

private
def check_coderay(config)
if (config["kramdown"] || {}).key?("use_coderay")
Jekyll::Deprecator.deprecation_message "Please change 'use_coderay'" \
" to 'enable_coderay' in your configuration file."
config["kramdown"]["use_coderay"] = config["kramdown"].delete("enable_coderay")
end
end

private
def check_maruku(config)
if config.fetch("markdown", "kramdown").to_s.casecmp("maruku") == 0
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
end
end
Expand Down

0 comments on commit 205acb0

Please sign in to comment.