Merge pull request #4940 from DirtyF/feature-rubocop

Merge pull request 4940
This commit is contained in:
jekyllbot 2016-06-06 07:53:33 -07:00
commit c8606c5765
6 changed files with 125 additions and 107 deletions

View File

@ -8,7 +8,6 @@ AllCops:
- lib/jekyll/command.rb - lib/jekyll/command.rb
- lib/jekyll/configuration.rb - lib/jekyll/configuration.rb
- lib/jekyll/convertible.rb - lib/jekyll/convertible.rb
- lib/jekyll/deprecator.rb
- lib/jekyll/document.rb - lib/jekyll/document.rb
- lib/jekyll/filters.rb - lib/jekyll/filters.rb
- lib/jekyll/regenerator.rb - lib/jekyll/regenerator.rb

View File

@ -32,7 +32,8 @@ module Jekyll
# Override of method_missing to check in @data for the key. # Override of method_missing to check in @data for the key.
def method_missing(method, *args, &blck) def method_missing(method, *args, &blck)
if docs.respond_to?(method.to_sym) if docs.respond_to?(method.to_sym)
Jekyll.logger.warn "Deprecation:", "#{label}.#{method} should be changed to #{label}.docs.#{method}." Jekyll.logger.warn "Deprecation:", "#{label}.#{method} should be changed to" \
"#{label}.docs.#{method}."
Jekyll.logger.warn "", "Called by #{caller.first}." Jekyll.logger.warn "", "Called by #{caller.first}."
docs.public_send(method.to_sym, *args, &blck) docs.public_send(method.to_sym, *args, &blck)
else else
@ -64,8 +65,10 @@ module Jekyll
Jekyll.logger.debug "Skipped From Publishing:", doc.relative_path Jekyll.logger.debug "Skipped From Publishing:", doc.relative_path
end end
else else
relative_dir = Jekyll.sanitized_path(relative_directory, File.dirname(file_path)).chomp("/.") relative_dir = Jekyll.sanitized_path(relative_directory,
files << StaticFile.new(site, site.source, relative_dir, File.basename(full_path), self) File.dirname(file_path)).chomp("/.")
files << StaticFile.new(site, site.source, relative_dir,
File.basename(full_path), self)
end end
end end
docs.sort! docs.sort!
@ -79,7 +82,7 @@ module Jekyll
return [] unless exists? return [] unless exists?
@entries ||= @entries ||=
Utils.safe_glob(collection_dir, ["**", "*"]).map do |entry| Utils.safe_glob(collection_dir, ["**", "*"]).map do |entry|
entry["#{collection_dir}/"] = '' entry["#{collection_dir}/"] = ""
entry entry
end end
end end
@ -161,7 +164,7 @@ module Jekyll
# #
# Returns a sanitized version of the label. # Returns a sanitized version of the label.
def sanitize_label(label) def sanitize_label(label)
label.gsub(/[^a-z0-9_\-\.]/i, '') label.gsub(/[^a-z0-9_\-\.]/i, "")
end end
# Produce a representation of this Collection for use in Liquid. # Produce a representation of this Collection for use in Liquid.
@ -179,14 +182,14 @@ module Jekyll
# #
# Returns true if the 'write' metadata is true, false otherwise. # Returns true if the 'write' metadata is true, false otherwise.
def write? def write?
!!metadata.fetch('output', false) !!metadata.fetch("output", false)
end end
# The URL template to render collection's documents at. # The URL template to render collection's documents at.
# #
# Returns the URL template to render collection's documents at. # Returns the URL template to render collection's documents at.
def url_template def url_template
@url_template ||= metadata.fetch('permalink') do @url_template ||= metadata.fetch("permalink") do
Utils.add_permalink_suffix("/:collection/:path", site.permalink_style) Utils.add_permalink_suffix("/:collection/:path", site.permalink_style)
end end
end end
@ -195,8 +198,8 @@ module Jekyll
# #
# Returns the metadata for this collection # Returns the metadata for this collection
def extract_metadata def extract_metadata
if site.config['collections'].is_a?(Hash) if site.config["collections"].is_a?(Hash)
site.config['collections'][label] || {} site.config["collections"][label] || {}
else else
{} {}
end end

View File

@ -46,19 +46,23 @@ module Jekyll
# #
# Returns nothing # Returns nothing
def add_build_options(c) def add_build_options(c)
c.option 'config', '--config CONFIG_FILE[,CONFIG_FILE2,...]', Array, 'Custom configuration file' c.option "config", "--config CONFIG_FILE[,CONFIG_FILE2,...]",
c.option 'destination', '-d', '--destination DESTINATION', 'The current folder will be generated into DESTINATION' Array, "Custom configuration file"
c.option 'source', '-s', '--source SOURCE', 'Custom source directory' c.option "destination", "-d", "--destination DESTINATION",
c.option 'future', '--future', 'Publishes posts with a future date' "The current folder will be generated into DESTINATION"
c.option 'limit_posts', '--limit_posts MAX_POSTS', Integer, 'Limits the number of posts to parse and publish' c.option "source", "-s", "--source SOURCE", "Custom source directory"
c.option 'watch', '-w', '--[no-]watch', 'Watch for changes and rebuild' c.option "future", "--future", "Publishes posts with a future date"
c.option 'force_polling', '--force_polling', 'Force watch to use polling' c.option "limit_posts", "--limit_posts MAX_POSTS", Integer,
c.option 'lsi', '--lsi', 'Use LSI for improved related posts' "Limits the number of posts to parse and publish"
c.option 'show_drafts', '-D', '--drafts', 'Render posts in the _drafts folder' c.option "watch", "-w", "--[no-]watch", "Watch for changes and rebuild"
c.option 'unpublished', '--unpublished', 'Render posts that were marked as unpublished' c.option "force_polling", "--force_polling", "Force watch to use polling"
c.option 'quiet', '-q', '--quiet', 'Silence output.' c.option "lsi", "--lsi", "Use LSI for improved related posts"
c.option 'verbose', '-V', '--verbose', 'Print verbose output.' c.option "show_drafts", "-D", "--drafts", "Render posts in the _drafts folder"
c.option 'incremental', '-I', '--incremental', 'Enable incremental rebuild.' c.option "unpublished", "--unpublished",
"Render posts that were marked as unpublished"
c.option "quiet", "-q", "--quiet", "Silence output."
c.option "verbose", "-V", "--verbose", "Print verbose output."
c.option "incremental", "-I", "--incremental", "Enable incremental rebuild."
end end
end end
end end

View File

@ -6,71 +6,71 @@ module Jekyll
# Strings rather than symbols are used for compatibility with YAML. # Strings rather than symbols are used for compatibility with YAML.
DEFAULTS = Configuration[{ DEFAULTS = Configuration[{
# Where things are # Where things are
'source' => Dir.pwd, "source" => Dir.pwd,
'destination' => File.join(Dir.pwd, '_site'), "destination" => File.join(Dir.pwd, "_site"),
'plugins_dir' => '_plugins', "plugins_dir" => "_plugins",
'layouts_dir' => '_layouts', "layouts_dir" => "_layouts",
'data_dir' => '_data', "data_dir" => "_data",
'includes_dir' => '_includes', "includes_dir" => "_includes",
'collections' => {}, "collections" => {},
# Handling Reading # Handling Reading
'safe' => false, "safe" => false,
'include' => ['.htaccess'], "include" => [".htaccess"],
'exclude' => [], "exclude" => [],
'keep_files' => ['.git', '.svn'], "keep_files" => [".git", ".svn"],
'encoding' => 'utf-8', "encoding" => "utf-8",
'markdown_ext' => 'markdown,mkdown,mkdn,mkd,md', "markdown_ext" => "markdown,mkdown,mkdn,mkd,md",
# Filtering Content # Filtering Content
'show_drafts' => nil, "show_drafts" => nil,
'limit_posts' => 0, "limit_posts" => 0,
'future' => false, "future" => false,
'unpublished' => false, "unpublished" => false,
# Plugins # Plugins
'whitelist' => [], "whitelist" => [],
'gems' => [], "gems" => [],
# Conversion # Conversion
'markdown' => 'kramdown', "markdown" => "kramdown",
'highlighter' => 'rouge', "highlighter" => "rouge",
'lsi' => false, "lsi" => false,
'excerpt_separator' => "\n\n", "excerpt_separator" => "\n\n",
'incremental' => false, "incremental" => false,
# Serving # Serving
'detach' => false, # default to not detaching the server "detach" => false, # default to not detaching the server
'port' => '4000', "port" => "4000",
'host' => '127.0.0.1', "host" => "127.0.0.1",
'baseurl' => '', "baseurl" => "",
'show_dir_listing' => false, "show_dir_listing" => false,
# Output Configuration # Output Configuration
'permalink' => 'date', "permalink" => "date",
'paginate_path' => '/page:num', "paginate_path" => "/page:num",
'timezone' => nil, # use the local timezone "timezone" => nil, # use the local timezone
'quiet' => false, "quiet" => false,
'verbose' => false, "verbose" => false,
'defaults' => [], "defaults" => [],
'rdiscount' => { "rdiscount" => {
'extensions' => [] "extensions" => []
}, },
'redcarpet' => { "redcarpet" => {
'extensions' => [] "extensions" => []
}, },
'kramdown' => { "kramdown" => {
'auto_ids' => true, "auto_ids" => true,
'toc_levels' => '1..6', "toc_levels" => "1..6",
'entity_output' => 'as_char', "entity_output" => "as_char",
'smart_quotes' => 'lsquo,rsquo,ldquo,rdquo', "smart_quotes" => "lsquo,rsquo,ldquo,rdquo",
'input' => "GFM", "input" => "GFM",
'hard_wrap' => false, "hard_wrap" => false,
'footnote_nr' => 1 "footnote_nr" => 1
} }
}.map { |k, v| [k, v.freeze] }].freeze }.map { |k, v| [k, v.freeze] }].freeze
@ -108,28 +108,29 @@ module Jekyll
# #
# Returns the path to the Jekyll source directory # Returns the path to the Jekyll source directory
def source(override) def source(override)
get_config_value_with_override('source', override) get_config_value_with_override("source", override)
end end
def quiet(override = {}) def quiet(override = {})
get_config_value_with_override('quiet', override) get_config_value_with_override("quiet", override)
end end
alias_method :quiet?, :quiet alias_method :quiet?, :quiet
def verbose(override = {}) def verbose(override = {})
get_config_value_with_override('verbose', override) get_config_value_with_override("verbose", override)
end end
alias_method :verbose?, :verbose alias_method :verbose?, :verbose
def safe_load_file(filename) def safe_load_file(filename)
case File.extname(filename) case File.extname(filename)
when /\.toml/i when /\.toml/i
Jekyll::External.require_with_graceful_fail('toml') unless defined?(TOML) Jekyll::External.require_with_graceful_fail("toml") unless defined?(TOML)
TOML.load_file(filename) TOML.load_file(filename)
when /\.ya?ml/i when /\.ya?ml/i
SafeYAML.load_file(filename) || {} SafeYAML.load_file(filename) || {}
else else
raise ArgumentError, "No parser for '#{filename}' is available. Use a .toml or .y(a)ml file instead." raise ArgumentError, "No parser for '#{filename}' is available.
Use a .toml or .y(a)ml file instead."
end end
end end
@ -140,12 +141,15 @@ module Jekyll
# Returns an Array of config files # Returns an Array of config files
def config_files(override) def config_files(override)
# Adjust verbosity quickly # Adjust verbosity quickly
Jekyll.logger.adjust_verbosity(:quiet => quiet?(override), :verbose => verbose?(override)) Jekyll.logger.adjust_verbosity(
:quiet => quiet?(override),
:verbose => verbose?(override)
)
# Get configuration from <source>/_config.yml or <source>/<config_file> # Get configuration from <source>/_config.yml or <source>/<config_file>
config_files = override.delete('config') config_files = override.delete("config")
if config_files.to_s.empty? if config_files.to_s.empty?
default = %w(yml yaml).find(-> { 'yml' }) do |ext| default = %w(yml yaml).find(-> { "yml" }) do |ext|
File.exist?(Jekyll.sanitized_path(source(override), "_config.#{ext}")) File.exist?(Jekyll.sanitized_path(source(override), "_config.#{ext}"))
end end
config_files = Jekyll.sanitized_path(source(override), "_config.#{default}") config_files = Jekyll.sanitized_path(source(override), "_config.#{default}")
@ -170,7 +174,8 @@ module Jekyll
Jekyll.logger.warn "Configuration file:", "none" Jekyll.logger.warn "Configuration file:", "none"
{} {}
else else
Jekyll.logger.error "Fatal:", "The configuration file '#{file}' could not be found." Jekyll.logger.error "Fatal:", "The configuration file '#{file}'
could not be found."
raise LoadError, "The Configuration file '#{file}' could not be found." raise LoadError, "The Configuration file '#{file}' could not be found."
end end
end end
@ -193,7 +198,7 @@ module Jekyll
rescue ArgumentError => err rescue ArgumentError => err
Jekyll.logger.warn "WARNING:", "Error reading configuration. " \ Jekyll.logger.warn "WARNING:", "Error reading configuration. " \
"Using defaults (and options)." "Using defaults (and options)."
$stderr.puts "#{err}" $stderr.puts err
end end
configuration.fix_common_issues.backwards_compatibilize.add_default_collections configuration.fix_common_issues.backwards_compatibilize.add_default_collections
@ -215,34 +220,34 @@ module Jekyll
def backwards_compatibilize def backwards_compatibilize
config = clone config = clone
# Provide backwards-compatibility # Provide backwards-compatibility
if config.key?('auto') || config.key?('watch') if config.key?("auto") || config.key?("watch")
Jekyll::Deprecator.deprecation_message "Auto-regeneration can no longer" \ Jekyll::Deprecator.deprecation_message "Auto-regeneration can no longer" \
" be set from your configuration file(s). Use the"\ " be set from your configuration file(s). Use the" \
" --[no-]watch/-w command-line option instead." " --[no-]watch/-w command-line option instead."
config.delete('auto') config.delete("auto")
config.delete('watch') config.delete("watch")
end end
if config.key? 'server' if config.key?("server")
Jekyll::Deprecator.deprecation_message "The 'server' configuration option" \ Jekyll::Deprecator.deprecation_message "The 'server' configuration option" \
" is no longer accepted. Use the 'jekyll serve'" \ " is no longer accepted. Use the 'jekyll serve'" \
" subcommand to serve your site with WEBrick." " subcommand to serve your site with WEBrick."
config.delete('server') config.delete("server")
end end
renamed_key 'server_port', 'port', config renamed_key "server_port", "port", config
renamed_key 'plugins', 'plugins_dir', config renamed_key "plugins", "plugins_dir", config
renamed_key 'layouts', 'layouts_dir', config renamed_key "layouts", "layouts_dir", config
renamed_key 'data_source', 'data_dir', config renamed_key "data_source", "data_dir", config
if config.key? 'pygments' if config.key?("pygments")
Jekyll::Deprecator.deprecation_message "The 'pygments' configuration option" \ Jekyll::Deprecator.deprecation_message "The 'pygments' configuration option" \
" has been renamed to 'highlighter'. Please update your" \ " has been renamed to 'highlighter'. Please update your" \
" config file accordingly. The allowed values are 'rouge', " \ " config file accordingly. The allowed values are 'rouge', " \
"'pygments' or null." "'pygments' or null."
config['highlighter'] = 'pygments' if config['pygments'] config["highlighter"] = "pygments" if config["pygments"]
config.delete('pygments') config.delete("pygments")
end end
%w(include exclude).each do |option| %w(include exclude).each do |option|
@ -256,13 +261,13 @@ module Jekyll
config[option].map!(&:to_s) if config[option] config[option].map!(&:to_s) if config[option]
end end
if (config['kramdown'] || {}).key?('use_coderay') if (config["kramdown"] || {}).key?("use_coderay")
Jekyll::Deprecator.deprecation_message "Please change 'use_coderay'" \ Jekyll::Deprecator.deprecation_message "Please change 'use_coderay'" \
" to 'enable_coderay' in your configuration file." " to 'enable_coderay' in your configuration file."
config['kramdown']['use_coderay'] = config['kramdown'].delete('enable_coderay') config["kramdown"]["use_coderay"] = config["kramdown"].delete("enable_coderay")
end end
if config.fetch('markdown', 'kramdown').to_s.downcase.eql?("maruku") if config.fetch("markdown", "kramdown").to_s.casecmp("maruku") == 0
Jekyll.logger.abort_with "Error:", "You're using the 'maruku' " \ Jekyll.logger.abort_with "Error:", "You're using the 'maruku' " \
"Markdown processor, which has been removed as of 3.0.0. " \ "Markdown processor, which has been removed as of 3.0.0. " \
"We recommend you switch to Kramdown. To do this, replace " \ "We recommend you switch to Kramdown. To do this, replace " \
@ -276,10 +281,12 @@ module Jekyll
def fix_common_issues def fix_common_issues
config = clone config = clone
if config.key?('paginate') && (!config['paginate'].is_a?(Integer) || config['paginate'] < 1) if config.key?("paginate") && (!config["paginate"].is_a?(Integer) ||
Jekyll.logger.warn "Config Warning:", "The `paginate` key must be a" \ config["paginate"] < 1)
" positive integer or nil. It's currently set to '#{config['paginate'].inspect}'."
config['paginate'] = nil 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 end
config config

View File

@ -9,20 +9,24 @@ module Jekyll
'serve' subcommand." 'serve' subcommand."
arg_is_present? args, "--no-server", "To build Jekyll without launching a server, \ arg_is_present? args, "--no-server", "To build Jekyll without launching a server, \
use the 'build' subcommand." use the 'build' subcommand."
arg_is_present? args, "--auto", "The switch '--auto' has been replaced with '--watch'." arg_is_present? args, "--auto", "The switch '--auto' has been replaced with \
'--watch'."
arg_is_present? args, "--no-auto", "To disable auto-replication, simply leave off \ arg_is_present? args, "--no-auto", "To disable auto-replication, simply leave off \
the '--watch' switch." the '--watch' switch."
arg_is_present? args, "--pygments", "The 'pygments'settings has been removed in \ arg_is_present? args, "--pygments", "The 'pygments'settings has been removed in \
favour of 'highlighter'." favour of 'highlighter'."
arg_is_present? args, "--paginate", "The 'paginate' setting can only be set in your \ arg_is_present? args, "--paginate", "The 'paginate' setting can only be set in \
your config files."
arg_is_present? args, "--url", "The 'url' setting can only be set in your \
config files." config files."
arg_is_present? args, "--url", "The 'url' setting can only be set in your config files."
no_subcommand(args) no_subcommand(args)
end end
def no_subcommand(args) def no_subcommand(args)
if args.size > 0 && args.first =~ /^--/ && !%w(--help --version).include?(args.first) unless args.empty? ||
deprecation_message "Jekyll now uses subcommands instead of just switches. Run `jekyll help` to find out more." args.first !~ %r(!/^--/!) || %w(--help --version).include?(args.first)
deprecation_message "Jekyll now uses subcommands instead of just switches. \
Run `jekyll help` to find out more."
abort abort
end end
end end
@ -39,7 +43,8 @@ module Jekyll
def defaults_deprecate_type(old, current) def defaults_deprecate_type(old, current)
Jekyll.logger.warn "Defaults:", "The '#{old}' type has become '#{current}'." Jekyll.logger.warn "Defaults:", "The '#{old}' type has become '#{current}'."
Jekyll.logger.warn "Defaults:", "Please update your front-matter defaults to use 'type: #{current}'." Jekyll.logger.warn "Defaults:", "Please update your front-matter defaults to use \
'type: #{current}'."
end end
end end

View File

@ -23,7 +23,7 @@ module Jekyll
# A set of extensions that are considered HTML or HTML-like so we # A set of extensions that are considered HTML or HTML-like so we
# should not alter them, this includes .xhtml through XHTM5. # should not alter them, this includes .xhtml through XHTM5.
HTML_EXTENSIONS = %W( HTML_EXTENSIONS = %w(
.html .html
.xhtml .xhtml
.htm .htm