hashrocket killa
This commit is contained in:
parent
147b0a6626
commit
6760d855bc
|
@ -10,6 +10,7 @@ AllCops:
|
|||
- '**/tmp/**/*'
|
||||
- '**/bin/**/*'
|
||||
- 'middleman-core/lib/middleman-core/step_definitions/**/*'
|
||||
- 'middleman-core/lib/vendored-middleman-deps/**/*'
|
||||
- 'middleman-templates/lib/middleman-templates/**/*'
|
||||
- 'middleman-core/fixtures/**/*'
|
||||
- 'middleman-core/features/**/*'
|
||||
|
|
12
Rakefile
12
Rakefile
|
@ -11,11 +11,11 @@ middleman_gems = %w(middleman-core middleman-templates middleman-cli middleman)
|
|||
GEM_PATHS = middleman_gems.freeze
|
||||
|
||||
def sh_rake(command)
|
||||
sh "#{Gem.ruby} -S rake #{command}", :verbose => true
|
||||
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)
|
||||
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
|
||||
|
||||
|
@ -29,7 +29,7 @@ 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) }
|
||||
%w(tmp pkg coverage).each { |dir| sh 'rm -rf %s' % File.join(g, dir) }
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -54,7 +54,7 @@ task :bump, [:version] do |t, args|
|
|||
end
|
||||
|
||||
desc 'Executes a fresh install removing all middleman version and then reinstall all gems'
|
||||
task :fresh => [:uninstall, :install, :clean]
|
||||
task fresh: [:uninstall, :install, :clean]
|
||||
|
||||
desc 'Pushes repository to GitHub'
|
||||
task :push do
|
||||
|
@ -65,7 +65,7 @@ task :push do
|
|||
end
|
||||
|
||||
desc 'Release all middleman gems'
|
||||
task :publish => :push do
|
||||
task publish: :push do
|
||||
say 'Pushing to rubygems...'
|
||||
GEM_PATHS.each do |dir|
|
||||
Dir.chdir(dir) { sh_rake('release') }
|
||||
|
@ -115,4 +115,4 @@ rescue LoadError
|
|||
end
|
||||
|
||||
desc 'Run tests for all middleman gems'
|
||||
task :default => :test
|
||||
task default: :test
|
||||
|
|
|
@ -20,14 +20,14 @@ Cucumber::Rake::Task.new do |t|
|
|||
exempt_tags << '--tags ~@nojava' if RUBY_PLATFORM == 'java'
|
||||
exempt_tags << '--tags ~@encoding' unless Object.const_defined?(:Encoding)
|
||||
exempt_tags << '--tags ~@travishatesme' if ENV['TRAVIS'] == 'true'
|
||||
t.cucumber_opts = "--color #{exempt_tags.join(" ")} --strict --format #{ENV['CUCUMBER_FORMAT'] || 'Fivemat'}"
|
||||
t.cucumber_opts = "--color #{exempt_tags.join(' ')} --strict --format #{ENV['CUCUMBER_FORMAT'] || 'Fivemat'}"
|
||||
end
|
||||
|
||||
Cucumber::Rake::Task.new(:cucumber_wip) do |t|
|
||||
exempt_tags = ['--tags @wip']
|
||||
exempt_tags << '--tags ~@nojava' if RUBY_PLATFORM == 'java'
|
||||
exempt_tags << '--tags ~@encoding' unless Object.const_defined?(:Encoding)
|
||||
t.cucumber_opts = "--color #{exempt_tags.join(" ")} --strict --format #{ENV['CUCUMBER_FORMAT'] || 'Fivemat'}"
|
||||
t.cucumber_opts = "--color #{exempt_tags.join(' ')} --strict --format #{ENV['CUCUMBER_FORMAT'] || 'Fivemat'}"
|
||||
end
|
||||
|
||||
require 'rspec/core/rake_task'
|
||||
|
@ -38,8 +38,8 @@ RSpec::Core::RakeTask.new do |spec|
|
|||
end
|
||||
|
||||
desc 'Run tests, both RSpec and Cucumber'
|
||||
task :test => [:spec, :cucumber]
|
||||
task test: [:spec, :cucumber]
|
||||
|
||||
YARD::Rake::YardocTask.new
|
||||
|
||||
task :default => :test
|
||||
task default: :test
|
||||
|
|
|
@ -8,9 +8,7 @@ require 'thor/group'
|
|||
|
||||
# CLI Module
|
||||
module Middleman
|
||||
|
||||
module Cli
|
||||
|
||||
# The base task from which everything else extends
|
||||
class Base < Thor
|
||||
class << self
|
||||
|
@ -39,7 +37,7 @@ module Middleman
|
|||
def help(meth=nil, subcommand=false)
|
||||
if meth && !self.respond_to?(meth)
|
||||
klass, task = Thor::Util.find_class_and_task_by_namespace("#{meth}:#{meth}")
|
||||
klass.start(['-h', task].compact, :shell => self.shell)
|
||||
klass.start(['-h', task].compact, shell: shell)
|
||||
else
|
||||
list = []
|
||||
Thor::Util.thor_classes_in(Middleman::Cli).each do |thor_class|
|
||||
|
@ -48,7 +46,7 @@ module Middleman
|
|||
list.sort! { |a, b| a[0] <=> b[0] }
|
||||
|
||||
shell.say 'Tasks:'
|
||||
shell.print_table(list, :ident => 2, :truncate => true)
|
||||
shell.print_table(list, ident: 2, truncate: true)
|
||||
shell.say %(\nSee 'middleman help <command>' for more information on specific command.)
|
||||
shell.say
|
||||
end
|
||||
|
@ -59,7 +57,7 @@ module Middleman
|
|||
def method_missing(meth, *args)
|
||||
meth = meth.to_s
|
||||
|
||||
if self.class.map.has_key?(meth)
|
||||
if self.class.map.key?(meth)
|
||||
meth = self.class.map[meth]
|
||||
end
|
||||
|
||||
|
@ -68,7 +66,7 @@ module Middleman
|
|||
if klass.nil?
|
||||
tasks_dir = File.join(Dir.pwd, 'tasks')
|
||||
|
||||
if File.exists?(tasks_dir)
|
||||
if File.exist?(tasks_dir)
|
||||
Dir[File.join(tasks_dir, '**/*_task.rb')].each { |f| require f }
|
||||
klass, task = Thor::Util.find_class_and_task_by_namespace("#{meth}:#{meth}")
|
||||
end
|
||||
|
@ -78,7 +76,7 @@ module Middleman
|
|||
raise Thor::Error.new "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 => self.shell)
|
||||
klass.start(args, shell: shell)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -4,7 +4,7 @@ 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
|
||||
|
@ -19,31 +19,31 @@ module Middleman::Cli
|
|||
|
||||
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)'
|
||||
type: :boolean,
|
||||
default: true,
|
||||
desc: 'Remove orphaned files from build (--no-clean to disable)'
|
||||
method_option :glob,
|
||||
:type => :string,
|
||||
:aliases => '-g',
|
||||
:default => nil,
|
||||
:desc => 'Build a subset of the project'
|
||||
type: :string,
|
||||
aliases: '-g',
|
||||
default: nil,
|
||||
desc: 'Build a subset of the project'
|
||||
method_option :verbose,
|
||||
:type => :boolean,
|
||||
:default => false,
|
||||
:desc => 'Print debug messages'
|
||||
type: :boolean,
|
||||
default: false,
|
||||
desc: 'Print debug messages'
|
||||
method_option :instrument,
|
||||
:type => :string,
|
||||
:default => false,
|
||||
:desc => 'Print instrument messages'
|
||||
type: :string,
|
||||
default: false,
|
||||
desc: 'Print instrument messages'
|
||||
method_option :profile,
|
||||
:type => :boolean,
|
||||
:default => false,
|
||||
:desc => 'Generate profiling report for the build'
|
||||
type: :boolean,
|
||||
default: false,
|
||||
desc: 'Generate profiling report for the build'
|
||||
|
||||
# Core build Thor command
|
||||
# @return [void]
|
||||
def build
|
||||
if !ENV['MM_ROOT']
|
||||
unless ENV['MM_ROOT']
|
||||
raise Thor::Error, 'Error: Could not find a Middleman project config, perhaps you are in the wrong folder?'
|
||||
end
|
||||
|
||||
|
@ -61,7 +61,7 @@ module Middleman::Cli
|
|||
self.class.shared_instance(options['verbose'], options['instrument'])
|
||||
|
||||
opts = {}
|
||||
opts[:glob] = options['glob'] if options.has_key?('glob')
|
||||
opts[:glob] = options['glob'] if options.key?('glob')
|
||||
opts[:clean] = options['clean']
|
||||
|
||||
self.class.shared_instance.run_hook :before_build, self
|
||||
|
@ -71,15 +71,15 @@ module Middleman::Cli
|
|||
self.class.shared_instance.run_hook :after_build, self
|
||||
self.class.shared_instance.config_context.execute_after_build_callbacks(self)
|
||||
|
||||
if self.had_errors && !self.debugging
|
||||
if had_errors && !debugging
|
||||
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
|
||||
shell.say msg, :red
|
||||
end
|
||||
|
||||
exit(1) if self.had_errors
|
||||
exit(1) if had_errors
|
||||
end
|
||||
|
||||
# Static methods
|
||||
|
@ -135,11 +135,11 @@ module Middleman::Cli
|
|||
# @return [void]
|
||||
def clean!
|
||||
@to_clean.each do |f|
|
||||
base.remove_file f, :force => true
|
||||
base.remove_file f, force: true
|
||||
end
|
||||
|
||||
Dir[@build_dir.join('**', '*')].select { |d| File.directory?(d) }.each do |d|
|
||||
base.remove_file d, :force => true if directory_empty? d
|
||||
base.remove_file d, force: true if directory_empty? d
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
# CLI Module
|
||||
module Middleman::Cli
|
||||
# Alias "c" to "console"
|
||||
Base.map({ 'c' => 'console' })
|
||||
Base.map('c' => 'console')
|
||||
|
||||
# The CLI Console class
|
||||
class Console < Thor
|
||||
|
@ -13,20 +13,20 @@ module Middleman::Cli
|
|||
|
||||
desc 'console [options]', 'Start an interactive console in the context of your Middleman application'
|
||||
method_option :environment,
|
||||
:aliases => '-e',
|
||||
:default => ENV['MM_ENV'] || ENV['RACK_ENV'] || 'development',
|
||||
:desc => 'The environment Middleman will run under'
|
||||
aliases: '-e',
|
||||
default: ENV['MM_ENV'] || ENV['RACK_ENV'] || 'development',
|
||||
desc: 'The environment Middleman will run under'
|
||||
method_option :verbose,
|
||||
:type => :boolean,
|
||||
:default => false,
|
||||
:desc => 'Print debug messages'
|
||||
type: :boolean,
|
||||
default: false,
|
||||
desc: 'Print debug messages'
|
||||
def console
|
||||
require 'middleman-core'
|
||||
require 'irb'
|
||||
|
||||
opts = {
|
||||
:environment => options['environment'],
|
||||
:debug => options['verbose']
|
||||
environment: options['environment'],
|
||||
debug: options['verbose']
|
||||
}
|
||||
|
||||
@app = ::Middleman::Application.server.inst do
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
# CLI Module
|
||||
module Middleman::Cli
|
||||
|
||||
# A thor task for creating new projects
|
||||
class Extension < Thor
|
||||
include Thor::Actions
|
||||
|
@ -10,7 +9,7 @@ module Middleman::Cli
|
|||
namespace :extension
|
||||
|
||||
# Required path for the new project to be generated
|
||||
argument :name, :type => :string
|
||||
argument :name, type: :string
|
||||
|
||||
# Template files are relative to this file
|
||||
# @return [String]
|
||||
|
@ -20,9 +19,9 @@ module Middleman::Cli
|
|||
|
||||
desc 'extension [options]', 'Create Middleman extension scaffold NAME'
|
||||
method_option 'skip-git',
|
||||
:type => :boolean,
|
||||
:default => false,
|
||||
:desc => 'Skip Git ignores and keeps'
|
||||
type: :boolean,
|
||||
default: false,
|
||||
desc: 'Skip Git ignores and keeps'
|
||||
|
||||
# The extension task
|
||||
# @param [String] name
|
||||
|
@ -38,7 +37,6 @@ module Middleman::Cli
|
|||
end
|
||||
|
||||
# Output a .gitignore file
|
||||
class_option :git, :type => :boolean, :default => true
|
||||
|
||||
class_option :git, type: :boolean, default: true
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,7 +2,6 @@ require 'middleman-templates'
|
|||
|
||||
# CLI Module
|
||||
module Middleman::Cli
|
||||
|
||||
# A thor task for creating new projects
|
||||
class Init < Thor
|
||||
check_unknown_options!
|
||||
|
@ -12,36 +11,36 @@ module Middleman::Cli
|
|||
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}"
|
||||
aliases: '-T',
|
||||
default: 'default',
|
||||
desc: "Use a project template: #{available_templates}"
|
||||
method_option 'css_dir',
|
||||
# :default => "stylesheets",
|
||||
:desc => 'The path to the css files'
|
||||
desc: 'The path to the css files'
|
||||
method_option 'js_dir',
|
||||
# :default => "javascripts",
|
||||
:desc => 'The path to the javascript files'
|
||||
desc: 'The path to the javascript files'
|
||||
method_option 'images_dir',
|
||||
# :default => "images",
|
||||
:desc => 'The path to the image files'
|
||||
desc: 'The path to the image files'
|
||||
method_option 'rack',
|
||||
:type => :boolean,
|
||||
:default => false,
|
||||
:desc => 'Include a config.ru file'
|
||||
type: :boolean,
|
||||
default: false,
|
||||
desc: 'Include a config.ru file'
|
||||
method_option 'skip-bundle',
|
||||
:type => :boolean,
|
||||
:aliases => '-B',
|
||||
:default => false,
|
||||
:desc => "Don't run bundle install"
|
||||
type: :boolean,
|
||||
aliases: '-B',
|
||||
default: false,
|
||||
desc: "Don't run bundle install"
|
||||
method_option 'skip-git',
|
||||
:type => :boolean,
|
||||
:default => false,
|
||||
:desc => 'Skip Git ignores and keeps'
|
||||
type: :boolean,
|
||||
default: false,
|
||||
desc: 'Skip Git ignores and keeps'
|
||||
# The init task
|
||||
# @param [String] name
|
||||
def init(name='.')
|
||||
key = options[:template].to_sym
|
||||
unless ::Middleman::Templates.registered.has_key?(key)
|
||||
unless ::Middleman::Templates.registered.key?(key)
|
||||
raise Thor::Error.new "Unknown project template '#{key}'"
|
||||
end
|
||||
|
||||
|
@ -55,9 +54,9 @@ module Middleman::Cli
|
|||
end
|
||||
|
||||
# Map "i", "new" and "n" to "init"
|
||||
Base.map({
|
||||
Base.map(
|
||||
'i' => 'init',
|
||||
'new' => 'init',
|
||||
'n' => 'init'
|
||||
})
|
||||
)
|
||||
end
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
# CLI Module
|
||||
module Middleman::Cli
|
||||
|
||||
# Server thor task
|
||||
class Server < Thor
|
||||
check_unknown_options!
|
||||
|
@ -9,68 +8,68 @@ module Middleman::Cli
|
|||
|
||||
desc 'server [options]', 'Start the preview server'
|
||||
method_option :environment,
|
||||
:aliases => '-e',
|
||||
:default => ENV['MM_ENV'] || ENV['RACK_ENV'] || 'development',
|
||||
:desc => 'The environment Middleman will run under'
|
||||
aliases: '-e',
|
||||
default: ENV['MM_ENV'] || ENV['RACK_ENV'] || 'development',
|
||||
desc: 'The environment Middleman will run under'
|
||||
method_option :host,
|
||||
:type => :string,
|
||||
:aliases => '-h',
|
||||
:default => '0.0.0.0',
|
||||
:desc => 'Bind to HOST address'
|
||||
type: :string,
|
||||
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,
|
||||
:desc => 'Print debug messages'
|
||||
type: :boolean,
|
||||
default: false,
|
||||
desc: 'Print debug messages'
|
||||
method_option :instrument,
|
||||
:type => :string,
|
||||
:default => false,
|
||||
:desc => 'Print instrument messages'
|
||||
type: :string,
|
||||
default: false,
|
||||
desc: 'Print instrument messages'
|
||||
method_option :disable_watcher,
|
||||
:type => :boolean,
|
||||
:default => false,
|
||||
:desc => 'Disable the file change and delete watcher process'
|
||||
type: :boolean,
|
||||
default: false,
|
||||
desc: 'Disable the file change and delete watcher process'
|
||||
method_option :profile,
|
||||
:type => :boolean,
|
||||
:default => false,
|
||||
:desc => 'Generate profiling report for server startup'
|
||||
type: :boolean,
|
||||
default: false,
|
||||
desc: 'Generate profiling report for server startup'
|
||||
method_option :reload_paths,
|
||||
:type => :string,
|
||||
:default => false,
|
||||
:desc => 'Additional paths to auto-reload when files change'
|
||||
type: :string,
|
||||
default: false,
|
||||
desc: 'Additional paths to auto-reload when files change'
|
||||
method_option :force_polling,
|
||||
:type => :boolean,
|
||||
:default => false,
|
||||
:desc => 'Force file watcher into polling mode'
|
||||
type: :boolean,
|
||||
default: false,
|
||||
desc: 'Force file watcher into polling mode'
|
||||
method_option :latency,
|
||||
:type => :numeric,
|
||||
:aliases => '-l',
|
||||
:default => 0.25,
|
||||
:desc => 'Set file watcher latency, in seconds'
|
||||
type: :numeric,
|
||||
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'
|
||||
|
||||
if !ENV['MM_ROOT']
|
||||
unless ENV['MM_ROOT']
|
||||
puts '== Could not find a Middleman project config.rb'
|
||||
exit
|
||||
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'
|
||||
|
@ -83,5 +82,5 @@ module Middleman::Cli
|
|||
end
|
||||
|
||||
# Map "s" to "server"
|
||||
Base.map({ 's' => 'server' })
|
||||
Base.map('s' => 'server')
|
||||
end
|
||||
|
|
|
@ -9,6 +9,6 @@ end
|
|||
|
||||
require 'rake/clean'
|
||||
|
||||
task :test => ['cucumber']
|
||||
task test: ['cucumber']
|
||||
|
||||
task :default => :test
|
||||
task default: :test
|
||||
|
|
|
@ -28,7 +28,6 @@ class MyExtension < ::Middleman::Extension
|
|||
# def a_helper
|
||||
# end
|
||||
# end
|
||||
|
||||
end
|
||||
|
||||
# Register extensions which can be activated
|
||||
|
|
|
@ -4,10 +4,8 @@ $LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir)
|
|||
|
||||
# Top-level Middleman namespace
|
||||
module Middleman
|
||||
|
||||
# Backwards compatibility namespace
|
||||
module Features; end
|
||||
|
||||
end
|
||||
|
||||
require 'middleman-core/version'
|
||||
|
|
|
@ -52,13 +52,13 @@ module Middleman
|
|||
def self.root
|
||||
ENV['MM_ROOT'] || Dir.pwd
|
||||
end
|
||||
delegate :root, :to => :"self.class"
|
||||
delegate :root, to: :"self.class"
|
||||
|
||||
# Pathname-addressed root
|
||||
def self.root_path
|
||||
Pathname(root)
|
||||
end
|
||||
delegate :root_path, :to => :"self.class"
|
||||
delegate :root_path, to: :"self.class"
|
||||
|
||||
# Name of the source directory
|
||||
# @return [String]
|
||||
|
@ -165,7 +165,7 @@ module Middleman
|
|||
attr_reader :template_context_class
|
||||
|
||||
attr_reader :generic_template_context
|
||||
delegate :link_to, :image_tag, :asset_path, :to => :generic_template_context
|
||||
delegate :link_to, :image_tag, :asset_path, to: :generic_template_context
|
||||
|
||||
# Initialize the Middleman project
|
||||
def initialize(&block)
|
||||
|
@ -210,7 +210,7 @@ module Middleman
|
|||
end
|
||||
|
||||
def add_to_instance(name, &func)
|
||||
self.define_singleton_method(name, &func)
|
||||
define_singleton_method(name, &func)
|
||||
end
|
||||
|
||||
def add_to_config_context(name, &func)
|
||||
|
@ -236,7 +236,7 @@ module Middleman
|
|||
File.join(root, config[:source])
|
||||
end
|
||||
|
||||
delegate :instrument, :to => ::Middleman::Util
|
||||
delegate :instrument, to: ::Middleman::Util
|
||||
|
||||
# Work around this bug: http://bugs.ruby-lang.org/issues/4521
|
||||
# where Ruby will call to_s/inspect while printing exception
|
||||
|
@ -245,7 +245,7 @@ module Middleman
|
|||
def to_s
|
||||
"#<Middleman::Application:0x#{object_id}>"
|
||||
end
|
||||
alias :inspect :to_s # Ruby 2.0 calls inspect for NoMethodError instead of to_s
|
||||
alias_method :inspect, :to_s # Ruby 2.0 calls inspect for NoMethodError instead of to_s
|
||||
|
||||
# Hooks clones _hooks from the class to the instance.
|
||||
# https://github.com/apotonick/hooks/blob/master/lib/hooks/instance_hooks.rb#L10
|
||||
|
|
|
@ -6,7 +6,7 @@ module Middleman
|
|||
attr_reader :app
|
||||
|
||||
# Whitelist methods that can reach out.
|
||||
delegate :config, :logger, :activate, :use, :map, :mime_type, :data, :root, :to => :app
|
||||
delegate :config, :logger, :activate, :use, :map, :mime_type, :data, :root, to: :app
|
||||
|
||||
def initialize(app, template_context_class)
|
||||
@app = app
|
||||
|
|
|
@ -5,7 +5,7 @@ module Middleman
|
|||
module Global
|
||||
def self.included(app)
|
||||
app.send :extend, ClassMethods
|
||||
app.send :delegate, :config, :to => :"self.class"
|
||||
app.send :delegate, :config, to: :"self.class"
|
||||
end
|
||||
|
||||
module ClassMethods
|
||||
|
@ -75,7 +75,7 @@ module Middleman
|
|||
# @param [Symbol] key
|
||||
# @return [Boolean]
|
||||
def defines_setting?(key)
|
||||
@settings.has_key?(key)
|
||||
@settings.key?(key)
|
||||
end
|
||||
|
||||
# Define a new setting, with optional default and user-friendly description.
|
||||
|
@ -87,7 +87,7 @@ module Middleman
|
|||
# @return [ConfigSetting]
|
||||
def define_setting(key, default=nil, description=nil)
|
||||
raise "Setting #{key} doesn't exist" if @finalized
|
||||
raise "Setting #{key} already defined" if @settings.has_key?(key)
|
||||
raise "Setting #{key} already defined" if @settings.key?(key)
|
||||
raise 'Setting key must be a Symbol' unless key.is_a? Symbol
|
||||
|
||||
@settings[key] = ConfigSetting.new(key, default, description)
|
||||
|
@ -102,7 +102,7 @@ module Middleman
|
|||
|
||||
# Deep duplicate of the configuration manager
|
||||
def dup
|
||||
ConfigurationManager.new.tap {|c| c.load_settings(self.all_settings) }
|
||||
ConfigurationManager.new.tap { |c| c.load_settings(all_settings) }
|
||||
end
|
||||
|
||||
# Load in a list of settings
|
||||
|
|
|
@ -2,7 +2,6 @@ require 'middleman-core/renderers/sass'
|
|||
require 'compass'
|
||||
|
||||
class Middleman::CoreExtensions::Compass < ::Middleman::Extension
|
||||
|
||||
def initialize(app, options_hash={}, &block)
|
||||
super
|
||||
|
||||
|
|
|
@ -1,10 +1,8 @@
|
|||
module Middleman
|
||||
module CoreExtensions
|
||||
|
||||
# The data extension parses YAML and JSON files in the data/ directory
|
||||
# and makes them available to config.rb, templates and extensions
|
||||
module Data
|
||||
|
||||
# Extension registered
|
||||
class << self
|
||||
# @private
|
||||
|
@ -23,12 +21,12 @@ module Middleman
|
|||
# Setup data files before anything else so they are available when
|
||||
# parsing config.rb
|
||||
def initialize
|
||||
self.files.changed DataStore.matcher do |file|
|
||||
self.data.touch_file(file) if file.start_with?("#{config[:data_dir]}/")
|
||||
files.changed DataStore.matcher do |file|
|
||||
data.touch_file(file) if file.start_with?("#{config[:data_dir]}/")
|
||||
end
|
||||
|
||||
self.files.deleted DataStore.matcher do |file|
|
||||
self.data.remove_file(file) if file.start_with?("#{config[:data_dir]}/")
|
||||
files.deleted DataStore.matcher do |file|
|
||||
data.remove_file(file) if file.start_with?("#{config[:data_dir]}/")
|
||||
end
|
||||
|
||||
super
|
||||
|
@ -44,10 +42,8 @@ module Middleman
|
|||
|
||||
# The core logic behind the data extension.
|
||||
class DataStore
|
||||
|
||||
# Static methods
|
||||
class << self
|
||||
|
||||
# The regex which tells Middleman which files are for data
|
||||
#
|
||||
# @return [Regexp]
|
||||
|
@ -136,7 +132,7 @@ module Middleman
|
|||
data_branch = data_branch[dir]
|
||||
end
|
||||
|
||||
data_branch.delete(basename) if data_branch.has_key?(basename)
|
||||
data_branch.delete(basename) if data_branch.key?(basename)
|
||||
end
|
||||
|
||||
# Get a hash from either internal static data or a callback
|
||||
|
@ -149,10 +145,10 @@ module Middleman
|
|||
@@local_sources ||= {}
|
||||
@@callback_sources ||= {}
|
||||
|
||||
if self.store.has_key?(path.to_s)
|
||||
response = self.store[path.to_s]
|
||||
elsif self.callbacks.has_key?(path.to_s)
|
||||
response = self.callbacks[path.to_s].call()
|
||||
if store.key?(path.to_s)
|
||||
response = store[path.to_s]
|
||||
elsif callbacks.key?(path.to_s)
|
||||
response = callbacks[path.to_s].call
|
||||
end
|
||||
|
||||
response
|
||||
|
@ -163,7 +159,7 @@ module Middleman
|
|||
# @param [String] path The namespace to search for
|
||||
# @return [Hash, nil]
|
||||
def method_missing(path)
|
||||
if @local_data.has_key?(path.to_s)
|
||||
if @local_data.key?(path.to_s)
|
||||
return @local_data[path.to_s]
|
||||
else
|
||||
result = data_for_path(path)
|
||||
|
@ -178,7 +174,7 @@ module Middleman
|
|||
|
||||
# Needed so that method_missing makes sense
|
||||
def respond_to?(method, include_private=false)
|
||||
super || has_key?(method)
|
||||
super || key?(method)
|
||||
end
|
||||
|
||||
# Make DataStore act like a hash. Return requested data, or
|
||||
|
@ -187,11 +183,11 @@ module Middleman
|
|||
# @param [String, Symbol] key The name of the data namespace
|
||||
# @return [Hash, nil]
|
||||
def [](key)
|
||||
__send__(key) if has_key?(key)
|
||||
__send__(key) if key?(key)
|
||||
end
|
||||
|
||||
def has_key?(key)
|
||||
@local_data.has_key?(key.to_s) || !!(data_for_path(key))
|
||||
@local_data.key?(key.to_s) || !!(data_for_path(key))
|
||||
end
|
||||
|
||||
# Convert all the data into a static hash
|
||||
|
@ -200,11 +196,11 @@ module Middleman
|
|||
def to_h
|
||||
data = {}
|
||||
|
||||
self.store.each do |k, v|
|
||||
store.each do |k, v|
|
||||
data[k] = data_for_path(k)
|
||||
end
|
||||
|
||||
self.callbacks.each do |k, v|
|
||||
callbacks.each do |k, v|
|
||||
data[k] = data_for_path(k)
|
||||
end
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ require 'padrino-helpers'
|
|||
class Padrino::Helpers::OutputHelpers::ErbHandler
|
||||
# Force Erb capture not to use safebuffer
|
||||
def capture_from_template(*args, &block)
|
||||
self.output_buffer, _buf_was = '', self.output_buffer
|
||||
self.output_buffer, _buf_was = '', output_buffer
|
||||
raw = block.call(*args)
|
||||
captured = template.instance_variable_get(:@_out_buf)
|
||||
self.output_buffer = _buf_was
|
||||
|
@ -16,7 +16,6 @@ class Padrino::Helpers::OutputHelpers::ErbHandler
|
|||
end
|
||||
|
||||
class Middleman::CoreExtensions::DefaultHelpers < ::Middleman::Extension
|
||||
|
||||
def initialize(app, options_hash={}, &block)
|
||||
super
|
||||
|
||||
|
|
|
@ -32,7 +32,6 @@
|
|||
module Middleman
|
||||
module CoreExtensions
|
||||
module Extensions
|
||||
|
||||
# Register extension
|
||||
class << self
|
||||
# @private
|
||||
|
@ -49,7 +48,7 @@ module Middleman
|
|||
|
||||
app.extend ClassMethods
|
||||
app.send :include, InstanceMethods
|
||||
app.delegate :configure, :to => :"self.class"
|
||||
app.delegate :configure, to: :"self.class"
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -123,7 +122,7 @@ module Middleman
|
|||
|
||||
# Check for and evaluate local configuration
|
||||
local_config = File.join(root, 'config.rb')
|
||||
if File.exists? local_config
|
||||
if File.exist? local_config
|
||||
logger.debug '== Reading: Local config'
|
||||
config_context.instance_eval File.read(local_config), local_config, 1
|
||||
end
|
||||
|
@ -153,7 +152,7 @@ module Middleman
|
|||
config_context.execute_after_configuration_callbacks
|
||||
|
||||
logger.debug 'Loaded extensions:'
|
||||
self.extensions.each do |ext, klass|
|
||||
extensions.each do |ext, klass|
|
||||
if ext.is_a?(Hash)
|
||||
ext.each do |k, _|
|
||||
logger.debug "== Extension: #{k}"
|
||||
|
|
|
@ -7,7 +7,7 @@ module Middleman
|
|||
# Setup a default helpers paths
|
||||
app.config.define_setting :helpers_dir, 'helpers', 'Directory to autoload helper modules from'
|
||||
app.config.define_setting :helpers_filename_glob, '**.rb', 'Glob pattern for matching helper ruby files'
|
||||
app.config.define_setting :helpers_filename_to_module_name_proc, Proc.new { |filename|
|
||||
app.config.define_setting :helpers_filename_to_module_name_proc, proc { |filename|
|
||||
basename = File.basename(filename, File.extname(filename))
|
||||
basename.camelcase
|
||||
}, 'Proc implementing the conversion from helper filename to module name'
|
||||
|
@ -15,7 +15,7 @@ module Middleman
|
|||
# After config
|
||||
app.after_configuration do
|
||||
helpers_path = File.join(root, config[:helpers_dir])
|
||||
next unless File.exists?(helpers_path)
|
||||
next unless File.exist?(helpers_path)
|
||||
|
||||
Dir[File.join(helpers_path, config[:helpers_filename_glob])].each do |filename|
|
||||
module_name = config[:helpers_filename_to_module_name_proc].call(filename)
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
module Middleman
|
||||
module CoreExtensions
|
||||
module FileWatcher
|
||||
|
||||
IGNORE_LIST = [
|
||||
/^bin(\/|$)/,
|
||||
/^\.bundle(\/|$)/,
|
||||
|
@ -23,7 +22,6 @@ module Middleman
|
|||
|
||||
# Setup extension
|
||||
class << self
|
||||
|
||||
# Once registered
|
||||
def included(app)
|
||||
require 'pathname'
|
||||
|
@ -51,7 +49,6 @@ module Middleman
|
|||
|
||||
# Instance methods
|
||||
module InstanceMethods
|
||||
|
||||
# Access the file api
|
||||
# @return [Middleman::CoreExtensions::FileWatcher::API]
|
||||
def files
|
||||
|
@ -61,10 +58,9 @@ module Middleman
|
|||
|
||||
# Core File Change API class
|
||||
class API
|
||||
|
||||
attr_reader :app
|
||||
attr_reader :known_paths
|
||||
delegate :logger, :to => :app
|
||||
delegate :logger, to: :app
|
||||
|
||||
# Initialize api and internal path cache
|
||||
def initialize(app)
|
||||
|
@ -101,7 +97,7 @@ module Middleman
|
|||
path = Pathname(path)
|
||||
logger.debug "== File Change: #{path}"
|
||||
@known_paths << path
|
||||
self.run_callbacks(path, :changed)
|
||||
run_callbacks(path, :changed)
|
||||
end
|
||||
|
||||
# Notify callbacks that a file was deleted
|
||||
|
@ -112,7 +108,7 @@ module Middleman
|
|||
path = Pathname(path)
|
||||
logger.debug "== File Deletion: #{path}"
|
||||
@known_paths.delete(path)
|
||||
self.run_callbacks(path, :deleted)
|
||||
run_callbacks(path, :deleted)
|
||||
end
|
||||
|
||||
# Manually trigger update events
|
||||
|
@ -150,7 +146,7 @@ module Middleman
|
|||
|
||||
def exists?(path)
|
||||
p = Pathname(path)
|
||||
p = p.relative_path_from(Pathname(@app.root)) if !p.relative?
|
||||
p = p.relative_path_from(Pathname(@app.root)) unless p.relative?
|
||||
@known_paths.include?(p)
|
||||
end
|
||||
|
||||
|
@ -171,7 +167,7 @@ module Middleman
|
|||
# @return [void]
|
||||
def run_callbacks(path, callbacks_name)
|
||||
path = path.to_s
|
||||
self.send(callbacks_name).each do |callback, matcher|
|
||||
send(callbacks_name).each do |callback, matcher|
|
||||
next unless matcher.nil? || path.match(matcher)
|
||||
@app.instance_exec(path, &callback)
|
||||
end
|
||||
|
|
|
@ -9,9 +9,7 @@ require 'active_support/json'
|
|||
|
||||
# Extensions namespace
|
||||
module Middleman::CoreExtensions
|
||||
|
||||
class FrontMatter < ::Middleman::Extension
|
||||
|
||||
YAML_ERRORS = [StandardError]
|
||||
|
||||
# https://github.com/tenderlove/psych/issues/23
|
||||
|
@ -52,7 +50,7 @@ module Middleman::CoreExtensions
|
|||
end
|
||||
end
|
||||
|
||||
{ :options => data }
|
||||
{ options: data }
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -37,8 +37,8 @@ class Middleman::CoreExtensions::Internationalization < ::Middleman::Extension
|
|||
|
||||
configure_i18n
|
||||
|
||||
if !app.build?
|
||||
logger.info "== Locales: #{langs.join(", ")} (Default #{@mount_at_root})"
|
||||
unless app.build?
|
||||
logger.info "== Locales: #{langs.join(', ')} (Default #{@mount_at_root})"
|
||||
end
|
||||
|
||||
# Don't output localizable files
|
||||
|
@ -55,7 +55,7 @@ class Middleman::CoreExtensions::Internationalization < ::Middleman::Extension
|
|||
end
|
||||
end
|
||||
|
||||
delegate :logger, :to => :app
|
||||
delegate :logger, to: :app
|
||||
|
||||
def langs
|
||||
@_langs ||= get_known_languages
|
||||
|
@ -70,7 +70,7 @@ class Middleman::CoreExtensions::Internationalization < ::Middleman::Extension
|
|||
|
||||
resources.each do |resource|
|
||||
# If it uses file extension localization
|
||||
if !parse_locale_extension(resource.path).nil?
|
||||
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)
|
||||
|
@ -90,7 +90,6 @@ class Middleman::CoreExtensions::Internationalization < ::Middleman::Extension
|
|||
|
||||
private
|
||||
|
||||
|
||||
def on_file_changed(file)
|
||||
if @locales_regex =~ file
|
||||
@_langs = nil # Clear langs cache
|
||||
|
@ -125,11 +124,11 @@ class Middleman::CoreExtensions::Internationalization < ::Middleman::Extension
|
|||
end
|
||||
|
||||
{
|
||||
:locals => {
|
||||
:lang => lang,
|
||||
:page_id => page_id
|
||||
locals: {
|
||||
lang: lang,
|
||||
page_id: page_id
|
||||
},
|
||||
:options => { :lang => lang }
|
||||
options: { lang: lang }
|
||||
}
|
||||
end
|
||||
|
||||
|
@ -168,9 +167,9 @@ class Middleman::CoreExtensions::Internationalization < ::Middleman::Extension
|
|||
def build_resource(path, source_path, page_id, lang)
|
||||
old_locale = ::I18n.locale
|
||||
::I18n.locale = lang
|
||||
localized_page_id = ::I18n.t("paths.#{page_id}", :default => page_id, :fallback => [])
|
||||
localized_page_id = ::I18n.t("paths.#{page_id}", default: page_id, fallback: [])
|
||||
|
||||
prefix = if (options[:mount_at_root] == lang) || (options[:mount_at_root] == nil && langs[0] == lang)
|
||||
prefix = if (options[:mount_at_root] == lang) || (options[:mount_at_root].nil? && langs[0] == lang)
|
||||
'/'
|
||||
else
|
||||
replacement = options[:lang_map].fetch(lang, lang)
|
||||
|
|
|
@ -2,13 +2,10 @@ require 'middleman-core/template_context'
|
|||
|
||||
# Rendering extension
|
||||
module Middleman
|
||||
|
||||
module CoreExtensions
|
||||
module Rendering
|
||||
|
||||
# Setup extension
|
||||
class << self
|
||||
|
||||
# Once registered
|
||||
def included(app)
|
||||
app.define_hook :before_render
|
||||
|
|
|
@ -9,10 +9,8 @@ require 'middleman-core/template_renderer'
|
|||
|
||||
module Middleman
|
||||
module CoreExtensions
|
||||
|
||||
# Base helper to manipulate asset paths
|
||||
module Request
|
||||
|
||||
# Extension registered
|
||||
class << self
|
||||
# @private
|
||||
|
@ -60,9 +58,7 @@ module Middleman
|
|||
# @private
|
||||
# @param [Middleman::Application] inst
|
||||
# @return [void]
|
||||
def inst=(inst)
|
||||
@inst = inst
|
||||
end
|
||||
attr_writer :inst
|
||||
|
||||
# Return built Rack app
|
||||
#
|
||||
|
@ -152,9 +148,8 @@ module Middleman
|
|||
|
||||
# Methods to be mixed-in to Middleman::Application
|
||||
module InstanceMethods
|
||||
|
||||
delegate :use, :to => :"self.class"
|
||||
delegate :map, :to => :"self.class"
|
||||
delegate :use, to: :"self.class"
|
||||
delegate :map, to: :"self.class"
|
||||
|
||||
def call(env)
|
||||
dup.call!(env)
|
||||
|
@ -168,7 +163,7 @@ module Middleman
|
|||
req = ::Rack::Request.new(env)
|
||||
res = ::Rack::Response.new
|
||||
|
||||
logger.debug "== Request: #{env["PATH_INFO"]}"
|
||||
logger.debug "== Request: #{env['PATH_INFO']}"
|
||||
|
||||
# Catch :halt exceptions and use that response if given
|
||||
catch(:halt) do
|
||||
|
@ -239,7 +234,7 @@ module Middleman
|
|||
# @param [String] value Mime type
|
||||
# @return [void]
|
||||
def mime_type(type, value)
|
||||
type = ".#{type}" unless type.to_s[0] == ?.
|
||||
type = ".#{type}" unless type.to_s[0] == '.'
|
||||
::Rack::Mime::MIME_TYPES[type] = value
|
||||
end
|
||||
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
module Middleman
|
||||
module CoreExtensions
|
||||
module Routing
|
||||
|
||||
# Sandboxed layout to implement temporary overriding of layout.
|
||||
class LayoutBlock
|
||||
attr_reader :scope
|
||||
|
@ -17,7 +16,7 @@ module Middleman
|
|||
@scope.page(url, opts)
|
||||
end
|
||||
|
||||
delegate :proxy, :to => :scope
|
||||
delegate :proxy, to: :scope
|
||||
end
|
||||
|
||||
# Takes a block which allows many pages to have the same layout
|
||||
|
@ -46,7 +45,7 @@ module Middleman
|
|||
|
||||
# Default layout
|
||||
options[:layout] = @app.config[:layout] if options[:layout].nil?
|
||||
metadata = { :options => options, :locals => options.delete(:locals) || {} }
|
||||
metadata = { options: options, locals: options.delete(:locals) || {} }
|
||||
|
||||
# If the url is a regexp
|
||||
unless url.is_a?(Regexp) || url.include?('*')
|
||||
|
|
|
@ -2,11 +2,10 @@ require 'active_support/core_ext/module/delegation'
|
|||
require 'active_support/core_ext/class/attribute'
|
||||
|
||||
module Middleman
|
||||
|
||||
class Extension
|
||||
class_attribute :supports_multiple_instances, :instance_reader => false, :instance_writer => false
|
||||
class_attribute :defined_helpers, :instance_reader => false, :instance_writer => false
|
||||
class_attribute :ext_name, :instance_reader => false, :instance_writer => false
|
||||
class_attribute :supports_multiple_instances, instance_reader: false, instance_writer: false
|
||||
class_attribute :defined_helpers, instance_reader: false, instance_writer: false
|
||||
class_attribute :ext_name, instance_reader: false, instance_writer: false
|
||||
|
||||
class << self
|
||||
def config
|
||||
|
@ -51,7 +50,7 @@ module Middleman
|
|||
name = instance.class.ext_name
|
||||
return unless @_extension_activation_callbacks && @_extension_activation_callbacks[name]
|
||||
@_extension_activation_callbacks[name].each do |block|
|
||||
block.arity == 1 ? block.call(instance) : block.call()
|
||||
block.arity == 1 ? block.call(instance) : block.call
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -59,7 +58,7 @@ module Middleman
|
|||
attr_accessor :options
|
||||
attr_reader :app
|
||||
|
||||
delegate :after_extension_activated, :to => :"::Middleman::Extension"
|
||||
delegate :after_extension_activated, to: :"::Middleman::Extension"
|
||||
|
||||
def initialize(klass, options_hash={}, &block)
|
||||
@_helpers = []
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
module Middleman
|
||||
|
||||
module Extensions
|
||||
|
||||
class << self
|
||||
def registered
|
||||
@_registered ||= {}
|
||||
|
@ -32,7 +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.has_key?(name.to_sym)
|
||||
if registered.key?(name.to_sym)
|
||||
raise "There is already an extension registered with the name '#{name}'"
|
||||
end
|
||||
|
||||
|
@ -41,7 +39,7 @@ module Middleman
|
|||
elsif namespace && namespace.ancestors.include?(::Middleman::Extension)
|
||||
namespace
|
||||
else
|
||||
raise "You must provide a Middleman::Extension or a block that returns a Middleman::Extension"
|
||||
raise 'You must provide a Middleman::Extension or a block that returns a Middleman::Extension'
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -49,17 +47,17 @@ module Middleman
|
|||
def load(name)
|
||||
name = name.to_sym
|
||||
|
||||
unless registered.has_key?(name)
|
||||
unless registered.key?(name)
|
||||
raise "Unknown Extension: #{name}. Check the name and make sure you have referenced the extension's gem in your Gemfile."
|
||||
end
|
||||
|
||||
extension = registered[name]
|
||||
if extension.is_a?(Proc)
|
||||
extension = extension.call()
|
||||
extension = extension.call
|
||||
registered[name] = extension
|
||||
end
|
||||
|
||||
if !extension.ancestors.include?(::Middleman::Extension)
|
||||
unless extension.ancestors.include?(::Middleman::Extension)
|
||||
raise "Tried to activate old-style extension: #{name}. They are no longer supported."
|
||||
end
|
||||
|
||||
|
@ -116,7 +114,7 @@ module Middleman
|
|||
# @return [Boolean] Whether the file exists
|
||||
def spec_has_file?(spec, path)
|
||||
full_path = File.join(spec.full_gem_path, path)
|
||||
File.exists?(full_path)
|
||||
File.exist?(full_path)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -18,7 +18,7 @@ class Middleman::Extensions::AssetHash < ::Middleman::Extension
|
|||
# Allow specifying regexes to ignore, plus always ignore apple touch icons
|
||||
@ignore = Array(options.ignore) + [/^apple-touch-icon/]
|
||||
|
||||
app.use Middleware, :exts => options.exts, :middleman_app => app, :ignore => @ignore
|
||||
app.use Middleware, exts: options.exts, middleman_app: app, ignore: @ignore
|
||||
end
|
||||
|
||||
# Update the main sitemap resource list
|
||||
|
@ -64,7 +64,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]
|
||||
|
@ -141,9 +141,7 @@ class Middleman::Extensions::AssetHash < ::Middleman::Extension
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
# =================Temp Generate Test data==============================
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
# Automatic Image alt tags from image names extension
|
||||
class Middleman::Extensions::AutomaticAltTags < ::Middleman::Extension
|
||||
|
||||
def initialize(app, options_hash={}, &block)
|
||||
super
|
||||
end
|
||||
|
@ -10,14 +9,14 @@ class Middleman::Extensions::AutomaticAltTags < ::Middleman::Extension
|
|||
# containing image name.
|
||||
|
||||
def image_tag(path)
|
||||
if !path.include?('://')
|
||||
unless path.include?('://')
|
||||
params[:alt] ||= ''
|
||||
|
||||
real_path = path
|
||||
real_path = File.join(images_dir, real_path) unless real_path.start_with?('/')
|
||||
full_path = File.join(source_dir, real_path)
|
||||
|
||||
if File.exists?(full_path)
|
||||
if File.exist?(full_path)
|
||||
begin
|
||||
alt_text = File.basename(full_path, '.*')
|
||||
alt_text.capitalize!
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
# Automatic Image Sizes extension
|
||||
class Middleman::Extensions::AutomaticImageSizes < ::Middleman::Extension
|
||||
|
||||
def initialize(app, options_hash={}, &block)
|
||||
super
|
||||
|
||||
|
@ -16,22 +15,22 @@ class Middleman::Extensions::AutomaticImageSizes < ::Middleman::Extension
|
|||
# @param [Hash] params
|
||||
# @return [String]
|
||||
def image_tag(path, params={})
|
||||
if !params.has_key?(:width) && !params.has_key?(:height) && !path.include?('://')
|
||||
if !params.key?(:width) && !params.key?(:height) && !path.include?('://')
|
||||
params[:alt] ||= ''
|
||||
|
||||
real_path = path
|
||||
real_path = File.join(config[:images_dir], real_path) unless real_path.start_with?('/')
|
||||
full_path = File.join(source_dir, real_path)
|
||||
|
||||
if File.exists?(full_path)
|
||||
if File.exist?(full_path)
|
||||
begin
|
||||
width, height = ::FastImage.size(full_path, :raise_on_failure => true)
|
||||
width, height = ::FastImage.size(full_path, raise_on_failure: true)
|
||||
params[:width] = width
|
||||
params[:height] = height
|
||||
rescue FastImage::UnknownImageType
|
||||
# No message, it's just not supported
|
||||
rescue
|
||||
warn "Couldn't determine dimensions for image #{path}: #{$!.message}"
|
||||
warn "Couldn't determine dimensions for image #{path}: #{$ERROR_INFO.message}"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
# The Cache Buster extension
|
||||
class Middleman::Extensions::CacheBuster < ::Middleman::Extension
|
||||
|
||||
def initialize(app, options_hash={}, &block)
|
||||
super
|
||||
|
||||
|
|
|
@ -147,7 +147,7 @@ class Middleman::Extensions::Lorem < ::Middleman::Extension
|
|||
def image(size, options={})
|
||||
domain = options[:domain] || 'http://placehold.it'
|
||||
src = "#{domain}/#{size}"
|
||||
hex = %w[a b c d e f 0 1 2 3 4 5 6 7 8 9]
|
||||
hex = %w(a b c d e f 0 1 2 3 4 5 6 7 8 9)
|
||||
background_color = options[:background_color]
|
||||
color = options[:color]
|
||||
|
||||
|
@ -159,7 +159,7 @@ class Middleman::Extensions::Lorem < ::Middleman::Extension
|
|||
src << "/#{background_color.sub(/^#/, '')}" if background_color
|
||||
src << '/ccc' if background_color.nil? && color
|
||||
src << "/#{color.sub(/^#/, '')}" if color
|
||||
src << "&text=#{Rack::Utils::escape(options[:text])}" if options[:text]
|
||||
src << "&text=#{Rack::Utils.escape(options[:text])}" if options[:text]
|
||||
|
||||
src
|
||||
end
|
||||
|
|
|
@ -2,22 +2,22 @@
|
|||
class Middleman::Extensions::MinifyCss < ::Middleman::Extension
|
||||
option :inline, false, 'Whether to minify CSS inline within HTML files'
|
||||
option :ignore, [], 'Patterns to avoid minifying'
|
||||
option :compressor, Proc.new {
|
||||
option :compressor, proc {
|
||||
require 'sass'
|
||||
SassCompressor
|
||||
}, 'Set the CSS compressor to use.'
|
||||
|
||||
def after_configuration
|
||||
# Setup Rack middleware to minify CSS
|
||||
app.use Rack, :compressor => options[:compressor],
|
||||
:ignore => Array(options[:ignore]) + [/\.min\./],
|
||||
:inline => options[:inline]
|
||||
app.use Rack, compressor: options[:compressor],
|
||||
ignore: Array(options[:ignore]) + [/\.min\./],
|
||||
inline: options[:inline]
|
||||
end
|
||||
|
||||
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 = { style: :compressed }
|
||||
root_node.render.strip
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,21 +2,20 @@
|
|||
class Middleman::Extensions::MinifyJavascript < ::Middleman::Extension
|
||||
option :inline, false, 'Whether to minify JS inline within HTML files'
|
||||
option :ignore, [], 'Patterns to avoid minifying'
|
||||
option :compressor, Proc.new {
|
||||
option :compressor, proc {
|
||||
require 'uglifier'
|
||||
::Uglifier.new
|
||||
}, 'Set the JS compressor to use.'
|
||||
|
||||
def after_configuration
|
||||
# Setup Rack middleware to minify CSS
|
||||
app.use Rack, :compressor => options[:compressor],
|
||||
:ignore => Array(options[:ignore]) + [/\.min\./],
|
||||
:inline => options[:inline]
|
||||
app.use Rack, compressor: options[:compressor],
|
||||
ignore: Array(options[:ignore]) + [/\.min\./],
|
||||
inline: options[:inline]
|
||||
end
|
||||
|
||||
# Rack middleware to look for JS and compress it
|
||||
class Rack
|
||||
|
||||
# Init
|
||||
# @param [Class] app
|
||||
# @param [Hash] options
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
# Relative Assets extension
|
||||
class Middleman::Extensions::RelativeAssets < ::Middleman::Extension
|
||||
|
||||
def initialize(app, options_hash={}, &block)
|
||||
super
|
||||
|
||||
|
|
|
@ -2,14 +2,12 @@ require 'tilt'
|
|||
require 'active_support/core_ext/string/output_safety'
|
||||
|
||||
module Middleman
|
||||
|
||||
class FileRenderer
|
||||
|
||||
def self.cache
|
||||
@_cache ||= ::Tilt::Cache.new
|
||||
end
|
||||
|
||||
delegate :cache, :to => :"self.class"
|
||||
delegate :cache, to: :"self.class"
|
||||
|
||||
def initialize(app, path)
|
||||
@app = app
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
require 'pathname'
|
||||
|
||||
module Middleman
|
||||
|
||||
class << self
|
||||
def setup_load_paths
|
||||
@_is_setup ||= begin
|
||||
|
@ -31,11 +30,11 @@ module Middleman
|
|||
def setup_bundler
|
||||
ENV['BUNDLE_GEMFILE'] ||= findup('Gemfile', ENV['MM_ROOT'])
|
||||
|
||||
if !File.exists?(ENV['BUNDLE_GEMFILE'])
|
||||
unless File.exist?(ENV['BUNDLE_GEMFILE'])
|
||||
ENV['BUNDLE_GEMFILE'] = File.expand_path('../../../../Gemfile', __FILE__)
|
||||
end
|
||||
|
||||
if File.exists?(ENV['BUNDLE_GEMFILE'])
|
||||
if File.exist?(ENV['BUNDLE_GEMFILE'])
|
||||
require 'bundler/setup'
|
||||
Bundler.require
|
||||
else
|
||||
|
@ -49,7 +48,5 @@ module Middleman
|
|||
return false if cwd.root?
|
||||
findup(filename, cwd.parent)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -4,10 +4,8 @@ require 'active_support/logger'
|
|||
require 'thread'
|
||||
|
||||
module Middleman
|
||||
|
||||
# The Middleman Logger
|
||||
class Logger < ActiveSupport::Logger
|
||||
|
||||
def self.singleton(*args)
|
||||
if !@_logger || args.length > 0
|
||||
if args.length == 1 && (args.first.is_a?(::String) || args.first.respond_to?(:write))
|
||||
|
@ -42,7 +40,7 @@ module Middleman
|
|||
return if @instrumenting.is_a?(String) && @instrumenting != 'instrument' && !message.include?(@instrumenting)
|
||||
|
||||
evt = ActiveSupport::Notifications::Event.new(message, *args)
|
||||
self.info "== Instrument (#{evt.name.sub(/.middleman$/, '')}): #{evt.duration}ms"
|
||||
info "== Instrument (#{evt.name.sub(/.middleman$/, '')}): #{evt.duration}ms"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -19,7 +19,7 @@ module Middleman
|
|||
meta_pages = self
|
||||
@rack_app = Rack::Builder.new do
|
||||
# Serve assets from metadata/assets
|
||||
use Rack::Static, :urls => ['/assets'], :root => File.join(File.dirname(__FILE__), 'meta_pages')
|
||||
use Rack::Static, urls: ['/assets'], root: File.join(File.dirname(__FILE__), 'meta_pages')
|
||||
|
||||
map '/' do
|
||||
run meta_pages.method(:index)
|
||||
|
@ -54,7 +54,7 @@ module Middleman
|
|||
sitemap_tree.add_resource resource
|
||||
end
|
||||
|
||||
template('sitemap.html.erb', :sitemap_tree => sitemap_tree)
|
||||
template('sitemap.html.erb', sitemap_tree: sitemap_tree)
|
||||
end
|
||||
|
||||
# Inspect configuration
|
||||
|
@ -80,9 +80,9 @@ module Middleman
|
|||
end
|
||||
|
||||
template('config.html.erb',
|
||||
:global_config => global_config,
|
||||
:extension_config => extension_config,
|
||||
:registered_extensions => Middleman::Extensions.registered.dup)
|
||||
global_config: global_config,
|
||||
extension_config: extension_config,
|
||||
registered_extensions: Middleman::Extensions.registered.dup)
|
||||
end
|
||||
|
||||
private
|
||||
|
|
|
@ -15,17 +15,17 @@ module Middleman
|
|||
content = ''
|
||||
key_classes = ['key']
|
||||
key_classes << 'modified' if @setting.value_set?
|
||||
content << content_tag(:span, @setting.key.pretty_inspect.strip, :class => key_classes.join(' '))
|
||||
content << content_tag(:span, @setting.key.pretty_inspect.strip, class: key_classes.join(' '))
|
||||
content << ' = '
|
||||
content << content_tag(:span, @setting.value.pretty_inspect.strip, :class => 'value')
|
||||
content << content_tag(:span, @setting.value.pretty_inspect.strip, class: 'value')
|
||||
if @setting.default && @setting.value_set? && @setting.default != @setting.value
|
||||
content << content_tag(:span, :class => 'default') do
|
||||
content << content_tag(:span, class: 'default') do
|
||||
"(Default: #{@setting.default.inspect})"
|
||||
end
|
||||
end
|
||||
|
||||
if @setting.description
|
||||
content << content_tag(:p, :class => 'description') do
|
||||
content << content_tag(:p, class: 'description') do
|
||||
@setting.description
|
||||
end
|
||||
end
|
||||
|
|
|
@ -14,7 +14,7 @@ module Middleman
|
|||
def render
|
||||
classes = 'resource-details'
|
||||
classes << ' ignored' if @resource.ignored?
|
||||
content_tag :div, :class => classes do
|
||||
content_tag :div, class: classes do
|
||||
content_tag :table do
|
||||
content = ''
|
||||
resource_properties.each do |label, value|
|
||||
|
@ -38,7 +38,7 @@ module Middleman
|
|||
build_path = @resource.destination_path
|
||||
build_path = 'Not built' if ignored?
|
||||
props['Build Path'] = build_path if @resource.path != build_path
|
||||
props['URL'] = content_tag(:a, @resource.url, :href => @resource.url) unless ignored?
|
||||
props['URL'] = content_tag(:a, @resource.url, href: @resource.url) unless ignored?
|
||||
props['Source File'] = @resource.source_file.sub(/^#{Regexp.escape(ENV['MM_ROOT'] + '/')}/, '')
|
||||
|
||||
data = @resource.data
|
||||
|
|
|
@ -4,12 +4,11 @@ require 'middleman-core/logger'
|
|||
|
||||
module Middleman
|
||||
module PreviewServer
|
||||
|
||||
DEFAULT_PORT = 4567
|
||||
|
||||
class << self
|
||||
attr_reader :app, :host, :port
|
||||
delegate :logger, :to => :app
|
||||
delegate :logger, to: :app
|
||||
|
||||
# Start an instance of Middleman::Application
|
||||
# @return [void]
|
||||
|
@ -70,7 +69,7 @@ module Middleman
|
|||
|
||||
begin
|
||||
app = new_app
|
||||
rescue Exception => e
|
||||
rescue => e
|
||||
logger.error "Error reloading Middleman: #{e}\n#{e.backtrace.join("\n")}"
|
||||
logger.info '== The Middleman is still running the application from before the error'
|
||||
return
|
||||
|
@ -120,7 +119,7 @@ module Middleman
|
|||
if first_run
|
||||
# Watcher Library
|
||||
require 'listen'
|
||||
@listener = Listen.to(Dir.pwd, :relative_paths => true, :force_polling => @options[:force_polling])
|
||||
@listener = Listen.to(Dir.pwd, relative_paths: true, force_polling: @options[:force_polling])
|
||||
@listener.latency(@options[:latency])
|
||||
end
|
||||
|
||||
|
@ -166,10 +165,10 @@ module Middleman
|
|||
# @return [void]
|
||||
def setup_webrick(is_logging)
|
||||
http_opts = {
|
||||
:BindAddress => host,
|
||||
:Port => port,
|
||||
:AccessLog => [],
|
||||
:DoNotReverseLookup => true
|
||||
BindAddress: host,
|
||||
Port: port,
|
||||
AccessLog: [],
|
||||
DoNotReverseLookup: true
|
||||
}
|
||||
|
||||
if is_logging
|
||||
|
@ -236,7 +235,6 @@ module Middleman
|
|||
host = (@host == '0.0.0.0') ? 'localhost' : @host
|
||||
URI("http://#{host}:#{@port}")
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
class FilteredWebrickLog < ::WEBrick::Log
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
module Middleman
|
||||
module Profiling
|
||||
|
||||
# The profiler instance. There can only be one!
|
||||
def self.profiler=(prof)
|
||||
@profiler = prof
|
||||
|
@ -31,12 +30,10 @@ module Middleman
|
|||
# A profiler that uses ruby-prof
|
||||
class RubyProfProfiler
|
||||
def initialize
|
||||
begin
|
||||
require 'ruby-prof'
|
||||
rescue LoadError
|
||||
raise "To use the --profile option, you must add the 'ruby-prof' gem to your Gemfile"
|
||||
end
|
||||
end
|
||||
|
||||
def start
|
||||
RubyProf.start
|
||||
|
@ -50,7 +47,7 @@ module Middleman
|
|||
outfile = (outfile + '.html') unless outfile.end_with? '.html'
|
||||
FileUtils.mkdir_p(File.dirname(outfile))
|
||||
File.open(outfile, 'w') do |f|
|
||||
printer.print(f, :min_percent=> 1)
|
||||
printer.print(f, min_percent: 1)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -3,10 +3,8 @@ require 'coffee_script'
|
|||
|
||||
module Middleman
|
||||
module Renderers
|
||||
|
||||
# CoffeeScript Renderer
|
||||
module CoffeeScript
|
||||
|
||||
# Setup extension
|
||||
class << self
|
||||
# Once registered
|
||||
|
@ -19,7 +17,7 @@ module Middleman
|
|||
DebuggingCoffeeScriptTemplate.middleman_app = self
|
||||
end
|
||||
end
|
||||
alias :included :registered
|
||||
alias_method :included, :registered
|
||||
end
|
||||
|
||||
# A Template for Tilt which outputs debug messages
|
||||
|
|
|
@ -4,7 +4,6 @@ module Middleman
|
|||
module ERb
|
||||
# Setup extension
|
||||
class << self
|
||||
|
||||
# once registered
|
||||
def registered(app)
|
||||
# After config
|
||||
|
@ -12,7 +11,7 @@ module Middleman
|
|||
::Tilt.prefer(Template, :erb)
|
||||
end
|
||||
end
|
||||
alias :included :registered
|
||||
alias_method :included, :registered
|
||||
end
|
||||
|
||||
class Template < ::Tilt::ErubisTemplate
|
||||
|
|
|
@ -13,7 +13,6 @@ end
|
|||
|
||||
module Middleman
|
||||
module Renderers
|
||||
|
||||
# Haml precompiles filters before the scope is even available,
|
||||
# thus making it impossible to pass our Middleman instance
|
||||
# in. So we have to resort to heavy hackery :(
|
||||
|
@ -24,7 +23,7 @@ module Middleman
|
|||
def evaluate(scope, locals, &block)
|
||||
::Middleman::Renderers::Haml.last_haml_scope = scope
|
||||
|
||||
options = @options.merge(:filename => eval_file, :line => line)
|
||||
options = @options.merge(filename: eval_file, line: line)
|
||||
@engine = ::Haml::Engine.new(data, options)
|
||||
output = @engine.render(scope, locals, &block)
|
||||
|
||||
|
@ -47,7 +46,7 @@ module Middleman
|
|||
# Add haml helpers to context
|
||||
::Middleman::TemplateContext.send :include, ::Haml::Helpers
|
||||
end
|
||||
alias :included :registered
|
||||
alias_method :included, :registered
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,7 +2,6 @@ require 'kramdown'
|
|||
|
||||
module Middleman
|
||||
module Renderers
|
||||
|
||||
# Our own Kramdown Tilt template that simply uses our custom renderer.
|
||||
class KramdownTemplate < ::Tilt::KramdownTemplate
|
||||
def evaluate(scope, locals, &block)
|
||||
|
@ -34,7 +33,7 @@ module Middleman
|
|||
mail_addr = el.attr['href'].sub(/\Amailto:/, '')
|
||||
href = obfuscate('mailto') << ':' << obfuscate(mail_addr)
|
||||
content = obfuscate(content) if content == mail_addr
|
||||
return %Q{<a href="#{href}">#{content}</a>}
|
||||
return %Q(<a href="#{href}">#{content}</a>)
|
||||
end
|
||||
|
||||
attr = el.attr.dup
|
||||
|
|
|
@ -2,13 +2,10 @@ require 'less'
|
|||
|
||||
module Middleman
|
||||
module Renderers
|
||||
|
||||
# Sass renderer
|
||||
module Less
|
||||
|
||||
# Setup extension
|
||||
class << self
|
||||
|
||||
# Once registered
|
||||
def registered(app)
|
||||
# Default less options
|
||||
|
@ -23,23 +20,20 @@ module Middleman
|
|||
::Tilt.prefer(LocalLoadingLessTemplate)
|
||||
end
|
||||
|
||||
alias :included :registered
|
||||
alias_method :included, :registered
|
||||
end
|
||||
|
||||
# A SassTemplate for Tilt which outputs debug messages
|
||||
class LocalLoadingLessTemplate < ::Tilt::LessTemplate
|
||||
|
||||
def prepare
|
||||
if ::Less.const_defined? :Engine
|
||||
@engine = ::Less::Engine.new(data)
|
||||
else
|
||||
parser = ::Less::Parser.new(options.merge :filename => eval_file, :line => line, :paths => ['.', File.dirname(eval_file)])
|
||||
parser = ::Less::Parser.new(options.merge filename: eval_file, line: line, paths: ['.', File.dirname(eval_file)])
|
||||
@engine = parser.parse(data)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -3,13 +3,10 @@ require 'liquid'
|
|||
|
||||
module Middleman
|
||||
module Renderers
|
||||
|
||||
# Liquid Renderer
|
||||
module Liquid
|
||||
|
||||
# Setup extension
|
||||
class << self
|
||||
|
||||
# Once registerd
|
||||
def registered(app)
|
||||
# After config, setup liquid partial paths
|
||||
|
@ -18,14 +15,13 @@ module Middleman
|
|||
|
||||
# Convert data object into a hash for liquid
|
||||
sitemap.provides_metadata %r{\.liquid$} do |path|
|
||||
{ :locals => { :data => data.to_h } }
|
||||
{ locals: { data: data.to_h } }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
alias :included :registered
|
||||
alias_method :included, :registered
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,12 +1,9 @@
|
|||
module Middleman
|
||||
module Renderers
|
||||
|
||||
# Markdown renderer
|
||||
module Markdown
|
||||
|
||||
# Setup extension
|
||||
class << self
|
||||
|
||||
# Once registered
|
||||
def registered(app)
|
||||
# Set our preference for a markdown engine
|
||||
|
@ -25,7 +22,7 @@ module Middleman
|
|||
elsif config[:markdown_engine] == :kramdown
|
||||
require 'middleman-core/renderers/kramdown'
|
||||
::Tilt.prefer(::Middleman::Renderers::KramdownTemplate, *markdown_exts)
|
||||
elsif !config[:markdown_engine].nil?
|
||||
elsif config[:markdown_engine]
|
||||
# Map symbols to classes
|
||||
markdown_engine_klass = if config[:markdown_engine].is_a? Symbol
|
||||
engine = config[:markdown_engine].to_s
|
||||
|
@ -48,9 +45,8 @@ module Middleman
|
|||
end
|
||||
end
|
||||
|
||||
alias :included :registered
|
||||
alias_method :included, :registered
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,20 +2,18 @@ require 'redcarpet'
|
|||
|
||||
module Middleman
|
||||
module Renderers
|
||||
|
||||
class RedcarpetTemplate < ::Tilt::RedcarpetTemplate::Redcarpet2
|
||||
|
||||
# because tilt has decided to convert these
|
||||
# in the wrong direction
|
||||
ALIASES = {
|
||||
:escape_html => :filter_html
|
||||
escape_html: :filter_html
|
||||
}
|
||||
|
||||
# Overwrite built-in Tilt version.
|
||||
# Don't overload :renderer option with smartypants
|
||||
# Support renderer-level options
|
||||
def generate_renderer
|
||||
return options.delete(:renderer) if options.has_key?(:renderer)
|
||||
return options.delete(:renderer) if options.key?(:renderer)
|
||||
|
||||
covert_options_to_aliases!
|
||||
|
||||
|
@ -32,8 +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.inject({}) do |sum, opt|
|
||||
sum[opt] = options.delete(opt) if options.has_key?(opt)
|
||||
render_options = possible_render_opts.reduce({}) do |sum, opt|
|
||||
sum[opt] = options.delete(opt) if options.key?(opt)
|
||||
sum
|
||||
end
|
||||
|
||||
|
@ -52,7 +50,7 @@ module Middleman
|
|||
|
||||
def covert_options_to_aliases!
|
||||
ALIASES.each do |aka, actual|
|
||||
options[actual] = options.delete(aka) if options.has_key? aka
|
||||
options[actual] = options.delete(aka) if options.key? aka
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -69,23 +67,23 @@ module Middleman
|
|||
|
||||
def image(link, title, alt_text)
|
||||
if !@local_options[:no_images]
|
||||
scope.image_tag(link, :title => title, :alt => alt_text)
|
||||
scope.image_tag(link, title: title, alt: alt_text)
|
||||
else
|
||||
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})}
|
||||
end
|
||||
end
|
||||
|
||||
def link(link, title, content)
|
||||
if !@local_options[:no_links]
|
||||
attributes = { :title => title }
|
||||
attributes = { title: title }
|
||||
attributes.merge!(@local_options[:link_attributes]) if @local_options[:link_attributes]
|
||||
|
||||
scope.link_to(content, link, attributes)
|
||||
else
|
||||
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})}
|
||||
end
|
||||
end
|
||||
|
|
|
@ -3,13 +3,10 @@ require 'compass/import-once'
|
|||
|
||||
module Middleman
|
||||
module Renderers
|
||||
|
||||
# Sass renderer
|
||||
module Sass
|
||||
|
||||
# Setup extension
|
||||
class << self
|
||||
|
||||
# Once registered
|
||||
def registered(app)
|
||||
# Default sass options
|
||||
|
@ -26,16 +23,15 @@ module Middleman
|
|||
::Compass::ImportOnce.activate!
|
||||
end
|
||||
|
||||
alias :included :registered
|
||||
alias_method :included, :registered
|
||||
end
|
||||
|
||||
# A SassTemplate for Tilt which outputs debug messages
|
||||
class SassPlusCSSFilenameTemplate < ::Tilt::SassTemplate
|
||||
|
||||
def initialize(*args, &block)
|
||||
super
|
||||
|
||||
if @options.has_key?(:context)
|
||||
if @options.key?(:context)
|
||||
@context = @options[:context]
|
||||
end
|
||||
end
|
||||
|
@ -59,14 +55,14 @@ module Middleman
|
|||
begin
|
||||
@engine.render
|
||||
rescue ::Sass::SyntaxError => e
|
||||
::Sass::SyntaxError.exception_to_css(e, :full_exception => true)
|
||||
::Sass::SyntaxError.exception_to_css(e, full_exception: true)
|
||||
end
|
||||
end
|
||||
|
||||
# Change Sass path, for url functions, to the build folder if we're building
|
||||
# @return [Hash]
|
||||
def sass_options
|
||||
more_opts = { :filename => eval_file, :line => line, :syntax => syntax }
|
||||
more_opts = { filename: eval_file, line: line, syntax: syntax }
|
||||
|
||||
if @context.is_a?(::Middleman::TemplateContext) && file
|
||||
location_of_sass_file = @context.source_dir
|
||||
|
@ -82,7 +78,6 @@ module Middleman
|
|||
|
||||
# SCSS version of the above template
|
||||
class ScssPlusCSSFilenameTemplate < SassPlusCSSFilenameTemplate
|
||||
|
||||
# Define the expected syntax for the template
|
||||
# @return [Symbol]
|
||||
def syntax
|
||||
|
|
|
@ -17,26 +17,23 @@ end
|
|||
|
||||
module Middleman
|
||||
module Renderers
|
||||
|
||||
# Slim renderer
|
||||
module Slim
|
||||
|
||||
# Setup extension
|
||||
class << self
|
||||
|
||||
# Once registered
|
||||
def registered(app)
|
||||
# Setup Slim options to work with partials
|
||||
::Slim::Engine.set_default_options(
|
||||
:buffer => '@_out_buf',
|
||||
:use_html_safe => true,
|
||||
:generator => ::Temple::Generators::RailsOutputBuffer,
|
||||
:disable_escape => true
|
||||
buffer: '@_out_buf',
|
||||
use_html_safe: true,
|
||||
generator: ::Temple::Generators::RailsOutputBuffer,
|
||||
disable_escape: true
|
||||
)
|
||||
|
||||
app.after_configuration do
|
||||
context_hack = {
|
||||
:context => self
|
||||
context: self
|
||||
}
|
||||
|
||||
::Slim::Embedded::SassEngine.disable_option_validator!
|
||||
|
@ -46,7 +43,7 @@ module Middleman
|
|||
end
|
||||
end
|
||||
|
||||
alias :included :registered
|
||||
alias_method :included, :registered
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -3,22 +3,18 @@ require 'stylus/tilt'
|
|||
|
||||
module Middleman
|
||||
module Renderers
|
||||
|
||||
# Sass renderer
|
||||
module Stylus
|
||||
|
||||
# Setup extension
|
||||
class << self
|
||||
|
||||
# Once registered
|
||||
def registered(app)
|
||||
# Default stylus options
|
||||
app.config.define_setting :styl, {}, 'Stylus config options'
|
||||
end
|
||||
|
||||
alias :included :registered
|
||||
end
|
||||
|
||||
alias_method :included, :registered
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,30 +1,27 @@
|
|||
# Core Sitemap Extensions
|
||||
module Middleman
|
||||
module Sitemap
|
||||
|
||||
# Setup Extension
|
||||
class << self
|
||||
|
||||
# Once registered
|
||||
def included(app)
|
||||
|
||||
# Set to automatically convert some characters into a directory
|
||||
app.config.define_setting :automatic_directory_matcher, nil, 'Set to automatically convert some characters into a directory'
|
||||
|
||||
# Setup callbacks which can exclude paths from the sitemap
|
||||
app.config.define_setting :ignored_sitemap_matchers, {
|
||||
# dotfiles and folders in the root
|
||||
:root_dotfiles => proc { |file| file.start_with?('.') },
|
||||
root_dotfiles: proc { |file| file.start_with?('.') },
|
||||
|
||||
# Files starting with an dot, but not .htaccess
|
||||
:source_dotfiles => proc { |file|
|
||||
source_dotfiles: proc { |file|
|
||||
file =~ %r{/\.} && file !~ %r{/\.(htaccess|htpasswd|nojekyll)}
|
||||
},
|
||||
|
||||
# Files starting with an underscore, but not a double-underscore
|
||||
:partials => proc { |file| file =~ %r{/_[^_]} },
|
||||
partials: proc { |file| file =~ %r{/_[^_]} },
|
||||
|
||||
:layout => proc { |file, app|
|
||||
layout: proc { |file, app|
|
||||
file.start_with?(File.join(app.config[:source], 'layout.')) || file.start_with?(File.join(app.config[:source], 'layouts/'))
|
||||
}
|
||||
}, 'Callbacks that can exclude paths from the sitemap'
|
||||
|
@ -32,7 +29,6 @@ module Middleman
|
|||
# Include instance methods
|
||||
::Middleman::TemplateContext.send :include, InstanceMethods
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
# Sitemap instance methods
|
||||
|
@ -53,7 +49,6 @@ module Middleman
|
|||
return nil unless current_path
|
||||
sitemap.find_resource_by_destination_path(current_path)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,9 +1,6 @@
|
|||
module Middleman
|
||||
|
||||
module Sitemap
|
||||
|
||||
module Extensions
|
||||
|
||||
# Class to handle managing ignores
|
||||
class Ignores
|
||||
def initialize(sitemap)
|
||||
|
@ -23,15 +20,15 @@ module Middleman
|
|||
# @return [void]
|
||||
def create_ignore(path=nil, &block)
|
||||
if path.is_a? Regexp
|
||||
@ignored_callbacks << Proc.new {|p| p =~ path }
|
||||
@ignored_callbacks << proc { |p| p =~ path }
|
||||
elsif path.is_a? String
|
||||
path_clean = ::Middleman::Util.normalize_path(path)
|
||||
if path_clean.include?('*') # It's a glob
|
||||
@ignored_callbacks << Proc.new {|p| File.fnmatch(path_clean, p) }
|
||||
@ignored_callbacks << proc { |p| File.fnmatch(path_clean, p) }
|
||||
else
|
||||
# Add a specific-path ignore unless that path is already covered
|
||||
return if ignored?(path_clean)
|
||||
@ignored_callbacks << Proc.new {|p| p == path_clean }
|
||||
@ignored_callbacks << proc { |p| p == path_clean }
|
||||
end
|
||||
elsif block_given?
|
||||
@ignored_callbacks << block
|
||||
|
@ -51,7 +48,6 @@ module Middleman
|
|||
|
||||
# Helpers methods for Resources
|
||||
module IgnoreResourceInstanceMethods
|
||||
|
||||
# Whether the Resource is ignored
|
||||
# @return [Boolean]
|
||||
def ignored?
|
||||
|
|
|
@ -1,13 +1,9 @@
|
|||
require 'set'
|
||||
|
||||
module Middleman
|
||||
|
||||
module Sitemap
|
||||
|
||||
module Extensions
|
||||
|
||||
class OnDisk
|
||||
|
||||
attr_accessor :sitemap
|
||||
attr_accessor :waiting_for_ready
|
||||
|
||||
|
|
|
@ -1,9 +1,6 @@
|
|||
module Middleman
|
||||
|
||||
module Sitemap
|
||||
|
||||
module Extensions
|
||||
|
||||
# Manages the list of proxy configurations and manipulates the sitemap
|
||||
# to include new resources based on those configurations
|
||||
class Proxies
|
||||
|
@ -26,13 +23,13 @@ module Middleman
|
|||
def create_proxy(path, target, opts={})
|
||||
options = opts.dup
|
||||
|
||||
metadata = { :options => {}, :locals => {} }
|
||||
metadata = { options: {}, locals: {} }
|
||||
metadata[:locals] = options.delete(:locals) || {}
|
||||
|
||||
@app.ignore(target) if options.delete(:ignore)
|
||||
metadata[:options] = options
|
||||
|
||||
@proxy_configs << ProxyConfiguration.new(:path => path, :target => target, :metadata => metadata)
|
||||
@proxy_configs << ProxyConfiguration.new(path: path, target: target, metadata: metadata)
|
||||
|
||||
@app.sitemap.rebuild_resource_list!(:added_proxy)
|
||||
end
|
||||
|
@ -106,9 +103,7 @@ module Middleman
|
|||
|
||||
# The path of the page this page is proxied to, or nil if it's not proxied.
|
||||
# @return [String]
|
||||
def proxied_to
|
||||
@proxied_to
|
||||
end
|
||||
attr_reader :proxied_to
|
||||
|
||||
# The resource for the page this page is proxied to. Throws an exception
|
||||
# if there is no resource.
|
||||
|
|
|
@ -1,11 +1,8 @@
|
|||
require 'middleman-core/sitemap/resource'
|
||||
|
||||
module Middleman
|
||||
|
||||
module Sitemap
|
||||
|
||||
module Extensions
|
||||
|
||||
# Manages the list of proxy configurations and manipulates the sitemap
|
||||
# to include new resources based on those configurations
|
||||
class Redirects
|
||||
|
@ -58,10 +55,10 @@ module Middleman
|
|||
end
|
||||
|
||||
def render(*args, &block)
|
||||
url = ::Middleman::Util.url_for(store.app, @request_path, {
|
||||
:relative => false,
|
||||
:find_resource => true
|
||||
})
|
||||
url = ::Middleman::Util.url_for(store.app, @request_path,
|
||||
relative: false,
|
||||
find_resource: true
|
||||
)
|
||||
|
||||
if output
|
||||
output.call(path, url)
|
||||
|
@ -99,7 +96,6 @@ module Middleman
|
|||
def metadata
|
||||
@local_metadata.dup
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,11 +1,7 @@
|
|||
module Middleman
|
||||
|
||||
module Sitemap
|
||||
|
||||
module Extensions
|
||||
|
||||
class RequestEndpoints
|
||||
|
||||
# Manages the list of proxy configurations and manipulates the sitemap
|
||||
# to include new resources based on those configurations
|
||||
def initialize(sitemap)
|
||||
|
@ -21,13 +17,13 @@ module Middleman
|
|||
# differs from the output path
|
||||
def create_endpoint(path, opts={}, &block)
|
||||
endpoint = {
|
||||
:request_path => path
|
||||
request_path: path
|
||||
}
|
||||
|
||||
if block_given?
|
||||
endpoint[:output] = block
|
||||
else
|
||||
endpoint[:request_path] = opts[:path] if opts.has_key?(:path)
|
||||
endpoint[:request_path] = opts[:path] if opts.key?(:path)
|
||||
end
|
||||
|
||||
@endpoints[path] = endpoint
|
||||
|
@ -44,7 +40,7 @@ module Middleman
|
|||
path,
|
||||
config[:request_path]
|
||||
)
|
||||
r.output = config[:output] if config.has_key?(:output)
|
||||
r.output = config[:output] if config.key?(:output)
|
||||
r
|
||||
end
|
||||
end
|
||||
|
@ -64,12 +60,10 @@ module Middleman
|
|||
end
|
||||
|
||||
def render(*args, &block)
|
||||
return self.output.call if self.output
|
||||
return output.call if output
|
||||
end
|
||||
|
||||
def request_path
|
||||
@request_path
|
||||
end
|
||||
attr_reader :request_path
|
||||
|
||||
def binary?
|
||||
false
|
||||
|
|
|
@ -1,9 +1,6 @@
|
|||
module Middleman
|
||||
|
||||
module Sitemap
|
||||
|
||||
module Extensions
|
||||
|
||||
module Traversal
|
||||
# This resource's parent resource
|
||||
# @return [Middleman::Sitemap::Resource, nil]
|
||||
|
@ -28,14 +25,14 @@ module Middleman
|
|||
|
||||
if eponymous_directory?
|
||||
base_path = eponymous_directory_path
|
||||
prefix = %r|^#{base_path.sub("/", "\\/")}|
|
||||
prefix = %r{^#{base_path.sub("/", "\\/")}}
|
||||
else
|
||||
base_path = path.sub("#{app.config[:index_file]}", '')
|
||||
prefix = %r|^#{base_path.sub("/", "\\/")}|
|
||||
prefix = %r{^#{base_path.sub("/", "\\/")}}
|
||||
end
|
||||
|
||||
store.resources.select do |sub_resource|
|
||||
if sub_resource.path == self.path || sub_resource.path !~ prefix
|
||||
if sub_resource.path == path || sub_resource.path !~ prefix
|
||||
false
|
||||
else
|
||||
inner_path = sub_resource.path.sub(prefix, '')
|
||||
|
@ -72,7 +69,7 @@ module Middleman
|
|||
return true
|
||||
end
|
||||
full_path = File.join(app.source_dir, eponymous_directory_path)
|
||||
!!(File.exists?(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
|
||||
|
|
|
@ -4,10 +4,8 @@ require 'middleman-core/file_renderer'
|
|||
require 'middleman-core/template_renderer'
|
||||
|
||||
module Middleman
|
||||
|
||||
# Sitemap namespace
|
||||
module Sitemap
|
||||
|
||||
# Sitemap Resource class
|
||||
class Resource
|
||||
include Middleman::Sitemap::Extensions::Traversal
|
||||
|
@ -15,7 +13,7 @@ module Middleman
|
|||
|
||||
# @return [Middleman::Application]
|
||||
attr_reader :app
|
||||
delegate :logger, :instrument, :to => :app
|
||||
delegate :logger, :instrument, to: :app
|
||||
|
||||
# @return [Middleman::Sitemap::Store]
|
||||
attr_reader :store
|
||||
|
@ -48,7 +46,7 @@ module Middleman
|
|||
@source_file = source_file
|
||||
@destination_path = @path
|
||||
|
||||
@local_metadata = { :options => {}, :locals => {} }
|
||||
@local_metadata = { options: {}, locals: {} }
|
||||
end
|
||||
|
||||
# Whether this resource has a template file
|
||||
|
@ -89,27 +87,27 @@ module Middleman
|
|||
end
|
||||
|
||||
def request_path
|
||||
self.destination_path
|
||||
destination_path
|
||||
end
|
||||
|
||||
# Render this resource
|
||||
# @return [String]
|
||||
def render(opts={}, locs={})
|
||||
if !template?
|
||||
unless template?
|
||||
return ::Middleman::FileRenderer.new(@app, source_file).get_template_data_for_file
|
||||
end
|
||||
|
||||
relative_source = Pathname(source_file).relative_path_from(Pathname(app.root))
|
||||
|
||||
instrument 'render.resource', :path => relative_source, :destination_path => destination_path do
|
||||
instrument 'render.resource', path: relative_source, destination_path: destination_path do
|
||||
md = metadata.dup
|
||||
opts = md[:options].deep_merge(opts)
|
||||
locs = md[:locals].deep_merge(locs)
|
||||
locs[:current_path] ||= self.destination_path
|
||||
locs[:current_path] ||= destination_path
|
||||
|
||||
# Certain output file types don't use layouts
|
||||
if !opts.has_key?(:layout)
|
||||
opts[:layout] = false if %w(.js .json .css .txt).include?(self.ext)
|
||||
unless opts.key?(:layout)
|
||||
opts[:layout] = false if %w(.js .json .css .txt).include?(ext)
|
||||
end
|
||||
|
||||
renderer = ::Middleman::TemplateRenderer.new(@app, source_file)
|
||||
|
|
|
@ -10,10 +10,8 @@ require 'middleman-core/sitemap/extensions/proxies'
|
|||
require 'middleman-core/sitemap/extensions/ignores'
|
||||
|
||||
module Middleman
|
||||
|
||||
# Sitemap namespace
|
||||
module Sitemap
|
||||
|
||||
# The Store class
|
||||
#
|
||||
# The Store manages a collection of Resource objects, which represent
|
||||
|
@ -21,7 +19,6 @@ module Middleman
|
|||
# which is the path relative to the source directory, minus any template
|
||||
# extensions. All "path" parameters used in this class are source paths.
|
||||
class Store
|
||||
|
||||
# @return [Middleman::Application]
|
||||
attr_accessor :app
|
||||
|
||||
|
@ -57,7 +54,7 @@ module Middleman
|
|||
register_resource_list_manipulator(k, m.new(self))
|
||||
end
|
||||
|
||||
app.config_context.class.send :delegate, :sitemap, :to => :app
|
||||
app.config_context.class.send :delegate, :sitemap, to: :app
|
||||
end
|
||||
|
||||
# Register a klass which can manipulate the main site map list. Best to register
|
||||
|
@ -134,9 +131,9 @@ module Middleman
|
|||
# @param [String] source_file
|
||||
# @return [Hash]
|
||||
def metadata_for_file(source_file)
|
||||
blank_metadata = { :options => {}, :locals => {} }
|
||||
blank_metadata = { options: {}, locals: {} }
|
||||
|
||||
provides_metadata.inject(blank_metadata) do |result, (callback, matcher)|
|
||||
provides_metadata.reduce(blank_metadata) do |result, (callback, matcher)|
|
||||
next result if matcher && !source_file.match(matcher)
|
||||
|
||||
metadata = callback.call(source_file).dup
|
||||
|
@ -162,9 +159,9 @@ module Middleman
|
|||
def metadata_for_path(request_path)
|
||||
return @_cached_metadata[request_path] if @_cached_metadata[request_path]
|
||||
|
||||
blank_metadata = { :options => {}, :locals => {} }
|
||||
blank_metadata = { options: {}, locals: {} }
|
||||
|
||||
@_cached_metadata[request_path] = provides_metadata_for_path.inject(blank_metadata) do |result, (callback, matcher)|
|
||||
@_cached_metadata[request_path] = provides_metadata_for_path.reduce(blank_metadata) do |result, (callback, matcher)|
|
||||
case matcher
|
||||
when Regexp
|
||||
next result unless request_path =~ matcher
|
||||
|
@ -215,7 +212,7 @@ module Middleman
|
|||
|
||||
@app.logger.debug '== Rebuilding resource list'
|
||||
|
||||
@resources = @resource_list_manipulators.inject([]) do |result, (_, inst)|
|
||||
@resources = @resource_list_manipulators.reduce([]) do |result, (_, inst)|
|
||||
newres = inst.manipulate_resource_list(result)
|
||||
|
||||
# Reset lookup cache
|
||||
|
|
|
@ -6,7 +6,7 @@ module Middleman
|
|||
attr_reader :app
|
||||
attr_accessor :current_engine
|
||||
|
||||
delegate :config, :logger, :sitemap, :build?, :development?, :data, :extensions, :source_dir, :root, :to => :app
|
||||
delegate :config, :logger, :sitemap, :build?, :development?, :data, :extensions, :source_dir, :root, to: :app
|
||||
|
||||
def initialize(app, locs={}, opts={})
|
||||
@app = app
|
||||
|
@ -30,13 +30,13 @@ module Middleman
|
|||
# Save current buffer for later
|
||||
_buf_was = save_buffer
|
||||
|
||||
layout_path = ::Middleman::TemplateRenderer.locate_layout(@app, layout_name, self.current_engine)
|
||||
layout_path = ::Middleman::TemplateRenderer.locate_layout(@app, layout_name, current_engine)
|
||||
|
||||
extension = File.extname(layout_path)
|
||||
engine = extension[1..-1].to_sym
|
||||
|
||||
# Store last engine for later (could be inside nested renders)
|
||||
self.current_engine, engine_was = engine, self.current_engine
|
||||
self.current_engine, engine_was = engine, current_engine
|
||||
|
||||
begin
|
||||
content = if block_given?
|
||||
|
@ -76,12 +76,12 @@ module Middleman
|
|||
resolve_opts[:preferred_engine] = File.extname(resource.source_file)[1..-1].to_sym
|
||||
|
||||
# Look for partials relative to the current path
|
||||
relative_dir = File.join(current_dir.sub(%r{^#{Regexp.escape(self.source_dir)}/?}, ''), data)
|
||||
relative_dir = File.join(current_dir.sub(%r{^#{Regexp.escape(source_dir)}/?}, ''), data)
|
||||
|
||||
found_partial = ::Middleman::TemplateRenderer.resolve_template(@app, relative_dir, resolve_opts)
|
||||
end
|
||||
|
||||
if !found_partial
|
||||
unless found_partial
|
||||
partials_path = File.join(@app.config[:partials_dir], data)
|
||||
found_partial = ::Middleman::TemplateRenderer.resolve_template(@app, partials_path, resolve_opts)
|
||||
end
|
||||
|
|
|
@ -4,14 +4,12 @@ require 'middleman-core/template_context'
|
|||
require 'middleman-core/file_renderer'
|
||||
|
||||
module Middleman
|
||||
|
||||
class TemplateRenderer
|
||||
|
||||
def self.cache
|
||||
@_cache ||= ::Tilt::Cache.new
|
||||
end
|
||||
|
||||
delegate :cache, :to => :"self.class"
|
||||
delegate :cache, to: :"self.class"
|
||||
|
||||
# Custom error class for handling
|
||||
class TemplateNotFound < RuntimeError; end
|
||||
|
@ -82,7 +80,7 @@ module Middleman
|
|||
# @return [String]
|
||||
def fetch_layout(engine, opts)
|
||||
# The layout name comes from either the system default or the options
|
||||
local_layout = opts.has_key?(:layout) ? opts[:layout] : @app.config[:layout]
|
||||
local_layout = opts.key?(:layout) ? opts[:layout] : @app.config[:layout]
|
||||
return false unless local_layout
|
||||
|
||||
# Look for engine-specific options
|
||||
|
@ -90,9 +88,9 @@ module Middleman
|
|||
|
||||
# The engine for the layout can be set in options, engine_options or passed
|
||||
# into this method
|
||||
layout_engine = if opts.has_key?(:layout_engine)
|
||||
layout_engine = if opts.key?(:layout_engine)
|
||||
opts[:layout_engine]
|
||||
elsif engine_options.has_key?(:layout_engine)
|
||||
elsif engine_options.key?(:layout_engine)
|
||||
engine_options[:layout_engine]
|
||||
else
|
||||
engine
|
||||
|
@ -131,7 +129,7 @@ module Middleman
|
|||
layout_path = false
|
||||
|
||||
resolve_opts = {}
|
||||
resolve_opts[:preferred_engine] = preferred_engine if !preferred_engine.nil?
|
||||
resolve_opts[:preferred_engine] = preferred_engine unless preferred_engine.nil?
|
||||
|
||||
# Check layouts folder
|
||||
layout_path = resolve_template(app, File.join(app.config[:layouts_dir], name.to_s), resolve_opts)
|
||||
|
@ -167,7 +165,7 @@ module Middleman
|
|||
preferred_engines = ['*']
|
||||
|
||||
# If we're specifically looking for a preferred engine
|
||||
if options.has_key?(:preferred_engine)
|
||||
if options.key?(:preferred_engine)
|
||||
extension_class = ::Tilt[options[:preferred_engine]]
|
||||
matched_exts = []
|
||||
|
||||
|
@ -202,7 +200,7 @@ module Middleman
|
|||
# If we found one, return it
|
||||
if found_path
|
||||
found_path
|
||||
elsif File.exists?(on_disk_path)
|
||||
elsif File.exist?(on_disk_path)
|
||||
on_disk_path
|
||||
else
|
||||
false
|
||||
|
|
|
@ -14,7 +14,6 @@ require 'rack/mime'
|
|||
module Middleman
|
||||
module Util
|
||||
class << self
|
||||
|
||||
# Whether the source file is binary.
|
||||
#
|
||||
# @param [String] filename The file to check.
|
||||
|
@ -27,7 +26,7 @@ module Middleman
|
|||
|
||||
return false if Tilt.registered?(ext.sub('.', ''))
|
||||
|
||||
dot_ext = (ext.to_s[0] == ?.) ? ext.dup : ".#{ext}"
|
||||
dot_ext = (ext.to_s[0] == '.') ? ext.dup : ".#{ext}"
|
||||
|
||||
if mime = ::Rack::Mime.mime_type(dot_ext, nil)
|
||||
!nonbinary_mime?(mime)
|
||||
|
@ -210,7 +209,7 @@ module Middleman
|
|||
def full_path(path, app)
|
||||
resource = app.sitemap.find_resource_by_destination_path(path)
|
||||
|
||||
if !resource
|
||||
unless resource
|
||||
# Try it with /index.html at the end
|
||||
indexed_path = File.join(path.sub(%r{/$}, ''), app.config[:index_file])
|
||||
resource = app.sitemap.find_resource_by_destination_path(indexed_path)
|
||||
|
@ -294,7 +293,6 @@ module Middleman
|
|||
# hash.foo? #=> true
|
||||
#
|
||||
class HashWithIndifferentAccess < ::Hash #:nodoc:
|
||||
|
||||
def initialize(hash={})
|
||||
super()
|
||||
hash.each do |key, value|
|
||||
|
@ -315,7 +313,7 @@ module Middleman
|
|||
end
|
||||
|
||||
def values_at(*indices)
|
||||
indices.collect { |key| self[convert_key(key)] }
|
||||
indices.map { |key| self[convert_key(key)] }
|
||||
end
|
||||
|
||||
def merge(other)
|
||||
|
|
|
@ -97,7 +97,7 @@ if ENV['HOME']
|
|||
|
||||
# If a template.rb file is found require it (therefore registering the template)
|
||||
# else register the folder as a Local template (which when built, just copies the folder)
|
||||
if File.exists?(template_file)
|
||||
if File.exist?(template_file)
|
||||
require template_file
|
||||
else
|
||||
Middleman::Templates.register(File.basename(dir).to_sym, Middleman::Templates::Local)
|
||||
|
|
Loading…
Reference in a new issue