Skip to content

Commit

Permalink
Rubocop cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
DirtyF committed Jun 6, 2016
1 parent 1f01c88 commit f41bd1b
Show file tree
Hide file tree
Showing 6 changed files with 125 additions and 107 deletions.
1 change: 0 additions & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 12 additions & 9 deletions lib/jekyll/collection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ def respond_to?(method, include_private = false)
# 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
Expand Down Expand Up @@ -64,8 +65,10 @@ def read
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!
Expand All @@ -79,7 +82,7 @@ def entries
return [] unless exists?
@entries ||=
Utils.safe_glob(collection_dir, ["**", "*"]).map do |entry|
entry["#{collection_dir}/"] = ''
entry["#{collection_dir}/"] = ""
entry
end
end
Expand Down Expand Up @@ -161,7 +164,7 @@ def inspect
#
# 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.
Expand All @@ -179,14 +182,14 @@ def to_liquid
#
# 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
Expand All @@ -195,8 +198,8 @@ def url_template
#
# 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
Expand Down
30 changes: 17 additions & 13 deletions lib/jekyll/command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,23 @@ def configuration_from_options(options)
#
# 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
Expand Down
161 changes: 84 additions & 77 deletions lib/jekyll/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,71 +6,71 @@ class Configuration < Hash
# 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

Expand Down Expand Up @@ -108,28 +108,29 @@ def get_config_value_with_override(config_key, override)
#
# 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

Expand All @@ -140,12 +141,15 @@ def safe_load_file(filename)
# 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}")
Expand All @@ -170,7 +174,8 @@ def read_config_file(file)
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
Expand All @@ -193,7 +198,7 @@ def read_config_files(files)
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
Expand All @@ -215,34 +220,34 @@ def csv_to_array(csv)
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|
Expand All @@ -256,13 +261,13 @@ def backwards_compatibilize
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 " \
Expand All @@ -276,10 +281,12 @@ def backwards_compatibilize
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
Expand Down
Loading

0 comments on commit f41bd1b

Please sign in to comment.