Great rubocop-ing
This commit is contained in:
parent
8f75f6516d
commit
04dc48f13d
78 changed files with 457 additions and 607 deletions
52
.rubocop.yml
52
.rubocop.yml
|
@ -1,18 +1,19 @@
|
|||
AllCops:
|
||||
Include:
|
||||
- Rakefile
|
||||
- Gemfile
|
||||
- config.ru
|
||||
- gem_rake_helper.rb
|
||||
- '**/Rakefile'
|
||||
- '**/Gemfile'
|
||||
- '**/config.ru'
|
||||
- '**/gem_rake_helper.rb'
|
||||
Exclude:
|
||||
- script/**
|
||||
- vendor/**
|
||||
- bin/**
|
||||
- middleman-core/lib/vendored-middleman-deps/**
|
||||
- middleman-core/bin/**
|
||||
- middleman-core/fixtures/**
|
||||
- middleman-core/features/**
|
||||
- middleman-core/spec/**
|
||||
- 'script/**/*'
|
||||
- 'vendor/**/*'
|
||||
- '**/tmp/**/*'
|
||||
- '**/bin/**/*'
|
||||
- 'middleman-core/lib/middleman-core/step_definitions/**/*'
|
||||
- 'middleman-core/lib/vendored-middleman-deps/**/*'
|
||||
- 'middleman-core/fixtures/**/*'
|
||||
- 'middleman-core/features/**/*'
|
||||
- 'middleman-core/spec/**/*'
|
||||
LineLength:
|
||||
Enabled: false
|
||||
MethodLength:
|
||||
|
@ -24,4 +25,29 @@ Documentation:
|
|||
Encoding:
|
||||
Enabled: false
|
||||
HashSyntax:
|
||||
EnforcedStyle: ruby19
|
||||
# EnforcedStyle: ruby19
|
||||
Enabled: false
|
||||
SpaceAroundEqualsInParameterDefault:
|
||||
EnforcedStyle: no_space
|
||||
Blocks:
|
||||
Enabled: false
|
||||
PerlBackrefs:
|
||||
Enabled: false
|
||||
ClassAndModuleChildren:
|
||||
Enabled: false
|
||||
AssignmentInCondition:
|
||||
Enabled: false
|
||||
CyclomaticComplexity:
|
||||
Enabled: false
|
||||
HandleExceptions:
|
||||
Enabled: false
|
||||
EndAlignment:
|
||||
AlignWith: variable
|
||||
SignalException:
|
||||
Enabled: false
|
||||
RegexpLiteral:
|
||||
Enabled: false
|
||||
FormatString:
|
||||
Enabled: false
|
||||
CaseIndentation:
|
||||
IndentWhenRelativeTo: end
|
1
Gemfile
1
Gemfile
|
@ -30,7 +30,6 @@ platforms :jruby do
|
|||
end
|
||||
|
||||
# Code Quality
|
||||
gem 'cane', :platforms => [:mri_19, :mri_20], :require => false
|
||||
gem 'coveralls', :require => false
|
||||
gem 'rubocop', :require => false
|
||||
|
||||
|
|
56
Rakefile
56
Rakefile
|
@ -14,41 +14,17 @@ def sh_rake(command)
|
|||
sh "#{Gem.ruby} -S rake #{command}", :verbose => true
|
||||
end
|
||||
|
||||
def say(text, color=:magenta)
|
||||
n = { :bold => 1, :red => 31, :green => 32, :yellow => 33, :blue => 34, :magenta => 35 }.fetch(color, 0)
|
||||
puts "\e[%dm%s\e[0m" % [n, text]
|
||||
end
|
||||
|
||||
desc "Run 'install' for all projects"
|
||||
task :install do
|
||||
GEM_PATHS.each do |dir|
|
||||
Dir.chdir(dir) { sh_rake(:install) }
|
||||
end
|
||||
end
|
||||
|
||||
desc 'Clean pkg and other stuff'
|
||||
task :clean do
|
||||
GEM_PATHS.each do |g|
|
||||
%w[tmp pkg coverage].each { |dir| sh 'rm -rf %s' % File.join(g, dir) }
|
||||
end
|
||||
end
|
||||
|
||||
desc 'Clean pkg and other stuff'
|
||||
task :uninstall do
|
||||
sh 'gem search --no-version middleman | grep middleman | xargs gem uninstall -a'
|
||||
end
|
||||
|
||||
desc 'Displays the current version'
|
||||
task :version do
|
||||
say "Current version: #{Middleman::VERSION}"
|
||||
puts "Current version: #{Middleman::VERSION}"
|
||||
end
|
||||
|
||||
desc 'Bumps the version number based on given version'
|
||||
task :bump, [:version] do |t, args|
|
||||
task :bump, [:version] do |_, args|
|
||||
raise 'Please specify version=x.x.x !' unless args.version
|
||||
version_path = File.dirname(__FILE__) + '/middleman-core/lib/middleman-core/version.rb'
|
||||
version_text = File.read(version_path).sub(/VERSION = '[\d\.\w]+'/, "VERSION = '#{args.version}'")
|
||||
say "Updating Middleman to version #{args.version}"
|
||||
puts "Updating Middleman to version #{args.version}"
|
||||
File.open(version_path, 'w') { |f| f.write version_text }
|
||||
sh 'git commit -a -m "Bumped version to %s"' % args.version
|
||||
end
|
||||
|
@ -58,7 +34,7 @@ task :fresh => [:uninstall, :install, :clean]
|
|||
|
||||
desc 'Pushes repository to GitHub'
|
||||
task :push do
|
||||
say 'Pushing to github...'
|
||||
puts 'Pushing to github...'
|
||||
sh "git tag v#{Middleman::VERSION}"
|
||||
sh 'git push origin master'
|
||||
sh "git push origin v#{Middleman::VERSION}"
|
||||
|
@ -66,7 +42,7 @@ end
|
|||
|
||||
desc 'Release all middleman gems'
|
||||
task :publish => :push do
|
||||
say 'Pushing to rubygems...'
|
||||
puts 'Pushing to rubygems...'
|
||||
GEM_PATHS.each do |dir|
|
||||
Dir.chdir(dir) { sh_rake('release') }
|
||||
end
|
||||
|
@ -94,24 +70,10 @@ task :spec do
|
|||
end
|
||||
end
|
||||
|
||||
begin
|
||||
require 'cane/rake_task'
|
||||
desc 'Run cane to check quality metrics'
|
||||
Cane::RakeTask.new(:quality) do |cane|
|
||||
cane.no_style = true
|
||||
cane.no_doc = true
|
||||
cane.abc_glob = 'middleman*/lib/middleman*/**/*.rb'
|
||||
end
|
||||
rescue LoadError
|
||||
end
|
||||
|
||||
begin
|
||||
require 'rubocop/rake_task'
|
||||
desc 'Run RuboCop to check code consistency'
|
||||
Rubocop::RakeTask.new(:rubocop) do |task|
|
||||
task.fail_on_error = false
|
||||
end
|
||||
rescue LoadError
|
||||
require 'rubocop/rake_task'
|
||||
desc 'Run RuboCop to check code consistency'
|
||||
Rubocop::RakeTask.new(:rubocop) do |task|
|
||||
task.fail_on_error = false
|
||||
end
|
||||
|
||||
desc 'Run tests for all middleman gems'
|
||||
|
|
|
@ -20,14 +20,14 @@ Cucumber::Rake::Task.new do |t|
|
|||
exempt_tags << '--tags ~@nojava' if RUBY_PLATFORM == 'java'
|
||||
exempt_tags << '--tags ~@encoding' unless Object.const_defined?(:Encoding)
|
||||
exempt_tags << '--tags ~@travishatesme' if ENV['TRAVIS'] == 'true'
|
||||
t.cucumber_opts = "--color #{exempt_tags.join(" ")} --strict --format #{ENV['CUCUMBER_FORMAT'] || 'Fivemat'}"
|
||||
t.cucumber_opts = "--color #{exempt_tags.join(' ')} --strict --format #{ENV['CUCUMBER_FORMAT'] || 'Fivemat'}"
|
||||
end
|
||||
|
||||
Cucumber::Rake::Task.new(:cucumber_wip) do |t|
|
||||
exempt_tags = ['--tags @wip']
|
||||
exempt_tags << '--tags ~@nojava' if RUBY_PLATFORM == 'java'
|
||||
exempt_tags << '--tags ~@encoding' unless Object.const_defined?(:Encoding)
|
||||
t.cucumber_opts = "--color #{exempt_tags.join(" ")} --strict --format #{ENV['CUCUMBER_FORMAT'] || 'Fivemat'}"
|
||||
t.cucumber_opts = "--color #{exempt_tags.join(' ')} --strict --format #{ENV['CUCUMBER_FORMAT'] || 'Fivemat'}"
|
||||
end
|
||||
|
||||
require 'rspec/core/rake_task'
|
||||
|
|
|
@ -4,10 +4,8 @@ $LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir)
|
|||
|
||||
# Top-level Middleman namespace
|
||||
module Middleman
|
||||
|
||||
# Backwards compatibility namespace
|
||||
module Features; end
|
||||
|
||||
end
|
||||
|
||||
require 'middleman-core/version'
|
||||
|
|
|
@ -225,7 +225,7 @@ module Middleman
|
|||
def to_s
|
||||
"#<Middleman::Application:0x#{object_id}>"
|
||||
end
|
||||
alias :inspect :to_s # Ruby 2.0 calls inspect for NoMethodError instead of to_s
|
||||
alias_method :inspect, :to_s # Ruby 2.0 calls inspect for NoMethodError instead of to_s
|
||||
|
||||
# Hooks clones _hooks from the class to the instance.
|
||||
# https://github.com/apotonick/hooks/blob/master/lib/hooks/instance_hooks.rb#L10
|
||||
|
|
|
@ -4,9 +4,7 @@ require 'thor/group'
|
|||
|
||||
# CLI Module
|
||||
module Middleman
|
||||
|
||||
module Cli
|
||||
|
||||
# The base task from which everything else etends
|
||||
class Base < Thor
|
||||
class << self
|
||||
|
@ -32,16 +30,16 @@ module Middleman
|
|||
# @param [Symbol, String, nil] meth
|
||||
# @param [Boolean] subcommand
|
||||
# @return [void]
|
||||
def help(meth = nil, subcommand = false)
|
||||
def help(meth=nil, subcommand=false)
|
||||
if meth && !self.respond_to?(meth)
|
||||
klass, task = Thor::Util.find_class_and_task_by_namespace("#{meth}:#{meth}")
|
||||
klass.start(['-h', task].compact, :shell => self.shell)
|
||||
klass.start(['-h', task].compact, :shell => shell)
|
||||
else
|
||||
list = []
|
||||
Thor::Util.thor_classes_in(Middleman::Cli).each do |thor_class|
|
||||
list += thor_class.printable_tasks(false)
|
||||
end
|
||||
list.sort!{ |a,b| a[0] <=> b[0] }
|
||||
list.sort! { |a, b| a[0] <=> b[0] }
|
||||
|
||||
shell.say 'Tasks:'
|
||||
shell.print_table(list, :ident => 2, :truncate => true)
|
||||
|
@ -54,7 +52,7 @@ module Middleman
|
|||
def method_missing(meth, *args)
|
||||
meth = meth.to_s
|
||||
|
||||
if self.class.map.has_key?(meth)
|
||||
if self.class.map.key?(meth)
|
||||
meth = self.class.map[meth]
|
||||
end
|
||||
|
||||
|
@ -63,17 +61,17 @@ module Middleman
|
|||
if klass.nil?
|
||||
tasks_dir = File.join(Dir.pwd, 'tasks')
|
||||
|
||||
if File.exists?(tasks_dir)
|
||||
if File.exist?(tasks_dir)
|
||||
Dir[File.join(tasks_dir, '**/*_task.rb')].each { |f| require f }
|
||||
klass, task = Thor::Util.find_class_and_task_by_namespace("#{meth}:#{meth}")
|
||||
end
|
||||
end
|
||||
|
||||
if klass.nil?
|
||||
raise Thor::Error.new "There's no '#{meth}' command for Middleman. Try 'middleman help' for a list of commands."
|
||||
raise Thor::Error, "There's no '#{meth}' command for Middleman. Try 'middleman help' for a list of commands."
|
||||
else
|
||||
args.unshift(task) if task
|
||||
klass.start(args, :shell => self.shell)
|
||||
klass.start(args, :shell => shell)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -4,7 +4,7 @@ require 'set'
|
|||
# CLI Module
|
||||
module Middleman::Cli
|
||||
# Alias "b" to "build"
|
||||
Base.map({ 'b' => 'build' })
|
||||
Base.map('b' => 'build')
|
||||
|
||||
# The CLI Build class
|
||||
class Build < Thor
|
||||
|
@ -19,31 +19,31 @@ module Middleman::Cli
|
|||
|
||||
desc 'build [options]', 'Builds the static site for deployment'
|
||||
method_option :clean,
|
||||
:type => :boolean,
|
||||
:default => true,
|
||||
:desc => 'Remove orphaned files from build (--no-clean to disable)'
|
||||
:type => :boolean,
|
||||
:default => true,
|
||||
:desc => 'Remove orphaned files from build (--no-clean to disable)'
|
||||
method_option :glob,
|
||||
:type => :string,
|
||||
:aliases => '-g',
|
||||
:default => nil,
|
||||
:desc => 'Build a subset of the project'
|
||||
:type => :string,
|
||||
:aliases => '-g',
|
||||
:default => nil,
|
||||
:desc => 'Build a subset of the project'
|
||||
method_option :verbose,
|
||||
:type => :boolean,
|
||||
:default => false,
|
||||
:desc => 'Print debug messages'
|
||||
:type => :boolean,
|
||||
:default => false,
|
||||
:desc => 'Print debug messages'
|
||||
method_option :instrument,
|
||||
:type => :string,
|
||||
:default => false,
|
||||
:desc => 'Print instrument messages'
|
||||
:type => :string,
|
||||
:default => false,
|
||||
:desc => 'Print instrument messages'
|
||||
method_option :profile,
|
||||
:type => :boolean,
|
||||
:default => false,
|
||||
:desc => 'Generate profiling report for the build'
|
||||
:type => :boolean,
|
||||
:default => false,
|
||||
:desc => 'Generate profiling report for the build'
|
||||
|
||||
# Core build Thor command
|
||||
# @return [void]
|
||||
def build
|
||||
if !ENV['MM_ROOT']
|
||||
unless ENV['MM_ROOT']
|
||||
raise Thor::Error, 'Error: Could not find a Middleman project config, perhaps you are in the wrong folder?'
|
||||
end
|
||||
|
||||
|
@ -62,7 +62,7 @@ module Middleman::Cli
|
|||
self.class.shared_instance(options['verbose'], options['instrument'])
|
||||
|
||||
opts = {}
|
||||
opts[:glob] = options['glob'] if options.has_key?('glob')
|
||||
opts[:glob] = options['glob'] if options.key?('glob')
|
||||
opts[:clean] = options['clean']
|
||||
|
||||
self.class.shared_instance.run_hook :before_build, self
|
||||
|
@ -71,15 +71,15 @@ module Middleman::Cli
|
|||
|
||||
self.class.shared_instance.run_hook :after_build, self
|
||||
|
||||
if self.had_errors && !self.debugging
|
||||
if had_errors && !debugging
|
||||
msg = 'There were errors during this build'
|
||||
unless options['verbose']
|
||||
msg << ', re-run with `middleman build --verbose` to see the full exception.'
|
||||
end
|
||||
self.shell.say msg, :red
|
||||
shell.say msg, :red
|
||||
end
|
||||
|
||||
exit(1) if self.had_errors
|
||||
exit(1) if had_errors
|
||||
end
|
||||
|
||||
# Static methods
|
||||
|
@ -129,7 +129,7 @@ module Middleman::Cli
|
|||
clean! if should_clean?
|
||||
end
|
||||
|
||||
protected
|
||||
protected
|
||||
|
||||
# Remove files which were not built in this cycle
|
||||
# @return [void]
|
||||
|
@ -138,7 +138,7 @@ module Middleman::Cli
|
|||
base.remove_file f, :force => true
|
||||
end
|
||||
|
||||
Dir[@build_dir.join('**', '*')].select {|d| File.directory?(d) }.each do |d|
|
||||
Dir[@build_dir.join('**', '*')].select { |d| File.directory?(d) }.each do |d|
|
||||
base.remove_file d, :force => true if directory_empty? d
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
# CLI Module
|
||||
module Middleman::Cli
|
||||
|
||||
# A initializing Bundler
|
||||
class Bundle < Thor
|
||||
include Thor::Actions
|
||||
|
@ -12,7 +11,7 @@ module Middleman::Cli
|
|||
|
||||
# The setup task
|
||||
def bundle
|
||||
run('bundle install')#, :capture => true)
|
||||
run('bundle install')# , :capture => true)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -28,13 +27,13 @@ module Middleman::Cli
|
|||
# The upgrade task
|
||||
def upgrade
|
||||
inside(ENV['MM_ROOT']) do
|
||||
run('bundle update')#, :capture => true)
|
||||
run('bundle update')# , :capture => true)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Map "u" to "upgrade"
|
||||
Base.map({
|
||||
'u' => 'upgrade'
|
||||
})
|
||||
Base.map(
|
||||
'u' => 'upgrade'
|
||||
)
|
||||
end
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
# CLI Module
|
||||
module Middleman::Cli
|
||||
|
||||
# A thor task for creating new projects
|
||||
class Console < Thor
|
||||
include Thor::Actions
|
||||
|
@ -11,13 +10,13 @@ module Middleman::Cli
|
|||
|
||||
desc 'console [options]', 'Start an interactive console in the context of your Middleman application'
|
||||
method_option :environment,
|
||||
:aliases => '-e',
|
||||
:default => ENV['MM_ENV'] || ENV['RACK_ENV'] || 'development',
|
||||
:desc => 'The environment Middleman will run under'
|
||||
:aliases => '-e',
|
||||
:default => ENV['MM_ENV'] || ENV['RACK_ENV'] || 'development',
|
||||
:desc => 'The environment Middleman will run under'
|
||||
method_option :verbose,
|
||||
:type => :boolean,
|
||||
:default => false,
|
||||
:desc => 'Print debug messages'
|
||||
:type => :boolean,
|
||||
:default => false,
|
||||
:desc => 'Print debug messages'
|
||||
def console
|
||||
require 'middleman-core'
|
||||
require 'irb'
|
||||
|
@ -27,7 +26,7 @@ module Middleman::Cli
|
|||
:debug => options['verbose']
|
||||
}
|
||||
|
||||
@app =::Middleman::Application.server.inst do
|
||||
@app = ::Middleman::Application.server.inst do
|
||||
if opts[:environment]
|
||||
set :environment, opts[:environment].to_sym
|
||||
end
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
# CLI Module
|
||||
module Middleman::Cli
|
||||
|
||||
# A thor task for creating new projects
|
||||
class Extension < Thor
|
||||
include Thor::Actions
|
||||
|
@ -44,6 +43,5 @@ module Middleman::Cli
|
|||
copy_file 'gitignore', File.join(name, '.gitignore')
|
||||
end
|
||||
}
|
||||
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,7 +2,6 @@ require 'middleman-core/templates'
|
|||
|
||||
# CLI Module
|
||||
module Middleman::Cli
|
||||
|
||||
# A thor task for creating new projects
|
||||
class Init < Thor
|
||||
check_unknown_options!
|
||||
|
@ -12,41 +11,41 @@ module Middleman::Cli
|
|||
desc 'init NAME [options]', 'Create new project NAME'
|
||||
available_templates = ::Middleman::Templates.registered.keys.join(', ')
|
||||
method_option 'template',
|
||||
:aliases => '-T',
|
||||
:default => 'default',
|
||||
:desc => "Use a project template: #{available_templates}"
|
||||
:aliases => '-T',
|
||||
:default => 'default',
|
||||
:desc => "Use a project template: #{available_templates}"
|
||||
method_option 'css_dir',
|
||||
# :default => "stylesheets",
|
||||
:desc => 'The path to the css files'
|
||||
:desc => 'The path to the css files'
|
||||
method_option 'js_dir',
|
||||
# :default => "javascripts",
|
||||
:desc => 'The path to the javascript files'
|
||||
:desc => 'The path to the javascript files'
|
||||
method_option 'images_dir',
|
||||
# :default => "images",
|
||||
:desc => 'The path to the image files'
|
||||
:desc => 'The path to the image files'
|
||||
method_option 'rack',
|
||||
:type => :boolean,
|
||||
:default => false,
|
||||
:desc => 'Include a config.ru file'
|
||||
:type => :boolean,
|
||||
:default => false,
|
||||
:desc => 'Include a config.ru file'
|
||||
method_option 'skip-gemfile',
|
||||
:type => :boolean,
|
||||
:default => false,
|
||||
:desc => "Don't create a Gemfile"
|
||||
:type => :boolean,
|
||||
:default => false,
|
||||
:desc => "Don't create a Gemfile"
|
||||
method_option 'skip-bundle',
|
||||
:type => :boolean,
|
||||
:aliases => '-B',
|
||||
:default => false,
|
||||
:desc => "Don't run bundle install"
|
||||
:type => :boolean,
|
||||
:aliases => '-B',
|
||||
:default => false,
|
||||
:desc => "Don't run bundle install"
|
||||
method_option 'skip-git',
|
||||
:type => :boolean,
|
||||
:default => false,
|
||||
:desc => 'Skip Git ignores and keeps'
|
||||
:type => :boolean,
|
||||
:default => false,
|
||||
:desc => 'Skip Git ignores and keeps'
|
||||
# The init task
|
||||
# @param [String] name
|
||||
def init(name = '.')
|
||||
def init(name='.')
|
||||
key = options[:template].to_sym
|
||||
unless ::Middleman::Templates.registered.has_key?(key)
|
||||
raise Thor::Error.new "Unknown project template '#{key}'"
|
||||
unless ::Middleman::Templates.registered.key?(key)
|
||||
raise Thor::Error, "Unknown project template '#{key}'"
|
||||
end
|
||||
|
||||
thor_group = ::Middleman::Templates.registered[key]
|
||||
|
@ -59,9 +58,9 @@ module Middleman::Cli
|
|||
end
|
||||
|
||||
# Map "i", "new" and "n" to "init"
|
||||
Base.map({
|
||||
'i' => 'init',
|
||||
'new' => 'init',
|
||||
'n' => 'init'
|
||||
})
|
||||
Base.map(
|
||||
'i' => 'init',
|
||||
'new' => 'init',
|
||||
'n' => 'init'
|
||||
)
|
||||
end
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
# CLI Module
|
||||
module Middleman::Cli
|
||||
|
||||
# Server thor task
|
||||
class Server < Thor
|
||||
check_unknown_options!
|
||||
|
@ -9,54 +8,54 @@ module Middleman::Cli
|
|||
|
||||
desc 'server [options]', 'Start the preview server'
|
||||
method_option :environment,
|
||||
:aliases => '-e',
|
||||
:default => ENV['MM_ENV'] || ENV['RACK_ENV'] || 'development',
|
||||
:desc => 'The environment Middleman will run under'
|
||||
:aliases => '-e',
|
||||
:default => ENV['MM_ENV'] || ENV['RACK_ENV'] || 'development',
|
||||
:desc => 'The environment Middleman will run under'
|
||||
method_option :host,
|
||||
:type => :string,
|
||||
:aliases => '-h',
|
||||
:default => '0.0.0.0',
|
||||
:desc => 'Bind to HOST address'
|
||||
:type => :string,
|
||||
:aliases => '-h',
|
||||
:default => '0.0.0.0',
|
||||
:desc => 'Bind to HOST address'
|
||||
method_option :port,
|
||||
:aliases => '-p',
|
||||
:default => '4567',
|
||||
:desc => 'The port Middleman will listen on'
|
||||
:aliases => '-p',
|
||||
:default => '4567',
|
||||
:desc => 'The port Middleman will listen on'
|
||||
method_option :verbose,
|
||||
:type => :boolean,
|
||||
:default => false,
|
||||
:desc => 'Print debug messages'
|
||||
:type => :boolean,
|
||||
:default => false,
|
||||
:desc => 'Print debug messages'
|
||||
method_option :instrument,
|
||||
:type => :string,
|
||||
:default => false,
|
||||
:desc => 'Print instrument messages'
|
||||
:type => :string,
|
||||
:default => false,
|
||||
:desc => 'Print instrument messages'
|
||||
method_option :disable_watcher,
|
||||
:type => :boolean,
|
||||
:default => false,
|
||||
:desc => 'Disable the file change and delete watcher process'
|
||||
:type => :boolean,
|
||||
:default => false,
|
||||
:desc => 'Disable the file change and delete watcher process'
|
||||
method_option :profile,
|
||||
:type => :boolean,
|
||||
:default => false,
|
||||
:desc => 'Generate profiling report for server startup'
|
||||
:type => :boolean,
|
||||
:default => false,
|
||||
:desc => 'Generate profiling report for server startup'
|
||||
method_option :reload_paths,
|
||||
:type => :string,
|
||||
:default => false,
|
||||
:desc => 'Additional paths to auto-reload when files change'
|
||||
:type => :string,
|
||||
:default => false,
|
||||
:desc => 'Additional paths to auto-reload when files change'
|
||||
method_option :force_polling,
|
||||
:type => :boolean,
|
||||
:default => false,
|
||||
:desc => 'Force file watcher into polling mode'
|
||||
:type => :boolean,
|
||||
:default => false,
|
||||
:desc => 'Force file watcher into polling mode'
|
||||
method_option :latency,
|
||||
:type => :numeric,
|
||||
:aliases => '-l',
|
||||
:default => 0.25,
|
||||
:desc => 'Set file watcher latency, in seconds'
|
||||
:type => :numeric,
|
||||
:aliases => '-l',
|
||||
:default => 0.25,
|
||||
:desc => 'Set file watcher latency, in seconds'
|
||||
|
||||
# Start the server
|
||||
def server
|
||||
require 'middleman-core'
|
||||
require 'middleman-core/preview_server'
|
||||
|
||||
if !ENV['MM_ROOT']
|
||||
unless ENV['MM_ROOT']
|
||||
puts '== Could not find a Middleman project config.rb'
|
||||
puts '== Treating directory as a static site to be served'
|
||||
ENV['MM_ROOT'] = Dir.pwd
|
||||
|
@ -85,5 +84,5 @@ module Middleman::Cli
|
|||
end
|
||||
|
||||
# Map "s" to "server"
|
||||
Base.map({ 's' => 'server' })
|
||||
Base.map('s' => 'server')
|
||||
end
|
||||
|
|
|
@ -39,7 +39,7 @@ module Middleman
|
|||
end
|
||||
|
||||
# Needed so that method_missing makes sense
|
||||
def respond_to?(method, include_private = false)
|
||||
def respond_to?(method, include_private=false)
|
||||
super || config.defines_setting?(method)
|
||||
end
|
||||
end
|
||||
|
@ -53,7 +53,7 @@ module Middleman
|
|||
# @deprecated Prefer accessing settings through "config".
|
||||
#
|
||||
# @return [ConfigurationManager]
|
||||
alias :settings :config
|
||||
alias_method :settings, :config
|
||||
|
||||
# Set attributes (global variables)
|
||||
#
|
||||
|
@ -80,7 +80,7 @@ module Middleman
|
|||
end
|
||||
|
||||
# Needed so that method_missing makes sense
|
||||
def respond_to?(method, include_private = false)
|
||||
def respond_to?(method, include_private=false)
|
||||
super || config.defines_setting?(method)
|
||||
end
|
||||
end
|
||||
|
@ -135,7 +135,7 @@ module Middleman
|
|||
end
|
||||
|
||||
# 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))
|
||||
end
|
||||
|
||||
|
@ -143,7 +143,7 @@ module Middleman
|
|||
# @param [Symbol] key
|
||||
# @return [Boolean]
|
||||
def defines_setting?(key)
|
||||
@settings.has_key?(key)
|
||||
@settings.key?(key)
|
||||
end
|
||||
|
||||
# Define a new setting, with optional default and user-friendly description.
|
||||
|
@ -155,7 +155,7 @@ module Middleman
|
|||
# @return [ConfigSetting]
|
||||
def define_setting(key, default=nil, description=nil)
|
||||
raise "Setting #{key} doesn't exist" if @finalized
|
||||
raise "Setting #{key} already defined" if @settings.has_key?(key)
|
||||
raise "Setting #{key} already defined" if @settings.key?(key)
|
||||
raise 'Setting key must be a Symbol' unless key.is_a? Symbol
|
||||
|
||||
@settings[key] = ConfigSetting.new(key, default, description)
|
||||
|
@ -170,7 +170,7 @@ module Middleman
|
|||
|
||||
# Deep duplicate of the configuration manager
|
||||
def dup
|
||||
ConfigurationManager.new.tap {|c| c.load_settings(self.all_settings) }
|
||||
ConfigurationManager.new.tap { |c| c.load_settings(all_settings) }
|
||||
end
|
||||
|
||||
# Load in a list of settings
|
||||
|
|
|
@ -1,10 +1,8 @@
|
|||
module Middleman
|
||||
module CoreExtensions
|
||||
|
||||
# The data extension parses YAML and JSON files in the data/ directory
|
||||
# and makes them available to config.rb, templates and extensions
|
||||
module Data
|
||||
|
||||
# Extension registered
|
||||
class << self
|
||||
# @private
|
||||
|
@ -16,7 +14,7 @@ module Middleman
|
|||
app.config.define_setting :data_dir, 'data', 'The directory data files are stored in'
|
||||
app.send :include, InstanceMethods
|
||||
end
|
||||
alias :included :registered
|
||||
alias_method :included, :registered
|
||||
end
|
||||
|
||||
# Instance methods
|
||||
|
@ -24,12 +22,12 @@ module Middleman
|
|||
# Setup data files before anything else so they are available when
|
||||
# parsing config.rb
|
||||
def initialize
|
||||
self.files.changed DataStore.matcher do |file|
|
||||
self.data.touch_file(file) if file.start_with?("#{config[:data_dir]}/")
|
||||
files.changed DataStore.matcher do |file|
|
||||
data.touch_file(file) if file.start_with?("#{config[:data_dir]}/")
|
||||
end
|
||||
|
||||
self.files.deleted DataStore.matcher do |file|
|
||||
self.data.remove_file(file) if file.start_with?("#{config[:data_dir]}/")
|
||||
files.deleted DataStore.matcher do |file|
|
||||
data.remove_file(file) if file.start_with?("#{config[:data_dir]}/")
|
||||
end
|
||||
|
||||
super
|
||||
|
@ -45,10 +43,8 @@ module Middleman
|
|||
|
||||
# The core logic behind the data extension.
|
||||
class DataStore
|
||||
|
||||
# Static methods
|
||||
class << self
|
||||
|
||||
# The regex which tells Middleman which files are for data
|
||||
#
|
||||
# @return [Regexp]
|
||||
|
@ -137,7 +133,7 @@ module Middleman
|
|||
data_branch = data_branch[dir]
|
||||
end
|
||||
|
||||
data_branch.delete(basename) if data_branch.has_key?(basename)
|
||||
data_branch.delete(basename) if data_branch.key?(basename)
|
||||
end
|
||||
|
||||
# Get a hash from either internal static data or a callback
|
||||
|
@ -150,10 +146,10 @@ module Middleman
|
|||
@@local_sources ||= {}
|
||||
@@callback_sources ||= {}
|
||||
|
||||
if self.store.has_key?(path.to_s)
|
||||
response = self.store[path.to_s]
|
||||
elsif self.callbacks.has_key?(path.to_s)
|
||||
response = self.callbacks[path.to_s].call()
|
||||
if store.key?(path.to_s)
|
||||
response = store[path.to_s]
|
||||
elsif callbacks.key?(path.to_s)
|
||||
response = callbacks[path.to_s].call
|
||||
end
|
||||
|
||||
response
|
||||
|
@ -164,7 +160,7 @@ module Middleman
|
|||
# @param [String] path The namespace to search for
|
||||
# @return [Hash, nil]
|
||||
def method_missing(path)
|
||||
if @local_data.has_key?(path.to_s)
|
||||
if @local_data.key?(path.to_s)
|
||||
return @local_data[path.to_s]
|
||||
else
|
||||
result = data_for_path(path)
|
||||
|
@ -178,8 +174,8 @@ module Middleman
|
|||
end
|
||||
|
||||
# Needed so that method_missing makes sense
|
||||
def respond_to?(method, include_private = false)
|
||||
super || has_key?(method)
|
||||
def respond_to?(method, include_private=false)
|
||||
super || key?(method)
|
||||
end
|
||||
|
||||
# Make DataStore act like a hash. Return requested data, or
|
||||
|
@ -188,24 +184,26 @@ module Middleman
|
|||
# @param [String, Symbol] key The name of the data namespace
|
||||
# @return [Hash, nil]
|
||||
def [](key)
|
||||
__send__(key) if has_key?(key)
|
||||
__send__(key) if key?(key)
|
||||
end
|
||||
|
||||
def has_key?(key)
|
||||
@local_data.has_key?(key.to_s) || !!(data_for_path(key))
|
||||
@local_data.key?(key.to_s) || !!(data_for_path(key))
|
||||
end
|
||||
|
||||
alias_method :key?, :has_key?
|
||||
|
||||
# Convert all the data into a static hash
|
||||
#
|
||||
# @return [Hash]
|
||||
def to_h
|
||||
data = {}
|
||||
|
||||
self.store.each do |k, v|
|
||||
store.each do |k, _|
|
||||
data[k] = data_for_path(k)
|
||||
end
|
||||
|
||||
self.callbacks.each do |k, v|
|
||||
callbacks.each do |k, _|
|
||||
data[k] = data_for_path(k)
|
||||
end
|
||||
|
||||
|
|
|
@ -32,7 +32,6 @@
|
|||
module Middleman
|
||||
module CoreExtensions
|
||||
module Extensions
|
||||
|
||||
# Register extension
|
||||
class << self
|
||||
# @private
|
||||
|
@ -51,7 +50,7 @@ module Middleman
|
|||
app.send :include, InstanceMethods
|
||||
app.delegate :configure, :to => :"self.class"
|
||||
end
|
||||
alias :included :registered
|
||||
alias_method :included, :registered
|
||||
end
|
||||
|
||||
# Class methods
|
||||
|
@ -75,7 +74,7 @@ module Middleman
|
|||
else
|
||||
extend extension
|
||||
if extension.respond_to?(:registered)
|
||||
if extension.method(:registered).arity === 1
|
||||
if extension.method(:registered).arity == 1
|
||||
extension.registered(self, &block)
|
||||
else
|
||||
extension.registered(self, options, &block)
|
||||
|
@ -157,7 +156,7 @@ module Middleman
|
|||
|
||||
# Check for and evaluate local configuration
|
||||
local_config = File.join(root, 'config.rb')
|
||||
if File.exists? local_config
|
||||
if File.exist? local_config
|
||||
logger.debug '== Reading: Local config'
|
||||
instance_eval File.read(local_config), local_config, 1
|
||||
end
|
||||
|
@ -172,16 +171,16 @@ module Middleman
|
|||
# polluted with paths from other test app directories that don't
|
||||
# exist anymore.
|
||||
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!
|
||||
end
|
||||
|
||||
run_hook :after_configuration
|
||||
|
||||
logger.debug 'Loaded extensions:'
|
||||
self.extensions.each do |ext, klass|
|
||||
extensions.each do |ext, klass|
|
||||
if ext.is_a?(Hash)
|
||||
ext.each do |k,_|
|
||||
ext.each do |k, _|
|
||||
logger.debug "== Extension: #{k}"
|
||||
end
|
||||
else
|
||||
|
|
|
@ -2,16 +2,14 @@
|
|||
module Middleman
|
||||
module CoreExtensions
|
||||
module ExternalHelpers
|
||||
|
||||
# Setup extension
|
||||
class << self
|
||||
|
||||
# once registered
|
||||
def registered(app)
|
||||
# Setup a default helpers paths
|
||||
app.config.define_setting :helpers_dir, 'helpers', 'Directory to autoload helper modules from'
|
||||
app.config.define_setting :helpers_filename_glob, '**.rb', 'Glob pattern for matching helper ruby files'
|
||||
app.config.define_setting :helpers_filename_to_module_name_proc, Proc.new { |filename|
|
||||
app.config.define_setting :helpers_filename_to_module_name_proc, proc { |filename|
|
||||
basename = File.basename(filename, File.extname(filename))
|
||||
basename.camelcase
|
||||
}, 'Proc implementing the conversion from helper filename to module name'
|
||||
|
@ -19,7 +17,7 @@ module Middleman
|
|||
# After config
|
||||
app.after_configuration do
|
||||
helpers_path = File.join(root, config[:helpers_dir])
|
||||
next unless File.exists?(helpers_path)
|
||||
next unless File.exist?(helpers_path)
|
||||
|
||||
Dir[File.join(helpers_path, config[:helpers_filename_glob])].each do |filename|
|
||||
module_name = config[:helpers_filename_to_module_name_proc].call(filename)
|
||||
|
@ -32,7 +30,7 @@ module Middleman
|
|||
end
|
||||
end
|
||||
end
|
||||
alias :included :registered
|
||||
alias_method :included, :registered
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -5,7 +5,6 @@ require 'set'
|
|||
module Middleman
|
||||
module CoreExtensions
|
||||
module FileWatcher
|
||||
|
||||
IGNORE_LIST = [
|
||||
/^bin(\/|$)/,
|
||||
/^\.bundle(\/|$)/,
|
||||
|
@ -26,7 +25,6 @@ module Middleman
|
|||
|
||||
# Setup extension
|
||||
class << self
|
||||
|
||||
# Once registered
|
||||
def registered(app)
|
||||
app.send :include, InstanceMethods
|
||||
|
@ -47,12 +45,11 @@ module Middleman
|
|||
files.reload_path('.')
|
||||
end
|
||||
end
|
||||
alias :included :registered
|
||||
alias_method :included, :registered
|
||||
end
|
||||
|
||||
# Instance methods
|
||||
module InstanceMethods
|
||||
|
||||
# Access the file api
|
||||
# @return [Middleman::CoreExtensions::FileWatcher::API]
|
||||
def files
|
||||
|
@ -62,7 +59,6 @@ module Middleman
|
|||
|
||||
# Core File Change API class
|
||||
class API
|
||||
|
||||
attr_reader :app
|
||||
attr_reader :known_paths
|
||||
delegate :logger, :to => :app
|
||||
|
@ -102,7 +98,7 @@ module Middleman
|
|||
path = Pathname(path)
|
||||
logger.debug "== File Change: #{path}"
|
||||
@known_paths << path
|
||||
self.run_callbacks(path, :changed)
|
||||
run_callbacks(path, :changed)
|
||||
end
|
||||
|
||||
# Notify callbacks that a file was deleted
|
||||
|
@ -113,7 +109,7 @@ module Middleman
|
|||
path = Pathname(path)
|
||||
logger.debug "== File Deletion: #{path}"
|
||||
@known_paths.delete(path)
|
||||
self.run_callbacks(path, :deleted)
|
||||
run_callbacks(path, :deleted)
|
||||
end
|
||||
|
||||
# Manually trigger update events
|
||||
|
@ -151,7 +147,7 @@ module Middleman
|
|||
|
||||
def exists?(path)
|
||||
p = Pathname(path)
|
||||
p = p.relative_path_from(Pathname(@app.root)) if !p.relative?
|
||||
p = p.relative_path_from(Pathname(@app.root)) unless p.relative?
|
||||
@known_paths.include?(p)
|
||||
end
|
||||
|
||||
|
@ -163,7 +159,7 @@ module Middleman
|
|||
app.config[:file_watcher_ignore].any? { |r| path =~ r }
|
||||
end
|
||||
|
||||
protected
|
||||
protected
|
||||
|
||||
# Notify callbacks for a file given an array of callbacks
|
||||
#
|
||||
|
@ -172,7 +168,7 @@ module Middleman
|
|||
# @return [void]
|
||||
def run_callbacks(path, callbacks_name)
|
||||
path = path.to_s
|
||||
self.send(callbacks_name).each do |callback, matcher|
|
||||
send(callbacks_name).each do |callback, matcher|
|
||||
next unless matcher.nil? || path.match(matcher)
|
||||
@app.instance_exec(path, &callback)
|
||||
end
|
||||
|
|
|
@ -9,10 +9,8 @@ require 'active_support/json'
|
|||
|
||||
# Extensions namespace
|
||||
module Middleman::CoreExtensions
|
||||
|
||||
class FrontMatter < ::Middleman::Extension
|
||||
|
||||
YAML_ERRORS = [ StandardError ]
|
||||
YAML_ERRORS = [StandardError]
|
||||
|
||||
# https://github.com/tenderlove/psych/issues/23
|
||||
if defined?(Psych) && defined?(Psych::SyntaxError)
|
||||
|
@ -115,7 +113,7 @@ module Middleman::CoreExtensions
|
|||
@cache.delete(path)
|
||||
end
|
||||
|
||||
private
|
||||
private
|
||||
# Parse YAML frontmatter out of a string
|
||||
# @param [String] content
|
||||
# @return [Array<Hash, String>]
|
||||
|
@ -147,7 +145,7 @@ module Middleman::CoreExtensions
|
|||
content = content.sub(json_regex, '')
|
||||
|
||||
begin
|
||||
json = ($1+$2).sub(';;;', '{').sub(';;;', '}')
|
||||
json = ($1 + $2).sub(';;;', '{').sub(';;;', '}')
|
||||
data = ActiveSupport::JSON.decode(json).symbolize_keys
|
||||
rescue => e
|
||||
app.logger.error "JSON Exception parsing #{full_path}: #{e.message}"
|
||||
|
|
|
@ -10,10 +10,8 @@ end
|
|||
module Middleman
|
||||
module CoreExtensions
|
||||
module Rendering
|
||||
|
||||
# Setup extension
|
||||
class << self
|
||||
|
||||
# Once registered
|
||||
def registered(app)
|
||||
# Include methods
|
||||
|
@ -93,7 +91,7 @@ module Middleman
|
|||
|
||||
# Clean up missing Tilt exts
|
||||
app.after_configuration do
|
||||
Tilt.mappings.each do |key, klasses|
|
||||
Tilt.mappings.each do |key, _|
|
||||
begin
|
||||
Tilt[".#{key}"]
|
||||
rescue LoadError, NameError
|
||||
|
@ -103,7 +101,7 @@ module Middleman
|
|||
end
|
||||
end
|
||||
|
||||
alias :included :registered
|
||||
alias_method :included, :registered
|
||||
end
|
||||
|
||||
# Custom error class for handling
|
||||
|
@ -112,7 +110,6 @@ module Middleman
|
|||
|
||||
# Rendering instance methods
|
||||
module InstanceMethods
|
||||
|
||||
# Add or overwrite a default template extension
|
||||
#
|
||||
# @param [Hash] extension_map
|
||||
|
@ -140,7 +137,7 @@ module Middleman
|
|||
|
||||
# Use a dup of self as a context so that instance variables set within
|
||||
# the template don't persist for other templates.
|
||||
context = self.dup
|
||||
context = dup
|
||||
blocks.each do |block|
|
||||
context.instance_eval(&block)
|
||||
end
|
||||
|
@ -184,7 +181,7 @@ module Middleman
|
|||
# @param [String, Symbol] data
|
||||
# @param [Hash] options
|
||||
# @return [String]
|
||||
def render(engine, data, options={}, &block)
|
||||
def render(_, data, options={}, &block)
|
||||
data = data.to_s
|
||||
|
||||
locals = options[:locals]
|
||||
|
@ -198,13 +195,13 @@ module Middleman
|
|||
resolve_opts[:preferred_engine] = File.extname(resource.source_file)[1..-1].to_sym
|
||||
|
||||
# Look for partials relative to the current path
|
||||
relative_dir = File.join(current_dir.sub(%r{^#{Regexp.escape(self.source_dir)}/?}, ''), data)
|
||||
relative_dir = File.join(current_dir.sub(%r{^#{Regexp.escape(source_dir)}/?}, ''), data)
|
||||
|
||||
found_partial = resolve_template(relative_dir, resolve_opts)
|
||||
end
|
||||
|
||||
# Look in the partials_dir for the partial with the current engine
|
||||
if !found_partial
|
||||
unless found_partial
|
||||
partials_path = File.join(config[:partials_dir], data)
|
||||
found_partial = resolve_template(partials_path, resolve_opts)
|
||||
end
|
||||
|
@ -222,7 +219,7 @@ module Middleman
|
|||
# @param [Hash] opts
|
||||
# @param [Class] context
|
||||
# @return [String]
|
||||
def render_individual_file(path, locs = {}, opts = {}, context = self, &block)
|
||||
def render_individual_file(path, locs={}, opts={}, context=self, &block)
|
||||
path = path.to_s
|
||||
|
||||
# Detect the remdering engine from the extension
|
||||
|
@ -260,7 +257,7 @@ module Middleman
|
|||
|
||||
# Read compiled template from disk or cache
|
||||
template = cache.fetch(:compiled_template, extension, options, body) do
|
||||
::Tilt.new(path, 1, options) { body }
|
||||
::Tilt.new(path, 1, options) { body }
|
||||
end
|
||||
|
||||
# Render using Tilt
|
||||
|
@ -317,7 +314,7 @@ module Middleman
|
|||
# @return [String]
|
||||
def fetch_layout(engine, opts)
|
||||
# The layout name comes from either the system default or the options
|
||||
local_layout = opts.has_key?(:layout) ? opts[:layout] : config[:layout]
|
||||
local_layout = opts.key?(:layout) ? opts[:layout] : config[:layout]
|
||||
return false unless local_layout
|
||||
|
||||
# Look for engine-specific options
|
||||
|
@ -325,9 +322,9 @@ module Middleman
|
|||
|
||||
# The engine for the layout can be set in options, engine_options or passed
|
||||
# into this method
|
||||
layout_engine = if opts.has_key?(:layout_engine)
|
||||
layout_engine = if opts.key?(:layout_engine)
|
||||
opts[:layout_engine]
|
||||
elsif engine_options.has_key?(:layout_engine)
|
||||
elsif engine_options.key?(:layout_engine)
|
||||
engine_options[:layout_engine]
|
||||
else
|
||||
engine
|
||||
|
@ -354,11 +351,8 @@ module Middleman
|
|||
# @param [Symbol] preferred_engine
|
||||
# @return [String]
|
||||
def locate_layout(name, preferred_engine=nil)
|
||||
# Whether we've found the layout
|
||||
layout_path = false
|
||||
|
||||
resolve_opts = {}
|
||||
resolve_opts[:preferred_engine] = preferred_engine if !preferred_engine.nil?
|
||||
resolve_opts[:preferred_engine] = preferred_engine unless preferred_engine.nil?
|
||||
|
||||
# Check layouts folder
|
||||
layout_path = resolve_template(File.join(config[:layouts_dir], name.to_s), resolve_opts)
|
||||
|
@ -377,13 +371,13 @@ module Middleman
|
|||
# Save current buffer for later
|
||||
@_out_buf, _buf_was = '', @_out_buf
|
||||
|
||||
layout_path = locate_layout(layout_name, self.current_engine)
|
||||
layout_path = locate_layout(layout_name, current_engine)
|
||||
|
||||
extension = File.extname(layout_path)
|
||||
engine = extension[1..-1].to_sym
|
||||
|
||||
# Store last engine for later (could be inside nested renders)
|
||||
self.current_engine, engine_was = engine, self.current_engine
|
||||
self.current_engine, engine_was = engine, current_engine
|
||||
|
||||
begin
|
||||
content = if block_given?
|
||||
|
@ -423,15 +417,14 @@ module Middleman
|
|||
request_path = request_path.to_s
|
||||
cache.fetch(:resolve_template, request_path, options) do
|
||||
relative_path = Util.strip_leading_slash(request_path)
|
||||
on_disk_path = File.expand_path(relative_path, self.source_dir)
|
||||
on_disk_path = File.expand_path(relative_path, source_dir)
|
||||
|
||||
# By default, any engine will do
|
||||
preferred_engines = ['*']
|
||||
|
||||
# If we're specifically looking for a preferred engine
|
||||
if options.has_key?(:preferred_engine)
|
||||
if options.key?(:preferred_engine)
|
||||
extension_class = ::Tilt[options[:preferred_engine]]
|
||||
matched_exts = []
|
||||
|
||||
# Get a list of extensions for a preferred engine
|
||||
matched_exts = ::Tilt.mappings.select do |ext, engines|
|
||||
|
@ -464,7 +457,7 @@ module Middleman
|
|||
# If we found one, return it and the found engine
|
||||
if found_path
|
||||
found_path
|
||||
elsif File.exists?(on_disk_path)
|
||||
elsif File.exist?(on_disk_path)
|
||||
on_disk_path
|
||||
else
|
||||
false
|
||||
|
|
|
@ -8,15 +8,12 @@ require 'middleman-core/util'
|
|||
|
||||
module Middleman
|
||||
module CoreExtensions
|
||||
|
||||
# Base helper to manipulate asset paths
|
||||
module Request
|
||||
|
||||
# Extension registered
|
||||
class << self
|
||||
# @private
|
||||
def registered(app)
|
||||
|
||||
# CSSPIE HTC File
|
||||
::Rack::Mime::MIME_TYPES['.htc'] = 'text/x-component'
|
||||
|
||||
|
@ -32,7 +29,7 @@ module Middleman
|
|||
# Include instance methods
|
||||
app.send :include, InstanceMethods
|
||||
end
|
||||
alias :included :registered
|
||||
alias_method :included, :registered
|
||||
end
|
||||
|
||||
module ClassMethods
|
||||
|
@ -60,9 +57,7 @@ module Middleman
|
|||
# @private
|
||||
# @param [Middleman::Application] inst
|
||||
# @return [void]
|
||||
def inst=(inst)
|
||||
@inst = inst
|
||||
end
|
||||
attr_writer :inst
|
||||
|
||||
# Return built Rack app
|
||||
#
|
||||
|
@ -169,10 +164,10 @@ module Middleman
|
|||
# @return [void]
|
||||
def current_path=(path)
|
||||
Thread.current[:current_path] = path
|
||||
Thread.current[:legacy_request] = ::Thor::CoreExt::HashWithIndifferentAccess.new({
|
||||
:path => path,
|
||||
:params => req ? ::Thor::CoreExt::HashWithIndifferentAccess.new(req.params) : {}
|
||||
})
|
||||
Thread.current[:legacy_request] = ::Thor::CoreExt::HashWithIndifferentAccess.new(
|
||||
:path => path,
|
||||
:params => req ? ::Thor::CoreExt::HashWithIndifferentAccess.new(req.params) : {}
|
||||
)
|
||||
end
|
||||
|
||||
delegate :use, :to => :"self.class"
|
||||
|
@ -183,6 +178,7 @@ module Middleman
|
|||
def req
|
||||
Thread.current[:req]
|
||||
end
|
||||
|
||||
def req=(value)
|
||||
Thread.current[:req] = value
|
||||
end
|
||||
|
@ -199,7 +195,7 @@ module Middleman
|
|||
self.req = req = ::Rack::Request.new(env)
|
||||
res = ::Rack::Response.new
|
||||
|
||||
logger.debug "== Request: #{env["PATH_INFO"]}"
|
||||
logger.debug "== Request: #{env['PATH_INFO']}"
|
||||
|
||||
# Catch :halt exceptions and use that response if given
|
||||
catch(:halt) do
|
||||
|
@ -277,7 +273,7 @@ module Middleman
|
|||
# @param [String] value Mime type
|
||||
# @return [void]
|
||||
def mime_type(type, value)
|
||||
type = ".#{type}" unless type.to_s[0] == ?.
|
||||
type = ".#{type}" unless type.to_s[0] == '.'
|
||||
::Rack::Mime::MIME_TYPES[type] = value
|
||||
end
|
||||
|
||||
|
|
|
@ -11,14 +11,14 @@ module Middleman
|
|||
#
|
||||
# @param [String, Symbol] layout_name
|
||||
# @return [void]
|
||||
def with_layout(layout_name, &block)
|
||||
old_layout = config[:layout]
|
||||
def with_layout(layout_name, &block)
|
||||
old_layout = config[:layout]
|
||||
|
||||
config[:layout] = layout_name
|
||||
instance_exec(&block) if block_given?
|
||||
ensure
|
||||
config[:layout] = old_layout
|
||||
end
|
||||
config[:layout] = layout_name
|
||||
instance_exec(&block) if block_given?
|
||||
ensure
|
||||
config[:layout] = old_layout
|
||||
end
|
||||
|
||||
# The page method allows the layout to be set on a specific path
|
||||
#
|
||||
|
@ -28,43 +28,43 @@ module Middleman
|
|||
# @param [String] url
|
||||
# @param [Hash] opts
|
||||
# @return [void]
|
||||
def page(url, opts={}, &block)
|
||||
blocks = Array(block)
|
||||
def page(url, opts={}, &block)
|
||||
blocks = Array(block)
|
||||
|
||||
# Default layout
|
||||
opts[:layout] = config[:layout] if opts[:layout].nil?
|
||||
# Default layout
|
||||
opts[:layout] = config[:layout] if opts[:layout].nil?
|
||||
|
||||
# If the url is a regexp
|
||||
if url.is_a?(Regexp) || url.include?('*')
|
||||
# If the url is a regexp
|
||||
if url.is_a?(Regexp) || url.include?('*')
|
||||
|
||||
# Use the metadata loop for matching against paths at runtime
|
||||
sitemap.provides_metadata_for_path(url) do |_|
|
||||
{ :options => opts, :blocks => blocks }
|
||||
end
|
||||
|
||||
return
|
||||
end
|
||||
|
||||
# Normalized path
|
||||
url = '/' + Middleman::Util.normalize_path(url)
|
||||
if url.end_with?('/') || File.directory?(File.join(source_dir, url))
|
||||
url = File.join(url, config[:index_file])
|
||||
end
|
||||
|
||||
# Setup proxy
|
||||
if target = opts.delete(:proxy)
|
||||
# TODO: deprecate proxy through page?
|
||||
proxy(url, target, opts, &block) and return
|
||||
elsif opts.delete(:ignore)
|
||||
# TODO: deprecate ignore through page?
|
||||
ignore(url)
|
||||
end
|
||||
|
||||
# Setup a metadata matcher for rendering those options
|
||||
# Use the metadata loop for matching against paths at runtime
|
||||
sitemap.provides_metadata_for_path(url) do |_|
|
||||
{ :options => opts, :blocks => blocks }
|
||||
end
|
||||
|
||||
return
|
||||
end
|
||||
|
||||
# Normalized path
|
||||
url = '/' + Middleman::Util.normalize_path(url)
|
||||
if url.end_with?('/') || File.directory?(File.join(source_dir, url))
|
||||
url = File.join(url, config[:index_file])
|
||||
end
|
||||
|
||||
# Setup proxy
|
||||
if target = opts.delete(:proxy)
|
||||
# TODO: deprecate proxy through page?
|
||||
proxy(url, target, opts, &block) and return
|
||||
elsif opts.delete(:ignore)
|
||||
# TODO: deprecate ignore through page?
|
||||
ignore(url)
|
||||
end
|
||||
|
||||
# Setup a metadata matcher for rendering those options
|
||||
sitemap.provides_metadata_for_path(url) do |_|
|
||||
{ :options => opts, :blocks => blocks }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -5,10 +5,8 @@ require 'rack/showexceptions'
|
|||
module Middleman
|
||||
module CoreExtensions
|
||||
module ShowExceptions
|
||||
|
||||
# Setup extension
|
||||
class << self
|
||||
|
||||
# Once registered
|
||||
def registered(app)
|
||||
# Whether to catch and display exceptions
|
||||
|
|
|
@ -2,7 +2,6 @@ require 'active_support/core_ext/module/delegation'
|
|||
require 'active_support/core_ext/class/attribute'
|
||||
|
||||
module Middleman
|
||||
|
||||
class Extension
|
||||
class_attribute :supports_multiple_instances, :instance_reader => false, :instance_writer => false
|
||||
class_attribute :defined_helpers, :instance_reader => false, :instance_writer => false
|
||||
|
@ -34,10 +33,10 @@ module Middleman
|
|||
end
|
||||
|
||||
def extension_name
|
||||
self.ext_name || self.name.underscore.split('/').last.to_sym
|
||||
ext_name || name.underscore.split('/').last.to_sym
|
||||
end
|
||||
|
||||
def register(n=self.extension_name)
|
||||
def register(n=extension_name)
|
||||
::Middleman::Extensions.register(n, self)
|
||||
end
|
||||
|
||||
|
@ -59,7 +58,7 @@ module Middleman
|
|||
name = instance.class.extension_name
|
||||
return unless @_extension_activation_callbacks && @_extension_activation_callbacks[name]
|
||||
@_extension_activation_callbacks[name].each do |block|
|
||||
block.arity == 1 ? block.call(instance) : block.call()
|
||||
block.arity == 1 ? block.call(instance) : block.call
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -91,7 +90,7 @@ module Middleman
|
|||
end
|
||||
end
|
||||
|
||||
protected
|
||||
protected
|
||||
|
||||
def setup_options(options_hash, &block)
|
||||
@options = self.class.config.dup
|
||||
|
@ -142,7 +141,7 @@ module Middleman
|
|||
ext = self
|
||||
if ext.respond_to?(:before_build)
|
||||
@klass.before_build do |builder|
|
||||
if ext.method(:before_build).arity === 1
|
||||
if ext.method(:before_build).arity == 1
|
||||
ext.before_build(builder)
|
||||
else
|
||||
ext.before_build
|
||||
|
@ -155,7 +154,7 @@ module Middleman
|
|||
ext = self
|
||||
if ext.respond_to?(:after_build)
|
||||
@klass.after_build do |builder|
|
||||
if ext.method(:after_build).arity === 1
|
||||
if ext.method(:after_build).arity == 1
|
||||
ext.after_build(builder)
|
||||
else
|
||||
ext.after_build
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
module Middleman
|
||||
|
||||
module Extensions
|
||||
|
||||
class << self
|
||||
def registered
|
||||
@_registered ||= {}
|
||||
|
@ -24,7 +22,7 @@ module Middleman
|
|||
def register(name, namespace=nil, &block)
|
||||
# If we've already got a matching extension that passed the
|
||||
# version check, bail out.
|
||||
return if registered.has_key?(name.to_sym) &&
|
||||
return if registered.key?(name.to_sym) &&
|
||||
!registered[name.to_sym].is_a?(String)
|
||||
|
||||
registered[name.to_sym] = if block_given?
|
||||
|
@ -36,11 +34,11 @@ module Middleman
|
|||
|
||||
def load(name)
|
||||
name = name.to_sym
|
||||
return nil unless registered.has_key?(name)
|
||||
return nil unless registered.key?(name)
|
||||
|
||||
extension = registered[name]
|
||||
if extension.is_a?(Proc)
|
||||
extension = extension.call() || nil
|
||||
extension = extension.call || nil
|
||||
registered[name] = extension
|
||||
end
|
||||
|
||||
|
@ -92,7 +90,7 @@ module Middleman
|
|||
# @return [Boolean] Whether the file exists
|
||||
def spec_has_file?(spec, path)
|
||||
full_path = File.join(spec.full_gem_path, path)
|
||||
File.exists?(full_path)
|
||||
File.exist?(full_path)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
require 'pathname'
|
||||
|
||||
module Middleman
|
||||
|
||||
class << self
|
||||
def setup_load_paths
|
||||
@_is_setup ||= begin
|
||||
|
@ -20,12 +19,12 @@ module Middleman
|
|||
root_gemfile = File.expand_path('Gemfile', ENV['MM_ROOT'])
|
||||
ENV['BUNDLE_GEMFILE'] ||= root_gemfile
|
||||
|
||||
if !File.exists?(ENV['BUNDLE_GEMFILE'])
|
||||
unless File.exist?(ENV['BUNDLE_GEMFILE'])
|
||||
git_gemfile = Pathname.new(__FILE__).expand_path.parent.parent.parent + 'Gemfile'
|
||||
ENV['BUNDLE_GEMFILE'] = git_gemfile.to_s
|
||||
end
|
||||
|
||||
if File.exists?(ENV['BUNDLE_GEMFILE'])
|
||||
if File.exist?(ENV['BUNDLE_GEMFILE'])
|
||||
is_bundler_setup = true
|
||||
require 'bundler/setup'
|
||||
end
|
||||
|
@ -45,12 +44,10 @@ module Middleman
|
|||
end
|
||||
|
||||
# Recursive method to find config.rb
|
||||
def locate_root(cwd = Pathname.new(Dir.pwd))
|
||||
def locate_root(cwd=Pathname.new(Dir.pwd))
|
||||
return cwd.to_s if (cwd + 'config.rb').exist?
|
||||
return false if cwd.root?
|
||||
locate_root(cwd.parent)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -4,10 +4,8 @@ require 'active_support/logger'
|
|||
require 'thread'
|
||||
|
||||
module Middleman
|
||||
|
||||
# The Middleman Logger
|
||||
class Logger < ActiveSupport::Logger
|
||||
|
||||
def self.singleton(*args)
|
||||
if !@_logger || args.length > 0
|
||||
if args.length == 1 && (args.first.is_a?(::String) || args.first.respond_to?(:write))
|
||||
|
@ -42,7 +40,7 @@ module Middleman
|
|||
return if @instrumenting.is_a?(String) && @instrumenting != 'instrument' && !message.include?(@instrumenting)
|
||||
|
||||
evt = ActiveSupport::Notifications::Event.new(message, *args)
|
||||
self.info "== Instrument (#{evt.name.sub(/.middleman$/, '')}): #{evt.duration}ms"
|
||||
info "== Instrument (#{evt.name.sub(/.middleman$/, '')}): #{evt.duration}ms"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -40,12 +40,12 @@ module Middleman
|
|||
end
|
||||
|
||||
# The index page
|
||||
def index(env)
|
||||
def index(_)
|
||||
template('index.html.erb')
|
||||
end
|
||||
|
||||
# Inspect the sitemap
|
||||
def sitemap(env)
|
||||
def sitemap(_)
|
||||
resources = @middleman.inst.sitemap.resources(true)
|
||||
|
||||
sitemap_tree = SitemapTree.new
|
||||
|
@ -58,8 +58,8 @@ module Middleman
|
|||
end
|
||||
|
||||
# Inspect configuration
|
||||
def config(env)
|
||||
global_config = @middleman.inst.config.all_settings.map {|c| ConfigSetting.new(c) }
|
||||
def config(_)
|
||||
global_config = @middleman.inst.config.all_settings.map { |c| ConfigSetting.new(c) }
|
||||
extension_config = {}
|
||||
|
||||
@middleman.inst.extensions.each do |ext_name, extension|
|
||||
|
@ -96,11 +96,11 @@ module Middleman
|
|||
|
||||
# Respond to an HTML request
|
||||
def response(content)
|
||||
[ 200, {'Content-Type' => 'text/html'}, Array(content) ]
|
||||
[200, { 'Content-Type' => 'text/html' }, Array(content)]
|
||||
end
|
||||
|
||||
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
|
||||
|
|
|
@ -14,7 +14,7 @@ module Middleman
|
|||
|
||||
def render
|
||||
content = ''
|
||||
@children.keys.sort do |a,b|
|
||||
@children.keys.sort do |a, b|
|
||||
a_subtree = @children[a]
|
||||
b_subtree = @children[b]
|
||||
if a_subtree.is_a? SitemapResource
|
||||
|
|
|
@ -4,7 +4,6 @@ require 'middleman-core/logger'
|
|||
|
||||
module Middleman
|
||||
module PreviewServer
|
||||
|
||||
DEFAULT_PORT = 4567
|
||||
|
||||
class << self
|
||||
|
@ -70,7 +69,7 @@ module Middleman
|
|||
|
||||
begin
|
||||
app = new_app
|
||||
rescue Exception => e
|
||||
rescue => e
|
||||
logger.error "Error reloading Middleman: #{e}\n#{e.backtrace.join("\n")}"
|
||||
logger.info '== The Middleman is still running the application from before the error'
|
||||
return
|
||||
|
@ -89,7 +88,7 @@ module Middleman
|
|||
@webrick.shutdown
|
||||
end
|
||||
|
||||
private
|
||||
private
|
||||
def new_app
|
||||
opts = @options.dup
|
||||
server = ::Middleman::Application.server
|
||||
|
@ -181,7 +180,7 @@ module Middleman
|
|||
begin
|
||||
::WEBrick::HTTPServer.new(http_opts)
|
||||
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)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
module Middleman
|
||||
module Profiling
|
||||
|
||||
# The profiler instance. There can only be one!
|
||||
def self.profiler=(prof)
|
||||
@profiler = prof
|
||||
|
@ -31,11 +30,9 @@ module Middleman
|
|||
# A profiler that uses ruby-prof
|
||||
class RubyProfProfiler
|
||||
def initialize
|
||||
begin
|
||||
require 'ruby-prof'
|
||||
rescue LoadError
|
||||
raise "To use the --profile option, you must add the 'ruby-prof' gem to your Gemfile"
|
||||
end
|
||||
require 'ruby-prof'
|
||||
rescue LoadError
|
||||
raise "To use the --profile option, you must add the 'ruby-prof' gem to your Gemfile"
|
||||
end
|
||||
|
||||
def start
|
||||
|
@ -50,7 +47,7 @@ module Middleman
|
|||
outfile = (outfile + '.html') unless outfile.end_with? '.html'
|
||||
FileUtils.mkdir_p(File.dirname(outfile))
|
||||
File.open(outfile, 'w') do |f|
|
||||
printer.print(f, :min_percent=> 1)
|
||||
printer.print(f, :min_percent => 1)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -4,7 +4,6 @@ module Middleman
|
|||
module Renderers
|
||||
module AsciiDoc
|
||||
class << self
|
||||
|
||||
def registered(app)
|
||||
app.config.define_setting :asciidoc, {
|
||||
:safe => :safe,
|
||||
|
@ -35,11 +34,11 @@ module Middleman
|
|||
opts[:layout] = layout
|
||||
end
|
||||
end
|
||||
opts[:layout_engine] = (doc.attr 'page-layout-engine') if (doc.attr? 'page-layout-engine')
|
||||
opts[:layout_engine] = (doc.attr 'page-layout-engine') if doc.attr? 'page-layout-engine'
|
||||
# TODO override attributes to set docfile, docdir, docname, etc
|
||||
# alternative is to set :renderer_options, which get merged into options by the rendering extension
|
||||
#opts[:attributes] = config[:asciidoc][:attributes].dup
|
||||
#opts[:attributes].concat %W(docfile=#{path} docdir=#{File.dirname path} docname=#{(File.basename path).sub(/\.adoc$/, '')})
|
||||
# opts[:attributes] = config[:asciidoc][:attributes].dup
|
||||
# opts[:attributes].concat %W(docfile=#{path} docdir=#{File.dirname path} docname=#{(File.basename path).sub(/\.adoc$/, '')})
|
||||
|
||||
page = {}
|
||||
page[:title] = doc.doctitle
|
||||
|
@ -47,12 +46,12 @@ module Middleman
|
|||
# TODO grab all the author information
|
||||
page[:author] = (doc.attr 'author') unless (doc.attr 'author').nil?
|
||||
|
||||
{:options => opts, :page => ::Middleman::Util.recursively_enhance(page)}
|
||||
{ :options => opts, :page => ::Middleman::Util.recursively_enhance(page) }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
alias :included :registered
|
||||
alias_method :included, :registered
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -3,10 +3,8 @@ require 'coffee_script'
|
|||
|
||||
module Middleman
|
||||
module Renderers
|
||||
|
||||
# CoffeeScript Renderer
|
||||
module CoffeeScript
|
||||
|
||||
# Setup extension
|
||||
class << self
|
||||
# Once registered
|
||||
|
@ -20,7 +18,7 @@ module Middleman
|
|||
DebuggingCoffeeScriptTemplate.middleman_app = self
|
||||
end
|
||||
end
|
||||
alias :included :registered
|
||||
alias_method :included, :registered
|
||||
end
|
||||
|
||||
# A Template for Tilt which outputs debug messages
|
||||
|
|
|
@ -4,7 +4,6 @@ module Middleman
|
|||
module ERb
|
||||
# Setup extension
|
||||
class << self
|
||||
|
||||
# once registered
|
||||
def registered(app)
|
||||
app.before_configuration do
|
||||
|
@ -16,7 +15,7 @@ module Middleman
|
|||
::Tilt.prefer(Template, :erb)
|
||||
end
|
||||
end
|
||||
alias :included :registered
|
||||
alias_method :included, :registered
|
||||
end
|
||||
|
||||
class Template < ::Tilt::ErubisTemplate
|
||||
|
@ -26,7 +25,7 @@ module Middleman
|
|||
def precompiled_preamble(locals)
|
||||
original = super
|
||||
"__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
|
||||
|
|
|
@ -13,10 +13,8 @@ end
|
|||
|
||||
module Middleman
|
||||
module Renderers
|
||||
|
||||
# Haml Renderer
|
||||
module Haml
|
||||
|
||||
# Setup extension
|
||||
class << self
|
||||
# Once registered
|
||||
|
@ -33,7 +31,7 @@ module Middleman
|
|||
init_haml_helpers
|
||||
end
|
||||
end
|
||||
alias :included :registered
|
||||
alias_method :included, :registered
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,7 +2,6 @@ require 'kramdown'
|
|||
|
||||
module Middleman
|
||||
module Renderers
|
||||
|
||||
# Our own Kramdown Tilt template that simply uses our custom renderer.
|
||||
class KramdownTemplate < ::Tilt::KramdownTemplate
|
||||
def evaluate(scope, locals, &block)
|
||||
|
@ -32,7 +31,7 @@ module Middleman
|
|||
mail_addr = el.attr['href'].sub(/\Amailto:/, '')
|
||||
href = obfuscate('mailto') << ':' << obfuscate(mail_addr)
|
||||
content = obfuscate(content) if content == mail_addr
|
||||
return %Q{<a href="#{href}">#{content}</a>}
|
||||
return %Q(<a href="#{href}">#{content}</a>)
|
||||
end
|
||||
|
||||
attr = el.attr.dup
|
||||
|
|
|
@ -2,13 +2,10 @@ require 'less'
|
|||
|
||||
module Middleman
|
||||
module Renderers
|
||||
|
||||
# Sass renderer
|
||||
module Less
|
||||
|
||||
# Setup extension
|
||||
class << self
|
||||
|
||||
# Once registered
|
||||
def registered(app)
|
||||
# Default less options
|
||||
|
@ -27,12 +24,11 @@ module Middleman
|
|||
::Tilt.prefer(LocalLoadingLessTemplate)
|
||||
end
|
||||
|
||||
alias :included :registered
|
||||
alias_method :included, :registered
|
||||
end
|
||||
|
||||
# A SassTemplate for Tilt which outputs debug messages
|
||||
class LocalLoadingLessTemplate < ::Tilt::LessTemplate
|
||||
|
||||
def prepare
|
||||
if ::Less.const_defined? :Engine
|
||||
@engine = ::Less::Engine.new(data)
|
||||
|
@ -41,9 +37,7 @@ module Middleman
|
|||
@engine = parser.parse(data)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -3,13 +3,10 @@ require 'liquid'
|
|||
|
||||
module Middleman
|
||||
module Renderers
|
||||
|
||||
# Liquid Renderer
|
||||
module Liquid
|
||||
|
||||
# Setup extension
|
||||
class << self
|
||||
|
||||
# Once registerd
|
||||
def registered(app)
|
||||
app.before_configuration do
|
||||
|
@ -27,9 +24,8 @@ module Middleman
|
|||
end
|
||||
end
|
||||
|
||||
alias :included :registered
|
||||
alias_method :included, :registered
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,12 +1,9 @@
|
|||
module Middleman
|
||||
module Renderers
|
||||
|
||||
# Markdown renderer
|
||||
module Markdown
|
||||
|
||||
# Setup extension
|
||||
class << self
|
||||
|
||||
# Once registered
|
||||
def registered(app)
|
||||
# Set our preference for a markdown engine
|
||||
|
@ -35,7 +32,7 @@ module Middleman
|
|||
require 'middleman-core/renderers/kramdown'
|
||||
::Tilt.prefer(::Middleman::Renderers::KramdownTemplate, *markdown_exts)
|
||||
MiddlemanKramdownHTML.middleman_app = self
|
||||
elsif !config[:markdown_engine].nil?
|
||||
elsif config[:markdown_engine]
|
||||
# Map symbols to classes
|
||||
markdown_engine_klass = if config[:markdown_engine].is_a? Symbol
|
||||
engine = config[:markdown_engine].to_s
|
||||
|
@ -58,9 +55,8 @@ module Middleman
|
|||
end
|
||||
end
|
||||
|
||||
alias :included :registered
|
||||
alias_method :included, :registered
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,9 +2,7 @@ require 'redcarpet'
|
|||
|
||||
module Middleman
|
||||
module Renderers
|
||||
|
||||
class RedcarpetTemplate < ::Tilt::RedcarpetTemplate::Redcarpet2
|
||||
|
||||
# because tilt has decided to convert these
|
||||
# in the wrong direction
|
||||
ALIASES = {
|
||||
|
@ -15,7 +13,7 @@ module Middleman
|
|||
# Don't overload :renderer option with smartypants
|
||||
# Support renderer-level options
|
||||
def generate_renderer
|
||||
return options.delete(:renderer) if options.has_key?(:renderer)
|
||||
return options.delete(:renderer) if options.key?(:renderer)
|
||||
|
||||
covert_options_to_aliases!
|
||||
|
||||
|
@ -32,8 +30,8 @@ module Middleman
|
|||
# Renderer Options
|
||||
possible_render_opts = [:filter_html, :no_images, :no_links, :no_styles, :safe_links_only, :with_toc_data, :hard_wrap, :xhtml, :prettify, :link_attributes]
|
||||
|
||||
render_options = possible_render_opts.inject({}) do |sum, opt|
|
||||
sum[opt] = options.delete(opt) if options.has_key?(opt)
|
||||
render_options = possible_render_opts.reduce({}) do |sum, opt|
|
||||
sum[opt] = options.delete(opt) if options.key?(opt)
|
||||
sum
|
||||
end
|
||||
|
||||
|
@ -42,11 +40,11 @@ module Middleman
|
|||
|
||||
private
|
||||
|
||||
def covert_options_to_aliases!
|
||||
ALIASES.each do |aka, actual|
|
||||
options[actual] = options.delete(aka) if options.has_key? aka
|
||||
end
|
||||
def covert_options_to_aliases!
|
||||
ALIASES.each do |aka, actual|
|
||||
options[actual] = options.delete(aka) if options.key? aka
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Custom Redcarpet renderer that uses our helpers for images and links
|
||||
|
@ -64,7 +62,7 @@ module Middleman
|
|||
middleman_app.image_tag(link, :title => title, :alt => alt_text)
|
||||
else
|
||||
link_string = link.dup
|
||||
link_string << %Q{"#{title}"} if title && title.length > 0 && title != alt_text
|
||||
link_string << %Q("#{title}") if title && title.length > 0 && title != alt_text
|
||||
%Q{![#{alt_text}](#{link_string})}
|
||||
end
|
||||
end
|
||||
|
@ -72,12 +70,12 @@ module Middleman
|
|||
def link(link, title, content)
|
||||
if !@local_options[:no_links]
|
||||
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]
|
||||
|
||||
middleman_app.link_to(content, link, attributes )
|
||||
middleman_app.link_to(content, link, attributes)
|
||||
else
|
||||
link_string = link.dup
|
||||
link_string << %Q{"#{title}"} if title && title.length > 0 && title != alt_text
|
||||
link_string << %Q("#{title}") if title && title.length > 0 && title != alt_text
|
||||
%Q{[#{content}](#{link_string})}
|
||||
end
|
||||
end
|
||||
|
|
|
@ -3,13 +3,10 @@ require 'compass/import-once'
|
|||
|
||||
module Middleman
|
||||
module Renderers
|
||||
|
||||
# Sass renderer
|
||||
module Sass
|
||||
|
||||
# Setup extension
|
||||
class << self
|
||||
|
||||
# Once registered
|
||||
def registered(app)
|
||||
# Default sass options
|
||||
|
@ -31,16 +28,15 @@ module Middleman
|
|||
::Compass::ImportOnce.activate!
|
||||
end
|
||||
|
||||
alias :included :registered
|
||||
alias_method :included, :registered
|
||||
end
|
||||
|
||||
# A SassTemplate for Tilt which outputs debug messages
|
||||
class SassPlusCSSFilenameTemplate < ::Tilt::SassTemplate
|
||||
|
||||
def initialize(*args, &block)
|
||||
super
|
||||
|
||||
if @options.has_key?(:context)
|
||||
if @options.key?(:context)
|
||||
@context = @options[:context]
|
||||
end
|
||||
end
|
||||
|
@ -87,7 +83,6 @@ module Middleman
|
|||
|
||||
# SCSS version of the above template
|
||||
class ScssPlusCSSFilenameTemplate < SassPlusCSSFilenameTemplate
|
||||
|
||||
# Define the expected syntax for the template
|
||||
# @return [Symbol]
|
||||
def syntax
|
||||
|
|
|
@ -17,13 +17,10 @@ end
|
|||
|
||||
module Middleman
|
||||
module Renderers
|
||||
|
||||
# Slim renderer
|
||||
module Slim
|
||||
|
||||
# Setup extension
|
||||
class << self
|
||||
|
||||
# Once registered
|
||||
def registered(app)
|
||||
app.before_configuration do
|
||||
|
@ -50,7 +47,7 @@ module Middleman
|
|||
end
|
||||
end
|
||||
|
||||
alias :included :registered
|
||||
alias_method :included, :registered
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -3,13 +3,10 @@ require 'stylus/tilt'
|
|||
|
||||
module Middleman
|
||||
module Renderers
|
||||
|
||||
# Sass renderer
|
||||
module Stylus
|
||||
|
||||
# Setup extension
|
||||
class << self
|
||||
|
||||
# Once registered
|
||||
def registered(app)
|
||||
# Default less options
|
||||
|
@ -20,9 +17,8 @@ module Middleman
|
|||
end
|
||||
end
|
||||
|
||||
alias :included :registered
|
||||
alias_method :included, :registered
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -9,15 +9,11 @@ require 'middleman-core/sitemap/extensions/ignores'
|
|||
|
||||
# Core Sitemap Extensions
|
||||
module Middleman
|
||||
|
||||
module Sitemap
|
||||
|
||||
# Setup Extension
|
||||
class << self
|
||||
|
||||
# Once registered
|
||||
def registered(app)
|
||||
|
||||
app.register Middleman::Sitemap::Extensions::RequestEndpoints
|
||||
app.register Middleman::Sitemap::Extensions::Proxies
|
||||
app.register Middleman::Sitemap::Extensions::Ignores
|
||||
|
@ -39,8 +35,8 @@ module Middleman
|
|||
# Files starting with an underscore, but not a double-underscore
|
||||
:partials => proc { |file| file =~ %r{/_[^_]} },
|
||||
|
||||
:layout => proc { |file, app|
|
||||
file.start_with?(File.join(app.config[:source], 'layout.')) || file.start_with?(File.join(app.config[:source], 'layouts/'))
|
||||
:layout => proc { |file, sitemap_app|
|
||||
file.start_with?(File.join(sitemap_app.config[:source], 'layout.')) || file.start_with?(File.join(sitemap_app.config[:source], 'layouts/'))
|
||||
}
|
||||
}, 'Callbacks that can exclude paths from the sitemap'
|
||||
|
||||
|
@ -52,13 +48,11 @@ module Middleman
|
|||
sitemap
|
||||
end
|
||||
end
|
||||
alias :included :registered
|
||||
|
||||
alias_method :included, :registered
|
||||
end
|
||||
|
||||
# Sitemap instance methods
|
||||
module InstanceMethods
|
||||
|
||||
# Get the sitemap class instance
|
||||
# @return [Middleman::Sitemap::Store]
|
||||
def sitemap
|
||||
|
@ -77,7 +71,6 @@ module Middleman
|
|||
return nil unless current_path
|
||||
sitemap.find_resource_by_destination_path(current_path)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,14 +1,9 @@
|
|||
module Middleman
|
||||
|
||||
module Sitemap
|
||||
|
||||
module Extensions
|
||||
|
||||
module Ignores
|
||||
|
||||
# Setup extension
|
||||
class << self
|
||||
|
||||
# Once registered
|
||||
def registered(app)
|
||||
# Include methods
|
||||
|
@ -17,12 +12,11 @@ module Middleman
|
|||
::Middleman::Sitemap::Resource.send :include, ResourceInstanceMethods
|
||||
end
|
||||
|
||||
alias :included :registered
|
||||
alias_method :included, :registered
|
||||
end
|
||||
|
||||
# Helpers methods for Resources
|
||||
module ResourceInstanceMethods
|
||||
|
||||
# Whether the Resource is ignored
|
||||
# @return [Boolean]
|
||||
def ignored?
|
||||
|
@ -61,15 +55,15 @@ module Middleman
|
|||
# @return [void]
|
||||
def ignore(path=nil, &block)
|
||||
if path.is_a? Regexp
|
||||
@ignored_callbacks << Proc.new {|p| p =~ path }
|
||||
@ignored_callbacks << proc { |p| p =~ path }
|
||||
elsif path.is_a? String
|
||||
path_clean = ::Middleman::Util.normalize_path(path)
|
||||
if path_clean.include?('*') # It's a glob
|
||||
@ignored_callbacks << Proc.new {|p| File.fnmatch(path_clean, p) }
|
||||
@ignored_callbacks << proc { |p| File.fnmatch(path_clean, p) }
|
||||
else
|
||||
# Add a specific-path ignore unless that path is already covered
|
||||
return if ignored?(path_clean)
|
||||
@ignored_callbacks << Proc.new {|p| p == path_clean }
|
||||
@ignored_callbacks << proc { |p| p == path_clean }
|
||||
end
|
||||
elsif block_given?
|
||||
@ignored_callbacks << block
|
||||
|
|
|
@ -1,13 +1,9 @@
|
|||
require 'set'
|
||||
|
||||
module Middleman
|
||||
|
||||
module Sitemap
|
||||
|
||||
module Extensions
|
||||
|
||||
class OnDisk
|
||||
|
||||
attr_accessor :sitemap
|
||||
attr_accessor :waiting_for_ready
|
||||
|
||||
|
|
|
@ -1,14 +1,9 @@
|
|||
module Middleman
|
||||
|
||||
module Sitemap
|
||||
|
||||
module Extensions
|
||||
|
||||
module Proxies
|
||||
|
||||
# Setup extension
|
||||
class << self
|
||||
|
||||
# Once registered
|
||||
def registered(app)
|
||||
::Middleman::Sitemap::Resource.send :include, ResourceInstanceMethods
|
||||
|
@ -17,7 +12,7 @@ module Middleman
|
|||
app.send :include, InstanceMethods
|
||||
end
|
||||
|
||||
alias :included :registered
|
||||
alias_method :included, :registered
|
||||
end
|
||||
|
||||
module ResourceInstanceMethods
|
||||
|
@ -38,9 +33,7 @@ module Middleman
|
|||
|
||||
# The path of the page this page is proxied to, or nil if it's not proxied.
|
||||
# @return [String]
|
||||
def proxied_to
|
||||
@proxied_to
|
||||
end
|
||||
attr_reader :proxied_to
|
||||
|
||||
# The resource for the page this page is proxied to. Throws an exception
|
||||
# if there is no resource.
|
||||
|
|
|
@ -1,21 +1,16 @@
|
|||
module Middleman
|
||||
|
||||
module Sitemap
|
||||
|
||||
module Extensions
|
||||
|
||||
module Redirects
|
||||
|
||||
# Setup extension
|
||||
class << self
|
||||
|
||||
# Once registered
|
||||
def registered(app)
|
||||
# Include methods
|
||||
app.send :include, InstanceMethods
|
||||
end
|
||||
|
||||
alias :included :registered
|
||||
alias_method :included, :registered
|
||||
end
|
||||
|
||||
module InstanceMethods
|
||||
|
@ -78,10 +73,10 @@ module Middleman
|
|||
end
|
||||
|
||||
def render(*args, &block)
|
||||
url = ::Middleman::Util.url_for(store.app, @request_path, {
|
||||
:relative => false,
|
||||
:find_resource => true
|
||||
})
|
||||
url = ::Middleman::Util.url_for(store.app, @request_path,
|
||||
:relative => false,
|
||||
:find_resource => true
|
||||
)
|
||||
|
||||
if output
|
||||
output.call(path, url)
|
||||
|
@ -119,7 +114,6 @@ module Middleman
|
|||
def metadata
|
||||
@local_metadata.dup
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,21 +1,16 @@
|
|||
module Middleman
|
||||
|
||||
module Sitemap
|
||||
|
||||
module Extensions
|
||||
|
||||
module RequestEndpoints
|
||||
|
||||
# Setup extension
|
||||
class << self
|
||||
|
||||
# Once registered
|
||||
def registered(app)
|
||||
# Include methods
|
||||
app.send :include, InstanceMethods
|
||||
end
|
||||
|
||||
alias :included :registered
|
||||
alias_method :included, :registered
|
||||
end
|
||||
|
||||
module InstanceMethods
|
||||
|
@ -48,7 +43,7 @@ module Middleman
|
|||
if block_given?
|
||||
endpoint[:output] = block
|
||||
else
|
||||
endpoint[:request_path] = opts[:path] if opts.has_key?(:path)
|
||||
endpoint[:request_path] = opts[:path] if opts.key?(:path)
|
||||
end
|
||||
|
||||
@endpoints[path] = endpoint
|
||||
|
@ -65,7 +60,7 @@ module Middleman
|
|||
path,
|
||||
config[:request_path]
|
||||
)
|
||||
r.output = config[:output] if config.has_key?(:output)
|
||||
r.output = config[:output] if config.key?(:output)
|
||||
r
|
||||
end
|
||||
end
|
||||
|
@ -85,12 +80,10 @@ module Middleman
|
|||
end
|
||||
|
||||
def render(*args, &block)
|
||||
return self.output.call if self.output
|
||||
return output.call if output
|
||||
end
|
||||
|
||||
def request_path
|
||||
@request_path
|
||||
end
|
||||
attr_reader :request_path
|
||||
|
||||
def binary?
|
||||
false
|
||||
|
@ -107,7 +100,6 @@ module Middleman
|
|||
def metadata
|
||||
@local_metadata.dup
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,9 +1,6 @@
|
|||
module Middleman
|
||||
|
||||
module Sitemap
|
||||
|
||||
module Extensions
|
||||
|
||||
module Traversal
|
||||
# This resource's parent resource
|
||||
# @return [Middleman::Sitemap::Resource, nil]
|
||||
|
@ -28,14 +25,14 @@ module Middleman
|
|||
|
||||
if eponymous_directory?
|
||||
base_path = eponymous_directory_path
|
||||
prefix = %r|^#{base_path.sub("/", "\\/")}|
|
||||
prefix = %r{^#{base_path.sub("/", "\\/")}}
|
||||
else
|
||||
base_path = path.sub("#{app.index_file}", '')
|
||||
prefix = %r|^#{base_path.sub("/", "\\/")}|
|
||||
prefix = %r{^#{base_path.sub("/", "\\/")}}
|
||||
end
|
||||
|
||||
store.resources.select do |sub_resource|
|
||||
if sub_resource.path == self.path || sub_resource.path !~ prefix
|
||||
if sub_resource.path == path || sub_resource.path !~ prefix
|
||||
false
|
||||
else
|
||||
inner_path = sub_resource.path.sub(prefix, '')
|
||||
|
@ -72,7 +69,7 @@ module Middleman
|
|||
return true
|
||||
end
|
||||
full_path = File.join(app.source_dir, eponymous_directory_path)
|
||||
!!(File.exists?(full_path) && File.directory?(full_path))
|
||||
!!(File.exist?(full_path) && File.directory?(full_path))
|
||||
end
|
||||
|
||||
# The path for this resource if it were a directory, and not a file
|
||||
|
|
|
@ -2,7 +2,6 @@ require 'active_support/core_ext/object/inclusion'
|
|||
|
||||
module Middleman
|
||||
module Sitemap
|
||||
|
||||
# Code adapted from https://github.com/ralph/document_mapper/
|
||||
module Queryable
|
||||
OPERATOR_MAPPING = {
|
||||
|
@ -21,11 +20,11 @@ module Middleman
|
|||
OperatorNotSupportedError = Class.new StandardError
|
||||
|
||||
module API
|
||||
def select(options = {})
|
||||
def select(options={})
|
||||
documents = resources.select { |r| !r.raw_data.empty? }
|
||||
options[:where].each do |selector, selector_value|
|
||||
documents = documents.select do |document|
|
||||
next unless document.raw_data.has_key? selector.attribute
|
||||
next unless document.raw_data.key? selector.attribute
|
||||
document_value = document.raw_data[selector.attribute]
|
||||
operator = OPERATOR_MAPPING[selector.operator]
|
||||
document_value.send operator, selector_value
|
||||
|
@ -78,12 +77,12 @@ module Middleman
|
|||
symbol_hash = constraints_hash.reject { |key, value| key.is_a? Selector }
|
||||
symbol_hash.each do |attribute, value|
|
||||
selector = Selector.new(:attribute => attribute, :operator => 'equal')
|
||||
selector_hash.update({ selector => value })
|
||||
selector_hash.update(selector => value)
|
||||
end
|
||||
Query.new @model, opts(:where => @where.merge(selector_hash))
|
||||
end
|
||||
|
||||
def opts new_opts
|
||||
def opts(new_opts)
|
||||
{ :where => {}.merge(@where),
|
||||
:order_by => @order_by,
|
||||
:offset => @offset,
|
||||
|
@ -92,7 +91,7 @@ module Middleman
|
|||
end
|
||||
|
||||
def order_by(field)
|
||||
Query.new @model, opts(:order_by => field.is_a?(Symbol) ? {field => :asc} : field)
|
||||
Query.new @model, opts(:order_by => field.is_a?(Symbol) ? { field => :asc } : field)
|
||||
end
|
||||
|
||||
def offset(number)
|
||||
|
@ -104,11 +103,11 @@ module Middleman
|
|||
end
|
||||
|
||||
def first
|
||||
self.all.first
|
||||
all.first
|
||||
end
|
||||
|
||||
def last
|
||||
self.all.last
|
||||
all.last
|
||||
end
|
||||
|
||||
def all
|
||||
|
@ -126,7 +125,7 @@ module Middleman
|
|||
class Selector
|
||||
attr_reader :attribute, :operator
|
||||
|
||||
def initialize(opts = {})
|
||||
def initialize(opts={})
|
||||
unless VALID_OPERATORS.include? opts[:operator]
|
||||
raise OperatorNotSupportedError
|
||||
end
|
||||
|
@ -149,7 +148,7 @@ class Symbol
|
|||
|
||||
unless method_defined?(:"<=>")
|
||||
def <=>(other)
|
||||
self.to_s <=> other.to_s
|
||||
to_s <=> other.to_s
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,10 +2,8 @@ require 'middleman-core/sitemap/extensions/traversal'
|
|||
require 'middleman-core/sitemap/extensions/content_type'
|
||||
|
||||
module Middleman
|
||||
|
||||
# Sitemap namespace
|
||||
module Sitemap
|
||||
|
||||
# Sitemap Resource class
|
||||
class Resource
|
||||
include Middleman::Sitemap::Extensions::Traversal
|
||||
|
@ -62,13 +60,13 @@ module Middleman
|
|||
result = store.metadata_for_path(path).dup
|
||||
|
||||
file_meta = store.metadata_for_file(source_file).dup
|
||||
if file_meta.has_key?(:blocks)
|
||||
if file_meta.key?(:blocks)
|
||||
result[:blocks] += file_meta.delete(:blocks)
|
||||
end
|
||||
result.deep_merge!(file_meta)
|
||||
|
||||
local_meta = @local_metadata.dup
|
||||
if local_meta.has_key?(:blocks)
|
||||
if local_meta.key?(:blocks)
|
||||
result[:blocks] += local_meta.delete(:blocks)
|
||||
end
|
||||
result.deep_merge!(local_meta)
|
||||
|
@ -81,11 +79,11 @@ module Middleman
|
|||
# @param [Hash] metadata A metadata block like provides_metadata_for_path takes
|
||||
def add_metadata(metadata={}, &block)
|
||||
metadata = metadata.dup
|
||||
if metadata.has_key?(:blocks)
|
||||
if metadata.key?(:blocks)
|
||||
@local_metadata[:blocks] += metadata.delete(:blocks)
|
||||
end
|
||||
@local_metadata.deep_merge!(metadata)
|
||||
@local_metadata[:blocks] += [ block ] if block_given?
|
||||
@local_metadata[:blocks] += [block] if block_given?
|
||||
end
|
||||
|
||||
# The output/preview URL for this resource
|
||||
|
@ -99,13 +97,13 @@ module Middleman
|
|||
end
|
||||
|
||||
def request_path
|
||||
self.destination_path
|
||||
destination_path
|
||||
end
|
||||
|
||||
# Render this resource
|
||||
# @return [String]
|
||||
def render(opts={}, locs={}, &block)
|
||||
if !template?
|
||||
unless template?
|
||||
return app.template_data_for_file(source_file)
|
||||
end
|
||||
|
||||
|
@ -126,18 +124,18 @@ module Middleman
|
|||
locs = md[:locals].deep_merge(locs)
|
||||
|
||||
# Forward remaining data to helpers
|
||||
if md.has_key?(:page)
|
||||
if md.key?(:page)
|
||||
app.data.store('page', md[:page])
|
||||
end
|
||||
|
||||
blocks = Array(md[:blocks]).dup
|
||||
blocks << block if block_given?
|
||||
|
||||
app.current_path ||= self.destination_path
|
||||
app.current_path ||= destination_path
|
||||
|
||||
# Certain output file types don't use layouts
|
||||
if !opts.has_key?(:layout)
|
||||
opts[:layout] = false if %w(.js .json .css .txt).include?(self.ext)
|
||||
unless opts.key?(:layout)
|
||||
opts[:layout] = false if %w(.js .json .css .txt).include?(ext)
|
||||
end
|
||||
|
||||
app.render_template(source_file, locs, opts, blocks)
|
||||
|
|
|
@ -4,10 +4,8 @@ require 'monitor'
|
|||
require 'middleman-core/sitemap/queryable'
|
||||
|
||||
module Middleman
|
||||
|
||||
# Sitemap namespace
|
||||
module Sitemap
|
||||
|
||||
# The Store class
|
||||
#
|
||||
# The Store manages a collection of Resource objects, which represent
|
||||
|
@ -15,7 +13,6 @@ module Middleman
|
|||
# which is the path relative to the source directory, minus any template
|
||||
# extensions. All "path" parameters used in this class are source paths.
|
||||
class Store
|
||||
|
||||
# @return [Middleman::Application]
|
||||
attr_accessor :app
|
||||
|
||||
|
@ -122,12 +119,12 @@ module Middleman
|
|||
def metadata_for_file(source_file)
|
||||
blank_metadata = { :options => {}, :locals => {}, :page => {}, :blocks => [] }
|
||||
|
||||
provides_metadata.inject(blank_metadata) do |result, (callback, matcher)|
|
||||
provides_metadata.reduce(blank_metadata) do |result, (callback, matcher)|
|
||||
next result if matcher && !source_file.match(matcher)
|
||||
|
||||
metadata = callback.call(source_file).dup
|
||||
|
||||
if metadata.has_key?(:blocks)
|
||||
if metadata.key?(:blocks)
|
||||
result[:blocks] << metadata[:blocks]
|
||||
metadata.delete(:blocks)
|
||||
end
|
||||
|
@ -156,7 +153,7 @@ module Middleman
|
|||
|
||||
blank_metadata = { :options => {}, :locals => {}, :page => {}, :blocks => [] }
|
||||
|
||||
@_cached_metadata[request_path] = provides_metadata_for_path.inject(blank_metadata) do |result, (callback, matcher)|
|
||||
@_cached_metadata[request_path] = provides_metadata_for_path.reduce(blank_metadata) do |result, (callback, matcher)|
|
||||
case matcher
|
||||
when Regexp
|
||||
next result unless request_path =~ matcher
|
||||
|
@ -213,7 +210,7 @@ module Middleman
|
|||
|
||||
@app.logger.debug '== Rebuilding resource list'
|
||||
|
||||
@resources = @resource_list_manipulators.inject([]) do |result, (_, inst)|
|
||||
@resources = @resource_list_manipulators.reduce([]) do |result, (_, inst)|
|
||||
newres = inst.manipulate_resource_list(result)
|
||||
|
||||
# Reset lookup cache
|
||||
|
@ -269,9 +266,9 @@ module Middleman
|
|||
def find_extension(path, file)
|
||||
input_ext = File.extname(file)
|
||||
|
||||
if !input_ext.empty?
|
||||
unless input_ext.empty?
|
||||
input_ext = input_ext.split('.').last.to_sym
|
||||
if @app.template_extensions.has_key?(input_ext)
|
||||
if @app.template_extensions.key?(input_ext)
|
||||
path << ".#{@app.template_extensions[input_ext]}"
|
||||
end
|
||||
end
|
||||
|
|
|
@ -4,10 +4,8 @@ require 'thor/group'
|
|||
|
||||
# Templates namespace
|
||||
module Middleman::Templates
|
||||
|
||||
# Static methods
|
||||
class << self
|
||||
|
||||
# Get list of registered templates and add new ones
|
||||
#
|
||||
# Middleman::Templates.register(:ext_name, klass)
|
||||
|
@ -22,7 +20,7 @@ module Middleman::Templates
|
|||
end
|
||||
|
||||
# Middleman::Templates.register(name, klass)
|
||||
alias :registered :register
|
||||
alias_method :registered, :register
|
||||
end
|
||||
|
||||
# Base Template class. Handles basic options and paths.
|
||||
|
|
|
@ -1,15 +1,14 @@
|
|||
# Default Middleman template
|
||||
class Middleman::Templates::Default < Middleman::Templates::Base
|
||||
|
||||
class_option 'css_dir',
|
||||
:default => 'stylesheets',
|
||||
:desc => 'The path to the css files'
|
||||
:default => 'stylesheets',
|
||||
:desc => 'The path to the css files'
|
||||
class_option 'js_dir',
|
||||
:default => 'javascripts',
|
||||
:desc => 'The path to the javascript files'
|
||||
:default => 'javascripts',
|
||||
:desc => 'The path to the javascript files'
|
||||
class_option 'images_dir',
|
||||
:default => 'images',
|
||||
:desc => 'The path to the image files'
|
||||
:default => 'images',
|
||||
:desc => 'The path to the image files'
|
||||
|
||||
# Template files are relative to this file
|
||||
# @return [String]
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
# A barebones template with nothing much in it
|
||||
class Middleman::Templates::Empty < Middleman::Templates::Base
|
||||
|
||||
# Template files are relative to this file
|
||||
# @return [String]
|
||||
def self.source_root
|
||||
|
|
|
@ -16,4 +16,4 @@ group :test do
|
|||
gem 'fivemat'
|
||||
gem 'aruba'
|
||||
gem 'rspec'
|
||||
end
|
||||
end
|
||||
|
|
|
@ -11,4 +11,4 @@ require 'rake/clean'
|
|||
|
||||
task :test => ['cucumber']
|
||||
|
||||
task :default => :test
|
||||
task :default => :test
|
||||
|
|
|
@ -28,7 +28,6 @@ class MyExtension < ::Middleman::Extension
|
|||
# def a_helper
|
||||
# end
|
||||
# end
|
||||
|
||||
end
|
||||
|
||||
# Register extensions which can be activated
|
||||
|
|
|
@ -1,15 +1,14 @@
|
|||
# HTML5 Boilerplate template
|
||||
class Middleman::Templates::Html5 < Middleman::Templates::Base
|
||||
|
||||
class_option 'css_dir',
|
||||
:default => 'css',
|
||||
:desc => 'The path to the css files'
|
||||
:default => 'css',
|
||||
:desc => 'The path to the css files'
|
||||
class_option 'js_dir',
|
||||
:default => 'js',
|
||||
:desc => 'The path to the javascript files'
|
||||
:default => 'js',
|
||||
:desc => 'The path to the javascript files'
|
||||
class_option 'images_dir',
|
||||
:default => 'img',
|
||||
:desc => 'The path to the image files'
|
||||
:default => 'img',
|
||||
:desc => 'The path to the image files'
|
||||
|
||||
# Templates are relative to this file
|
||||
# @return [String]
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
# Local templates
|
||||
class Middleman::Templates::Local < Middleman::Templates::Base
|
||||
|
||||
# Look for templates in ~/.middleman
|
||||
# @return [String]
|
||||
def self.source_root
|
||||
|
@ -20,7 +19,7 @@ Dir[File.join(Middleman::Templates::Local.source_root, '*')].each do |dir|
|
|||
|
||||
template_file = File.join(dir, 'template.rb')
|
||||
|
||||
if File.exists?(template_file)
|
||||
if File.exist?(template_file)
|
||||
require template_file
|
||||
else
|
||||
Middleman::Templates.register(File.basename(dir).to_sym, Middleman::Templates::Local)
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
# Mobile HTML5 Boilerplate
|
||||
class Middleman::Templates::Mobile < Middleman::Templates::Base
|
||||
|
||||
# Slightly different paths
|
||||
class_option :css_dir, :default => 'css'
|
||||
class_option :js_dir, :default => 'js'
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
require 'rubygems'
|
||||
require 'middleman/rack'
|
||||
|
||||
run Middleman.server
|
||||
run Middleman.server
|
||||
|
|
|
@ -14,7 +14,6 @@ require 'rack/mime'
|
|||
module Middleman
|
||||
module Util
|
||||
class << self
|
||||
|
||||
# Whether the source file is binary.
|
||||
#
|
||||
# @param [String] filename The file to check.
|
||||
|
@ -27,7 +26,7 @@ module Middleman
|
|||
|
||||
return false if Tilt.registered?(ext.sub('.', ''))
|
||||
|
||||
dot_ext = (ext.to_s[0] == ?.) ? ext.dup : ".#{ext}"
|
||||
dot_ext = (ext.to_s[0] == '.') ? ext.dup : ".#{ext}"
|
||||
|
||||
if mime = ::Rack::Mime.mime_type(dot_ext, nil)
|
||||
!nonbinary_mime?(mime)
|
||||
|
@ -69,7 +68,7 @@ module Middleman
|
|||
# @return [String]
|
||||
def normalize_path(path)
|
||||
# The tr call works around a bug in Ruby's Unicode handling
|
||||
path.sub(%r{^/}, '').tr('','')
|
||||
path.sub(%r{^/}, '').tr('', '')
|
||||
end
|
||||
|
||||
# This is a separate method from normalize_path in case we
|
||||
|
@ -85,7 +84,7 @@ module Middleman
|
|||
def extract_response_text(response)
|
||||
# The rack spec states all response bodies must respond to each
|
||||
result = ''
|
||||
response.each do |part, s|
|
||||
response.each do |part, _|
|
||||
result << part
|
||||
end
|
||||
result
|
||||
|
@ -210,7 +209,7 @@ module Middleman
|
|||
def full_path(path, app)
|
||||
resource = app.sitemap.find_resource_by_destination_path(path)
|
||||
|
||||
if !resource
|
||||
unless resource
|
||||
# Try it with /index.html at the end
|
||||
indexed_path = File.join(path.sub(%r{/$}, ''), app.config[:index_file])
|
||||
resource = app.sitemap.find_resource_by_destination_path(indexed_path)
|
||||
|
@ -223,7 +222,7 @@ module Middleman
|
|||
end
|
||||
end
|
||||
|
||||
private
|
||||
private
|
||||
|
||||
# Is mime type known to be non-binary?
|
||||
#
|
||||
|
|
|
@ -2,7 +2,6 @@ require 'middleman-core/renderers/sass'
|
|||
require 'compass'
|
||||
|
||||
class Middleman::CoreExtensions::Compass < ::Middleman::Extension
|
||||
|
||||
def initialize(app, options_hash={}, &block)
|
||||
super
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ require 'padrino-helpers'
|
|||
class Padrino::Helpers::OutputHelpers::ErbHandler
|
||||
# Force Erb capture not to use safebuffer
|
||||
def capture_from_template(*args, &block)
|
||||
self.output_buffer, _buf_was = '', self.output_buffer
|
||||
self.output_buffer, _buf_was = '', output_buffer
|
||||
raw = block.call(*args)
|
||||
captured = template.instance_variable_get(:@_out_buf)
|
||||
self.output_buffer = _buf_was
|
||||
|
@ -16,7 +16,6 @@ class Padrino::Helpers::OutputHelpers::ErbHandler
|
|||
end
|
||||
|
||||
class Middleman::CoreExtensions::DefaultHelpers < ::Middleman::Extension
|
||||
|
||||
def initialize(app, options_hash={}, &block)
|
||||
super
|
||||
|
||||
|
@ -39,7 +38,7 @@ class Middleman::CoreExtensions::DefaultHelpers < ::Middleman::Extension
|
|||
helpers do
|
||||
|
||||
# Make all block content html_safe
|
||||
def content_tag(name, content = nil, options = nil, &block)
|
||||
def content_tag(name, content=nil, options=nil, &block)
|
||||
if block_given?
|
||||
options = content if content.is_a?(Hash)
|
||||
content = capture_html(&block)
|
||||
|
@ -108,8 +107,10 @@ class Middleman::CoreExtensions::DefaultHelpers < ::Middleman::Extension
|
|||
def auto_tag(asset_ext, asset_dir=nil)
|
||||
if asset_dir.nil?
|
||||
asset_dir = case asset_ext
|
||||
when :js then js_dir
|
||||
when :css then css_dir
|
||||
when :js
|
||||
js_dir
|
||||
when :css
|
||||
css_dir
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -124,7 +125,7 @@ class Middleman::CoreExtensions::DefaultHelpers < ::Middleman::Extension
|
|||
# Generate body css classes based on the current path
|
||||
#
|
||||
# @return [String]
|
||||
def page_classes(path = current_path.dup, options={})
|
||||
def page_classes(path=current_path.dup, options={})
|
||||
if path.is_a? Hash
|
||||
options = path
|
||||
path = current_path.dup
|
||||
|
@ -135,7 +136,7 @@ class Middleman::CoreExtensions::DefaultHelpers < ::Middleman::Extension
|
|||
|
||||
classes = []
|
||||
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'
|
||||
classes.map do |c|
|
||||
|
@ -155,13 +156,19 @@ class Middleman::CoreExtensions::DefaultHelpers < ::Middleman::Extension
|
|||
# @return [String]
|
||||
def asset_path(kind, source)
|
||||
return source if source.to_s.include?('//') || source.to_s.start_with?('data:')
|
||||
asset_folder = case kind
|
||||
when :css then css_dir
|
||||
when :js then js_dir
|
||||
when :images then images_dir
|
||||
when :fonts then fonts_dir
|
||||
else kind.to_s
|
||||
asset_folder = case kind
|
||||
when :css
|
||||
css_dir
|
||||
when :js
|
||||
js_dir
|
||||
when :images
|
||||
images_dir
|
||||
when :fonts
|
||||
fonts_dir
|
||||
else
|
||||
kind.to_s
|
||||
end
|
||||
|
||||
source = source.to_s.tr(' ', '')
|
||||
ignore_extension = (kind == :images || kind == :fonts) # don't append extension
|
||||
source << ".#{kind}" unless ignore_extension || source.end_with?(".#{kind}")
|
||||
|
@ -177,7 +184,7 @@ class Middleman::CoreExtensions::DefaultHelpers < ::Middleman::Extension
|
|||
# @return [String] The fully qualified asset url
|
||||
def asset_url(path, prefix='')
|
||||
# Don't touch assets which already have a full path
|
||||
if path.include?('//') or path.start_with?('data:')
|
||||
if path.include?('//') || path.start_with?('data:')
|
||||
path
|
||||
else # rewrite paths to use their destination path
|
||||
if resource = sitemap.find_resource_by_destination_path(url_for(path))
|
||||
|
@ -221,12 +228,12 @@ class Middleman::CoreExtensions::DefaultHelpers < ::Middleman::Extension
|
|||
options_index = block_given? ? 1 : 2
|
||||
|
||||
if block_given? && args.size > 2
|
||||
raise ArgumentError.new('Too many arguments to link_to(url, options={}, &block)')
|
||||
raise ArgumentError, 'Too many arguments to link_to(url, options={}, &block)'
|
||||
end
|
||||
|
||||
if url = args[url_arg_index]
|
||||
options = args[options_index] || {}
|
||||
raise ArgumentError.new('Options must be a hash') unless options.is_a?(Hash)
|
||||
raise ArgumentError, 'Options must be a hash' unless options.is_a?(Hash)
|
||||
|
||||
# Transform the url through our magic url_for method
|
||||
args[url_arg_index] = url_for(url, options)
|
||||
|
|
|
@ -37,8 +37,8 @@ class Middleman::CoreExtensions::Internationalization < ::Middleman::Extension
|
|||
|
||||
configure_i18n
|
||||
|
||||
if !app.build?
|
||||
logger.info "== Locales: #{langs.join(", ")} (Default #{@mount_at_root})"
|
||||
unless app.build?
|
||||
logger.info "== Locales: #{langs.join(', ')} (Default #{@mount_at_root})"
|
||||
end
|
||||
|
||||
# Don't output localizable files
|
||||
|
@ -70,10 +70,10 @@ class Middleman::CoreExtensions::Internationalization < ::Middleman::Extension
|
|||
|
||||
resources.each do |resource|
|
||||
# If it uses file extension localization
|
||||
if !parse_locale_extension(resource.path).nil?
|
||||
if parse_locale_extension(resource.path)
|
||||
result = parse_locale_extension(resource.path)
|
||||
lang, path, page_id = result
|
||||
new_resources << build_resource(path, resource.path, page_id, lang)
|
||||
ext_lang, path, page_id = result
|
||||
new_resources << build_resource(path, resource.path, page_id, ext_lang)
|
||||
# If it's a "localizable template"
|
||||
elsif File.fnmatch?(File.join(options[:templates_dir], '**'), resource.path)
|
||||
page_id = File.basename(resource.path, File.extname(resource.path))
|
||||
|
@ -90,7 +90,6 @@ class Middleman::CoreExtensions::Internationalization < ::Middleman::Extension
|
|||
|
||||
private
|
||||
|
||||
|
||||
def on_file_changed(file)
|
||||
if @locales_regex =~ file
|
||||
@_langs = nil # Clear langs cache
|
||||
|
@ -100,7 +99,7 @@ class Middleman::CoreExtensions::Internationalization < ::Middleman::Extension
|
|||
|
||||
def convert_glob_to_regex(glob)
|
||||
# File.fnmatch doesn't support brackets: {rb,yml,yaml}
|
||||
regex = @locales_glob.sub(/\./, '\.').sub(File.join('**', '*'), '.*').sub(/\//, '\/').sub('{rb,yml,yaml}', '(rb|ya?ml)')
|
||||
regex = glob.sub(/\./, '\.').sub(File.join('**', '*'), '.*').sub(/\//, '\/').sub('{rb,yml,yaml}', '(rb|ya?ml)')
|
||||
%r{^#{regex}}
|
||||
end
|
||||
|
||||
|
@ -124,7 +123,7 @@ class Middleman::CoreExtensions::Internationalization < ::Middleman::Extension
|
|||
lang = @mount_at_root
|
||||
end
|
||||
|
||||
instance_vars = Proc.new do
|
||||
instance_vars = proc do
|
||||
@lang = lang
|
||||
@page_id = page_id
|
||||
end
|
||||
|
@ -146,8 +145,10 @@ class Middleman::CoreExtensions::Internationalization < ::Middleman::Extension
|
|||
Array(options[:langs]).map(&:to_sym)
|
||||
else
|
||||
known_langs = app.files.known_paths.select do |p|
|
||||
p.to_s.match(@locales_regex) && (p.to_s.split(File::SEPARATOR).length === 2)
|
||||
end.map { |p|
|
||||
p.to_s.match(@locales_regex) && (p.to_s.split(File::SEPARATOR).length == 2)
|
||||
end
|
||||
|
||||
known_langs.map { |p|
|
||||
File.basename(p.to_s).sub(/\.ya?ml$/, '').sub(/\.rb$/, '')
|
||||
}.sort.map(&:to_sym)
|
||||
end
|
||||
|
@ -178,7 +179,7 @@ class Middleman::CoreExtensions::Internationalization < ::Middleman::Extension
|
|||
::I18n.locale = lang
|
||||
localized_page_id = ::I18n.t("paths.#{page_id}", :default => page_id, :fallback => [])
|
||||
|
||||
prefix = if (options[:mount_at_root] == lang) || (options[:mount_at_root] == nil && langs[0] == lang)
|
||||
prefix = if (options[:mount_at_root] == lang) || (options[:mount_at_root].nil? && langs[0] == lang)
|
||||
'/'
|
||||
else
|
||||
replacement = options[:lang_map].fetch(lang, lang)
|
||||
|
@ -190,7 +191,7 @@ class Middleman::CoreExtensions::Internationalization < ::Middleman::Extension
|
|||
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]
|
||||
|
||||
|
|
|
@ -44,7 +44,7 @@ class Middleman::Extensions::AssetHash < ::Middleman::Extension
|
|||
return if resource.ignored?
|
||||
|
||||
# Render through the Rack interface so middleware and mounted apps get a shot
|
||||
response = @rack_client.get(URI.escape(resource.destination_path), {}, { 'bypass_asset_hash' => 'true' })
|
||||
response = @rack_client.get(URI.escape(resource.destination_path), {}, 'bypass_asset_hash' => 'true')
|
||||
raise "#{resource.path} should be in the sitemap!" unless response.status == 200
|
||||
|
||||
digest = Digest::SHA1.hexdigest(response.body)[0..7]
|
||||
|
@ -63,7 +63,7 @@ class Middleman::Extensions::AssetHash < ::Middleman::Extension
|
|||
@rack_app = app
|
||||
@exts = options[:exts]
|
||||
@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]
|
||||
end
|
||||
|
||||
|
@ -85,7 +85,7 @@ class Middleman::Extensions::AssetHash < ::Middleman::Extension
|
|||
[status, headers, response]
|
||||
end
|
||||
|
||||
private
|
||||
private
|
||||
|
||||
def rewrite_paths(body, path)
|
||||
dirpath = Pathname.new(File.dirname(path))
|
||||
|
@ -111,9 +111,7 @@ class Middleman::Extensions::AssetHash < ::Middleman::Extension
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
# =================Temp Generate Test data==============================
|
||||
|
|
|
@ -14,7 +14,7 @@ class Middleman::Extensions::AssetHost < ::Middleman::Extension
|
|||
if asset_host.is_a?(Proc)
|
||||
config.asset_host(&asset_host)
|
||||
else
|
||||
config.asset_host do |asset|
|
||||
config.asset_host do |_|
|
||||
asset_host
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
# Automatic Image alt tags from image names extension
|
||||
class Middleman::Extensions::AutomaticAltTags < ::Middleman::Extension
|
||||
|
||||
def initialize(app, options_hash={}, &block)
|
||||
super
|
||||
end
|
||||
|
@ -10,14 +9,14 @@ class Middleman::Extensions::AutomaticAltTags < ::Middleman::Extension
|
|||
# containing image name.
|
||||
|
||||
def image_tag(path)
|
||||
if !path.include?('://')
|
||||
unless path.include?('://')
|
||||
params[:alt] ||= ''
|
||||
|
||||
real_path = path
|
||||
real_path = File.join(images_dir, real_path) unless real_path.start_with?('/')
|
||||
full_path = File.join(source_dir, real_path)
|
||||
|
||||
if File.exists?(full_path)
|
||||
if File.exist?(full_path)
|
||||
begin
|
||||
alt_text = File.basename(full_path, '.*')
|
||||
alt_text.capitalize!
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
# Automatic Image Sizes extension
|
||||
class Middleman::Extensions::AutomaticImageSizes < ::Middleman::Extension
|
||||
|
||||
def initialize(app, options_hash={}, &block)
|
||||
super
|
||||
|
||||
|
@ -16,14 +15,14 @@ class Middleman::Extensions::AutomaticImageSizes < ::Middleman::Extension
|
|||
# @param [Hash] params
|
||||
# @return [String]
|
||||
def image_tag(path, params={})
|
||||
if !params.has_key?(:width) && !params.has_key?(:height) && !path.include?('://')
|
||||
if !params.key?(:width) && !params.key?(:height) && !path.include?('://')
|
||||
params[:alt] ||= ''
|
||||
|
||||
real_path = path
|
||||
real_path = File.join(images_dir, real_path) unless real_path.start_with?('/')
|
||||
full_path = File.join(source_dir, real_path)
|
||||
|
||||
if File.exists?(full_path)
|
||||
if File.exist?(full_path)
|
||||
begin
|
||||
width, height = ::FastImage.size(full_path, :raise_on_failure => true)
|
||||
params[:width] = width
|
||||
|
@ -31,7 +30,7 @@ class Middleman::Extensions::AutomaticImageSizes < ::Middleman::Extension
|
|||
rescue FastImage::UnknownImageType
|
||||
# No message, it's just not supported
|
||||
rescue
|
||||
warn "Couldn't determine dimensions for image #{path}: #{$!.message}"
|
||||
warn "Couldn't determine dimensions for image #{path}: #{$ERROR_INFO.message}"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
# The Cache Buster extension
|
||||
class Middleman::Extensions::CacheBuster < ::Middleman::Extension
|
||||
|
||||
def initialize(app, options_hash={}, &block)
|
||||
super
|
||||
|
||||
|
|
|
@ -35,7 +35,7 @@ class Middleman::Extensions::Gzip < ::Middleman::Extension
|
|||
|
||||
# Farm out gzip tasks to threads and put the results in in_queue
|
||||
out_queue = Queue.new
|
||||
threads = num_threads.times.map do
|
||||
num_threads.times.each do
|
||||
Thread.new do
|
||||
while path = in_queue.pop
|
||||
out_queue << gzip_file(path.to_s)
|
||||
|
|
|
@ -94,11 +94,11 @@ class Middleman::Extensions::Lorem < ::Middleman::Extension
|
|||
# Get a placeholder date
|
||||
# @param [String] fmt
|
||||
# @return [String]
|
||||
def date(fmt = '%a %b %d, %Y')
|
||||
def date(fmt='%a %b %d, %Y')
|
||||
y = rand(20) + 1990
|
||||
m = rand(12) + 1
|
||||
d = rand(31) + 1
|
||||
Time.local(y,m,d).strftime(fmt)
|
||||
Time.local(y, m, d).strftime(fmt)
|
||||
end
|
||||
|
||||
# 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
|
||||
# @return [String]
|
||||
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.',
|
||||
'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!']
|
||||
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 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)]
|
||||
end
|
||||
|
||||
# Get a placeholder email address
|
||||
# @return [String]
|
||||
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)
|
||||
username = name.gsub(/[^\w]/, delimiters[rand(delimiters.size)])
|
||||
"#{username}@#{domains[rand(domains.size)]}".downcase
|
||||
|
@ -147,7 +147,7 @@ class Middleman::Extensions::Lorem < ::Middleman::Extension
|
|||
def image(size, options={})
|
||||
domain = options[:domain] || 'http://placehold.it'
|
||||
src = "#{domain}/#{size}"
|
||||
hex = %w[a b c d e f 0 1 2 3 4 5 6 7 8 9]
|
||||
hex = %w(a b c d e f 0 1 2 3 4 5 6 7 8 9)
|
||||
background_color = options[:background_color]
|
||||
color = options[:color]
|
||||
|
||||
|
@ -159,7 +159,7 @@ class Middleman::Extensions::Lorem < ::Middleman::Extension
|
|||
src << "/#{background_color.sub(/^#/, '')}" if background_color
|
||||
src << '/ccc' if background_color.nil? && color
|
||||
src << "/#{color.sub(/^#/, '')}" if color
|
||||
src << "&text=#{Rack::Utils::escape(options[:text])}" if options[:text]
|
||||
src << "&text=#{Rack::Utils.escape(options[:text])}" if options[:text]
|
||||
|
||||
src
|
||||
end
|
||||
|
|
|
@ -20,9 +20,9 @@ class Middleman::Extensions::MinifyCss < ::Middleman::Extension
|
|||
end
|
||||
|
||||
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.options = { :style => :compressed }
|
||||
root_node.options = options.merge(:style => :compressed)
|
||||
root_node.render.strip
|
||||
end
|
||||
end
|
||||
|
@ -49,7 +49,7 @@ class Middleman::Extensions::MinifyCss < ::Middleman::Extension
|
|||
|
||||
if inline_html_content?(env['PATH_INFO'])
|
||||
minified = ::Middleman::Util.extract_response_text(response)
|
||||
minified.gsub!(INLINE_CSS_REGEX) do |match|
|
||||
minified.gsub!(INLINE_CSS_REGEX) do
|
||||
$1 << @compressor.compress($2) << $3
|
||||
end
|
||||
|
||||
|
@ -65,13 +65,14 @@ class Middleman::Extensions::MinifyCss < ::Middleman::Extension
|
|||
[status, headers, response]
|
||||
end
|
||||
|
||||
private
|
||||
private
|
||||
|
||||
def inline_html_content?(path)
|
||||
(path.end_with?('.html') || path.end_with?('.php')) && @inline
|
||||
end
|
||||
|
||||
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
|
||||
|
|
|
@ -24,7 +24,6 @@ class Middleman::Extensions::MinifyJavascript < ::Middleman::Extension
|
|||
|
||||
# Rack middleware to look for JS and compress it
|
||||
class Rack
|
||||
|
||||
# Init
|
||||
# @param [Class] app
|
||||
# @param [Hash] options
|
||||
|
@ -51,7 +50,7 @@ class Middleman::Extensions::MinifyJavascript < ::Middleman::Extension
|
|||
|
||||
headers['Content-Length'] = ::Rack::Utils.bytesize(minified).to_s
|
||||
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)
|
||||
minified = @compressor.compress(uncompressed_source)
|
||||
|
||||
|
@ -65,7 +64,7 @@ class Middleman::Extensions::MinifyJavascript < ::Middleman::Extension
|
|||
[status, headers, response]
|
||||
end
|
||||
|
||||
private
|
||||
private
|
||||
|
||||
def minify_inline_content(uncompressed_source)
|
||||
uncompressed_source.gsub(/(<script[^>]*>\s*(?:\/\/(?:(?:<!--)|(?:<!\[CDATA\[))\n)?)(.*?)((?:(?:\n\s*)?\/\/(?:(?:-->)|(?:\]\]>)))?\s*<\/script>)/m) do |match|
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
# Relative Assets extension
|
||||
class Middleman::Extensions::RelativeAssets < ::Middleman::Extension
|
||||
|
||||
def initialize(app, options_hash={}, &block)
|
||||
super
|
||||
|
||||
|
|
|
@ -1,15 +1,14 @@
|
|||
# SMACSS
|
||||
class Middleman::Templates::Smacss < Middleman::Templates::Base
|
||||
|
||||
class_option 'css_dir',
|
||||
:default => 'stylesheets',
|
||||
:desc => 'The path to the css files'
|
||||
:default => 'stylesheets',
|
||||
:desc => 'The path to the css files'
|
||||
class_option 'js_dir',
|
||||
:default => 'javascripts',
|
||||
:desc => 'The path to the javascript files'
|
||||
:default => 'javascripts',
|
||||
:desc => 'The path to the javascript files'
|
||||
class_option 'images_dir',
|
||||
:default => 'images',
|
||||
:desc => 'The path to the image files'
|
||||
:default => 'images',
|
||||
:desc => 'The path to the image files'
|
||||
|
||||
# Template files are relative to this file
|
||||
# @return [String]
|
||||
|
|
Loading…
Reference in a new issue