rubocoping
This commit is contained in:
parent
bbc551624e
commit
7b85a44afb
|
@ -1,5 +1,6 @@
|
||||||
# Setup our load paths
|
|
||||||
# rubocop:disable FileName
|
# rubocop:disable FileName
|
||||||
|
|
||||||
|
# Setup our load paths
|
||||||
libdir = File.expand_path(File.dirname(__FILE__))
|
libdir = File.expand_path(File.dirname(__FILE__))
|
||||||
$LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir)
|
$LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir)
|
||||||
|
|
||||||
|
|
|
@ -168,11 +168,11 @@ module Middleman::Cli
|
||||||
path.to_s !~ /\/\./ || path.to_s =~ /\.(htaccess|htpasswd)/
|
path.to_s !~ /\/\./ || path.to_s =~ /\.(htaccess|htpasswd)/
|
||||||
end
|
end
|
||||||
|
|
||||||
if RUBY_PLATFORM =~ /darwin/
|
return unless RUBY_PLATFORM =~ /darwin/
|
||||||
|
|
||||||
# handle UTF-8-MAC filename on MacOS
|
# handle UTF-8-MAC filename on MacOS
|
||||||
@to_clean = @to_clean.map { |path| path.to_s.encode('UTF-8', 'UTF-8-MAC') }
|
@to_clean = @to_clean.map { |path| path.to_s.encode('UTF-8', 'UTF-8-MAC') }
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
# Actually build the app
|
# Actually build the app
|
||||||
# @return [void]
|
# @return [void]
|
||||||
|
@ -220,7 +220,8 @@ module Middleman::Cli
|
||||||
|
|
||||||
output_path = render_to_file(resource)
|
output_path = render_to_file(resource)
|
||||||
|
|
||||||
if should_clean? && output_path.exist?
|
return unless should_clean? && output_path.exist?
|
||||||
|
|
||||||
if RUBY_PLATFORM =~ /darwin/
|
if RUBY_PLATFORM =~ /darwin/
|
||||||
# handle UTF-8-MAC filename on MacOS
|
# handle UTF-8-MAC filename on MacOS
|
||||||
|
|
||||||
|
@ -229,7 +230,6 @@ module Middleman::Cli
|
||||||
@to_clean.delete(output_path.realpath)
|
@to_clean.delete(output_path.realpath)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
# Render a resource to a file.
|
# Render a resource to a file.
|
||||||
#
|
#
|
||||||
|
@ -279,9 +279,7 @@ module Middleman::Cli
|
||||||
end
|
end
|
||||||
|
|
||||||
def binary_encode(string)
|
def binary_encode(string)
|
||||||
if string.respond_to?(:force_encoding)
|
string.force_encoding('ascii-8bit') if string.respond_to?(:force_encoding)
|
||||||
string.force_encoding('ascii-8bit')
|
|
||||||
end
|
|
||||||
string
|
string
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -11,7 +11,7 @@ module Middleman::Cli
|
||||||
|
|
||||||
# The setup task
|
# The setup task
|
||||||
def bundle
|
def bundle
|
||||||
run('bundle install')# , :capture => true)
|
run('bundle install') # , :capture => true)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@ module Middleman::Cli
|
||||||
# The upgrade task
|
# The upgrade task
|
||||||
def upgrade
|
def upgrade
|
||||||
inside(ENV['MM_ROOT']) do
|
inside(ENV['MM_ROOT']) do
|
||||||
run('bundle update')# , :capture => true)
|
run('bundle update') # , :capture => true)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -188,9 +188,7 @@ module Middleman
|
||||||
logger.debug "== Extension: #{ext}"
|
logger.debug "== Extension: #{ext}"
|
||||||
end
|
end
|
||||||
|
|
||||||
if klass.is_a?(::Middleman::Extension)
|
::Middleman::Extension.activated_extension(klass) if klass.is_a?(::Middleman::Extension)
|
||||||
::Middleman::Extension.activated_extension(klass)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -118,12 +118,12 @@ module Middleman
|
||||||
|
|
||||||
def bind_before_configuration
|
def bind_before_configuration
|
||||||
ext = self
|
ext = self
|
||||||
if ext.respond_to?(:before_configuration)
|
return unless ext.respond_to?(:before_configuration)
|
||||||
|
|
||||||
@klass.before_configuration do
|
@klass.before_configuration do
|
||||||
ext.before_configuration
|
ext.before_configuration
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
def bind_after_configuration
|
def bind_after_configuration
|
||||||
ext = self
|
ext = self
|
||||||
|
@ -139,7 +139,8 @@ module Middleman
|
||||||
|
|
||||||
def bind_before_build
|
def bind_before_build
|
||||||
ext = self
|
ext = self
|
||||||
if ext.respond_to?(:before_build)
|
return unless ext.respond_to?(:before_build)
|
||||||
|
|
||||||
@klass.before_build do |builder|
|
@klass.before_build do |builder|
|
||||||
if ext.method(:before_build).arity == 1
|
if ext.method(:before_build).arity == 1
|
||||||
ext.before_build(builder)
|
ext.before_build(builder)
|
||||||
|
@ -148,11 +149,11 @@ module Middleman
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
def bind_after_build
|
def bind_after_build
|
||||||
ext = self
|
ext = self
|
||||||
if ext.respond_to?(:after_build)
|
return unless ext.respond_to?(:after_build)
|
||||||
|
|
||||||
@klass.after_build do |builder|
|
@klass.after_build do |builder|
|
||||||
if ext.method(:after_build).arity == 1
|
if ext.method(:after_build).arity == 1
|
||||||
ext.after_build(builder)
|
ext.after_build(builder)
|
||||||
|
@ -162,5 +163,4 @@ module Middleman
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -23,7 +23,7 @@ module Middleman
|
||||||
logger.info "== Inspect your site configuration at http://#{host}:#{port}/__middleman/"
|
logger.info "== Inspect your site configuration at http://#{host}:#{port}/__middleman/"
|
||||||
|
|
||||||
@initialized ||= false
|
@initialized ||= false
|
||||||
unless @initialized
|
return if @initialized
|
||||||
@initialized = true
|
@initialized = true
|
||||||
|
|
||||||
register_signal_handlers
|
register_signal_handlers
|
||||||
|
@ -45,7 +45,6 @@ module Middleman
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
# Detach the current Middleman::Application instance
|
# Detach the current Middleman::Application instance
|
||||||
# @return [void]
|
# @return [void]
|
||||||
|
@ -107,9 +106,7 @@ module Middleman
|
||||||
opts[:instrumenting] || false
|
opts[:instrumenting] || false
|
||||||
)
|
)
|
||||||
|
|
||||||
if opts[:environment]
|
config[:environment] = opts[:environment].to_sym if opts[:environment]
|
||||||
config[:environment] = opts[:environment].to_sym
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -153,7 +150,8 @@ module Middleman
|
||||||
# @return [void]
|
# @return [void]
|
||||||
def register_signal_handlers
|
def register_signal_handlers
|
||||||
%w(INT HUP TERM QUIT).each do |sig|
|
%w(INT HUP TERM QUIT).each do |sig|
|
||||||
if Signal.list[sig]
|
next unless Signal.list[sig]
|
||||||
|
|
||||||
Signal.trap(sig) do
|
Signal.trap(sig) do
|
||||||
# Do as little work as possible in the signal context
|
# Do as little work as possible in the signal context
|
||||||
$mm_shutdown = true
|
$mm_shutdown = true
|
||||||
|
@ -161,7 +159,6 @@ module Middleman
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
# Initialize webrick
|
# Initialize webrick
|
||||||
# @return [void]
|
# @return [void]
|
||||||
|
@ -234,9 +231,7 @@ module Middleman
|
||||||
|
|
||||||
class FilteredWebrickLog < ::WEBrick::Log
|
class FilteredWebrickLog < ::WEBrick::Log
|
||||||
def log(level, data)
|
def log(level, data)
|
||||||
unless data =~ %r{Could not determine content-length of response body.}
|
super(level, data) unless data =~ %r{Could not determine content-length of response body.}
|
||||||
super(level, data)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -20,8 +20,8 @@ module Middleman
|
||||||
# Pick a renderer
|
# Pick a renderer
|
||||||
renderer = MiddlemanRedcarpetHTML
|
renderer = MiddlemanRedcarpetHTML
|
||||||
|
|
||||||
# Support SmartyPants
|
|
||||||
if options.delete(:smartypants)
|
if options.delete(:smartypants)
|
||||||
|
# Support SmartyPants
|
||||||
renderer = Class.new(renderer) do
|
renderer = Class.new(renderer) do
|
||||||
include ::Redcarpet::Render::SmartyPants
|
include ::Redcarpet::Render::SmartyPants
|
||||||
end
|
end
|
||||||
|
@ -30,9 +30,8 @@ module Middleman
|
||||||
# Renderer Options
|
# 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]
|
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[opt] = options.delete(opt) if options.key?(opt)
|
||||||
sum
|
|
||||||
end
|
end
|
||||||
|
|
||||||
renderer.new(render_options)
|
renderer.new(render_options)
|
||||||
|
@ -63,7 +62,7 @@ module Middleman
|
||||||
else
|
else
|
||||||
link_string = link.dup
|
link_string = link.dup
|
||||||
link_string << %Q("#{title}") if title && title.length > 0 && title != alt_text
|
link_string << %Q("#{title}") if title && title.length > 0 && title != alt_text
|
||||||
%Q{![#{alt_text}](#{link_string})}
|
"![#{alt_text}](#{link_string})"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -76,7 +75,7 @@ module Middleman
|
||||||
else
|
else
|
||||||
link_string = link.dup
|
link_string = link.dup
|
||||||
link_string << %Q("#{title}") if title && title.length > 0 && title != alt_text
|
link_string << %Q("#{title}") if title && title.length > 0 && title != alt_text
|
||||||
%Q{[#{content}](#{link_string})}
|
"[#{content}](#{link_string})"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -57,25 +57,22 @@ module Middleman
|
||||||
# whether or not it belongs in the sitemap (like a partial)
|
# whether or not it belongs in the sitemap (like a partial)
|
||||||
@sitemap.rebuild_resource_list!(:touched_file)
|
@sitemap.rebuild_resource_list!(:touched_file)
|
||||||
|
|
||||||
unless waiting_for_ready || @app.build?
|
|
||||||
# Force sitemap rebuild so the next request is ready to go.
|
# Force sitemap rebuild so the next request is ready to go.
|
||||||
# Skip this during build because the builder will control sitemap refresh.
|
# Skip this during build because the builder will control sitemap refresh.
|
||||||
@sitemap.ensure_resource_list_updated!
|
@sitemap.ensure_resource_list_updated! unless waiting_for_ready || @app.build?
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Remove a file from the store
|
# Remove a file from the store
|
||||||
# @param [String] file
|
# @param [String] file
|
||||||
# @return [void]
|
# @return [void]
|
||||||
def remove_file(file)
|
def remove_file(file)
|
||||||
if @file_paths_on_disk.delete?(file)
|
return unless @file_paths_on_disk.delete?(file)
|
||||||
|
|
||||||
@sitemap.rebuild_resource_list!(:removed_file)
|
@sitemap.rebuild_resource_list!(:removed_file)
|
||||||
unless waiting_for_ready || @app.build?
|
|
||||||
# Force sitemap rebuild so the next request is ready to go.
|
# Force sitemap rebuild so the next request is ready to go.
|
||||||
# Skip this during build because the builder will control sitemap refresh.
|
# Skip this during build because the builder will control sitemap refresh.
|
||||||
@sitemap.ensure_resource_list_updated!
|
@sitemap.ensure_resource_list_updated! unless waiting_for_ready || @app.build?
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Update the main sitemap resource list
|
# Update the main sitemap resource list
|
||||||
|
|
|
@ -13,15 +13,15 @@ module Middleman
|
||||||
|
|
||||||
test_expr = parts.join('\\/')
|
test_expr = parts.join('\\/')
|
||||||
# A makeshift for eponymous reverse-lookup
|
# A makeshift for eponymous reverse-lookup
|
||||||
found = store.resources.find { |candidate|
|
found = store.resources.find do |candidate|
|
||||||
candidate.path =~ %r!^#{test_expr}(?:\.[a-zA-Z0-9]+|\/)$!
|
candidate.path =~ %r{^#{test_expr}(?:\.[a-zA-Z0-9]+|\/)$}
|
||||||
}
|
end
|
||||||
|
|
||||||
if found
|
if found
|
||||||
return found
|
found
|
||||||
else
|
else
|
||||||
parts.pop if is_index
|
parts.pop if is_index
|
||||||
return store.find_resource_by_destination_path("#{parts.join('/')}/#{app.index_file}")
|
store.find_resource_by_destination_path("#{parts.join('/')}/#{app.index_file}")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -75,6 +75,7 @@ module Middleman
|
||||||
if !path.end_with?("/#{app.index_file}") && destination_path.end_with?("/#{app.index_file}")
|
if !path.end_with?("/#{app.index_file}") && destination_path.end_with?("/#{app.index_file}")
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
full_path = File.join(app.source_dir, eponymous_directory_path)
|
full_path = File.join(app.source_dir, eponymous_directory_path)
|
||||||
File.exist?(full_path) && File.directory?(full_path)
|
File.exist?(full_path) && File.directory?(full_path)
|
||||||
end
|
end
|
||||||
|
|
|
@ -91,11 +91,11 @@ class Middleman::CoreExtensions::Internationalization < ::Middleman::Extension
|
||||||
private
|
private
|
||||||
|
|
||||||
def on_file_changed(file)
|
def on_file_changed(file)
|
||||||
if @locales_regex =~ file
|
return unless @locales_regex =~ file
|
||||||
|
|
||||||
@_langs = nil # Clear langs cache
|
@_langs = nil # Clear langs cache
|
||||||
::I18n.reload!
|
::I18n.reload!
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
def convert_glob_to_regex(glob)
|
def convert_glob_to_regex(glob)
|
||||||
# File.fnmatch doesn't support brackets: {rb,yml,yaml}
|
# File.fnmatch doesn't support brackets: {rb,yml,yaml}
|
||||||
|
@ -108,10 +108,9 @@ class Middleman::CoreExtensions::Internationalization < ::Middleman::Extension
|
||||||
::I18n.reload!
|
::I18n.reload!
|
||||||
|
|
||||||
::I18n.default_locale = @mount_at_root
|
::I18n.default_locale = @mount_at_root
|
||||||
|
|
||||||
# Reset fallbacks to fall back to our new default
|
# Reset fallbacks to fall back to our new default
|
||||||
if ::I18n.respond_to? :fallbacks
|
::I18n.fallbacks = ::I18n::Locale::Fallbacks.new if ::I18n.respond_to?(:fallbacks)
|
||||||
::I18n.fallbacks = ::I18n::Locale::Fallbacks.new
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def metadata_for_path(url)
|
def metadata_for_path(url)
|
||||||
|
|
|
@ -55,12 +55,12 @@ class Middleman::Extensions::Gzip < ::Middleman::Extension
|
||||||
num_paths.times do
|
num_paths.times do
|
||||||
output_filename, old_size, new_size = out_queue.pop
|
output_filename, old_size, new_size = out_queue.pop
|
||||||
|
|
||||||
if output_filename
|
next unless output_filename
|
||||||
|
|
||||||
total_savings += (old_size - new_size)
|
total_savings += (old_size - new_size)
|
||||||
size_change_word = (old_size - new_size) > 0 ? 'smaller' : 'larger'
|
size_change_word = (old_size - new_size) > 0 ? 'smaller' : 'larger'
|
||||||
builder.say_status :gzip, "#{output_filename} (#{app.number_to_human_size((old_size - new_size).abs)} #{size_change_word})"
|
builder.say_status :gzip, "#{output_filename} (#{app.number_to_human_size((old_size - new_size).abs)} #{size_change_word})"
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
builder.say_status :gzip, "Total gzip savings: #{app.number_to_human_size(total_savings)}", :blue
|
builder.say_status :gzip, "Total gzip savings: #{app.number_to_human_size(total_savings)}", :blue
|
||||||
I18n.locale = old_locale
|
I18n.locale = old_locale
|
||||||
|
|
Loading…
Reference in a new issue