Implemented Rubocop

- just took a stab at running the StringLiterals cop to get a taste.
This commit is contained in:
Karl Freeman 2013-12-28 00:26:31 +00:00
parent e996868033
commit 03d6e6c990
80 changed files with 510 additions and 477 deletions

View file

@ -28,7 +28,7 @@ module Middleman
def ignored?
@app.ignore_manager.ignored?(path) ||
(!proxy? &&
@app.ignore_manager.ignored?(source_file.sub("#{@app.source_dir}/", ""))
@app.ignore_manager.ignored?(source_file.sub("#{@app.source_dir}/", ''))
)
end
end
@ -64,7 +64,7 @@ module Middleman
@ignored_callbacks << Proc.new {|p| p =~ path }
elsif path.is_a? String
path_clean = ::Middleman::Util.normalize_path(path)
if path_clean.include?("*") # It's a glob
if path_clean.include?('*') # It's a glob
@ignored_callbacks << Proc.new {|p| File.fnmatch(path_clean, p) }
else
# Add a specific-path ignore unless that path is already covered

View file

@ -8,7 +8,7 @@ module Middleman
# This resource's parent resource
# @return [Middleman::Sitemap::Resource, nil]
def parent
parts = path.split("/")
parts = path.split('/')
parts.pop if path.include?(app.index_file)
return nil if parts.length < 1
@ -16,7 +16,7 @@ module Middleman
parts.pop
parts << app.index_file
parent_path = "/" + parts.join("/")
parent_path = '/' + parts.join('/')
store.find_resource_by_destination_path(parent_path)
end
@ -30,7 +30,7 @@ module Middleman
base_path = eponymous_directory_path
prefix = %r|^#{base_path.sub("/", "\\/")}|
else
base_path = path.sub("#{app.index_file}", "")
base_path = path.sub("#{app.index_file}", '')
prefix = %r|^#{base_path.sub("/", "\\/")}|
end
@ -38,8 +38,8 @@ module Middleman
if sub_resource.path == self.path || sub_resource.path !~ prefix
false
else
inner_path = sub_resource.path.sub(prefix, "")
parts = inner_path.split("/")
inner_path = sub_resource.path.sub(prefix, '')
parts = inner_path.split('/')
if parts.length == 1
true
elsif parts.length == 2
@ -79,7 +79,7 @@ module Middleman
# (e.g., for 'gallery.html' this would return 'gallery/')
# @return [String]
def eponymous_directory_path
path.sub(ext, '/').sub(/\/$/, "") + "/"
path.sub(ext, '/').sub(/\/$/, '') + '/'
end
end
end

View file

@ -1,4 +1,4 @@
require "active_support/core_ext/object/inclusion"
require 'active_support/core_ext/object/inclusion'
module Middleman
module Sitemap

View file

@ -1,5 +1,5 @@
require "middleman-core/sitemap/extensions/traversal"
require "middleman-core/sitemap/extensions/content_type"
require 'middleman-core/sitemap/extensions/traversal'
require 'middleman-core/sitemap/extensions/content_type'
module Middleman
@ -111,14 +111,14 @@ module Middleman
relative_source = Pathname(source_file).relative_path_from(Pathname(app.root))
instrument "render.resource", :path => relative_source do
instrument 'render.resource', :path => relative_source do
md = metadata.dup
opts = md[:options].deep_merge(opts)
# Pass "renderer_options" hash from frontmatter along to renderer
if md[:page]["renderer_options"]
if md[:page]['renderer_options']
opts[:renderer_options] = {}
md[:page]["renderer_options"].each do |k, v|
md[:page]['renderer_options'].each do |k, v|
opts[:renderer_options][k.to_sym] = v
end
end
@ -127,7 +127,7 @@ module Middleman
# Forward remaining data to helpers
if md.has_key?(:page)
app.data.store("page", md[:page])
app.data.store('page', md[:page])
end
blocks = Array(md[:blocks]).dup

View file

@ -1,7 +1,7 @@
# Used for merging results of metadata callbacks
require "active_support/core_ext/hash/deep_merge"
require 'active_support/core_ext/hash/deep_merge'
require 'monitor'
require "middleman-core/sitemap/queryable"
require 'middleman-core/sitemap/queryable'
module Middleman
@ -161,7 +161,7 @@ module Middleman
when Regexp
next result unless request_path =~ matcher
when String
next result unless File.fnmatch("/" + Util.strip_leading_slash(matcher), "/#{request_path}")
next result unless File.fnmatch('/' + Util.strip_leading_slash(matcher), "/#{request_path}")
end
metadata = callback.call(request_path).dup
@ -178,14 +178,14 @@ module Middleman
def file_to_path(file)
file = File.join(@app.root, file)
prefix = @app.source_dir.sub(/\/$/, "") + "/"
prefix = @app.source_dir.sub(/\/$/, '') + '/'
return false unless file.start_with?(prefix)
path = file.sub(prefix, "")
path = file.sub(prefix, '')
# Replace a file name containing automatic_directory_matcher with a folder
unless @app.config[:automatic_directory_matcher].nil?
path = path.gsub(@app.config[:automatic_directory_matcher], "/")
path = path.gsub(@app.config[:automatic_directory_matcher], '/')
end
extensionless_path(path)
@ -211,7 +211,7 @@ module Middleman
return unless @needs_sitemap_rebuild
@needs_sitemap_rebuild = false
@app.logger.debug "== Rebuilding resource list"
@app.logger.debug '== Rebuilding resource list'
@resources = @resource_list_manipulators.inject([]) do |result, (_, inst)|
newres = inst.manipulate_resource_list(result)
@ -244,7 +244,7 @@ module Middleman
# @return [String]
def remove_templating_extensions(path)
# Strip templating extensions as long as Tilt knows them
path = path.sub(File.extname(path), "") while ::Tilt[path]
path = path.sub(File.extname(path), '') while ::Tilt[path]
path
end
@ -270,7 +270,7 @@ module Middleman
input_ext = File.extname(file)
if !input_ext.empty?
input_ext = input_ext.split(".").last.to_sym
input_ext = input_ext.split('.').last.to_sym
if @app.template_extensions.has_key?(input_ext)
path << ".#{@app.template_extensions[input_ext]}"
end