Rubocop tweaks
This commit is contained in:
parent
4be3fcfd31
commit
c87e2e026e
|
@ -31,7 +31,7 @@ HashSyntax:
|
||||||
EnforcedStyle: ruby19
|
EnforcedStyle: ruby19
|
||||||
SpaceAroundEqualsInParameterDefault:
|
SpaceAroundEqualsInParameterDefault:
|
||||||
EnforcedStyle: no_space
|
EnforcedStyle: no_space
|
||||||
Blocks:
|
BlockDelimiters:
|
||||||
Enabled: false
|
Enabled: false
|
||||||
PerlBackrefs:
|
PerlBackrefs:
|
||||||
Enabled: false
|
Enabled: false
|
||||||
|
|
|
@ -152,8 +152,8 @@ class Middleman::Extensions::Lorem < ::Middleman::Extension
|
||||||
color = options[:color]
|
color = options[:color]
|
||||||
|
|
||||||
if options[:random_color]
|
if options[:random_color]
|
||||||
background_color = hex.shuffle[0...6].join
|
background_color = hex.sample(6).join
|
||||||
color = hex.shuffle[0...6].join
|
color = hex.sample(6).join
|
||||||
end
|
end
|
||||||
|
|
||||||
src << "/#{background_color.sub(/^#/, '')}" if background_color
|
src << "/#{background_color.sub(/^#/, '')}" if background_color
|
||||||
|
|
|
@ -89,6 +89,7 @@ module Middleman
|
||||||
File.fnmatch(value, validator)
|
File.fnmatch(value, validator)
|
||||||
else
|
else
|
||||||
# If some unknown thing, don't ignore
|
# If some unknown thing, don't ignore
|
||||||
|
false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -14,6 +14,8 @@ module Middleman
|
||||||
extend Forwardable
|
extend Forwardable
|
||||||
include Contracts
|
include Contracts
|
||||||
|
|
||||||
|
Matcher = Or[Regexp, RespondTo[:call]]
|
||||||
|
|
||||||
# A reference to the current app.
|
# A reference to the current app.
|
||||||
Contract IsA['Middleman::Application']
|
Contract IsA['Middleman::Application']
|
||||||
attr_reader :app
|
attr_reader :app
|
||||||
|
@ -246,28 +248,24 @@ module Middleman
|
||||||
# Backwards compatible change handler.
|
# Backwards compatible change handler.
|
||||||
#
|
#
|
||||||
# @param [nil,Regexp] matcher A Regexp to match the change path against
|
# @param [nil,Regexp] matcher A Regexp to match the change path against
|
||||||
# Contract Maybe[Regexp] => Any
|
Contract Maybe[Matcher] => Any
|
||||||
def changed(matcher=nil, &block)
|
def changed(matcher=nil, &block)
|
||||||
on_change :source do |updated, _removed|
|
on_change :source do |updated, _removed|
|
||||||
updated.select { |f|
|
updated
|
||||||
matcher.nil? ? true : matches?(matcher, f)
|
.select { |f| matcher.nil? ? true : matches?(matcher, f) }
|
||||||
}.each do |f|
|
.each { |f| block.call(f[:relative_path]) }
|
||||||
block.call(f[:relative_path])
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Backwards compatible delete handler.
|
# Backwards compatible delete handler.
|
||||||
#
|
#
|
||||||
# @param [nil,Regexp] matcher A Regexp to match the change path against
|
# @param [nil,Regexp] matcher A Regexp to match the change path against
|
||||||
# Contract Maybe[Regexp] => Any
|
Contract Maybe[Matcher] => Any
|
||||||
def deleted(matcher=nil, &block)
|
def deleted(matcher=nil, &block)
|
||||||
on_change :source do |_updated, removed|
|
on_change :source do |_updated, removed|
|
||||||
removed.select { |f|
|
removed
|
||||||
matcher.nil? ? true : matches?(matcher, f)
|
.select { |f| matcher.nil? ? true : matches?(matcher, f) }
|
||||||
}.each do |f|
|
.each { |f| block.call(f[:relative_path]) }
|
||||||
block.call(f[:relative_path])
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -287,7 +285,7 @@ module Middleman
|
||||||
# @param [Regexp, #call] validator The match validator.
|
# @param [Regexp, #call] validator The match validator.
|
||||||
# @param [Middleman::SourceFile] file The file to check.
|
# @param [Middleman::SourceFile] file The file to check.
|
||||||
# @return [Boolean]
|
# @return [Boolean]
|
||||||
Contract Or[Regexp, RespondTo[:call]], SourceFile => Bool
|
Contract Matcher, SourceFile => Bool
|
||||||
def matches?(validator, file)
|
def matches?(validator, file)
|
||||||
path = file[:relative_path]
|
path = file[:relative_path]
|
||||||
if validator.is_a? Regexp
|
if validator.is_a? Regexp
|
||||||
|
|
|
@ -252,7 +252,7 @@ module Middleman
|
||||||
|
|
||||||
Contract Pathname => Pathname
|
Contract Pathname => Pathname
|
||||||
def strip_extensions(p)
|
def strip_extensions(p)
|
||||||
p = p.sub_ext('') while ::Tilt[p.to_s] || p.extname === '.html'
|
p = p.sub_ext('') while ::Tilt[p.to_s] || p.extname == '.html'
|
||||||
Pathname(p.to_s + '.*')
|
Pathname(p.to_s + '.*')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -262,9 +262,9 @@ module Middleman
|
||||||
# @return [Boolean]
|
# @return [Boolean]
|
||||||
Contract IsA['Middleman::SourceFile'] => Bool
|
Contract IsA['Middleman::SourceFile'] => Bool
|
||||||
def valid?(file)
|
def valid?(file)
|
||||||
globally_valid = @validator.call(file) && !globally_ignored?(file)
|
return false unless @validator.call(file) && !globally_ignored?(file)
|
||||||
|
|
||||||
globally_valid && if @only.empty?
|
if @only.empty?
|
||||||
!@ignored.call(file)
|
!@ignored.call(file)
|
||||||
else
|
else
|
||||||
@only.any? { |reg| reg.match(file[:relative_path].to_s) }
|
@only.any? { |reg| reg.match(file[:relative_path].to_s) }
|
||||||
|
|
|
@ -87,13 +87,11 @@ module Middleman
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def method_missing(key, *args)
|
def method_missing(key, *_args)
|
||||||
if key?(key.to_sym)
|
if key?(key.to_sym)
|
||||||
self[key.to_sym]
|
self[key.to_sym]
|
||||||
elsif key?(key.to_s)
|
elsif key?(key.to_s)
|
||||||
self[key.to_s]
|
self[key.to_s]
|
||||||
else
|
|
||||||
super
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -131,7 +129,6 @@ module Middleman
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
# Normalize a path to not include a leading slash
|
# Normalize a path to not include a leading slash
|
||||||
# @param [String] path
|
# @param [String] path
|
||||||
# @return [String]
|
# @return [String]
|
||||||
|
|
Loading…
Reference in a new issue