Rubocop'd

This commit is contained in:
Thomas Reynolds 2014-04-29 11:43:05 -07:00
commit f513ab77b3
45 changed files with 146 additions and 190 deletions

View file

@ -12,7 +12,6 @@ gem 'rspec', '~> 2.12'
gem 'simplecov'
# Optional middleman dependencies, included for tests
gem 'haml', '~> 4.0.0', require: false # Make sure to use Haml 4 for tests
gem 'sinatra', require: false
gem 'slim', require: false
gem 'liquid', require: false
@ -30,7 +29,6 @@ platforms :jruby do
end
# Code Quality
gem 'cane', platforms: [:mri_19, :mri_20], require: false
gem 'coveralls', require: false
gem 'rubocop', require: false, group: :development

View file

@ -1,5 +1,4 @@
require 'rubygems' unless defined?(Gem)
# require 'fileutils' unless defined?(FileUtils)
require 'rubygems' unless defined?(Gem)
require 'rake'
require File.expand_path('../middleman-core/lib/middleman-core/version.rb', __FILE__)
@ -14,51 +13,14 @@ def sh_rake(command)
sh "#{Gem.ruby} -S rake #{command}", verbose: true
end
def say(text, color=:magenta)
n = { bold: 1, red: 31, green: 32, yellow: 33, blue: 34, magenta: 35 }.fetch(color, 0)
puts "\e[%dm%s\e[0m" % [n, text]
end
desc "Run 'install' for all projects"
task :install do
GEM_PATHS.each do |dir|
Dir.chdir(dir) { sh_rake(:install) }
end
end
desc 'Clean pkg and other stuff'
task :clean do
GEM_PATHS.each do |g|
%w(tmp pkg coverage).each { |dir| sh 'rm -rf %s' % File.join(g, dir) }
end
end
desc 'Clean pkg and other stuff'
task :uninstall do
sh 'gem search --no-version middleman | grep middleman | xargs gem uninstall -a'
end
desc 'Displays the current version'
task :version do
say "Current version: #{Middleman::VERSION}"
puts "Current version: #{Middleman::VERSION}"
end
desc 'Bumps the version number based on given version'
task :bump, [:version] do |t, args|
raise 'Please specify version=x.x.x !' unless args.version
version_path = File.dirname(__FILE__) + '/middleman-core/lib/middleman-core/version.rb'
version_text = File.read(version_path).sub(/VERSION = '[\d\.\w]+'/, "VERSION = '#{args.version}'")
say "Updating Middleman to version #{args.version}"
File.open(version_path, 'w') { |f| f.write version_text }
sh 'git commit -a -m "Bumped version to %s"' % args.version
end
desc 'Executes a fresh install removing all middleman version and then reinstall all gems'
task fresh: [:uninstall, :install, :clean]
desc 'Pushes repository to GitHub'
task :push do
say 'Pushing to github...'
puts 'Pushing to github...'
sh "git tag v#{Middleman::VERSION}"
sh 'git push origin master'
sh "git push origin v#{Middleman::VERSION}"
@ -66,11 +28,10 @@ end
desc 'Release all middleman gems'
task publish: :push do
say 'Pushing to rubygems...'
puts 'Pushing to rubygems...'
GEM_PATHS.each do |dir|
Dir.chdir(dir) { sh_rake('release') }
end
Rake::Task['clean'].invoke
end
desc 'Generate documentation for all middleman gems'
@ -85,6 +46,7 @@ task :test do
GEM_PATHS.each do |g|
Dir.chdir("#{File.join(ROOT, g)}") { sh "#{Gem.ruby} -S rake test" }
end
Rake::Task['rubocop'].invoke
end
desc 'Run specs for all middleman gems'
@ -94,24 +56,10 @@ task :spec do
end
end
begin
require 'cane/rake_task'
desc 'Run cane to check quality metrics'
Cane::RakeTask.new(:quality) do |cane|
cane.no_style = true
cane.no_doc = true
cane.abc_glob = 'middleman*/lib/middleman*/**/*.rb'
end
rescue LoadError
end
begin
require 'rubocop/rake_task'
desc 'Run RuboCop to check code consistency'
Rubocop::RakeTask.new(:rubocop) do |task|
task.fail_on_error = false
end
rescue LoadError
require 'rubocop/rake_task'
desc 'Run RuboCop to check code consistency'
Rubocop::RakeTask.new(:rubocop) do |task|
task.fail_on_error = false
end
desc 'Run tests for all middleman gems'

View file

@ -1,3 +1,5 @@
# rubocop:disable FileName
# Setup our load paths
libdir = File.expand_path(File.dirname(__FILE__))
$LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir)
@ -34,6 +36,7 @@ module Middleman
# @param [Symbol, String, nil] meth
# @param [Boolean] subcommand
# @return [void]
# rubocop:disable UnusedMethodArgument
def help(meth=nil, subcommand=false)
if meth && !self.respond_to?(meth)
klass, task = Thor::Util.find_class_and_task_by_namespace("#{meth}:#{meth}")
@ -56,10 +59,7 @@ module Middleman
# @param [Symbol] meth
def method_missing(meth, *args)
meth = meth.to_s
if self.class.map.key?(meth)
meth = self.class.map[meth]
end
meth = self.class.map[meth] if self.class.map.key?(meth)
klass, task = Thor::Util.find_class_and_task_by_namespace("#{meth}:#{meth}")
@ -73,7 +73,7 @@ module Middleman
end
if klass.nil?
raise Thor::Error.new "There's no '#{meth}' command for Middleman. Try 'middleman help' for a list of commands."
raise Thor::Error, "There's no '#{meth}' command for Middleman. Try 'middleman help' for a list of commands."
else
args.unshift(task) if task
klass.start(args, shell: shell)

View file

@ -273,7 +273,6 @@ module Middleman::Cli
base.say_status :error, file_name, :red
if base.debugging
raise e
exit(1)
elsif base.options['verbose']
base.shell.say response, :red
end

View file

@ -30,9 +30,7 @@ module Middleman::Cli
}
@app = ::Middleman::Application.server.inst do
if opts[:environment]
config[:environment] = opts[:environment].to_sym
end
config[:environment] = opts[:environment].to_sym if opts[:environment]
::Middleman::Logger.singleton(opts[:debug] ? 0 : 1, opts[:instrumenting] || false)
end

View file

@ -41,7 +41,7 @@ module Middleman::Cli
def init(name='.')
key = options[:template].to_sym
unless ::Middleman::Templates.registered.key?(key)
raise Thor::Error.new "Unknown project template '#{key}'"
raise Thor::Error, "Unknown project template '#{key}'"
end
thor_group = ::Middleman::Templates.registered[key]

View file

@ -1,3 +1,5 @@
# rubocop:disable FileName
# Setup our load paths
libdir = File.expand_path(File.dirname(__FILE__))
$LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir)

View file

@ -43,16 +43,17 @@ module Middleman
# Get the value of a setting by key. Returns nil if there is no such setting.
# @return [Object]
def [](key)
setting = @settings[key]
setting ? setting.value : nil
setting_obj = setting(key)
setting_obj ? setting_obj.value : nil
end
# Set the value of a setting by key. Creates the setting if it doesn't exist.
# @param [Symbol] key
# @param [Object] val
# rubocop:disable UselessSetterCall
def []=(key, val)
setting = @settings[key] || define_setting(key)
setting.value = val
setting_obj = setting(key) || define_setting(key)
setting_obj.value = val
end
# Allow configuration settings to be read and written via methods
@ -159,6 +160,7 @@ module Middleman
end
# Whether or not there has been a value set beyond the default
# rubocop:disable TrivialAccessors
def value_set?
@value_set
end

View file

@ -142,9 +142,6 @@ module Middleman
def data_for_path(path)
response = nil
@@local_sources ||= {}
@@callback_sources ||= {}
if store.key?(path.to_s)
response = store[path.to_s]
elsif callbacks.key?(path.to_s)
@ -163,10 +160,7 @@ module Middleman
return @local_data[path.to_s]
else
result = data_for_path(path)
if result
return ::Middleman::Util.recursively_enhance(result)
end
return ::Middleman::Util.recursively_enhance(result) if result
end
super
@ -186,21 +180,23 @@ module Middleman
__send__(key) if key?(key)
end
def has_key?(key)
@local_data.key?(key.to_s) || !!(data_for_path(key))
def key?(key)
@local_data.key?(key.to_s) || data_for_path(key)
end
alias_method :has_key?, :key?
# Convert all the data into a static hash
#
# @return [Hash]
def to_h
data = {}
store.each do |k, v|
store.each do |k, _|
data[k] = data_for_path(k)
end
callbacks.each do |k, v|
callbacks.each do |k, _|
data[k] = data_for_path(k)
end

View file

@ -6,6 +6,7 @@ require 'padrino-helpers'
class Padrino::Helpers::OutputHelpers::ErbHandler
# Force Erb capture not to use safebuffer
# rubocop:disable UnderscorePrefixedVariableName
def capture_from_template(*args, &block)
self.output_buffer, _buf_was = '', output_buffer
raw = block.call(*args)
@ -38,6 +39,7 @@ class Middleman::CoreExtensions::DefaultHelpers < ::Middleman::Extension
helpers do
# Make all block content html_safe
# rubocop:disable Semicolon
def content_tag(name, content=nil, options=nil, &block)
# safe_content_tag(name, content, options, &block)
if block_given?
@ -70,6 +72,7 @@ class Middleman::CoreExtensions::DefaultHelpers < ::Middleman::Extension
ActiveSupport::SafeBuffer.new.safe_concat(result)
end
# rubocop:disable MultilineBlockChain, UnusedBlockArgument
def auto_find_proper_handler(&block)
if block_given?
engine = File.extname(block.source_location[0])[1..-1].to_sym
@ -116,8 +119,10 @@ class Middleman::CoreExtensions::DefaultHelpers < ::Middleman::Extension
def auto_tag(asset_ext, asset_dir=nil)
if asset_dir.nil?
asset_dir = case asset_ext
when :js then config[:js_dir]
when :css then config[:css_dir]
when :js
config[:js_dir]
when :css
config[:css_dir]
end
end
@ -164,13 +169,20 @@ class Middleman::CoreExtensions::DefaultHelpers < ::Middleman::Extension
# @return [String]
def asset_path(kind, source, options={})
return source if source.to_s.include?('//') || source.to_s.start_with?('data:')
asset_folder = case kind
when :css then config[:css_dir]
when :js then config[:js_dir]
when :images then config[:images_dir]
when :fonts then config[:fonts_dir]
else kind.to_s
asset_folder = case kind
when :css
config[:css_dir]
when :js
config[:js_dir]
when :images
config[:images_dir]
when :fonts
config[:fonts_dir]
else
kind.to_s
end
source = source.to_s.tr(' ', '')
ignore_extension = (kind == :images || kind == :fonts) # don't append extension
source << ".#{kind}" unless ignore_extension || source.end_with?(".#{kind}")
@ -185,9 +197,10 @@ class Middleman::CoreExtensions::DefaultHelpers < ::Middleman::Extension
# @param [String] prefix The type prefix (such as "images")
# @param [Hash] options Data to pass through.
# @return [String] The fully qualified asset url
# rubocop:disable UnusedMethodArgument
def asset_url(path, prefix='', options={})
# Don't touch assets which already have a full path
if path.include?('//') or path.start_with?('data:')
if path.include?('//') || path.start_with?('data:')
path
else # rewrite paths to use their destination path
if resource = sitemap.find_resource_by_destination_path(url_for(path))
@ -229,12 +242,12 @@ class Middleman::CoreExtensions::DefaultHelpers < ::Middleman::Extension
options_index = block_given? ? 1 : 2
if block_given? && args.size > 2
raise ArgumentError.new('Too many arguments to link_to(url, options={}, &block)')
raise ArgumentError, 'Too many arguments to link_to(url, options={}, &block)'
end
if url = args[url_arg_index]
options = args[options_index] || {}
raise ArgumentError.new('Options must be a hash') unless options.is_a?(Hash)
raise ArgumentError, 'Options must be a hash' unless options.is_a?(Hash)
# Transform the url through our magic url_for method
args[url_arg_index] = url_for(url, options)

View file

@ -73,6 +73,7 @@ module Middleman
#
# @param [Symbol, Module] ext Which extension to activate
# @return [void]
# rubocop:disable BlockNesting
def activate(ext, options={}, &block)
extension = ::Middleman::Extensions.load(ext)
logger.debug "== Activating: #{ext}"

View file

@ -119,6 +119,7 @@ module Middleman::CoreExtensions
end
private
# Parse YAML frontmatter out of a string
# @param [String] content
# @return [Array<Hash, String>]

View file

@ -58,7 +58,7 @@ class Middleman::CoreExtensions::Internationalization < ::Middleman::Extension
delegate :logger, to: :app
def langs
@_langs ||= get_known_languages
@_langs ||= known_languages
end
# Update the main sitemap resource list
@ -72,8 +72,8 @@ class Middleman::CoreExtensions::Internationalization < ::Middleman::Extension
# If it uses file extension localization
if parse_locale_extension(resource.path)
result = parse_locale_extension(resource.path)
lang, path, page_id = result
new_resources << build_resource(path, resource.path, page_id, lang)
ext_lang, path, page_id = result
new_resources << build_resource(path, resource.path, page_id, ext_lang)
# If it's a "localizable template"
elsif File.fnmatch?(File.join(options[:templates_dir], '**'), resource.path)
page_id = File.basename(resource.path, File.extname(resource.path))
@ -99,7 +99,7 @@ class Middleman::CoreExtensions::Internationalization < ::Middleman::Extension
def convert_glob_to_regex(glob)
# File.fnmatch doesn't support brackets: {rb,yml,yaml}
regex = @locales_glob.sub(/\./, '\.').sub(File.join('**', '*'), '.*').sub(/\//, '\/').sub('{rb,yml,yaml}', '(rb|ya?ml)')
regex = glob.sub(/\./, '\.').sub(File.join('**', '*'), '.*').sub(/\//, '\/').sub('{rb,yml,yaml}', '(rb|ya?ml)')
%r{^#{regex}}
end
@ -115,7 +115,7 @@ class Middleman::CoreExtensions::Internationalization < ::Middleman::Extension
end
def metadata_for_path(url)
if d = get_localization_data(url)
if d = localization_data(url)
lang, page_id = d
else
# Default to the @mount_at_root lang
@ -132,19 +132,21 @@ class Middleman::CoreExtensions::Internationalization < ::Middleman::Extension
}
end
def get_known_languages
def known_languages
if options[:langs]
Array(options[:langs]).map(&:to_sym)
else
known_langs = app.files.known_paths.select do |p|
p.to_s.match(@locales_regex) && (p.to_s.split(File::SEPARATOR).length === 2)
end.map { |p|
p.to_s.match(@locales_regex) && (p.to_s.split(File::SEPARATOR).length == 2)
end
known_langs.map { |p|
File.basename(p.to_s).sub(/\.ya?ml$/, '').sub(/\.rb$/, '')
}.sort.map(&:to_sym)
end
end
def get_localization_data(path)
def localization_data(path)
@_localization_data ||= {}
@_localization_data[path]
end

View file

@ -1,6 +1,7 @@
require 'middleman-core/template_context'
# Rendering extension
# rubocop:disable UnderscorePrefixedVariableName
module Middleman
module CoreExtensions
module Rendering
@ -75,7 +76,7 @@ module Middleman
# Clean up missing Tilt exts
app.after_configuration do
Tilt.mappings.each do |key, klasses|
Tilt.mappings.each do |key, _|
begin
Tilt[".#{key}"]
rescue LoadError, NameError

View file

@ -70,15 +70,15 @@ module Middleman
app.use Rack::Lint
app.use Rack::Head
Array(@middleware).each do |klass, options, block|
app.use(klass, *options, &block)
Array(@middleware).each do |klass, options, middleware_block|
app.use(klass, *options, &middleware_block)
end
inner_app = inst(&block)
app.map('/') { run inner_app }
Array(@mappings).each do |path, block|
app.map(path, &block)
Array(@mappings).each do |path, map_block|
app.map(path, &map_block)
end
app
@ -126,6 +126,7 @@ module Middleman
# configuration can be included later without impacting
# other classes and instances.
#
# rubocop:disable ClassVars
# @return [Class]
def server(&block)
@@servercounter ||= 0
@ -189,7 +190,7 @@ module Middleman
# @param env
# @param [Rack::Request] req
# @param [Rack::Response] res
def process_request(env, req, res)
def process_request(env, _, res)
start_time = Time.now
request_path = URI.decode(env['PATH_INFO'].dup)

View file

@ -13,9 +13,7 @@ module Middleman
# When in dev
app.configure :development do
# Include middlemare
if config[:show_exceptions]
use ::Rack::ShowExceptions
end
use ::Rack::ShowExceptions if config[:show_exceptions]
end
end
end

View file

@ -87,7 +87,7 @@ module Middleman
protected
def setup_options(options_hash, &block)
def setup_options(options_hash)
@options = self.class.config.dup
@options.finalize!
@ -122,10 +122,9 @@ module Middleman
def bind_after_configuration
ext = self
@klass.after_configuration do
if ext.respond_to?(:after_configuration)
ext.after_configuration
end
ext.after_configuration if ext.respond_to?(:after_configuration)
# rubocop:disable IfUnlessModifier
if ext.respond_to?(:manipulate_resource_list)
ext.app.sitemap.register_resource_list_manipulator(ext.class.ext_name, ext)
end
@ -136,7 +135,7 @@ module Middleman
ext = self
if ext.respond_to?(:before_build)
@klass.before_build do |builder|
if ext.method(:before_build).arity === 1
if ext.method(:before_build).arity == 1
ext.before_build(builder)
else
ext.before_build
@ -149,7 +148,7 @@ module Middleman
ext = self
if ext.respond_to?(:after_build)
@klass.after_build do |builder|
if ext.method(:after_build).arity === 1
if ext.method(:after_build).arity == 1
ext.after_build(builder)
else
ext.after_build

View file

@ -30,9 +30,7 @@ module Middleman
# extension is activated.
def register(name, namespace=nil, &block)
# If we've already got an extension registered under this name, bail out
if registered.key?(name.to_sym)
raise "There is already an extension registered with the name '#{name}'"
end
raise "There is already an extension registered with the name '#{name}'" if registered.key?(name.to_sym)
registered[name.to_sym] = if block_given?
block

View file

@ -39,7 +39,9 @@ class Middleman::Extensions::AssetHash < ::Middleman::Extension
else
-1
end
end.each do |resource|
end
sorted_resources.each do |resource|
next unless options.exts.include?(resource.ext)
next if ignored_resource?(resource)
next if resource.ignored?
@ -64,7 +66,7 @@ class Middleman::Extensions::AssetHash < ::Middleman::Extension
def hashed_filename(resource)
# Render through the Rack interface so middleware and mounted apps get a shot
response = @rack_client.get(URI.escape(resource.destination_path), 'bypass_asset_hash' => 'true')
response = @rack_client.get(URI.escape(resource.destination_path), 'bypass_asset_hash' => 'true')
raise "#{resource.path} should be in the sitemap!" unless response.status == 200
digest = Digest::SHA1.hexdigest(response.body)[0..7]

View file

@ -14,7 +14,7 @@ class Middleman::Extensions::AssetHost < ::Middleman::Extension
if asset_host.is_a?(Proc)
config.asset_host(&asset_host)
else
config.asset_host do |asset|
config.asset_host do |_|
asset_host
end
end

View file

@ -39,7 +39,7 @@ class Middleman::Extensions::Gzip < ::Middleman::Extension
# Farm out gzip tasks to threads and put the results in in_queue
out_queue = Queue.new
threads = num_threads.times.map do
num_threads.times.each do
Thread.new do
while path = in_queue.pop
out_queue << gzip_file(path.to_s)

View file

@ -17,7 +17,7 @@ class Middleman::Extensions::MinifyCss < ::Middleman::Extension
class SassCompressor
def self.compress(style, options={})
root_node = ::Sass::SCSS::CssParser.new(style, 'middleman-css-input', 1).parse
root_node.options = { style: :compressed }
root_node.options = options.merge(style: :compressed)
root_node.render.strip
end
end
@ -47,7 +47,7 @@ class Middleman::Extensions::MinifyCss < ::Middleman::Extension
if inline_html_content?(env['PATH_INFO'])
minified = ::Middleman::Util.extract_response_text(response)
minified.gsub!(INLINE_CSS_REGEX) do |match|
minified.gsub!(INLINE_CSS_REGEX) do
$1 << @compressor.compress($2) << $3
end
@ -64,6 +64,7 @@ class Middleman::Extensions::MinifyCss < ::Middleman::Extension
end
private
def inline_html_content?(path)
(path.end_with?('.html') || path.end_with?('.php')) && @inline
end

View file

@ -20,6 +20,7 @@ module Middleman
# @param [Hash] opts
# @param [Class] context
# @return [String]
# rubocop:disable UnderscorePrefixedVariableName
def render(locs={}, opts={}, context, &block)
path = @path.dup
@ -37,7 +38,7 @@ module Middleman
body = if opts[:template_body]
opts.delete(:template_body)
else
get_template_data_for_file
template_data_for_file
end
# Merge per-extension options from config
@ -81,7 +82,7 @@ module Middleman
# Get the template data from a path
# @param [String] path
# @return [String]
def get_template_data_for_file
def template_data_for_file
if @app.extensions[:front_matter]
@app.extensions[:front_matter].template_data_for_file(@path)
else

View file

@ -40,12 +40,12 @@ module Middleman
end
# The index page
def index(env)
def index(_)
template('index.html.erb')
end
# Inspect the sitemap
def sitemap(env)
def sitemap(_)
resources = @middleman.inst.sitemap.resources(true)
sitemap_tree = SitemapTree.new
@ -58,7 +58,7 @@ module Middleman
end
# Inspect configuration
def config(env)
def config(_)
global_config = @middleman.inst.config.all_settings.map { |c| ConfigSetting.new(c) }
extension_config = {}

View file

@ -13,8 +13,7 @@ module Middleman
end
def render
content = ''
@children.keys.sort do |a, b|
sorted_children_keys = @children.keys.sort do |a, b|
a_subtree = @children[a]
b_subtree = @children[b]
if a_subtree.is_a? SitemapResource
@ -32,7 +31,9 @@ module Middleman
else
a.downcase <=> b.downcase
end
end.each do |path_part|
end
sorted_children_keys.reduce('') do |content, path_part|
subtree = @children[path_part]
content << "<details class='#{subtree.css_classes.join(' ')}'>"
content << '<summary>'
@ -41,7 +42,6 @@ module Middleman
content << subtree.render
content << '</details>'
end
content
end
def css_classes

View file

@ -2,6 +2,7 @@ require 'webrick'
require 'middleman-core/meta_pages'
require 'middleman-core/logger'
# rubocop:disable GlobalVars
module Middleman
module PreviewServer
DEFAULT_PORT = 4567
@ -14,7 +15,7 @@ module Middleman
# @return [void]
def start(opts={})
@options = opts
@host = @options[:host] || Socket.ip_address_list.find(&:ipv4_private?).ip_address
@host = @options[:host] || '0.0.0.0'
@port = @options[:port] || DEFAULT_PORT
mount_instance(new_app)
@ -89,6 +90,7 @@ module Middleman
end
private
def new_app
opts = @options.dup
server = ::Middleman::Application.server

View file

@ -1,6 +1,7 @@
module Middleman
module Profiling
# The profiler instance. There can only be one!
# rubocop:disable TrivialAccessors
def self.profiler=(prof)
@profiler = prof
end
@ -23,7 +24,7 @@ module Middleman
def start
end
def report(report_name)
def report(_)
end
end

View file

@ -40,7 +40,7 @@ module Middleman
# Setup extension
class << self
# Once registered
def registered(app)
def registered(_)
::Tilt.prefer(::Middleman::Renderers::HamlTemplate, 'haml')
# Add haml helpers to context

View file

@ -4,7 +4,7 @@ module Middleman
module Renderers
# Our own Kramdown Tilt template that simply uses our custom renderer.
class KramdownTemplate < ::Tilt::KramdownTemplate
def evaluate(scope, locals, &block)
def evaluate(scope, *)
@output ||= begin
MiddlemanKramdownHTML.scope = ::Middleman::Renderers::Haml.last_haml_scope || scope
@ -19,7 +19,7 @@ module Middleman
class MiddlemanKramdownHTML < ::Kramdown::Converter::Html
cattr_accessor :scope
def convert_img(el, indent)
def convert_img(el, _)
attrs = el.attr.dup
link = attrs.delete('src')

View file

@ -14,7 +14,7 @@ module Middleman
::Liquid::Template.file_system = ::Liquid::LocalFileSystem.new(source_dir)
# Convert data object into a hash for liquid
sitemap.provides_metadata %r{\.liquid$} do |path|
sitemap.provides_metadata %r{\.liquid$} do
{ locals: { data: data.to_h } }
end
end

View file

@ -38,7 +38,7 @@ module Middleman
renderer.new(render_options)
end
def evaluate(scope, locals, &block)
def evaluate(scope, _)
@output ||= begin
MiddlemanRedcarpetHTML.scope = ::Middleman::Renderers::Haml.last_haml_scope || scope

View file

@ -31,9 +31,7 @@ module Middleman
def initialize(*args, &block)
super
if @options.key?(:context)
@context = @options[:context]
end
@context = @options[:context] if @options.key?(:context)
end
# Define the expected syntax for the template
@ -46,9 +44,8 @@ module Middleman
# Add exception messaging
# @param [Class] context
# @param [Hash] locals
# @return [String]
def evaluate(context, locals, &block)
def evaluate(context, _)
@context ||= context
@engine = ::Sass::Engine.new(data, sass_options)

View file

@ -21,8 +21,8 @@ module Middleman
# Files starting with an underscore, but not a double-underscore
partials: proc { |file| file =~ %r{/_[^_]} },
layout: proc { |file, app|
file.start_with?(File.join(app.config[:source], 'layout.')) || file.start_with?(File.join(app.config[:source], 'layouts/'))
layout: proc { |file, sitemap_app|
file.start_with?(File.join(sitemap_app.config[:source], 'layout.')) || file.start_with?(File.join(sitemap_app.config[:source], 'layouts/'))
}
}, 'Callbacks that can exclude paths from the sitemap'

View file

@ -35,13 +35,13 @@ module Middleman
# Update or add an on-disk file path
# @param [String] file
# @return [Boolean]
def touch_file(file, rebuild=true)
def touch_file(file)
return false if File.directory?(file)
path = @sitemap.file_to_path(file)
return false unless path
ignored = @app.config[:ignored_sitemap_matchers].any? do |name, callback|
ignored = @app.config[:ignored_sitemap_matchers].any? do |_, callback|
if callback.arity == 1
callback.call(file)
else
@ -67,7 +67,7 @@ module Middleman
# Remove a file from the store
# @param [String] file
# @return [void]
def remove_file(file, rebuild=true)
def remove_file(file)
if @file_paths_on_disk.delete?(file)
@sitemap.rebuild_resource_list!(:removed_file)
unless waiting_for_ready || @app.build?

View file

@ -88,8 +88,9 @@ module Middleman
module ProxyResourceInstanceMethods
# Whether this page is a proxy
# @return [Boolean]
# rubocop:disable TrivialAccessors
def proxy?
!!@proxied_to
@proxied_to
end
# Set this page to proxy to a target path
@ -122,6 +123,7 @@ module Middleman
proxy_resource
end
# rubocop:disable AccessorMethodName
def get_source_file
if proxy?
proxied_to_resource.source_file

View file

@ -17,9 +17,7 @@ module Middleman
# @param [String] path
# @param [Hash] opts The :to value gives a target path
def create_redirect(path, opts={}, &block)
if block_given?
opts[:template] = block
end
opts[:template] = block if block_given?
@redirects[path] = opts
@ -54,7 +52,7 @@ module Middleman
true
end
def render(*args, &block)
def render(*)
url = ::Middleman::Util.url_for(store.app, @request_path,
relative: false,
find_resource: true

View file

@ -59,7 +59,7 @@ module Middleman
true
end
def render(*args, &block)
def render(*)
return output.call if output
end

View file

@ -69,7 +69,7 @@ module Middleman
return true
end
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
# The path for this resource if it were a directory, and not a file

View file

@ -93,9 +93,7 @@ module Middleman
# Render this resource
# @return [String]
def render(opts={}, locs={})
unless template?
return ::Middleman::FileRenderer.new(@app, source_file).get_template_data_for_file
end
return ::Middleman::FileRenderer.new(@app, source_file).template_data_for_file unless template?
relative_source = Pathname(source_file).relative_path_from(Pathname(app.root))

View file

@ -63,12 +63,13 @@ module Middleman
# @param [Symbol] name Name of the manipulator for debugging
# @param [Class, Module] inst Abstract namespace which can update the resource list
# @return [void]
def register_resource_list_manipulator(name, inst, unused=true)
def register_resource_list_manipulator(name, inst, *)
@resource_list_manipulators << [name, inst]
rebuild_resource_list!(:registered_new)
end
# Rebuild the list of resources from scratch, using registed manipulators
# rubocop:disable UnusedMethodArgument
# @return [void]
def rebuild_resource_list!(reason=nil)
@lock.synchronize do
@ -254,9 +255,7 @@ module Middleman
if @app.respond_to? :langs
path_bits = path.split('.')
lang = path_bits.last
if @app.langs.include?(lang.to_sym)
return path_bits[0..-2].join('.')
end
return path_bits[0..-2].join('.') if @app.langs.include?(lang.to_sym)
end
path

View file

@ -25,7 +25,7 @@ end
Given /^"([^\"]*)" is set to "([^\"]*)"$/ do |variable, value|
@initialize_commands ||= []
@initialize_commands << lambda {
config[variable.to_sym] = value
config[variable.to_sym] = value
}
end

View file

@ -1,6 +1,7 @@
require 'middleman-core/file_renderer'
require 'middleman-core/template_renderer'
# rubocop:disable UnderscorePrefixedVariableName
module Middleman
class TemplateContext
attr_reader :app
@ -19,6 +20,7 @@ module Middleman
_buf_was
end
# rubocop:disable TrivialAccessors
def restore_buffer(_buf_was)
@_out_buf = _buf_was
end
@ -62,7 +64,7 @@ module Middleman
# @param [String, Symbol] data
# @param [Hash] options
# @return [String]
def render(engine, data, options={}, &block)
def render(_, data, options={}, &block)
data = data.to_s
locals = options[:locals]

View file

@ -37,9 +37,7 @@ module Middleman
# Sandboxed class for template eval
context = @app.template_context_class.new(@app, locs, opts)
if context.respond_to?(:init_haml_helpers)
context.init_haml_helpers
end
context.init_haml_helpers if context.respond_to?(:init_haml_helpers)
# Keep rendering template until we've used up all extensions. This
# handles cases like `style.css.sass.erb`
@ -125,9 +123,6 @@ module Middleman
# @param [Symbol] preferred_engine
# @return [String]
def self.locate_layout(app, name, preferred_engine=nil)
# Whether we've found the layout
layout_path = false
resolve_opts = {}
resolve_opts[:preferred_engine] = preferred_engine unless preferred_engine.nil?
@ -167,10 +162,9 @@ module Middleman
# If we're specifically looking for a preferred engine
if options.key?(:preferred_engine)
extension_class = ::Tilt[options[:preferred_engine]]
matched_exts = []
# Get a list of extensions for a preferred engine
matched_exts = ::Tilt.mappings.select do |ext, engines|
matched_exts = ::Tilt.mappings.select do |_, engines|
engines.include? extension_class
end.keys

View file

@ -84,7 +84,7 @@ module Middleman
def extract_response_text(response)
# The rack spec states all response bodies must respond to each
result = ''
response.each do |part, s|
response.each do |part, _|
result << part
end
result
@ -338,13 +338,13 @@ module Middleman
key.is_a?(Symbol) ? key.to_s : key
end
# Magic predicates. For instance:
#
# options.force? # => !!options['force']
# options.shebang # => "/usr/lib/local/ruby"
# options.test_framework?(:rspec) # => options[:test_framework] == :rspec
#
def method_missing(method, *args, &block)
# Magic predicates. For instance:
#
# options.force? # => !!options['force']
# options.shebang # => "/usr/lib/local/ruby"
# options.test_framework?(:rspec) # => options[:test_framework] == :rspec
# rubocop:disable DoubleNegation
def method_missing(method, *args)
method = method.to_s
if method =~ /^(\w+)\?$/
if args.empty?

View file

@ -1,3 +1,5 @@
# rubocop:disable FileName
# Setup our load paths
libdir = File.expand_path(File.dirname(__FILE__))
$LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir)