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