Implemented Rubocop

- just took a stab at running the StringLiterals cop to get a taste.
This commit is contained in:
Karl Freeman 2013-12-28 00:26:31 +00:00
parent e996868033
commit 03d6e6c990
80 changed files with 510 additions and 477 deletions

View file

@ -1,11 +1,11 @@
require "middleman-core"
require "fileutils"
require 'middleman-core'
require 'fileutils'
require 'set'
# CLI Module
module Middleman::Cli
# Alias "b" to "build"
Base.map({ "b" => "build" })
Base.map({ 'b' => 'build' })
# The CLI Build class
class Build < Thor
@ -18,14 +18,14 @@ module Middleman::Cli
namespace :build
desc "build [options]", "Builds the static site for deployment"
desc 'build [options]', 'Builds the static site for deployment'
method_option :clean,
:type => :boolean,
:default => true,
:desc => 'Remove orphaned files from build (--no-clean to disable)'
method_option :glob,
:type => :string,
:aliases => "-g",
:aliases => '-g',
:default => nil,
:desc => 'Build a subset of the project'
method_option :verbose,
@ -44,33 +44,33 @@ module Middleman::Cli
# Core build Thor command
# @return [void]
def build
if !ENV["MM_ROOT"]
raise Thor::Error, "Error: Could not find a Middleman project config, perhaps you are in the wrong folder?"
if !ENV['MM_ROOT']
raise Thor::Error, 'Error: Could not find a Middleman project config, perhaps you are in the wrong folder?'
end
# Use Rack::Test for inspecting a running server for output
require "rack"
require "rack/test"
require 'rack'
require 'rack/test'
require 'find'
@debugging = Middleman::Cli::Base.respond_to?(:debugging) && Middleman::Cli::Base.debugging
self.had_errors = false
self.class.shared_instance(options["verbose"], options["instrument"])
self.class.shared_instance(options['verbose'], options['instrument'])
opts = {}
opts[:glob] = options["glob"] if options.has_key?("glob")
opts[:clean] = options["clean"]
opts[:glob] = options['glob'] if options.has_key?('glob')
opts[:clean] = options['clean']
action BuildAction.new(self, opts)
self.class.shared_instance.run_hook :after_build, self
if self.had_errors && !self.debugging
msg = "There were errors during this build"
unless options["verbose"]
msg << ", re-run with `middleman build --verbose` to see the full exception."
msg = 'There were errors during this build'
unless options['verbose']
msg << ', re-run with `middleman build --verbose` to see the full exception.'
end
self.shell.say msg, :red
end
@ -134,7 +134,7 @@ module Middleman::Cli
base.remove_file f, :force => true
end
Dir[@build_dir.join("**", "*")].select {|d| File.directory?(d) }.each do |d|
Dir[@build_dir.join('**', '*')].select {|d| File.directory?(d) }.each do |d|
base.remove_file d, :force => true if directory_empty? d
end
end
@ -177,15 +177,15 @@ module Middleman::Cli
sort_order = %w(.png .jpeg .jpg .gif .bmp .svg .svgz .ico .woff .otf .ttf .eot .js .css)
# Pre-request CSS to give Compass a chance to build sprites
logger.debug "== Prerendering CSS"
logger.debug '== Prerendering CSS'
@app.sitemap.resources.select do |resource|
resource.ext == ".css"
resource.ext == '.css'
end.each do |resource|
@rack.get(URI.escape(resource.destination_path))
end
logger.debug "== Checking for Compass sprites"
logger.debug '== Checking for Compass sprites'
# Double-check for compass sprites
@app.files.find_new_files((@source_dir + @app.images_dir).relative_path_from(@app.root_path))
@ -195,7 +195,7 @@ module Middleman::Cli
# find files in the build folder when it needs to generate sprites for the
# css files
logger.debug "== Building files"
logger.debug '== Building files'
resources = @app.sitemap.resources.sort_by do |r|
sort_order.index(r.ext) || 100
@ -222,7 +222,7 @@ module Middleman::Cli
end
end
::Middleman::Profiling.report("build")
::Middleman::Profiling.report('build')
end
# Render a resource to a file.
@ -268,14 +268,14 @@ module Middleman::Cli
if base.debugging
raise e
exit(1)
elsif base.options["verbose"]
elsif base.options['verbose']
base.shell.say response, :red
end
end
def binary_encode(string)
if string.respond_to?(:force_encoding)
string.force_encoding("ascii-8bit")
string.force_encoding('ascii-8bit')
end
string
end

View file

@ -8,7 +8,7 @@ module Middleman::Cli
namespace :bundle
desc "bundle", "Setup initial bundle", :hide => true
desc 'bundle', 'Setup initial bundle', :hide => true
# The setup task
def bundle
@ -23,11 +23,11 @@ module Middleman::Cli
namespace :upgrade
desc "upgrade", "Upgrade installed bundle"
desc 'upgrade', 'Upgrade installed bundle'
# The upgrade task
def upgrade
inside(ENV["MM_ROOT"]) do
inside(ENV['MM_ROOT']) do
run('bundle update')#, :capture => true)
end
end
@ -35,6 +35,6 @@ module Middleman::Cli
# Map "u" to "upgrade"
Base.map({
"u" => "upgrade"
'u' => 'upgrade'
})
end

View file

@ -9,18 +9,18 @@ module Middleman::Cli
namespace :console
desc "console [options]", "Start an interactive console in the context of your Middleman application"
desc 'console [options]', 'Start an interactive console in the context of your Middleman application'
method_option :environment,
:aliases => "-e",
:aliases => '-e',
:default => ENV['MM_ENV'] || ENV['RACK_ENV'] || 'development',
:desc => "The environment Middleman will run under"
:desc => 'The environment Middleman will run under'
method_option :verbose,
:type => :boolean,
:default => false,
:desc => 'Print debug messages'
def console
require "middleman-core"
require "irb"
require 'middleman-core'
require 'irb'
opts = {
:environment => options['environment'],

View file

@ -15,22 +15,22 @@ module Middleman::Cli
# Template files are relative to this file
# @return [String]
def self.source_root
File.join(File.dirname(__FILE__), "..", "templates", "extension")
File.join(File.dirname(__FILE__), '..', 'templates', 'extension')
end
desc "extension [options]", "Create Middleman extension scaffold NAME"
desc 'extension [options]', 'Create Middleman extension scaffold NAME'
# The extension task
# @param [String] name
def extension
generate_gitignore!
template "Rakefile", File.join(name, "Rakefile")
template "gemspec", File.join(name, "#{name}.gemspec")
template "Gemfile", File.join(name, "Gemfile")
template "lib/middleman_extension.rb", File.join(name, "lib", "middleman_extension.rb")
template "lib/lib.rb", File.join(name, "lib", "#{name}.rb")
template "features/support/env.rb", File.join(name, "features", "support", "env.rb")
empty_directory File.join(name, "fixtures")
template 'Rakefile', File.join(name, 'Rakefile')
template 'gemspec', File.join(name, "#{name}.gemspec")
template 'Gemfile', File.join(name, 'Gemfile')
template 'lib/middleman_extension.rb', File.join(name, 'lib', 'middleman_extension.rb')
template 'lib/lib.rb', File.join(name, 'lib', "#{name}.rb")
template 'features/support/env.rb', File.join(name, 'features', 'support', 'env.rb')
empty_directory File.join(name, 'fixtures')
end
# Output a .gitignore file
@ -41,7 +41,7 @@ module Middleman::Cli
# @return [void]
def generate_gitignore!
return unless options[:git]
copy_file "gitignore", File.join(name, ".gitignore")
copy_file 'gitignore', File.join(name, '.gitignore')
end
}

View file

@ -1,4 +1,4 @@
require "middleman-core/templates"
require 'middleman-core/templates'
# CLI Module
module Middleman::Cli
@ -9,35 +9,35 @@ module Middleman::Cli
namespace :init
desc "init NAME [options]", "Create new project NAME"
available_templates = ::Middleman::Templates.registered.keys.join(", ")
method_option "template",
:aliases => "-T",
:default => "default",
desc 'init NAME [options]', 'Create new project NAME'
available_templates = ::Middleman::Templates.registered.keys.join(', ')
method_option 'template',
:aliases => '-T',
:default => 'default',
:desc => "Use a project template: #{available_templates}"
method_option "css_dir",
method_option 'css_dir',
# :default => "stylesheets",
:desc => 'The path to the css files'
method_option "js_dir",
method_option 'js_dir',
# :default => "javascripts",
:desc => 'The path to the javascript files'
method_option "images_dir",
method_option 'images_dir',
# :default => "images",
:desc => 'The path to the image files'
method_option "rack",
method_option 'rack',
:type => :boolean,
:default => false,
:desc => 'Include a config.ru file'
method_option "skip-gemfile",
method_option 'skip-gemfile',
:type => :boolean,
:default => false,
:desc => "Don't create a Gemfile"
method_option "skip-bundle",
method_option 'skip-bundle',
:type => :boolean,
:aliases => "-B",
:aliases => '-B',
:default => false,
:desc => "Don't run bundle install"
method_option "skip-git",
method_option 'skip-git',
:type => :boolean,
:default => false,
:desc => 'Skip Git ignores and keeps'
@ -60,8 +60,8 @@ module Middleman::Cli
# Map "i", "new" and "n" to "init"
Base.map({
"i" => "init",
"new" => "init",
"n" => "init"
'i' => 'init',
'new' => 'init',
'n' => 'init'
})
end

View file

@ -7,20 +7,20 @@ module Middleman::Cli
namespace :server
desc "server [options]", "Start the preview server"
desc 'server [options]', 'Start the preview server'
method_option :environment,
:aliases => "-e",
:aliases => '-e',
:default => ENV['MM_ENV'] || ENV['RACK_ENV'] || 'development',
:desc => "The environment Middleman will run under"
:desc => 'The environment Middleman will run under'
method_option :host,
:type => :string,
:aliases => "-h",
:default => "0.0.0.0",
:desc => "Bind to HOST address"
:aliases => '-h',
:default => '0.0.0.0',
:desc => 'Bind to HOST address'
method_option :port,
:aliases => "-p",
:default => "4567",
:desc => "The port Middleman will listen on"
:aliases => '-p',
:default => '4567',
:desc => 'The port Middleman will listen on'
method_option :verbose,
:type => :boolean,
:default => false,
@ -47,35 +47,35 @@ module Middleman::Cli
:desc => 'Force file watcher into polling mode'
method_option :latency,
:type => :numeric,
:aliases => "-l",
:aliases => '-l',
:default => 0.25,
:desc => 'Set file watcher latency, in seconds'
# Start the server
def server
require "middleman-core"
require "middleman-core/preview_server"
require 'middleman-core'
require 'middleman-core/preview_server'
if !ENV["MM_ROOT"]
puts "== Could not find a Middleman project config.rb"
puts "== Treating directory as a static site to be served"
ENV["MM_ROOT"] = Dir.pwd
ENV["MM_SOURCE"] = ""
if !ENV['MM_ROOT']
puts '== Could not find a Middleman project config.rb'
puts '== Treating directory as a static site to be served'
ENV['MM_ROOT'] = Dir.pwd
ENV['MM_SOURCE'] = ''
end
params = {
:port => options["port"],
:host => options["host"],
:environment => options["environment"],
:debug => options["verbose"],
:instrumenting => options["instrument"],
:disable_watcher => options["disable_watcher"],
:reload_paths => options["reload_paths"],
:force_polling => options["force_polling"],
:latency => options["latency"]
:port => options['port'],
:host => options['host'],
:environment => options['environment'],
:debug => options['verbose'],
:instrumenting => options['instrument'],
:disable_watcher => options['disable_watcher'],
:reload_paths => options['reload_paths'],
:force_polling => options['force_polling'],
:latency => options['latency']
}
puts "== The Middleman is loading"
puts '== The Middleman is loading'
::Middleman::PreviewServer.start(params)
end
end
@ -85,5 +85,5 @@ module Middleman::Cli
end
# Map "s" to "server"
Base.map({ "s" => "server" })
Base.map({ 's' => 'server' })
end