rubocoping2

This commit is contained in:
Thomas Reynolds 2014-07-02 10:39:43 -07:00
commit 52c8109ca3
8 changed files with 79 additions and 90 deletions

View file

@ -170,10 +170,10 @@ module Middleman::Cli
path.to_s !~ /\/\./ || path.to_s =~ /\.(htaccess|htpasswd)/
end
if RUBY_PLATFORM =~ /darwin/
# handle UTF-8-MAC filename on MacOS
@to_clean = @to_clean.map { |path| path.to_s.encode('UTF-8', 'UTF-8-MAC') }
end
return unless RUBY_PLATFORM =~ /darwin/
# handle UTF-8-MAC filename on MacOS
@to_clean = @to_clean.map { |path| path.to_s.encode('UTF-8', 'UTF-8-MAC') }
end
# Actually build the app
@ -222,14 +222,14 @@ module Middleman::Cli
output_path = render_to_file(resource)
if should_clean? && output_path.exist?
if RUBY_PLATFORM =~ /darwin/
# handle UTF-8-MAC filename on MacOS
return unless should_clean? && output_path.exist?
@to_clean.delete(output_path.realpath.to_s.encode('UTF-8', 'UTF-8-MAC'))
else
@to_clean.delete(output_path.realpath)
end
if RUBY_PLATFORM =~ /darwin/
# handle UTF-8-MAC filename on MacOS
@to_clean.delete(output_path.realpath.to_s.encode('UTF-8', 'UTF-8-MAC'))
else
@to_clean.delete(output_path.realpath)
end
end
@ -281,9 +281,7 @@ module Middleman::Cli
end
def binary_encode(string)
if string.respond_to?(:force_encoding)
string.force_encoding('ascii-8bit')
end
string.force_encoding('ascii-8bit') if string.respond_to?(:force_encoding)
string
end
end

View file

@ -92,10 +92,10 @@ class Middleman::CoreExtensions::Internationalization < ::Middleman::Extension
private
def on_file_changed(file)
if @locales_regex =~ file
@langs = nil # Clear langs cache
::I18n.reload!
end
return unless @locales_regex =~ file
@_langs = nil # Clear langs cache
::I18n.reload!
end
def convert_glob_to_regex(glob)
@ -109,10 +109,9 @@ class Middleman::CoreExtensions::Internationalization < ::Middleman::Extension
::I18n.reload!
::I18n.default_locale = @mount_at_root
# Reset fallbacks to fall back to our new default
if ::I18n.respond_to? :fallbacks
::I18n.fallbacks = ::I18n::Locale::Fallbacks.new
end
::I18n.fallbacks = ::I18n::Locale::Fallbacks.new if ::I18n.respond_to?(:fallbacks)
end
def known_languages

View file

@ -269,10 +269,10 @@ module Middleman
def bind_before_configuration
ext = self
if ext.respond_to?(:before_configuration)
@klass.before_configuration do
ext.before_configuration
end
return unless ext.respond_to?(:before_configuration)
@klass.before_configuration do
ext.before_configuration
end
end
@ -289,26 +289,26 @@ module Middleman
def bind_before_build
ext = self
if ext.respond_to?(:before_build)
@klass.before_build do |builder|
if ext.method(:before_build).arity == 1
ext.before_build(builder)
else
ext.before_build
end
return unless ext.respond_to?(:before_build)
@klass.before_build do |builder|
if ext.method(:before_build).arity == 1
ext.before_build(builder)
else
ext.before_build
end
end
end
def bind_after_build
ext = self
if ext.respond_to?(:after_build)
@klass.after_build do |builder|
if ext.method(:after_build).arity == 1
ext.after_build(builder)
else
ext.after_build
end
return unless ext.respond_to?(:after_build)
@klass.after_build do |builder|
if ext.method(:after_build).arity == 1
ext.after_build(builder)
else
ext.after_build
end
end
end

View file

@ -59,11 +59,11 @@ class Middleman::Extensions::Gzip < ::Middleman::Extension
num_paths.times do
output_filename, old_size, new_size = out_queue.pop
if output_filename
total_savings += (old_size - new_size)
size_change_word = (old_size - new_size) > 0 ? 'smaller' : 'larger'
builder.say_status :gzip, "#{output_filename} (#{NumberHelpers.new.number_to_human_size((old_size - new_size).abs)} #{size_change_word})"
end
next unless output_filename
total_savings += (old_size - new_size)
size_change_word = (old_size - new_size) > 0 ? 'smaller' : 'larger'
builder.say_status :gzip, "#{output_filename} (#{NumberHelpers.new.number_to_human_size((old_size - new_size).abs)} #{size_change_word})"
end
builder.say_status :gzip, "Total gzip savings: #{NumberHelpers.new.number_to_human_size(total_savings)}", :blue

View file

@ -22,26 +22,25 @@ module Middleman
logger.info "== Inspect your site configuration at #{uri + '__middleman'}"
@initialized ||= false
unless @initialized
@initialized = true
return if @initialized
@initialized = true
register_signal_handlers
register_signal_handlers
# Save the last-used @options so it may be re-used when
# reloading later on.
::Middleman::Profiling.report('server_start')
# Save the last-used @options so it may be re-used when
# reloading later on.
::Middleman::Profiling.report('server_start')
loop do
@webrick.start
loop do
@webrick.start
# @mm_shutdown is set by the signal handler
if @mm_shutdown
shutdown
exit
elsif @mm_reload
@mm_reload = false
reload
end
# $mm_shutdown is set by the signal handler
if $mm_shutdown
shutdown
exit
elsif $mm_reload
$mm_reload = false
reload
end
end
end
@ -106,9 +105,7 @@ module Middleman
opts[:instrumenting] || false
)
if opts[:environment]
config[:environment] = opts[:environment].to_sym
end
config[:environment] = opts[:environment].to_sym if opts[:environment]
end
end
@ -152,12 +149,12 @@ module Middleman
# @return [void]
def register_signal_handlers
%w(INT HUP TERM QUIT).each do |sig|
if Signal.list[sig]
Signal.trap(sig) do
# Do as little work as possible in the signal context
@mm_shutdown = true
@webrick.stop
end
next unless Signal.list[sig]
Signal.trap(sig) do
# Do as little work as possible in the signal context
$mm_shutdown = true
@webrick.stop
end
end
end
@ -240,9 +237,7 @@ module Middleman
class FilteredWebrickLog < ::WEBrick::Log
def log(level, data)
unless data =~ %r{Could not determine content-length of response body.}
super(level, data)
end
super(level, data) unless data =~ %r{Could not determine content-length of response body.}
end
end
end

View file

@ -20,8 +20,8 @@ module Middleman
# Pick a renderer
renderer = MiddlemanRedcarpetHTML
# Support SmartyPants
if options.delete(:smartypants)
# Support SmartyPants
renderer = Class.new(renderer) do
include ::Redcarpet::Render::SmartyPants
end
@ -30,9 +30,8 @@ module Middleman
# Renderer Options
possible_render_opts = [:filter_html, :no_images, :no_links, :no_styles, :safe_links_only, :with_toc_data, :hard_wrap, :xhtml, :prettify, :link_attributes]
render_options = possible_render_opts.reduce({}) do |sum, opt|
render_options = possible_render_opts.each_with_object({}) do |opt, sum|
sum[opt] = options.delete(opt) if options.key?(opt)
sum
end
renderer.new(render_options)
@ -71,7 +70,7 @@ module Middleman
else
link_string = link.dup
link_string << %Q("#{title}") if title && title.length > 0 && title != alt_text
%Q{![#{alt_text}](#{link_string})}
"![#{alt_text}](#{link_string})"
end
end
@ -84,7 +83,7 @@ module Middleman
else
link_string = link.dup
link_string << %Q("#{title}") if title && title.length > 0 && title != alt_text
%Q{[#{content}](#{link_string})}
"[#{content}](#{link_string})"
end
end
end

View file

@ -59,25 +59,22 @@ module Middleman
# whether or not it belongs in the sitemap (like a partial)
@sitemap.rebuild_resource_list!(:touched_file)
unless waiting_for_ready || @app.build?
# Force sitemap rebuild so the next request is ready to go.
# Skip this during build because the builder will control sitemap refresh.
@sitemap.ensure_resource_list_updated!
end
# Force sitemap rebuild so the next request is ready to go.
# Skip this during build because the builder will control sitemap refresh.
@sitemap.ensure_resource_list_updated! unless waiting_for_ready || @app.build?
end
# Remove a file from the store
# @param [String] file
# @return [void]
def remove_file(file)
if @file_paths_on_disk.delete?(file)
@sitemap.rebuild_resource_list!(:removed_file)
unless waiting_for_ready || @app.build?
# Force sitemap rebuild so the next request is ready to go.
# Skip this during build because the builder will control sitemap refresh.
@sitemap.ensure_resource_list_updated!
end
end
return unless @file_paths_on_disk.delete?(file)
@sitemap.rebuild_resource_list!(:removed_file)
# Force sitemap rebuild so the next request is ready to go.
# Skip this during build because the builder will control sitemap refresh.
@sitemap.ensure_resource_list_updated! unless waiting_for_ready || @app.build?
end
# Update the main sitemap resource list

View file

@ -75,6 +75,7 @@ module Middleman
if !path.end_with?("/#{@app.config[:index_file]}") && destination_path.end_with?("/#{@app.config[:index_file]}")
return true
end
full_path = File.join(@app.source_dir, eponymous_directory_path)
File.exist?(full_path) && File.directory?(full_path)
end