mirror of
https://github.com/middleman/middleman.git
synced 2022-11-09 12:20:27 -05:00
Clean up some Rubocop warnings that were previously suppressed.
This commit is contained in:
parent
dd7f06968a
commit
9a3f9fe488
7 changed files with 39 additions and 53 deletions
|
@ -6,12 +6,11 @@ require 'padrino-helpers'
|
||||||
|
|
||||||
class Padrino::Helpers::OutputHelpers::ErbHandler
|
class Padrino::Helpers::OutputHelpers::ErbHandler
|
||||||
# Force Erb capture not to use safebuffer
|
# Force Erb capture not to use safebuffer
|
||||||
# rubocop:disable UnderscorePrefixedVariableName
|
|
||||||
def capture_from_template(*args, &block)
|
def capture_from_template(*args, &block)
|
||||||
self.output_buffer, _buf_was = '', output_buffer
|
self.output_buffer, buf_was = '', output_buffer
|
||||||
raw = block.call(*args)
|
raw = block.call(*args)
|
||||||
captured = template.instance_variable_get(:@_out_buf)
|
captured = template.instance_variable_get(:@_out_buf)
|
||||||
self.output_buffer = _buf_was
|
self.output_buffer = buf_was
|
||||||
engine_matches?(block) ? captured : raw
|
engine_matches?(block) ? captured : raw
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -39,7 +38,6 @@ class Middleman::CoreExtensions::DefaultHelpers < ::Middleman::Extension
|
||||||
helpers do
|
helpers do
|
||||||
|
|
||||||
# Make all block content html_safe
|
# Make all block content html_safe
|
||||||
# rubocop:disable Semicolon
|
|
||||||
def content_tag(name, content=nil, options=nil, &block)
|
def content_tag(name, content=nil, options=nil, &block)
|
||||||
# safe_content_tag(name, content, options, &block)
|
# safe_content_tag(name, content, options, &block)
|
||||||
if block_given?
|
if block_given?
|
||||||
|
@ -53,7 +51,10 @@ class Middleman::CoreExtensions::DefaultHelpers < ::Middleman::Extension
|
||||||
output.safe_concat "<#{name}#{attributes}>"
|
output.safe_concat "<#{name}#{attributes}>"
|
||||||
|
|
||||||
if content.respond_to?(:each) && !content.is_a?(String)
|
if content.respond_to?(:each) && !content.is_a?(String)
|
||||||
content.each { |c| output.safe_concat c; output.safe_concat ::Padrino::Helpers::TagHelpers::NEWLINE }
|
content.each do |c|
|
||||||
|
output.safe_concat c
|
||||||
|
output.safe_concat ::Padrino::Helpers::TagHelpers::NEWLINE
|
||||||
|
end
|
||||||
else
|
else
|
||||||
output.safe_concat "#{content}"
|
output.safe_concat "#{content}"
|
||||||
end
|
end
|
||||||
|
@ -72,17 +73,10 @@ class Middleman::CoreExtensions::DefaultHelpers < ::Middleman::Extension
|
||||||
ActiveSupport::SafeBuffer.new.safe_concat(result)
|
ActiveSupport::SafeBuffer.new.safe_concat(result)
|
||||||
end
|
end
|
||||||
|
|
||||||
# rubocop:disable MultilineBlockChain, UnusedBlockArgument
|
|
||||||
def auto_find_proper_handler(&block)
|
def auto_find_proper_handler(&block)
|
||||||
if block_given?
|
if block_given?
|
||||||
engine = File.extname(block.source_location[0])[1..-1].to_sym
|
engine = File.extname(block.source_location[0])[1..-1].to_sym
|
||||||
::Padrino::Helpers::OutputHelpers.handlers.select do |e, h|
|
::Padrino::Helpers::OutputHelpers.handlers.select { |e, _| e == engine }.values.map { |h| h.new(self) }.find { |h| h.engine_matches?(block) }
|
||||||
e == engine
|
|
||||||
end.values.map do |h|
|
|
||||||
h.new(self)
|
|
||||||
end.find do |h|
|
|
||||||
h.engine_matches?(block)
|
|
||||||
end
|
|
||||||
else
|
else
|
||||||
find_proper_handler
|
find_proper_handler
|
||||||
end
|
end
|
||||||
|
@ -195,10 +189,8 @@ class Middleman::CoreExtensions::DefaultHelpers < ::Middleman::Extension
|
||||||
#
|
#
|
||||||
# @param [String] path The path (such as "photo.jpg")
|
# @param [String] path The path (such as "photo.jpg")
|
||||||
# @param [String] prefix The type prefix (such as "images")
|
# @param [String] prefix The type prefix (such as "images")
|
||||||
# @param [Hash] options Data to pass through.
|
|
||||||
# @return [String] The fully qualified asset url
|
# @return [String] The fully qualified asset url
|
||||||
# rubocop:disable UnusedMethodArgument
|
def asset_url(path, prefix='', _)
|
||||||
def asset_url(path, prefix='', options={})
|
|
||||||
# Don't touch assets which already have a full path
|
# Don't touch assets which already have a full path
|
||||||
if path.include?('//') || path.start_with?('data:')
|
if path.include?('//') || path.start_with?('data:')
|
||||||
path
|
path
|
||||||
|
|
|
@ -124,12 +124,11 @@ module Middleman
|
||||||
# configuration can be included later without impacting
|
# configuration can be included later without impacting
|
||||||
# other classes and instances.
|
# other classes and instances.
|
||||||
#
|
#
|
||||||
# rubocop:disable ClassVars
|
|
||||||
# @return [Class]
|
# @return [Class]
|
||||||
def server(&block)
|
def server(&block)
|
||||||
@@servercounter ||= 0
|
@servercounter ||= 0
|
||||||
@@servercounter += 1
|
@servercounter += 1
|
||||||
const_set("MiddlemanApplication#{@@servercounter}", Class.new(Middleman::Application, &block))
|
const_set("MiddlemanApplication#{@servercounter}", Class.new(Middleman::Application, &block))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -280,7 +280,6 @@ module Middleman
|
||||||
@klass.after_configuration do
|
@klass.after_configuration do
|
||||||
ext.after_configuration if ext.respond_to?(:after_configuration)
|
ext.after_configuration if ext.respond_to?(:after_configuration)
|
||||||
|
|
||||||
# rubocop:disable IfUnlessModifier
|
|
||||||
if ext.respond_to?(:manipulate_resource_list)
|
if ext.respond_to?(:manipulate_resource_list)
|
||||||
ext.app.sitemap.register_resource_list_manipulator(ext.class.ext_name, ext, ext.class.resource_list_manipulator_priority)
|
ext.app.sitemap.register_resource_list_manipulator(ext.class.ext_name, ext, ext.class.resource_list_manipulator_priority)
|
||||||
end
|
end
|
||||||
|
|
|
@ -20,7 +20,6 @@ module Middleman
|
||||||
# @param [Hash] opts
|
# @param [Hash] opts
|
||||||
# @param [Class] context
|
# @param [Class] context
|
||||||
# @return [String]
|
# @return [String]
|
||||||
# rubocop:disable UnderscorePrefixedVariableName
|
|
||||||
def render(locs={}, opts={}, context, &block)
|
def render(locs={}, opts={}, context, &block)
|
||||||
path = @path.dup
|
path = @path.dup
|
||||||
|
|
||||||
|
@ -32,7 +31,7 @@ module Middleman
|
||||||
context.current_engine, engine_was = engine, context.current_engine
|
context.current_engine, engine_was = engine, context.current_engine
|
||||||
|
|
||||||
# Save current buffer for later
|
# Save current buffer for later
|
||||||
_buf_was = context.save_buffer
|
buf_was = context.save_buffer
|
||||||
|
|
||||||
# Read from disk or cache the contents of the file
|
# Read from disk or cache the contents of the file
|
||||||
body = if opts[:template_body]
|
body = if opts[:template_body]
|
||||||
|
@ -85,7 +84,7 @@ module Middleman
|
||||||
output
|
output
|
||||||
ensure
|
ensure
|
||||||
# Reset stored buffer
|
# Reset stored buffer
|
||||||
context.restore_buffer(_buf_was)
|
context.restore_buffer(buf_was)
|
||||||
context.current_engine = engine_was
|
context.current_engine = engine_was
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,6 @@ require 'webrick'
|
||||||
require 'middleman-core/meta_pages'
|
require 'middleman-core/meta_pages'
|
||||||
require 'middleman-core/logger'
|
require 'middleman-core/logger'
|
||||||
|
|
||||||
# rubocop:disable GlobalVars
|
|
||||||
module Middleman
|
module Middleman
|
||||||
module PreviewServer
|
module PreviewServer
|
||||||
DEFAULT_PORT = 4567
|
DEFAULT_PORT = 4567
|
||||||
|
@ -35,12 +34,12 @@ module Middleman
|
||||||
loop do
|
loop do
|
||||||
@webrick.start
|
@webrick.start
|
||||||
|
|
||||||
# $mm_shutdown is set by the signal handler
|
# @mm_shutdown is set by the signal handler
|
||||||
if $mm_shutdown
|
if @mm_shutdown
|
||||||
shutdown
|
shutdown
|
||||||
exit
|
exit
|
||||||
elsif $mm_reload
|
elsif @mm_reload
|
||||||
$mm_reload = false
|
@mm_reload = false
|
||||||
reload
|
reload
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -130,7 +129,7 @@ module Middleman
|
||||||
|
|
||||||
# See if the changed file is config.rb or lib/*.rb
|
# See if the changed file is config.rb or lib/*.rb
|
||||||
if needs_to_reload?(added_and_modified + removed)
|
if needs_to_reload?(added_and_modified + removed)
|
||||||
$mm_reload = true
|
@mm_reload = true
|
||||||
@webrick.stop
|
@webrick.stop
|
||||||
else
|
else
|
||||||
added_and_modified.each do |path|
|
added_and_modified.each do |path|
|
||||||
|
@ -156,7 +155,7 @@ module Middleman
|
||||||
if Signal.list[sig]
|
if 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
|
||||||
@webrick.stop
|
@webrick.stop
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,23 +1,22 @@
|
||||||
module Middleman
|
module Middleman
|
||||||
module Profiling
|
module Profiling
|
||||||
|
class << self
|
||||||
# The profiler instance. There can only be one!
|
# The profiler instance. There can only be one!
|
||||||
# rubocop:disable TrivialAccessors
|
attr_writer :profiler
|
||||||
def self.profiler=(prof)
|
def profiler
|
||||||
@profiler = prof
|
|
||||||
end
|
|
||||||
def self.profiler
|
|
||||||
@profiler ||= NullProfiler.new
|
@profiler ||= NullProfiler.new
|
||||||
end
|
end
|
||||||
|
|
||||||
# Start the profiler
|
# Start the profiler
|
||||||
def self.start
|
def start
|
||||||
profiler.start
|
profiler.start
|
||||||
end
|
end
|
||||||
|
|
||||||
# Stop the profiler and generate a report. Make sure to call start first
|
# Stop the profiler and generate a report. Make sure to call start first
|
||||||
def self.report(report_name)
|
def report(report_name)
|
||||||
profiler.report(report_name)
|
profiler.report(report_name)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# A profiler that does nothing. The default.
|
# A profiler that does nothing. The default.
|
||||||
class NullProfiler
|
class NullProfiler
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
require 'middleman-core/file_renderer'
|
require 'middleman-core/file_renderer'
|
||||||
require 'middleman-core/template_renderer'
|
require 'middleman-core/template_renderer'
|
||||||
|
|
||||||
# rubocop:disable UnderscorePrefixedVariableName
|
|
||||||
module Middleman
|
module Middleman
|
||||||
class TemplateContext
|
class TemplateContext
|
||||||
attr_reader :app
|
attr_reader :app
|
||||||
|
@ -16,13 +15,13 @@ module Middleman
|
||||||
end
|
end
|
||||||
|
|
||||||
def save_buffer
|
def save_buffer
|
||||||
@_out_buf, _buf_was = '', @_out_buf
|
@_out_buf, buf_was = '', @_out_buf
|
||||||
_buf_was
|
buf_was
|
||||||
end
|
end
|
||||||
|
|
||||||
# rubocop:disable TrivialAccessors
|
# rubocop:disable TrivialAccessors
|
||||||
def restore_buffer(_buf_was)
|
def restore_buffer(buf_was)
|
||||||
@_out_buf = _buf_was
|
@_out_buf = buf_was
|
||||||
end
|
end
|
||||||
|
|
||||||
# Allow layouts to be wrapped in the contents of other layouts
|
# Allow layouts to be wrapped in the contents of other layouts
|
||||||
|
@ -30,7 +29,7 @@ module Middleman
|
||||||
# @return [void]
|
# @return [void]
|
||||||
def wrap_layout(layout_name, &block)
|
def wrap_layout(layout_name, &block)
|
||||||
# Save current buffer for later
|
# Save current buffer for later
|
||||||
_buf_was = save_buffer
|
buf_was = save_buffer
|
||||||
|
|
||||||
layout_path = ::Middleman::TemplateRenderer.locate_layout(@app, layout_name, current_engine)
|
layout_path = ::Middleman::TemplateRenderer.locate_layout(@app, layout_name, current_engine)
|
||||||
|
|
||||||
|
@ -48,7 +47,7 @@ module Middleman
|
||||||
end
|
end
|
||||||
ensure
|
ensure
|
||||||
# Reset stored buffer
|
# Reset stored buffer
|
||||||
restore_buffer(_buf_was)
|
restore_buffer(buf_was)
|
||||||
end
|
end
|
||||||
|
|
||||||
file_renderer = ::Middleman::FileRenderer.new(@app, layout_path)
|
file_renderer = ::Middleman::FileRenderer.new(@app, layout_path)
|
||||||
|
|
Loading…
Reference in a new issue