Merge pull request #4940 from DirtyF/feature-rubocop
Merge pull request 4940
This commit is contained in:
		
						commit
						c8606c5765
					
				|  | @ -8,7 +8,6 @@ AllCops: | |||
|   - lib/jekyll/command.rb | ||||
|   - lib/jekyll/configuration.rb | ||||
|   - lib/jekyll/convertible.rb | ||||
|   - lib/jekyll/deprecator.rb | ||||
|   - lib/jekyll/document.rb | ||||
|   - lib/jekyll/filters.rb | ||||
|   - lib/jekyll/regenerator.rb | ||||
|  |  | |||
|  | @ -32,7 +32,8 @@ module Jekyll | |||
|     # Override of method_missing to check in @data for the key. | ||||
|     def method_missing(method, *args, &blck) | ||||
|       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}." | ||||
|         docs.public_send(method.to_sym, *args, &blck) | ||||
|       else | ||||
|  | @ -64,8 +65,10 @@ module Jekyll | |||
|             Jekyll.logger.debug "Skipped From Publishing:", doc.relative_path | ||||
|           end | ||||
|         else | ||||
|           relative_dir = Jekyll.sanitized_path(relative_directory, File.dirname(file_path)).chomp("/.") | ||||
|           files << StaticFile.new(site, site.source, relative_dir, File.basename(full_path), self) | ||||
|           relative_dir = Jekyll.sanitized_path(relative_directory, | ||||
|             File.dirname(file_path)).chomp("/.") | ||||
|           files << StaticFile.new(site, site.source, relative_dir, | ||||
|             File.basename(full_path), self) | ||||
|         end | ||||
|       end | ||||
|       docs.sort! | ||||
|  | @ -79,7 +82,7 @@ module Jekyll | |||
|       return [] unless exists? | ||||
|       @entries ||= | ||||
|         Utils.safe_glob(collection_dir, ["**", "*"]).map do |entry| | ||||
|           entry["#{collection_dir}/"] = '' | ||||
|           entry["#{collection_dir}/"] = "" | ||||
|           entry | ||||
|         end | ||||
|     end | ||||
|  | @ -161,7 +164,7 @@ module Jekyll | |||
|     # | ||||
|     # Returns a sanitized version of the label. | ||||
|     def sanitize_label(label) | ||||
|       label.gsub(/[^a-z0-9_\-\.]/i, '') | ||||
|       label.gsub(/[^a-z0-9_\-\.]/i, "") | ||||
|     end | ||||
| 
 | ||||
|     # 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. | ||||
|     def write? | ||||
|       !!metadata.fetch('output', false) | ||||
|       !!metadata.fetch("output", false) | ||||
|     end | ||||
| 
 | ||||
|     # The URL template to render collection's documents at. | ||||
|     # | ||||
|     # Returns the URL template to render collection's documents at. | ||||
|     def url_template | ||||
|       @url_template ||= metadata.fetch('permalink') do | ||||
|       @url_template ||= metadata.fetch("permalink") do | ||||
|         Utils.add_permalink_suffix("/:collection/:path", site.permalink_style) | ||||
|       end | ||||
|     end | ||||
|  | @ -195,8 +198,8 @@ module Jekyll | |||
|     # | ||||
|     # Returns the metadata for this collection | ||||
|     def extract_metadata | ||||
|       if site.config['collections'].is_a?(Hash) | ||||
|         site.config['collections'][label] || {} | ||||
|       if site.config["collections"].is_a?(Hash) | ||||
|         site.config["collections"][label] || {} | ||||
|       else | ||||
|         {} | ||||
|       end | ||||
|  |  | |||
|  | @ -46,19 +46,23 @@ module Jekyll | |||
|       # | ||||
|       # Returns nothing | ||||
|       def add_build_options(c) | ||||
|         c.option 'config',  '--config CONFIG_FILE[,CONFIG_FILE2,...]', Array, 'Custom configuration file' | ||||
|         c.option 'destination', '-d', '--destination DESTINATION', 'The current folder will be generated into DESTINATION' | ||||
|         c.option 'source', '-s', '--source SOURCE', 'Custom source directory' | ||||
|         c.option 'future',  '--future', 'Publishes posts with a future date' | ||||
|         c.option 'limit_posts', '--limit_posts MAX_POSTS', Integer, 'Limits the number of posts to parse and publish' | ||||
|         c.option 'watch',   '-w', '--[no-]watch', 'Watch for changes and rebuild' | ||||
|         c.option 'force_polling', '--force_polling', 'Force watch to use polling' | ||||
|         c.option 'lsi',     '--lsi', 'Use LSI for improved related posts' | ||||
|         c.option 'show_drafts',  '-D', '--drafts', 'Render posts in the _drafts folder' | ||||
|         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.' | ||||
|         c.option "config", "--config CONFIG_FILE[,CONFIG_FILE2,...]", | ||||
|           Array, "Custom configuration file" | ||||
|         c.option "destination", "-d", "--destination DESTINATION", | ||||
|           "The current folder will be generated into DESTINATION" | ||||
|         c.option "source", "-s", "--source SOURCE", "Custom source directory" | ||||
|         c.option "future", "--future", "Publishes posts with a future date" | ||||
|         c.option "limit_posts", "--limit_posts MAX_POSTS", Integer, | ||||
|           "Limits the number of posts to parse and publish" | ||||
|         c.option "watch", "-w", "--[no-]watch", "Watch for changes and rebuild" | ||||
|         c.option "force_polling", "--force_polling", "Force watch to use polling" | ||||
|         c.option "lsi", "--lsi", "Use LSI for improved related posts" | ||||
|         c.option "show_drafts", "-D", "--drafts", "Render posts in the _drafts folder" | ||||
|         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 | ||||
|  |  | |||
|  | @ -6,71 +6,71 @@ module Jekyll | |||
|     # Strings rather than symbols are used for compatibility with YAML. | ||||
|     DEFAULTS = 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'   => {}, | ||||
|       "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'], | ||||
|       'exclude'       => [], | ||||
|       'keep_files'    => ['.git', '.svn'], | ||||
|       'encoding'      => 'utf-8', | ||||
|       'markdown_ext'  => 'markdown,mkdown,mkdn,mkd,md', | ||||
|       "safe"              => false, | ||||
|       "include"           => [".htaccess"], | ||||
|       "exclude"           => [], | ||||
|       "keep_files"        => [".git", ".svn"], | ||||
|       "encoding"          => "utf-8", | ||||
|       "markdown_ext"      => "markdown,mkdown,mkdn,mkd,md", | ||||
| 
 | ||||
|       # Filtering Content | ||||
|       'show_drafts'   => nil, | ||||
|       'limit_posts'   => 0, | ||||
|       'future'        => false, | ||||
|       'unpublished'   => false, | ||||
|       "show_drafts"       => nil, | ||||
|       "limit_posts"       => 0, | ||||
|       "future"            => false, | ||||
|       "unpublished"       => false, | ||||
| 
 | ||||
|       # Plugins | ||||
|       'whitelist'     => [], | ||||
|       'gems'          => [], | ||||
|       "whitelist"         => [], | ||||
|       "gems"              => [], | ||||
| 
 | ||||
|       # Conversion | ||||
|       'markdown'      => 'kramdown', | ||||
|       'highlighter'   => 'rouge', | ||||
|       'lsi'           => false, | ||||
|       'excerpt_separator' => "\n\n", | ||||
|       'incremental'   => false, | ||||
|       "markdown"          => "kramdown", | ||||
|       "highlighter"       => "rouge", | ||||
|       "lsi"               => false, | ||||
|       "excerpt_separator" => "\n\n", | ||||
|       "incremental"       => false, | ||||
| 
 | ||||
|       # Serving | ||||
|       'detach'        => false,          # default to not detaching the server | ||||
|       'port'          => '4000', | ||||
|       'host'          => '127.0.0.1', | ||||
|       'baseurl'       => '', | ||||
|       'show_dir_listing' => false, | ||||
|       "detach"            => false, # default to not detaching the server | ||||
|       "port"              => "4000", | ||||
|       "host"              => "127.0.0.1", | ||||
|       "baseurl"           => "", | ||||
|       "show_dir_listing"  => false, | ||||
| 
 | ||||
|       # Output Configuration | ||||
|       'permalink'     => 'date', | ||||
|       'paginate_path' => '/page:num', | ||||
|       'timezone'      => nil,           # use the local timezone | ||||
|       "permalink"         => "date", | ||||
|       "paginate_path"     => "/page:num", | ||||
|       "timezone"          => nil, # use the local timezone | ||||
| 
 | ||||
|       'quiet'         => false, | ||||
|       'verbose'       => false, | ||||
|       'defaults'      => [], | ||||
|       "quiet"             => false, | ||||
|       "verbose"           => false, | ||||
|       "defaults"          => [], | ||||
| 
 | ||||
|       'rdiscount' => { | ||||
|         'extensions' => [] | ||||
|       "rdiscount"         => { | ||||
|         "extensions" => [] | ||||
|       }, | ||||
| 
 | ||||
|       'redcarpet' => { | ||||
|         'extensions' => [] | ||||
|       "redcarpet"         => { | ||||
|         "extensions" => [] | ||||
|       }, | ||||
| 
 | ||||
|       'kramdown' => { | ||||
|         'auto_ids'       => true, | ||||
|         'toc_levels'     => '1..6', | ||||
|         'entity_output'  => 'as_char', | ||||
|         'smart_quotes'   => 'lsquo,rsquo,ldquo,rdquo', | ||||
|         'input'          => "GFM", | ||||
|         'hard_wrap'      => false, | ||||
|         'footnote_nr'    => 1 | ||||
|       "kramdown"          => { | ||||
|         "auto_ids"      => true, | ||||
|         "toc_levels"    => "1..6", | ||||
|         "entity_output" => "as_char", | ||||
|         "smart_quotes"  => "lsquo,rsquo,ldquo,rdquo", | ||||
|         "input"         => "GFM", | ||||
|         "hard_wrap"     => false, | ||||
|         "footnote_nr"   => 1 | ||||
|       } | ||||
|     }.map { |k, v| [k, v.freeze] }].freeze | ||||
| 
 | ||||
|  | @ -108,28 +108,29 @@ module Jekyll | |||
|     # | ||||
|     # Returns the path to the Jekyll source directory | ||||
|     def source(override) | ||||
|       get_config_value_with_override('source', override) | ||||
|       get_config_value_with_override("source", override) | ||||
|     end | ||||
| 
 | ||||
|     def quiet(override = {}) | ||||
|       get_config_value_with_override('quiet', override) | ||||
|       get_config_value_with_override("quiet", override) | ||||
|     end | ||||
|     alias_method :quiet?, :quiet | ||||
| 
 | ||||
|     def verbose(override = {}) | ||||
|       get_config_value_with_override('verbose', override) | ||||
|       get_config_value_with_override("verbose", override) | ||||
|     end | ||||
|     alias_method :verbose?, :verbose | ||||
| 
 | ||||
|     def safe_load_file(filename) | ||||
|       case File.extname(filename) | ||||
|       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) | ||||
|       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." | ||||
|         raise ArgumentError, "No parser for '#{filename}' is available. | ||||
|           Use a .toml or .y(a)ml file instead." | ||||
|       end | ||||
|     end | ||||
| 
 | ||||
|  | @ -140,12 +141,15 @@ module Jekyll | |||
|     # Returns an Array of config files | ||||
|     def config_files(override) | ||||
|       # 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> | ||||
|       config_files = override.delete('config') | ||||
|       config_files = override.delete("config") | ||||
|       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}")) | ||||
|         end | ||||
|         config_files = Jekyll.sanitized_path(source(override), "_config.#{default}") | ||||
|  | @ -170,7 +174,8 @@ module Jekyll | |||
|         Jekyll.logger.warn "Configuration file:", "none" | ||||
|         {} | ||||
|       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." | ||||
|       end | ||||
|     end | ||||
|  | @ -193,7 +198,7 @@ module Jekyll | |||
|       rescue ArgumentError => err | ||||
|         Jekyll.logger.warn "WARNING:", "Error reading configuration. " \ | ||||
|                      "Using defaults (and options)." | ||||
|         $stderr.puts "#{err}" | ||||
|         $stderr.puts err | ||||
|       end | ||||
| 
 | ||||
|       configuration.fix_common_issues.backwards_compatibilize.add_default_collections | ||||
|  | @ -215,34 +220,34 @@ module Jekyll | |||
|     def backwards_compatibilize | ||||
|       config = clone | ||||
|       # 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" \ | ||||
|                             " 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." | ||||
|         config.delete('auto') | ||||
|         config.delete('watch') | ||||
|         config.delete("auto") | ||||
|         config.delete("watch") | ||||
|       end | ||||
| 
 | ||||
|       if config.key? 'server' | ||||
|       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') | ||||
|         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 | ||||
|       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' | ||||
|       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') | ||||
|         config["highlighter"] = "pygments" if config["pygments"] | ||||
|         config.delete("pygments") | ||||
|       end | ||||
| 
 | ||||
|       %w(include exclude).each do |option| | ||||
|  | @ -256,13 +261,13 @@ module Jekyll | |||
|         config[option].map!(&:to_s) if config[option] | ||||
|       end | ||||
| 
 | ||||
|       if (config['kramdown'] || {}).key?('use_coderay') | ||||
|       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') | ||||
|         config["kramdown"]["use_coderay"] = config["kramdown"].delete("enable_coderay") | ||||
|       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' " \ | ||||
|           "Markdown processor, which has been removed as of 3.0.0. " \ | ||||
|           "We recommend you switch to Kramdown. To do this, replace " \ | ||||
|  | @ -276,10 +281,12 @@ module Jekyll | |||
|     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 | ||||
|       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 | ||||
|  |  | |||
|  | @ -9,20 +9,24 @@ module Jekyll | |||
|                           'serve' subcommand." | ||||
|       arg_is_present? args, "--no-server", "To build Jekyll without launching a server, \ | ||||
|                           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 \ | ||||
|                           the '--watch' switch." | ||||
|       arg_is_present? args, "--pygments", "The 'pygments'settings has been removed in \ | ||||
|                           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." | ||||
|       arg_is_present? args, "--url", "The 'url' setting can only be set in your config files." | ||||
|       no_subcommand(args) | ||||
|     end | ||||
| 
 | ||||
|     def no_subcommand(args) | ||||
|       if args.size > 0 && args.first =~ /^--/ && !%w(--help --version).include?(args.first) | ||||
|         deprecation_message "Jekyll now uses subcommands instead of just switches. Run `jekyll help` to find out more." | ||||
|       unless args.empty? || | ||||
|           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 | ||||
|       end | ||||
|     end | ||||
|  | @ -39,7 +43,8 @@ module Jekyll | |||
| 
 | ||||
|     def defaults_deprecate_type(old, 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 | ||||
|  |  | |||
|  | @ -23,7 +23,7 @@ module Jekyll | |||
|     # A set of extensions that are considered HTML or HTML-like so we | ||||
|     # should not alter them,  this includes .xhtml through XHTM5. | ||||
| 
 | ||||
|     HTML_EXTENSIONS = %W( | ||||
|     HTML_EXTENSIONS = %w( | ||||
|       .html | ||||
|       .xhtml | ||||
|       .htm | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue