Clean up whitespace, play with cane for testing style quality and code complexity
This commit is contained in:
parent
955c66a54f
commit
446aa6a4ba
133 changed files with 895 additions and 871 deletions
1
Gemfile
1
Gemfile
|
@ -17,6 +17,7 @@ group :test do
|
||||||
gem "slim"
|
gem "slim"
|
||||||
gem "coffee-filter", "~> 0.1.1"
|
gem "coffee-filter", "~> 0.1.1"
|
||||||
gem "liquid", "~> 2.2"
|
gem "liquid", "~> 2.2"
|
||||||
|
gem "cane"
|
||||||
|
|
||||||
platforms :ruby do
|
platforms :ruby do
|
||||||
gem "therubyracer"
|
gem "therubyracer"
|
||||||
|
|
7
Rakefile
7
Rakefile
|
@ -87,5 +87,12 @@ task :test do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
desc "Rune cane for all middleman gems"
|
||||||
|
task :cane do
|
||||||
|
GEM_PATHS.each do |g|
|
||||||
|
sh "cd #{File.join(ROOT, g)} && #{Gem.ruby} -S cane"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
desc "Run tests for all middleman gems"
|
desc "Run tests for all middleman gems"
|
||||||
task :default => :test
|
task :default => :test
|
|
@ -21,10 +21,10 @@ Cucumber::Rake::Task.new(:test, 'Run features that should pass') do |t|
|
||||||
exempt_tags << "--tags ~@nojava" if RUBY_PLATFORM == "java"
|
exempt_tags << "--tags ~@nojava" if RUBY_PLATFORM == "java"
|
||||||
exempt_tags << "--tags ~@encoding" unless Object.const_defined?(:Encoding)
|
exempt_tags << "--tags ~@encoding" unless Object.const_defined?(:Encoding)
|
||||||
exempt_tags << "--tags ~@travishatesme" if ENV["TRAVIS"] == "true"
|
exempt_tags << "--tags ~@travishatesme" if ENV["TRAVIS"] == "true"
|
||||||
|
|
||||||
t.cucumber_opts = "--color #{exempt_tags.join(" ")} --strict --format #{ENV['CUCUMBER_FORMAT'] || 'Fivemat'}"
|
t.cucumber_opts = "--color #{exempt_tags.join(" ")} --strict --format #{ENV['CUCUMBER_FORMAT'] || 'Fivemat'}"
|
||||||
end
|
end
|
||||||
|
|
||||||
YARD::Rake::YardocTask.new
|
YARD::Rake::YardocTask.new
|
||||||
|
|
||||||
task :default => :test
|
task :default => :test
|
||||||
|
|
2
middleman-core/.cane
Normal file
2
middleman-core/.cane
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
--exclusions-file .cane-exclusions.yml
|
||||||
|
--no-doc
|
5
middleman-core/.cane-exclusions.yml
Normal file
5
middleman-core/.cane-exclusions.yml
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
style:
|
||||||
|
- lib/middleman-core/vendor/hooks-0.2.0/lib/hooks/inheritable_attribute.rb
|
||||||
|
- lib/middleman-core/vendor/hooks-0.2.0/test/hooks_test.rb
|
||||||
|
- lib/middleman-core/vendor/hooks-0.2.0/test/inheritable_attribute_test.rb
|
||||||
|
- lib/middleman-core/vendor/hooks-0.2.0/lib/hooks.rb
|
|
@ -1,7 +1,7 @@
|
||||||
Given /^page "([^\"]*)" has layout "([^\"]*)"$/ do |url, layout|
|
Given /^page "([^\"]*)" has layout "([^\"]*)"$/ do |url, layout|
|
||||||
@initialize_commands ||= []
|
@initialize_commands ||= []
|
||||||
@initialize_commands << lambda {
|
@initialize_commands << lambda {
|
||||||
page(url, :layout => layout.to_sym)
|
page(url, :layout => layout.to_sym)
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -12,4 +12,4 @@ Given /^"([^\"]*)" with_layout block has layout "([^\"]*)"$/ do |url, layout|
|
||||||
page(url)
|
page(url)
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,4 +3,4 @@ ENV["AUTOLOAD_SPROCKETS"] = "false"
|
||||||
|
|
||||||
PROJECT_ROOT_PATH = File.dirname(File.dirname(File.dirname(__FILE__)))
|
PROJECT_ROOT_PATH = File.dirname(File.dirname(File.dirname(__FILE__)))
|
||||||
require File.join(PROJECT_ROOT_PATH, 'lib', 'middleman-core')
|
require File.join(PROJECT_ROOT_PATH, 'lib', 'middleman-core')
|
||||||
require File.join(PROJECT_ROOT_PATH, 'lib', 'middleman-core', 'step_definitions')
|
require File.join(PROJECT_ROOT_PATH, 'lib', 'middleman-core', 'step_definitions')
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
set :automatic_directory_matcher, "--"
|
set :automatic_directory_matcher, "--"
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
with_layout false do
|
with_layout false do
|
||||||
page "/data.html"
|
page "/data.html"
|
||||||
page "/data3.html"
|
page "/data3.html"
|
||||||
end
|
end
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
set :layout, false
|
set :layout, false
|
||||||
|
|
|
@ -8,4 +8,4 @@ page "/target_ignore.html", :proxy => "/should_be_ignored3.html", :ignore => tru
|
||||||
page "/fake/#{num}.html", :proxy => "/real/index.html" do
|
page "/fake/#{num}.html", :proxy => "/real/index.html" do
|
||||||
@num = num
|
@num = num
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -8,4 +8,4 @@ page "/target_ignore.html", :proxy => "/should_be_ignored3.html", :ignore => tru
|
||||||
page "/fake/#{num}.html", :proxy => "/real/index.html" do
|
page "/fake/#{num}.html", :proxy => "/real/index.html" do
|
||||||
@num = num
|
@num = num
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
with_layout false do
|
with_layout false do
|
||||||
page "/request-path.html"
|
page "/request-path.html"
|
||||||
end
|
end
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
set :erb, :layout_engine => :str
|
set :erb, :layout_engine => :str
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
data.pages.each do |p|
|
data.pages.each do |p|
|
||||||
page p.from, :proxy => p.to
|
page p.from, :proxy => p.to
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
require "lib/hello_helper"
|
require "lib/hello_helper"
|
||||||
helpers HelloHelper
|
helpers HelloHelper
|
||||||
|
|
||||||
page "/", :layout => false
|
page "/", :layout => false
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
module Derp
|
module Derp
|
||||||
def three; "Three"; end
|
def three; "Three"; end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
module FourHelpers
|
module FourHelpers
|
||||||
def four; "Four"; end
|
def four; "Four"; end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
module OneHelper
|
module OneHelper
|
||||||
def one; "One"; end
|
def one; "One"; end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
module YetAnotherThingy
|
module YetAnotherThingy
|
||||||
def two; "Two"; end
|
def two; "Two"; end
|
||||||
end
|
end
|
||||||
|
|
|
@ -2,4 +2,4 @@ module HelloHelper
|
||||||
def hello
|
def hello
|
||||||
"Hello World"
|
"Hello World"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -9,4 +9,4 @@ module ExtensionA
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
activate ExtensionA, :hello => "world", :hola => "mundo"
|
activate ExtensionA, :hello => "world", :hola => "mundo"
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
# Proxy ignored.html, which should ignore itself through a frontmatter
|
# Proxy ignored.html, which should ignore itself through a frontmatter
|
||||||
page 'proxied.html', :proxy => 'ignored.html'
|
page 'proxied.html', :proxy => 'ignored.html'
|
||||||
page 'override_layout.html', :layout => :alternate
|
page 'override_layout.html', :layout => :alternate
|
||||||
page 'page_mentioned.html'
|
page 'page_mentioned.html'
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
###
|
###
|
||||||
# Compass
|
# Compass
|
||||||
###
|
###
|
||||||
|
|
||||||
|
@ -16,13 +16,13 @@
|
||||||
###
|
###
|
||||||
|
|
||||||
# Per-page layout changes:
|
# Per-page layout changes:
|
||||||
#
|
#
|
||||||
# With no layout
|
# With no layout
|
||||||
# page "/path/to/file.html", :layout => false
|
# page "/path/to/file.html", :layout => false
|
||||||
#
|
#
|
||||||
# With alternative layout
|
# With alternative layout
|
||||||
# page "/path/to/file.html", :layout => :otherlayout
|
# page "/path/to/file.html", :layout => :otherlayout
|
||||||
#
|
#
|
||||||
# A path which all have the same layout
|
# A path which all have the same layout
|
||||||
# with_layout :admin do
|
# with_layout :admin do
|
||||||
# page "/admin/*"
|
# page "/admin/*"
|
||||||
|
@ -60,21 +60,21 @@
|
||||||
configure :build do
|
configure :build do
|
||||||
# For example, change the Compass output style for deployment
|
# For example, change the Compass output style for deployment
|
||||||
# activate :minify_css
|
# activate :minify_css
|
||||||
|
|
||||||
# Minify Javascript on build
|
# Minify Javascript on build
|
||||||
# activate :minify_javascript
|
# activate :minify_javascript
|
||||||
|
|
||||||
# Enable cache buster
|
# Enable cache buster
|
||||||
# activate :cache_buster
|
# activate :cache_buster
|
||||||
|
|
||||||
# Use relative URLs
|
# Use relative URLs
|
||||||
# activate :relative_assets
|
# activate :relative_assets
|
||||||
|
|
||||||
# Compress PNGs after build
|
# Compress PNGs after build
|
||||||
# First: gem install middleman-smusher
|
# First: gem install middleman-smusher
|
||||||
# require "middleman-smusher"
|
# require "middleman-smusher"
|
||||||
# activate :smusher
|
# activate :smusher
|
||||||
|
|
||||||
# Or use a different image path
|
# Or use a different image path
|
||||||
# set :http_path, "/Content/images/"
|
# set :http_path, "/Content/images/"
|
||||||
end
|
end
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
page "/index.html", :layout => false
|
page "/index.html", :layout => false
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
with_layout false do
|
with_layout false do
|
||||||
page "/spaces in file.html"
|
page "/spaces in file.html"
|
||||||
end
|
end
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Regular
|
Regular
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
README
|
README
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
set :layout, :custom
|
set :layout, :custom
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
set :layout, :custom
|
set :layout, :custom
|
||||||
|
|
||||||
page "/", :layout => :another
|
page "/", :layout => :another
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
set :layout, :custom
|
set :layout, :custom
|
||||||
|
|
|
@ -3,4 +3,4 @@ page "/path/*", :layout => "alt"
|
||||||
# Doesn't work, and shouldn't
|
# Doesn't work, and shouldn't
|
||||||
# page "/path/*" do
|
# page "/path/*" do
|
||||||
# set :layout, "alt"
|
# set :layout, "alt"
|
||||||
# end
|
# end
|
||||||
|
|
|
@ -8,4 +8,4 @@ end
|
||||||
|
|
||||||
map "/sinatra" do
|
map "/sinatra" do
|
||||||
run MySinatra
|
run MySinatra
|
||||||
end
|
end
|
||||||
|
|
|
@ -2,4 +2,4 @@ page "/sub/fake.html", :proxy => "/proxied.html", :ignore => true
|
||||||
page "/sub/fake2.html", :proxy => "/proxied.html", :ignore => true
|
page "/sub/fake2.html", :proxy => "/proxied.html", :ignore => true
|
||||||
|
|
||||||
page "/directory-indexed/fake.html", :proxy => "/proxied.html", :ignore => true
|
page "/directory-indexed/fake.html", :proxy => "/proxied.html", :ignore => true
|
||||||
page "/directory-indexed/fake2.html", :proxy => "/proxied.html", :ignore => true
|
page "/directory-indexed/fake2.html", :proxy => "/proxied.html", :ignore => true
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
page "/admin/*", :layout => :admin
|
page "/admin/*", :layout => :admin
|
||||||
|
|
6
middleman-core/lib/middleman-core.rb
Executable file → Normal file
6
middleman-core/lib/middleman-core.rb
Executable file → Normal file
|
@ -4,13 +4,13 @@ $LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir)
|
||||||
|
|
||||||
# Top-level Middleman namespace
|
# Top-level Middleman namespace
|
||||||
module Middleman
|
module Middleman
|
||||||
|
|
||||||
# Backwards compatibility namespace
|
# Backwards compatibility namespace
|
||||||
module Features; end
|
module Features; end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
require "middleman-core/version"
|
require "middleman-core/version"
|
||||||
require "middleman-core/util"
|
require "middleman-core/util"
|
||||||
require "middleman-core/extensions"
|
require "middleman-core/extensions"
|
||||||
require "middleman-core/application"
|
require "middleman-core/application"
|
||||||
|
|
|
@ -18,7 +18,7 @@ module Middleman
|
||||||
class Application
|
class Application
|
||||||
# Uses callbacks
|
# Uses callbacks
|
||||||
include Hooks
|
include Hooks
|
||||||
|
|
||||||
# Before request hook
|
# Before request hook
|
||||||
define_hook :before
|
define_hook :before
|
||||||
|
|
||||||
|
@ -215,7 +215,7 @@ module Middleman
|
||||||
def settings
|
def settings
|
||||||
self
|
self
|
||||||
end
|
end
|
||||||
|
|
||||||
delegate :logger, :instrument, :to => ::Middleman::Util
|
delegate :logger, :instrument, :to => ::Middleman::Util
|
||||||
|
|
||||||
# Work around this bug: http://bugs.ruby-lang.org/issues/4521
|
# Work around this bug: http://bugs.ruby-lang.org/issues/4521
|
||||||
|
|
|
@ -6,7 +6,7 @@ require "thor/group"
|
||||||
module Middleman
|
module Middleman
|
||||||
|
|
||||||
module Cli
|
module Cli
|
||||||
|
|
||||||
# The base task from which everything else etends
|
# The base task from which everything else etends
|
||||||
class Base < Thor
|
class Base < Thor
|
||||||
class << self
|
class << self
|
||||||
|
@ -18,7 +18,7 @@ module Middleman
|
||||||
if ARGV[0] != "help" && (ARGV.length < 1 || ARGV.first.include?("-"))
|
if ARGV[0] != "help" && (ARGV.length < 1 || ARGV.first.include?("-"))
|
||||||
ARGV.unshift("server")
|
ARGV.unshift("server")
|
||||||
end
|
end
|
||||||
|
|
||||||
super
|
super
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -28,7 +28,7 @@ module Middleman
|
||||||
require 'middleman-core/version'
|
require 'middleman-core/version'
|
||||||
say "Middleman #{Middleman::VERSION}"
|
say "Middleman #{Middleman::VERSION}"
|
||||||
end
|
end
|
||||||
|
|
||||||
# Override the Thor help method to find help for subtasks
|
# Override the Thor help method to find help for subtasks
|
||||||
# @param [Symbol, String, nil] meth
|
# @param [Symbol, String, nil] meth
|
||||||
# @param [Boolean] subcommand
|
# @param [Boolean] subcommand
|
||||||
|
@ -43,24 +43,24 @@ module Middleman
|
||||||
list += klass.printable_tasks(false)
|
list += klass.printable_tasks(false)
|
||||||
end
|
end
|
||||||
list.sort!{ |a,b| a[0] <=> b[0] }
|
list.sort!{ |a,b| a[0] <=> b[0] }
|
||||||
|
|
||||||
shell.say "Tasks:"
|
shell.say "Tasks:"
|
||||||
shell.print_table(list, :ident => 2, :truncate => true)
|
shell.print_table(list, :ident => 2, :truncate => true)
|
||||||
shell.say
|
shell.say
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Intercept missing methods and search subtasks for them
|
# Intercept missing methods and search subtasks for them
|
||||||
# @param [Symbol] meth
|
# @param [Symbol] meth
|
||||||
def method_missing(meth, *args)
|
def method_missing(meth, *args)
|
||||||
meth = meth.to_s
|
meth = meth.to_s
|
||||||
|
|
||||||
if self.class.map.has_key?(meth)
|
if self.class.map.has_key?(meth)
|
||||||
meth = self.class.map[meth]
|
meth = self.class.map[meth]
|
||||||
end
|
end
|
||||||
|
|
||||||
klass, task = Thor::Util.find_class_and_task_by_namespace("#{meth}:#{meth}")
|
klass, task = Thor::Util.find_class_and_task_by_namespace("#{meth}:#{meth}")
|
||||||
|
|
||||||
if klass.nil?
|
if klass.nil?
|
||||||
tasks_dir = File.join(Dir.pwd, "tasks")
|
tasks_dir = File.join(Dir.pwd, "tasks")
|
||||||
|
|
||||||
|
@ -69,7 +69,7 @@ module Middleman
|
||||||
klass, task = Thor::Util.find_class_and_task_by_namespace("#{meth}:#{meth}")
|
klass, task = Thor::Util.find_class_and_task_by_namespace("#{meth}:#{meth}")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if klass.nil?
|
if klass.nil?
|
||||||
super
|
super
|
||||||
else
|
else
|
||||||
|
|
|
@ -2,59 +2,59 @@ require "middleman-core"
|
||||||
|
|
||||||
# CLI Module
|
# CLI Module
|
||||||
module Middleman::Cli
|
module Middleman::Cli
|
||||||
|
|
||||||
# The CLI Build class
|
# The CLI Build class
|
||||||
class Build < Thor
|
class Build < Thor
|
||||||
include Thor::Actions
|
include Thor::Actions
|
||||||
|
|
||||||
attr_reader :debugging
|
attr_reader :debugging
|
||||||
|
|
||||||
check_unknown_options!
|
check_unknown_options!
|
||||||
|
|
||||||
namespace :build
|
namespace :build
|
||||||
|
|
||||||
desc "build [options]", "Builds the static site for deployment"
|
desc "build [options]", "Builds the static site for deployment"
|
||||||
method_option :clean,
|
method_option :clean,
|
||||||
:type => :boolean,
|
:type => :boolean,
|
||||||
:aliases => "-c",
|
:aliases => "-c",
|
||||||
:default => false,
|
:default => false,
|
||||||
:desc => 'Removes orphaned files or directories from build'
|
:desc => 'Removes orphaned files or directories from build'
|
||||||
method_option :glob,
|
method_option :glob,
|
||||||
:type => :string,
|
:type => :string,
|
||||||
:aliases => "-g",
|
:aliases => "-g",
|
||||||
:default => nil,
|
:default => nil,
|
||||||
:desc => 'Build a subset of the project'
|
:desc => 'Build a subset of the project'
|
||||||
method_option :verbose,
|
method_option :verbose,
|
||||||
:type => :boolean,
|
:type => :boolean,
|
||||||
:default => false,
|
:default => false,
|
||||||
:desc => 'Print debug messages'
|
:desc => 'Print debug messages'
|
||||||
method_option :instrument,
|
method_option :instrument,
|
||||||
:type => :string,
|
:type => :string,
|
||||||
:default => false,
|
:default => false,
|
||||||
:desc => 'Print instrument messages'
|
:desc => 'Print instrument messages'
|
||||||
method_option :profile,
|
method_option :profile,
|
||||||
:type => :boolean,
|
:type => :boolean,
|
||||||
:default => false,
|
:default => false,
|
||||||
:desc => 'Generate profiling report for the build'
|
:desc => 'Generate profiling report for the build'
|
||||||
|
|
||||||
# Core build Thor command
|
# Core build Thor command
|
||||||
# @return [void]
|
# @return [void]
|
||||||
def build
|
def build
|
||||||
if !ENV["MM_ROOT"]
|
if !ENV["MM_ROOT"]
|
||||||
raise Thor::Error, "Error: Could not find a Middleman project config, perhaps you are in the wrong folder?"
|
raise Thor::Error, "Error: Could not find a Middleman project config, perhaps you are in the wrong folder?"
|
||||||
end
|
end
|
||||||
|
|
||||||
# Use Rack::Test for inspecting a running server for output
|
# Use Rack::Test for inspecting a running server for output
|
||||||
require "rack"
|
require "rack"
|
||||||
require "rack/test"
|
require "rack/test"
|
||||||
|
|
||||||
require 'find'
|
require 'find'
|
||||||
|
|
||||||
@debugging = Middleman::Cli::Base.respond_to?(:debugging) && Middleman::Cli::Base.debugging
|
@debugging = Middleman::Cli::Base.respond_to?(:debugging) && Middleman::Cli::Base.debugging
|
||||||
@had_errors = false
|
@had_errors = false
|
||||||
|
|
||||||
self.class.shared_instance(options["verbose"], options["instrument"])
|
self.class.shared_instance(options["verbose"], options["instrument"])
|
||||||
|
|
||||||
self.class.shared_rack
|
self.class.shared_rack
|
||||||
|
|
||||||
opts = {}
|
opts = {}
|
||||||
|
@ -66,12 +66,12 @@ module Middleman::Cli
|
||||||
if @had_errors && !@debugging
|
if @had_errors && !@debugging
|
||||||
self.shell.say "There were errors during this build, re-run with --verbose to see the full exception."
|
self.shell.say "There were errors during this build, re-run with --verbose to see the full exception."
|
||||||
end
|
end
|
||||||
|
|
||||||
exit(1) if @had_errors
|
exit(1) if @had_errors
|
||||||
|
|
||||||
self.class.shared_instance.run_hook :after_build, self
|
self.class.shared_instance.run_hook :after_build, self
|
||||||
end
|
end
|
||||||
|
|
||||||
# Static methods
|
# Static methods
|
||||||
class << self
|
class << self
|
||||||
def exit_on_failure?
|
def exit_on_failure?
|
||||||
|
@ -87,14 +87,14 @@ module Middleman::Cli
|
||||||
logger(verbose ? 0 : 1, instrument)
|
logger(verbose ? 0 : 1, instrument)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Middleman::Application class singleton
|
# Middleman::Application class singleton
|
||||||
#
|
#
|
||||||
# @return [Middleman::Application]
|
# @return [Middleman::Application]
|
||||||
def shared_server
|
def shared_server
|
||||||
@_shared_server ||= shared_instance.class
|
@_shared_server ||= shared_instance.class
|
||||||
end
|
end
|
||||||
|
|
||||||
# Rack::Test::Session singleton
|
# Rack::Test::Session singleton
|
||||||
#
|
#
|
||||||
# @return [Rack::Test::Session]
|
# @return [Rack::Test::Session]
|
||||||
|
@ -104,13 +104,13 @@ module Middleman::Cli
|
||||||
::Rack::Test::Session.new(mock)
|
::Rack::Test::Session.new(mock)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Set the root path to the Middleman::Application's root
|
# Set the root path to the Middleman::Application's root
|
||||||
def source_root
|
def source_root
|
||||||
shared_instance.root
|
shared_instance.root
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
no_tasks {
|
no_tasks {
|
||||||
# Render a resource to a file.
|
# Render a resource to a file.
|
||||||
#
|
#
|
||||||
|
@ -134,10 +134,10 @@ module Middleman::Cli
|
||||||
|
|
||||||
output_file
|
output_file
|
||||||
end
|
end
|
||||||
|
|
||||||
def handle_error(file_name, response, e=Thor::Error.new(response))
|
def handle_error(file_name, response, e=Thor::Error.new(response))
|
||||||
@had_errors = true
|
@had_errors = true
|
||||||
|
|
||||||
say_status :error, file_name, :red
|
say_status :error, file_name, :red
|
||||||
if self.debugging
|
if self.debugging
|
||||||
raise e
|
raise e
|
||||||
|
@ -148,7 +148,7 @@ module Middleman::Cli
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
# A Thor Action, modular code, which does the majority of the work.
|
# A Thor Action, modular code, which does the majority of the work.
|
||||||
class GlobAction < ::Thor::Actions::EmptyDirectory
|
class GlobAction < ::Thor::Actions::EmptyDirectory
|
||||||
attr_reader :source
|
attr_reader :source
|
||||||
|
@ -169,7 +169,7 @@ module Middleman::Cli
|
||||||
|
|
||||||
super(base, @destination, config)
|
super(base, @destination, config)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Execute the action
|
# Execute the action
|
||||||
# @return [void]
|
# @return [void]
|
||||||
def invoke!
|
def invoke!
|
||||||
|
@ -179,21 +179,21 @@ module Middleman::Cli
|
||||||
end
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
# Remove files which were not built in this cycle
|
# Remove files which were not built in this cycle
|
||||||
# @return [void]
|
# @return [void]
|
||||||
def clean!
|
def clean!
|
||||||
files = @cleaning_queue.select { |q| q.file? }
|
files = @cleaning_queue.select { |q| q.file? }
|
||||||
directories = @cleaning_queue.select { |q| q.directory? }
|
directories = @cleaning_queue.select { |q| q.directory? }
|
||||||
|
|
||||||
files.each do |f|
|
files.each do |f|
|
||||||
base.remove_file f, :force => true
|
base.remove_file f, :force => true
|
||||||
end
|
end
|
||||||
|
|
||||||
directories = directories.sort_by {|d| d.to_s.length }.reverse!
|
directories = directories.sort_by {|d| d.to_s.length }.reverse!
|
||||||
|
|
||||||
directories.each do |d|
|
directories.each do |d|
|
||||||
base.remove_file d, :force => true if directory_empty? d
|
base.remove_file d, :force => true if directory_empty? d
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -216,11 +216,11 @@ module Middleman::Cli
|
||||||
def queue_current_paths
|
def queue_current_paths
|
||||||
@cleaning_queue = []
|
@cleaning_queue = []
|
||||||
return unless File.exist?(@destination)
|
return unless File.exist?(@destination)
|
||||||
|
|
||||||
paths = ::Middleman::Util.all_files_under(@destination)
|
paths = ::Middleman::Util.all_files_under(@destination)
|
||||||
@cleaning_queue += paths.select do |path|
|
@cleaning_queue += paths.select do |path|
|
||||||
!path.to_s.match(/\/\./) || path.to_s.match(/\.htaccess/)
|
!path.to_s.match(/\/\./) || path.to_s.match(/\.htaccess/)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Actually build the app
|
# Actually build the app
|
||||||
|
@ -228,7 +228,7 @@ module Middleman::Cli
|
||||||
def execute!
|
def execute!
|
||||||
# Sort order, images, fonts, js/css and finally everything else.
|
# Sort order, images, fonts, js/css and finally everything else.
|
||||||
sort_order = %w(.png .jpeg .jpg .gif .bmp .svg .svgz .ico .woff .otf .ttf .eot .js .css)
|
sort_order = %w(.png .jpeg .jpg .gif .bmp .svg .svgz .ico .woff .otf .ttf .eot .js .css)
|
||||||
|
|
||||||
# Pre-request CSS to give Compass a chance to build sprites
|
# Pre-request CSS to give Compass a chance to build sprites
|
||||||
logger.debug "== Prerendering CSS"
|
logger.debug "== Prerendering CSS"
|
||||||
|
|
||||||
|
@ -237,7 +237,7 @@ module Middleman::Cli
|
||||||
end.each do |resource|
|
end.each do |resource|
|
||||||
Middleman::Cli::Build.shared_rack.get(URI.escape(resource.destination_path))
|
Middleman::Cli::Build.shared_rack.get(URI.escape(resource.destination_path))
|
||||||
end
|
end
|
||||||
|
|
||||||
logger.debug "== Checking for Compass sprites"
|
logger.debug "== Checking for Compass sprites"
|
||||||
|
|
||||||
# Double-check for compass sprites
|
# Double-check for compass sprites
|
||||||
|
@ -265,7 +265,7 @@ module Middleman::Cli
|
||||||
::Middleman::Profiling.report("build")
|
::Middleman::Profiling.report("build")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Alias "b" to "build"
|
# Alias "b" to "build"
|
||||||
Base.map({ "b" => "build" })
|
Base.map({ "b" => "build" })
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,26 +1,26 @@
|
||||||
# CLI Module
|
# CLI Module
|
||||||
module Middleman::Cli
|
module Middleman::Cli
|
||||||
|
|
||||||
# A initializing Bundler
|
# A initializing Bundler
|
||||||
class Bundle < Thor
|
class Bundle < Thor
|
||||||
include Thor::Actions
|
include Thor::Actions
|
||||||
check_unknown_options!
|
check_unknown_options!
|
||||||
|
|
||||||
namespace :bundle
|
namespace :bundle
|
||||||
|
|
||||||
desc "bundle", "Setup initial bundle", :hide => true
|
desc "bundle", "Setup initial bundle", :hide => true
|
||||||
|
|
||||||
# The setup task
|
# The setup task
|
||||||
def bundle
|
def bundle
|
||||||
run('bundle install --without development test')#, :capture => true)
|
run('bundle install --without development test')#, :capture => true)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# A upgrading Bundler
|
# A upgrading Bundler
|
||||||
class Upgrade < Thor
|
class Upgrade < Thor
|
||||||
include Thor::Actions
|
include Thor::Actions
|
||||||
check_unknown_options!
|
check_unknown_options!
|
||||||
|
|
||||||
namespace :upgrade
|
namespace :upgrade
|
||||||
|
|
||||||
desc "upgrade", "Upgrade installed bundle"
|
desc "upgrade", "Upgrade installed bundle"
|
||||||
|
@ -32,7 +32,7 @@ module Middleman::Cli
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Map "u" to "upgrade"
|
# Map "u" to "upgrade"
|
||||||
Base.map({
|
Base.map({
|
||||||
"u" => "upgrade"
|
"u" => "upgrade"
|
||||||
|
|
|
@ -1,19 +1,19 @@
|
||||||
# CLI Module
|
# CLI Module
|
||||||
module Middleman::Cli
|
module Middleman::Cli
|
||||||
|
|
||||||
# A thor task for creating new projects
|
# A thor task for creating new projects
|
||||||
class Extension < Thor
|
class Extension < Thor
|
||||||
include Thor::Actions
|
include Thor::Actions
|
||||||
|
|
||||||
check_unknown_options!
|
check_unknown_options!
|
||||||
|
|
||||||
namespace :extension
|
namespace :extension
|
||||||
|
|
||||||
# Required path for the new project to be generated
|
# Required path for the new project to be generated
|
||||||
argument :name, :type => :string
|
argument :name, :type => :string
|
||||||
|
|
||||||
desc "extension [options]", "Create Middleman extension scaffold NAME"
|
desc "extension [options]", "Create Middleman extension scaffold NAME"
|
||||||
|
|
||||||
# The extension task
|
# The extension task
|
||||||
# @param [String] name
|
# @param [String] name
|
||||||
def extension
|
def extension
|
||||||
|
@ -25,7 +25,7 @@ module Middleman::Cli
|
||||||
template "features/support/env.rb", File.join(name, "features", "support", "env.rb")
|
template "features/support/env.rb", File.join(name, "features", "support", "env.rb")
|
||||||
empty_directory File.join(name, "fixtures")
|
empty_directory File.join(name, "fixtures")
|
||||||
end
|
end
|
||||||
|
|
||||||
# Template files are relative to this file
|
# Template files are relative to this file
|
||||||
# @return [String]
|
# @return [String]
|
||||||
def self.source_root
|
def self.source_root
|
||||||
|
|
|
@ -2,35 +2,35 @@ require "middleman-core/templates"
|
||||||
|
|
||||||
# CLI Module
|
# CLI Module
|
||||||
module Middleman::Cli
|
module Middleman::Cli
|
||||||
|
|
||||||
# A thor task for creating new projects
|
# A thor task for creating new projects
|
||||||
class Init < Thor
|
class Init < Thor
|
||||||
check_unknown_options!
|
check_unknown_options!
|
||||||
|
|
||||||
namespace :init
|
namespace :init
|
||||||
|
|
||||||
desc "init NAME [options]", "Create new project NAME"
|
desc "init NAME [options]", "Create new project NAME"
|
||||||
available_templates = ::Middleman::Templates.registered.keys.join(", ")
|
available_templates = ::Middleman::Templates.registered.keys.join(", ")
|
||||||
method_option "template",
|
method_option "template",
|
||||||
:aliases => "-T",
|
:aliases => "-T",
|
||||||
:default => "default",
|
:default => "default",
|
||||||
:desc => "Use a project template: #{available_templates}"
|
:desc => "Use a project template: #{available_templates}"
|
||||||
method_option "css_dir",
|
method_option "css_dir",
|
||||||
# :default => "stylesheets",
|
# :default => "stylesheets",
|
||||||
:desc => 'The path to the css files'
|
:desc => 'The path to the css files'
|
||||||
method_option "js_dir",
|
method_option "js_dir",
|
||||||
# :default => "javascripts",
|
# :default => "javascripts",
|
||||||
:desc => 'The path to the javascript files'
|
:desc => 'The path to the javascript files'
|
||||||
method_option "images_dir",
|
method_option "images_dir",
|
||||||
# :default => "images",
|
# :default => "images",
|
||||||
:desc => 'The path to the image files'
|
:desc => 'The path to the image files'
|
||||||
method_option "rack",
|
method_option "rack",
|
||||||
:type => :boolean,
|
:type => :boolean,
|
||||||
:default => false,
|
:default => false,
|
||||||
:desc => 'Include a config.ru file'
|
:desc => 'Include a config.ru file'
|
||||||
method_option "bundler",
|
method_option "bundler",
|
||||||
:type => :boolean,
|
:type => :boolean,
|
||||||
:default => false,
|
:default => false,
|
||||||
:desc => 'Create a Gemfile and use Bundler to manage gems'
|
:desc => 'Create a Gemfile and use Bundler to manage gems'
|
||||||
# The init task
|
# The init task
|
||||||
# @param [String] name
|
# @param [String] name
|
||||||
|
@ -39,7 +39,7 @@ module Middleman::Cli
|
||||||
unless ::Middleman::Templates.registered.has_key?(key)
|
unless ::Middleman::Templates.registered.has_key?(key)
|
||||||
raise Thor::Error.new "Unknown project template '#{key}'"
|
raise Thor::Error.new "Unknown project template '#{key}'"
|
||||||
end
|
end
|
||||||
|
|
||||||
thor_group = ::Middleman::Templates.registered[key]
|
thor_group = ::Middleman::Templates.registered[key]
|
||||||
thor_group.new([name], options).invoke_all
|
thor_group.new([name], options).invoke_all
|
||||||
end
|
end
|
||||||
|
@ -48,7 +48,7 @@ module Middleman::Cli
|
||||||
def self.exit_on_failure?
|
def self.exit_on_failure?
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|
||||||
# Map "i", "new" and "n" to "init"
|
# Map "i", "new" and "n" to "init"
|
||||||
Base.map({
|
Base.map({
|
||||||
"i" => "init",
|
"i" => "init",
|
||||||
|
|
|
@ -1,36 +1,36 @@
|
||||||
# CLI Module
|
# CLI Module
|
||||||
module Middleman::Cli
|
module Middleman::Cli
|
||||||
|
|
||||||
# Server thor task
|
# Server thor task
|
||||||
class Server < Thor
|
class Server < Thor
|
||||||
check_unknown_options!
|
check_unknown_options!
|
||||||
|
|
||||||
namespace :server
|
namespace :server
|
||||||
|
|
||||||
desc "server [options]", "Start the preview server"
|
desc "server [options]", "Start the preview server"
|
||||||
method_option :environment,
|
method_option :environment,
|
||||||
:aliases => "-e",
|
:aliases => "-e",
|
||||||
:default => ENV['MM_ENV'] || ENV['RACK_ENV'] || 'development',
|
:default => ENV['MM_ENV'] || ENV['RACK_ENV'] || 'development',
|
||||||
:desc => "The environment Middleman will run under"
|
:desc => "The environment Middleman will run under"
|
||||||
method_option :host,
|
method_option :host,
|
||||||
:type => :string,
|
:type => :string,
|
||||||
:aliases => "-h",
|
:aliases => "-h",
|
||||||
:default => "0.0.0.0",
|
:default => "0.0.0.0",
|
||||||
:desc => "Bind to HOST address"
|
:desc => "Bind to HOST address"
|
||||||
method_option :port,
|
method_option :port,
|
||||||
:aliases => "-p",
|
:aliases => "-p",
|
||||||
:default => "4567",
|
:default => "4567",
|
||||||
:desc => "The port Middleman will listen on"
|
:desc => "The port Middleman will listen on"
|
||||||
method_option :verbose,
|
method_option :verbose,
|
||||||
:type => :boolean,
|
:type => :boolean,
|
||||||
:default => false,
|
:default => false,
|
||||||
:desc => 'Print debug messages'
|
:desc => 'Print debug messages'
|
||||||
method_option :instrument,
|
method_option :instrument,
|
||||||
:type => :string,
|
:type => :string,
|
||||||
:default => false,
|
:default => false,
|
||||||
:desc => 'Print instrument messages'
|
:desc => 'Print instrument messages'
|
||||||
method_option "disable-watcher",
|
method_option "disable-watcher",
|
||||||
:type => :boolean,
|
:type => :boolean,
|
||||||
:default => false,
|
:default => false,
|
||||||
:desc => 'Disable the file change and delete watcher process'
|
:desc => 'Disable the file change and delete watcher process'
|
||||||
method_option :profile,
|
method_option :profile,
|
||||||
|
@ -42,7 +42,7 @@ module Middleman::Cli
|
||||||
def server
|
def server
|
||||||
require "middleman-core"
|
require "middleman-core"
|
||||||
require "middleman-core/preview_server"
|
require "middleman-core/preview_server"
|
||||||
|
|
||||||
if !ENV["MM_ROOT"]
|
if !ENV["MM_ROOT"]
|
||||||
puts "== Could not find a Middleman project config.rb"
|
puts "== Could not find a Middleman project config.rb"
|
||||||
puts "== Treating directory as a static site to be served"
|
puts "== Treating directory as a static site to be served"
|
||||||
|
@ -58,7 +58,7 @@ module Middleman::Cli
|
||||||
:instrumenting => options["instrument"],
|
:instrumenting => options["instrument"],
|
||||||
:"disable-watcher" => options["disable-watcher"]
|
:"disable-watcher" => options["disable-watcher"]
|
||||||
}
|
}
|
||||||
|
|
||||||
puts "== The Middleman is loading"
|
puts "== The Middleman is loading"
|
||||||
::Middleman::PreviewServer.start(params)
|
::Middleman::PreviewServer.start(params)
|
||||||
end
|
end
|
||||||
|
@ -66,8 +66,8 @@ module Middleman::Cli
|
||||||
|
|
||||||
def self.exit_on_failure?
|
def self.exit_on_failure?
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|
||||||
# Map "s" to "server"
|
# Map "s" to "server"
|
||||||
Base.map({ "s" => "server" })
|
Base.map({ "s" => "server" })
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
module Middleman
|
module Middleman
|
||||||
module CoreExtensions
|
module CoreExtensions
|
||||||
|
|
||||||
# Convenience methods to allow config.rb to talk to the Builder
|
# Convenience methods to allow config.rb to talk to the Builder
|
||||||
module Builder
|
module Builder
|
||||||
|
|
||||||
# Extension registered
|
# Extension registered
|
||||||
class << self
|
class << self
|
||||||
# @private
|
# @private
|
||||||
|
@ -14,4 +14,4 @@ module Middleman
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
56
middleman-core/lib/middleman-core/core_extensions/data.rb
Executable file → Normal file
56
middleman-core/lib/middleman-core/core_extensions/data.rb
Executable file → Normal file
|
@ -1,10 +1,10 @@
|
||||||
module Middleman
|
module Middleman
|
||||||
module CoreExtensions
|
module CoreExtensions
|
||||||
|
|
||||||
# The data extension parses YAML and JSON files in the data/ directory
|
# The data extension parses YAML and JSON files in the data/ directory
|
||||||
# and makes them available to config.rb, templates and extensions
|
# and makes them available to config.rb, templates and extensions
|
||||||
module Data
|
module Data
|
||||||
|
|
||||||
# Extension registered
|
# Extension registered
|
||||||
class << self
|
class << self
|
||||||
# @private
|
# @private
|
||||||
|
@ -12,13 +12,13 @@ module Middleman
|
||||||
# Data formats
|
# Data formats
|
||||||
require "yaml"
|
require "yaml"
|
||||||
require "active_support/json"
|
require "active_support/json"
|
||||||
|
|
||||||
app.set :data_dir, "data"
|
app.set :data_dir, "data"
|
||||||
app.send :include, InstanceMethods
|
app.send :include, InstanceMethods
|
||||||
end
|
end
|
||||||
alias :included :registered
|
alias :included :registered
|
||||||
end
|
end
|
||||||
|
|
||||||
# Instance methods
|
# Instance methods
|
||||||
module InstanceMethods
|
module InstanceMethods
|
||||||
# Setup data files before anything else so they are available when
|
# Setup data files before anything else so they are available when
|
||||||
|
@ -27,14 +27,14 @@ module Middleman
|
||||||
self.files.changed DataStore.matcher do |file|
|
self.files.changed DataStore.matcher do |file|
|
||||||
self.data.touch_file(file) if file.match(%r{^#{self.data_dir}\/})
|
self.data.touch_file(file) if file.match(%r{^#{self.data_dir}\/})
|
||||||
end
|
end
|
||||||
|
|
||||||
self.files.deleted DataStore.matcher do |file|
|
self.files.deleted DataStore.matcher do |file|
|
||||||
self.data.remove_file(file) if file.match(%r{^#{self.data_dir}\/})
|
self.data.remove_file(file) if file.match(%r{^#{self.data_dir}\/})
|
||||||
end
|
end
|
||||||
|
|
||||||
super
|
super
|
||||||
end
|
end
|
||||||
|
|
||||||
# The data object
|
# The data object
|
||||||
#
|
#
|
||||||
# @return [DataStore]
|
# @return [DataStore]
|
||||||
|
@ -42,13 +42,13 @@ module Middleman
|
||||||
@_data ||= DataStore.new(self)
|
@_data ||= DataStore.new(self)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# The core logic behind the data extension.
|
# The core logic behind the data extension.
|
||||||
class DataStore
|
class DataStore
|
||||||
|
|
||||||
# Static methods
|
# Static methods
|
||||||
class << self
|
class << self
|
||||||
|
|
||||||
# The regex which tells Middleman which files are for data
|
# The regex which tells Middleman which files are for data
|
||||||
#
|
#
|
||||||
# @return [Regexp]
|
# @return [Regexp]
|
||||||
|
@ -56,7 +56,7 @@ module Middleman
|
||||||
%r{[\w-]+\.(yml|yaml|json)$}
|
%r{[\w-]+\.(yml|yaml|json)$}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Store static data hash
|
# Store static data hash
|
||||||
#
|
#
|
||||||
# @param [Symbol] name Name of the data, used for namespacing
|
# @param [Symbol] name Name of the data, used for namespacing
|
||||||
|
@ -78,7 +78,7 @@ module Middleman
|
||||||
@_callback_sources[name.to_s] = proc unless name.nil? || proc.nil?
|
@_callback_sources[name.to_s] = proc unless name.nil? || proc.nil?
|
||||||
@_callback_sources
|
@_callback_sources
|
||||||
end
|
end
|
||||||
|
|
||||||
# Setup data store
|
# Setup data store
|
||||||
#
|
#
|
||||||
# @param [Middleman::Application] app The current instance of Middleman
|
# @param [Middleman::Application] app The current instance of Middleman
|
||||||
|
@ -86,7 +86,7 @@ module Middleman
|
||||||
@app = app
|
@app = app
|
||||||
@local_data = {}
|
@local_data = {}
|
||||||
end
|
end
|
||||||
|
|
||||||
# Update the internal cache for a given file path
|
# Update the internal cache for a given file path
|
||||||
#
|
#
|
||||||
# @param [String] file The file to be re-parsed
|
# @param [String] file The file to be re-parsed
|
||||||
|
@ -95,7 +95,7 @@ module Middleman
|
||||||
file = File.expand_path(file, @app.root)
|
file = File.expand_path(file, @app.root)
|
||||||
extension = File.extname(file)
|
extension = File.extname(file)
|
||||||
basename = File.basename(file, extension)
|
basename = File.basename(file, extension)
|
||||||
|
|
||||||
if %w(.yaml .yml).include?(extension)
|
if %w(.yaml .yml).include?(extension)
|
||||||
data = YAML.load_file(file)
|
data = YAML.load_file(file)
|
||||||
elsif extension == ".json"
|
elsif extension == ".json"
|
||||||
|
@ -106,7 +106,7 @@ module Middleman
|
||||||
|
|
||||||
@local_data[basename] = ::Middleman::Util.recursively_enhance(data)
|
@local_data[basename] = ::Middleman::Util.recursively_enhance(data)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Remove a given file from the internal cache
|
# Remove a given file from the internal cache
|
||||||
#
|
#
|
||||||
# @param [String] file The file to be cleared
|
# @param [String] file The file to be cleared
|
||||||
|
@ -116,26 +116,26 @@ module Middleman
|
||||||
basename = File.basename(file, extension)
|
basename = File.basename(file, extension)
|
||||||
@local_data.delete(basename) if @local_data.has_key?(basename)
|
@local_data.delete(basename) if @local_data.has_key?(basename)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Get a hash hash from either internal static data or a callback
|
# Get a hash hash from either internal static data or a callback
|
||||||
#
|
#
|
||||||
# @param [String, Symbol] path The name of the data namespace
|
# @param [String, Symbol] path The name of the data namespace
|
||||||
# @return [Hash, nil]
|
# @return [Hash, nil]
|
||||||
def data_for_path(path)
|
def data_for_path(path)
|
||||||
response = nil
|
response = nil
|
||||||
|
|
||||||
@@local_sources ||= {}
|
@@local_sources ||= {}
|
||||||
@@callback_sources ||= {}
|
@@callback_sources ||= {}
|
||||||
|
|
||||||
if self.store.has_key?(path.to_s)
|
if self.store.has_key?(path.to_s)
|
||||||
response = self.store[path.to_s]
|
response = self.store[path.to_s]
|
||||||
elsif self.callbacks.has_key?(path.to_s)
|
elsif self.callbacks.has_key?(path.to_s)
|
||||||
response = self.callbacks[path.to_s].call()
|
response = self.callbacks[path.to_s].call()
|
||||||
end
|
end
|
||||||
|
|
||||||
response
|
response
|
||||||
end
|
end
|
||||||
|
|
||||||
# "Magically" find namespaces of data if they exist
|
# "Magically" find namespaces of data if they exist
|
||||||
#
|
#
|
||||||
# @param [String] path The namespace to search for
|
# @param [String] path The namespace to search for
|
||||||
|
@ -145,36 +145,36 @@ module Middleman
|
||||||
return @local_data[path.to_s]
|
return @local_data[path.to_s]
|
||||||
else
|
else
|
||||||
result = data_for_path(path)
|
result = data_for_path(path)
|
||||||
|
|
||||||
if result
|
if result
|
||||||
return ::Middleman::Util.recursively_enhance(result)
|
return ::Middleman::Util.recursively_enhance(result)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
super
|
super
|
||||||
end
|
end
|
||||||
|
|
||||||
# Convert all the data into a static hash
|
# Convert all the data into a static hash
|
||||||
#
|
#
|
||||||
# @return [Hash]
|
# @return [Hash]
|
||||||
def to_h
|
def to_h
|
||||||
data = {}
|
data = {}
|
||||||
|
|
||||||
self.store.each do |k, v|
|
self.store.each do |k, v|
|
||||||
data[k] = data_for_path(k)
|
data[k] = data_for_path(k)
|
||||||
end
|
end
|
||||||
|
|
||||||
self.callbacks.each do |k, v|
|
self.callbacks.each do |k, v|
|
||||||
data[k] = data_for_path(k)
|
data[k] = data_for_path(k)
|
||||||
end
|
end
|
||||||
|
|
||||||
(@local_data || {}).each do |k, v|
|
(@local_data || {}).each do |k, v|
|
||||||
data[k] = v
|
data[k] = v
|
||||||
end
|
end
|
||||||
|
|
||||||
data
|
data
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -32,7 +32,7 @@
|
||||||
module Middleman
|
module Middleman
|
||||||
module CoreExtensions
|
module CoreExtensions
|
||||||
module Extensions
|
module Extensions
|
||||||
|
|
||||||
# Register extension
|
# Register extension
|
||||||
class << self
|
class << self
|
||||||
# @private
|
# @private
|
||||||
|
@ -44,13 +44,13 @@ module Middleman
|
||||||
app.define_hook :before_configuration
|
app.define_hook :before_configuration
|
||||||
app.define_hook :build_config
|
app.define_hook :build_config
|
||||||
app.define_hook :development_config
|
app.define_hook :development_config
|
||||||
|
|
||||||
if ENV["AUTOLOAD_SPROCKETS"]
|
if ENV["AUTOLOAD_SPROCKETS"]
|
||||||
app.set :autoload_sprockets, (ENV["AUTOLOAD_SPROCKETS"] == "true")
|
app.set :autoload_sprockets, (ENV["AUTOLOAD_SPROCKETS"] == "true")
|
||||||
else
|
else
|
||||||
app.set :autoload_sprockets, true
|
app.set :autoload_sprockets, true
|
||||||
end
|
end
|
||||||
|
|
||||||
app.extend ClassMethods
|
app.extend ClassMethods
|
||||||
app.send :include, InstanceMethods
|
app.send :include, InstanceMethods
|
||||||
app.delegate :configure, :to => :"self.class"
|
app.delegate :configure, :to => :"self.class"
|
||||||
|
@ -67,23 +67,23 @@ module Middleman
|
||||||
def configure(env, &block)
|
def configure(env, &block)
|
||||||
send("#{env}_config", &block)
|
send("#{env}_config", &block)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Alias `extensions` to access registered extensions
|
# Alias `extensions` to access registered extensions
|
||||||
#
|
#
|
||||||
# @return [Array<Module>]
|
# @return [Array<Module>]
|
||||||
def extensions
|
def extensions
|
||||||
@extensions ||= []
|
@extensions ||= []
|
||||||
end
|
end
|
||||||
|
|
||||||
# Register a new extension
|
# Register a new extension
|
||||||
#
|
#
|
||||||
# @param [Module] extension Extension modules to register
|
# @param [Module] extension Extension modules to register
|
||||||
# @param [Hash] options Per-extension options hash
|
# @param [Hash] options Per-extension options hash
|
||||||
# @return [void]
|
# @return [void]
|
||||||
def register(extension, options={}, &block)
|
def register(extension, options={}, &block)
|
||||||
@extensions ||= []
|
@extensions ||= []
|
||||||
@extensions += [extension]
|
@extensions += [extension]
|
||||||
|
|
||||||
extend extension
|
extend extension
|
||||||
if extension.respond_to?(:registered)
|
if extension.respond_to?(:registered)
|
||||||
if extension.method(:registered).arity === 1
|
if extension.method(:registered).arity === 1
|
||||||
|
@ -94,7 +94,7 @@ module Middleman
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Instance methods
|
# Instance methods
|
||||||
module InstanceMethods
|
module InstanceMethods
|
||||||
# This method is available in the project's `config.rb`.
|
# This method is available in the project's `config.rb`.
|
||||||
|
@ -111,7 +111,7 @@ module Middleman
|
||||||
else
|
else
|
||||||
::Middleman::Extensions.load(ext.to_sym)
|
::Middleman::Extensions.load(ext.to_sym)
|
||||||
end
|
end
|
||||||
|
|
||||||
if ext_module.nil?
|
if ext_module.nil?
|
||||||
logger.warning "== Unknown Extension: #{ext}"
|
logger.warning "== Unknown Extension: #{ext}"
|
||||||
else
|
else
|
||||||
|
@ -119,24 +119,24 @@ module Middleman
|
||||||
self.class.register(ext_module, options, &block)
|
self.class.register(ext_module, options, &block)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Load features before starting server
|
# Load features before starting server
|
||||||
def initialize
|
def initialize
|
||||||
super
|
super
|
||||||
|
|
||||||
self.class.inst = self
|
self.class.inst = self
|
||||||
run_hook :before_configuration
|
run_hook :before_configuration
|
||||||
|
|
||||||
# Search the root of the project for required files
|
# Search the root of the project for required files
|
||||||
$LOAD_PATH.unshift(root)
|
$LOAD_PATH.unshift(root)
|
||||||
|
|
||||||
# Check for and evaluate local configuration
|
# Check for and evaluate local configuration
|
||||||
local_config = File.join(root, "config.rb")
|
local_config = File.join(root, "config.rb")
|
||||||
if File.exists? local_config
|
if File.exists? local_config
|
||||||
logger.debug "== Reading: Local config"
|
logger.debug "== Reading: Local config"
|
||||||
instance_eval File.read(local_config), local_config, 1
|
instance_eval File.read(local_config), local_config, 1
|
||||||
end
|
end
|
||||||
|
|
||||||
if autoload_sprockets
|
if autoload_sprockets
|
||||||
begin
|
begin
|
||||||
require "middleman-sprockets"
|
require "middleman-sprockets"
|
||||||
|
@ -144,12 +144,12 @@ module Middleman
|
||||||
rescue LoadError
|
rescue LoadError
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
run_hook :build_config if build?
|
run_hook :build_config if build?
|
||||||
run_hook :development_config if development?
|
run_hook :development_config if development?
|
||||||
|
|
||||||
run_hook :after_configuration
|
run_hook :after_configuration
|
||||||
|
|
||||||
logger.debug "Loaded extensions:"
|
logger.debug "Loaded extensions:"
|
||||||
self.class.extensions.each do |ext|
|
self.class.extensions.each do |ext|
|
||||||
logger.debug "== Extension: #{ext}"
|
logger.debug "== Extension: #{ext}"
|
||||||
|
@ -158,4 +158,4 @@ module Middleman
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -2,10 +2,10 @@
|
||||||
module Middleman
|
module Middleman
|
||||||
module CoreExtensions
|
module CoreExtensions
|
||||||
module ExternalHelpers
|
module ExternalHelpers
|
||||||
|
|
||||||
# Setup extension
|
# Setup extension
|
||||||
class << self
|
class << self
|
||||||
|
|
||||||
# once registered
|
# once registered
|
||||||
def registered(app)
|
def registered(app)
|
||||||
# Setup a default helpers paths
|
# Setup a default helpers paths
|
||||||
|
@ -15,19 +15,19 @@ module Middleman
|
||||||
basename = File.basename(filename, File.extname(filename))
|
basename = File.basename(filename, File.extname(filename))
|
||||||
basename.camelcase
|
basename.camelcase
|
||||||
}
|
}
|
||||||
|
|
||||||
# After config
|
# After config
|
||||||
app.after_configuration do
|
app.after_configuration do
|
||||||
helpers_path = File.expand_path(helpers_dir, root)
|
helpers_path = File.expand_path(helpers_dir, root)
|
||||||
next unless File.exists?(helpers_path)
|
next unless File.exists?(helpers_path)
|
||||||
|
|
||||||
Dir[File.join(helpers_path, helpers_filename_glob)].each do |filename|
|
Dir[File.join(helpers_path, helpers_filename_glob)].each do |filename|
|
||||||
module_name = helpers_filename_to_module_name_proc.call(filename)
|
module_name = helpers_filename_to_module_name_proc.call(filename)
|
||||||
next unless module_name
|
next unless module_name
|
||||||
|
|
||||||
require filename
|
require filename
|
||||||
next unless Object.const_defined?(module_name.to_sym)
|
next unless Object.const_defined?(module_name.to_sym)
|
||||||
|
|
||||||
helpers Object.const_get(module_name.to_sym)
|
helpers Object.const_get(module_name.to_sym)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -36,4 +36,4 @@ module Middleman
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -5,7 +5,7 @@ require "set"
|
||||||
module Middleman
|
module Middleman
|
||||||
module CoreExtensions
|
module CoreExtensions
|
||||||
module FileWatcher
|
module FileWatcher
|
||||||
|
|
||||||
IGNORE_LIST = [
|
IGNORE_LIST = [
|
||||||
/^\.bundle\//,
|
/^\.bundle\//,
|
||||||
/^\.sass-cache\//,
|
/^\.sass-cache\//,
|
||||||
|
@ -22,16 +22,16 @@ module Middleman
|
||||||
|
|
||||||
# Setup extension
|
# Setup extension
|
||||||
class << self
|
class << self
|
||||||
|
|
||||||
# Once registered
|
# Once registered
|
||||||
def registered(app)
|
def registered(app)
|
||||||
app.send :include, InstanceMethods
|
app.send :include, InstanceMethods
|
||||||
|
|
||||||
# Before parsing config, load the data/ directory
|
# Before parsing config, load the data/ directory
|
||||||
app.before_configuration do
|
app.before_configuration do
|
||||||
files.reload_path(data_dir)
|
files.reload_path(data_dir)
|
||||||
end
|
end
|
||||||
|
|
||||||
# After config, load everything else
|
# After config, load everything else
|
||||||
app.ready do
|
app.ready do
|
||||||
files.reload_path('.')
|
files.reload_path('.')
|
||||||
|
@ -39,32 +39,32 @@ module Middleman
|
||||||
end
|
end
|
||||||
alias :included :registered
|
alias :included :registered
|
||||||
end
|
end
|
||||||
|
|
||||||
# Instance methods
|
# Instance methods
|
||||||
module InstanceMethods
|
module InstanceMethods
|
||||||
|
|
||||||
# Access the file api
|
# Access the file api
|
||||||
# @return [Middleman::CoreExtensions::FileWatcher::API]
|
# @return [Middleman::CoreExtensions::FileWatcher::API]
|
||||||
def files
|
def files
|
||||||
@_files_api ||= API.new(self)
|
@_files_api ||= API.new(self)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Core File Change API class
|
# Core File Change API class
|
||||||
class API
|
class API
|
||||||
|
|
||||||
attr_reader :app
|
attr_reader :app
|
||||||
delegate :logger, :to => :app
|
delegate :logger, :to => :app
|
||||||
|
|
||||||
# Initialize api and internal path cache
|
# Initialize api and internal path cache
|
||||||
def initialize(app)
|
def initialize(app)
|
||||||
@app = app
|
@app = app
|
||||||
@known_paths = Set.new
|
@known_paths = Set.new
|
||||||
|
|
||||||
@_changed = []
|
@_changed = []
|
||||||
@_deleted = []
|
@_deleted = []
|
||||||
end
|
end
|
||||||
|
|
||||||
# Add callback to be run on file change
|
# Add callback to be run on file change
|
||||||
#
|
#
|
||||||
# @param [nil,Regexp] matcher A Regexp to match the change path against
|
# @param [nil,Regexp] matcher A Regexp to match the change path against
|
||||||
|
@ -73,7 +73,7 @@ module Middleman
|
||||||
@_changed << [block, matcher] if block_given?
|
@_changed << [block, matcher] if block_given?
|
||||||
@_changed
|
@_changed
|
||||||
end
|
end
|
||||||
|
|
||||||
# Add callback to be run on file deletion
|
# Add callback to be run on file deletion
|
||||||
#
|
#
|
||||||
# @param [nil,Regexp] matcher A Regexp to match the deleted path against
|
# @param [nil,Regexp] matcher A Regexp to match the deleted path against
|
||||||
|
@ -82,7 +82,7 @@ module Middleman
|
||||||
@_deleted << [block, matcher] if block_given?
|
@_deleted << [block, matcher] if block_given?
|
||||||
@_deleted
|
@_deleted
|
||||||
end
|
end
|
||||||
|
|
||||||
# Notify callbacks that a file changed
|
# Notify callbacks that a file changed
|
||||||
#
|
#
|
||||||
# @param [Pathname] path The file that changed
|
# @param [Pathname] path The file that changed
|
||||||
|
@ -104,7 +104,7 @@ module Middleman
|
||||||
@known_paths.delete(path)
|
@known_paths.delete(path)
|
||||||
self.run_callbacks(path, :deleted)
|
self.run_callbacks(path, :deleted)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Manually trigger update events
|
# Manually trigger update events
|
||||||
#
|
#
|
||||||
# @param [Pathname] path The path to reload
|
# @param [Pathname] path The path to reload
|
||||||
|
@ -115,20 +115,20 @@ module Middleman
|
||||||
Dir.chdir @app.root_path do
|
Dir.chdir @app.root_path do
|
||||||
path = Pathname(path)
|
path = Pathname(path)
|
||||||
return unless path.exist?
|
return unless path.exist?
|
||||||
|
|
||||||
glob = (path + "**/*").to_s
|
glob = (path + "**/*").to_s
|
||||||
subset = @known_paths.select { |p| p.fnmatch(glob) }
|
subset = @known_paths.select { |p| p.fnmatch(glob) }
|
||||||
|
|
||||||
::Middleman::Util.all_files_under(path).each do |filepath|
|
::Middleman::Util.all_files_under(path).each do |filepath|
|
||||||
if only_new
|
if only_new
|
||||||
next if subset.include?(filepath)
|
next if subset.include?(filepath)
|
||||||
else
|
else
|
||||||
subset.delete(filepath)
|
subset.delete(filepath)
|
||||||
end
|
end
|
||||||
|
|
||||||
self.did_change(filepath)
|
self.did_change(filepath)
|
||||||
end
|
end
|
||||||
|
|
||||||
subset.each(&method(:did_delete)) unless only_new
|
subset.each(&method(:did_delete)) unless only_new
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -140,7 +140,7 @@ module Middleman
|
||||||
def find_new_files(path)
|
def find_new_files(path)
|
||||||
reload_path(path, true)
|
reload_path(path, true)
|
||||||
end
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
# Whether this path is ignored
|
# Whether this path is ignored
|
||||||
# @param [Pathname] path
|
# @param [Pathname] path
|
||||||
|
@ -148,7 +148,7 @@ module Middleman
|
||||||
def ignored?(path)
|
def ignored?(path)
|
||||||
IGNORE_LIST.any? { |r| path.to_s.match(r) }
|
IGNORE_LIST.any? { |r| path.to_s.match(r) }
|
||||||
end
|
end
|
||||||
|
|
||||||
# Notify callbacks for a file given an array of callbacks
|
# Notify callbacks for a file given an array of callbacks
|
||||||
#
|
#
|
||||||
# @param [Pathname] path The file that was changed
|
# @param [Pathname] path The file that was changed
|
||||||
|
|
|
@ -1,22 +1,22 @@
|
||||||
# Extensions namespace
|
# Extensions namespace
|
||||||
module Middleman::CoreExtensions
|
module Middleman::CoreExtensions
|
||||||
|
|
||||||
# Frontmatter namespace
|
# Frontmatter namespace
|
||||||
module FrontMatter
|
module FrontMatter
|
||||||
|
|
||||||
# Setup extension
|
# Setup extension
|
||||||
class << self
|
class << self
|
||||||
|
|
||||||
# Once registered
|
# Once registered
|
||||||
def registered(app)
|
def registered(app)
|
||||||
# Parsing YAML frontmatter
|
# Parsing YAML frontmatter
|
||||||
require "yaml"
|
require "yaml"
|
||||||
|
|
||||||
# Parsing JSON frontmatter
|
# Parsing JSON frontmatter
|
||||||
require "active_support/json"
|
require "active_support/json"
|
||||||
|
|
||||||
app.send :include, InstanceMethods
|
app.send :include, InstanceMethods
|
||||||
|
|
||||||
app.before_configuration do
|
app.before_configuration do
|
||||||
files.changed { |file| frontmatter_manager.clear_data(file) }
|
files.changed { |file| frontmatter_manager.clear_data(file) }
|
||||||
files.deleted { |file| frontmatter_manager.clear_data(file) }
|
files.deleted { |file| frontmatter_manager.clear_data(file) }
|
||||||
|
@ -29,36 +29,36 @@ module Middleman::CoreExtensions
|
||||||
:frontmatter,
|
:frontmatter,
|
||||||
frontmatter_manager
|
frontmatter_manager
|
||||||
)
|
)
|
||||||
|
|
||||||
sitemap.provides_metadata do |path|
|
sitemap.provides_metadata do |path|
|
||||||
fmdata = frontmatter_manager.data(path).first
|
fmdata = frontmatter_manager.data(path).first
|
||||||
|
|
||||||
data = {}
|
data = {}
|
||||||
%w(layout layout_engine).each do |opt|
|
%w(layout layout_engine).each do |opt|
|
||||||
data[opt.to_sym] = fmdata[opt] unless fmdata[opt].nil?
|
data[opt.to_sym] = fmdata[opt] unless fmdata[opt].nil?
|
||||||
end
|
end
|
||||||
|
|
||||||
{ :options => data, :page => fmdata }
|
{ :options => data, :page => fmdata }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
alias :included :registered
|
alias :included :registered
|
||||||
end
|
end
|
||||||
|
|
||||||
class FrontmatterManager
|
class FrontmatterManager
|
||||||
attr_reader :app
|
attr_reader :app
|
||||||
delegate :logger, :to => :app
|
delegate :logger, :to => :app
|
||||||
|
|
||||||
def initialize(app)
|
def initialize(app)
|
||||||
@app = app
|
@app = app
|
||||||
@cache = {}
|
@cache = {}
|
||||||
end
|
end
|
||||||
|
|
||||||
def data(path)
|
def data(path)
|
||||||
p = normalize_path(path)
|
p = normalize_path(path)
|
||||||
@cache[p] ||= frontmatter_and_content(p)
|
@cache[p] ||= frontmatter_and_content(p)
|
||||||
end
|
end
|
||||||
|
|
||||||
def clear_data(file)
|
def clear_data(file)
|
||||||
# Copied from Sitemap::Store#file_to_path, but without
|
# Copied from Sitemap::Store#file_to_path, but without
|
||||||
# removing the file extension
|
# removing the file extension
|
||||||
|
@ -69,13 +69,13 @@ module Middleman::CoreExtensions
|
||||||
|
|
||||||
@cache.delete(path)
|
@cache.delete(path)
|
||||||
end
|
end
|
||||||
|
|
||||||
YAML_ERRORS = [ Exception, ArgumentError ]
|
YAML_ERRORS = [ Exception, ArgumentError ]
|
||||||
|
|
||||||
if defined?(Psych) && defined?(Psych::SyntaxError)
|
if defined?(Psych) && defined?(Psych::SyntaxError)
|
||||||
YAML_ERRORS << Psych::SyntaxError
|
YAML_ERRORS << Psych::SyntaxError
|
||||||
end
|
end
|
||||||
|
|
||||||
# Parse YAML frontmatter out of a string
|
# Parse YAML frontmatter out of a string
|
||||||
# @param [String] content
|
# @param [String] content
|
||||||
# @return [Array<Hash, String>]
|
# @return [Array<Hash, String>]
|
||||||
|
@ -99,10 +99,10 @@ module Middleman::CoreExtensions
|
||||||
rescue
|
rescue
|
||||||
[{}, content]
|
[{}, content]
|
||||||
end
|
end
|
||||||
|
|
||||||
def parse_json_front_matter(content)
|
def parse_json_front_matter(content)
|
||||||
json_regex = /\A(;;;\s*\n.*?\n?)^(;;;\s*$\n?)/m
|
json_regex = /\A(;;;\s*\n.*?\n?)^(;;;\s*$\n?)/m
|
||||||
|
|
||||||
if content =~ json_regex
|
if content =~ json_regex
|
||||||
content = content.sub(json_regex, "")
|
content = content.sub(json_regex, "")
|
||||||
|
|
||||||
|
@ -122,16 +122,16 @@ module Middleman::CoreExtensions
|
||||||
rescue
|
rescue
|
||||||
[{}, content]
|
[{}, content]
|
||||||
end
|
end
|
||||||
|
|
||||||
# Get the frontmatter and plain content from a file
|
# Get the frontmatter and plain content from a file
|
||||||
# @param [String] path
|
# @param [String] path
|
||||||
# @return [Array<Thor::CoreExt::HashWithIndifferentAccess, String>]
|
# @return [Array<Thor::CoreExt::HashWithIndifferentAccess, String>]
|
||||||
def frontmatter_and_content(path)
|
def frontmatter_and_content(path)
|
||||||
full_path = File.expand_path(path, @app.source_dir)
|
full_path = File.expand_path(path, @app.source_dir)
|
||||||
|
|
||||||
content = File.read(full_path)
|
content = File.read(full_path)
|
||||||
data = {}
|
data = {}
|
||||||
|
|
||||||
begin
|
begin
|
||||||
if content =~ /\A.*coding:/
|
if content =~ /\A.*coding:/
|
||||||
lines = content.split(/\n/)
|
lines = content.split(/\n/)
|
||||||
|
@ -150,11 +150,11 @@ module Middleman::CoreExtensions
|
||||||
|
|
||||||
[::Middleman::Util.recursively_enhance(data).freeze, content]
|
[::Middleman::Util.recursively_enhance(data).freeze, content]
|
||||||
end
|
end
|
||||||
|
|
||||||
def normalize_path(path)
|
def normalize_path(path)
|
||||||
path.sub(@app.source_dir, "").sub(/^\//, "")
|
path.sub(@app.source_dir, "").sub(/^\//, "")
|
||||||
end
|
end
|
||||||
|
|
||||||
# Update the main sitemap resource list
|
# Update the main sitemap resource list
|
||||||
# @return [void]
|
# @return [void]
|
||||||
def manipulate_resource_list(resources)
|
def manipulate_resource_list(resources)
|
||||||
|
@ -163,21 +163,21 @@ module Middleman::CoreExtensions
|
||||||
r.frontmatter_ignored = true
|
r.frontmatter_ignored = true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
resources
|
resources
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
module ResourceInstanceMethods
|
module ResourceInstanceMethods
|
||||||
|
|
||||||
def frontmatter_ignored?
|
def frontmatter_ignored?
|
||||||
@_frontmatter_ignored || false
|
@_frontmatter_ignored || false
|
||||||
end
|
end
|
||||||
|
|
||||||
def frontmatter_ignored=(v)
|
def frontmatter_ignored=(v)
|
||||||
@_frontmatter_ignored = v
|
@_frontmatter_ignored = v
|
||||||
end
|
end
|
||||||
|
|
||||||
def ignored?
|
def ignored?
|
||||||
if frontmatter_ignored?
|
if frontmatter_ignored?
|
||||||
true
|
true
|
||||||
|
@ -193,21 +193,21 @@ module Middleman::CoreExtensions
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
module InstanceMethods
|
module InstanceMethods
|
||||||
|
|
||||||
# Access the Frontmatter API
|
# Access the Frontmatter API
|
||||||
def frontmatter_manager
|
def frontmatter_manager
|
||||||
@_frontmatter_manager ||= FrontmatterManager.new(self)
|
@_frontmatter_manager ||= FrontmatterManager.new(self)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Get the template data from a path
|
# Get the template data from a path
|
||||||
# @param [String] path
|
# @param [String] path
|
||||||
# @return [String]
|
# @return [String]
|
||||||
def template_data_for_file(path)
|
def template_data_for_file(path)
|
||||||
frontmatter_manager.data(path).last
|
frontmatter_manager.data(path).last
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -10,15 +10,15 @@ end
|
||||||
module Middleman
|
module Middleman
|
||||||
module CoreExtensions
|
module CoreExtensions
|
||||||
module Rendering
|
module Rendering
|
||||||
|
|
||||||
# Setup extension
|
# Setup extension
|
||||||
class << self
|
class << self
|
||||||
|
|
||||||
# Once registered
|
# Once registered
|
||||||
def registered(app)
|
def registered(app)
|
||||||
# Include methods
|
# Include methods
|
||||||
app.send :include, InstanceMethods
|
app.send :include, InstanceMethods
|
||||||
|
|
||||||
# Activate custom renderers
|
# Activate custom renderers
|
||||||
require "middleman-core/renderers/erb"
|
require "middleman-core/renderers/erb"
|
||||||
app.register Middleman::Renderers::ERb
|
app.register Middleman::Renderers::ERb
|
||||||
|
@ -61,7 +61,7 @@ module Middleman
|
||||||
app.register Middleman::Renderers::Slim
|
app.register Middleman::Renderers::Slim
|
||||||
rescue LoadError
|
rescue LoadError
|
||||||
end
|
end
|
||||||
|
|
||||||
# Less Support
|
# Less Support
|
||||||
begin
|
begin
|
||||||
require "middleman-core/renderers/less"
|
require "middleman-core/renderers/less"
|
||||||
|
@ -69,17 +69,17 @@ module Middleman
|
||||||
rescue LoadError
|
rescue LoadError
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
alias :included :registered
|
alias :included :registered
|
||||||
end
|
end
|
||||||
|
|
||||||
# Custom error class for handling
|
# Custom error class for handling
|
||||||
class TemplateNotFound < RuntimeError
|
class TemplateNotFound < RuntimeError
|
||||||
end
|
end
|
||||||
|
|
||||||
# Rendering instance methods
|
# Rendering instance methods
|
||||||
module InstanceMethods
|
module InstanceMethods
|
||||||
|
|
||||||
# Add or overwrite a default template extension
|
# Add or overwrite a default template extension
|
||||||
#
|
#
|
||||||
# @param [Hash] extension_map
|
# @param [Hash] extension_map
|
||||||
|
@ -89,7 +89,7 @@ module Middleman
|
||||||
@_template_extensions.merge!(extension_map) if extension_map
|
@_template_extensions.merge!(extension_map) if extension_map
|
||||||
@_template_extensions
|
@_template_extensions
|
||||||
end
|
end
|
||||||
|
|
||||||
# Render a template, with layout, given a path
|
# Render a template, with layout, given a path
|
||||||
#
|
#
|
||||||
# @param [String] path
|
# @param [String] path
|
||||||
|
@ -103,8 +103,8 @@ module Middleman
|
||||||
|
|
||||||
# Store last engine for later (could be inside nested renders)
|
# Store last engine for later (could be inside nested renders)
|
||||||
@current_engine, engine_was = engine, @current_engine
|
@current_engine, engine_was = engine, @current_engine
|
||||||
|
|
||||||
# Use a dup of self as a context so that instance variables set within
|
# Use a dup of self as a context so that instance variables set within
|
||||||
# the template don't persist for other templates.
|
# the template don't persist for other templates.
|
||||||
context = self.dup
|
context = self.dup
|
||||||
blocks.each do |block|
|
blocks.each do |block|
|
||||||
|
@ -126,26 +126,26 @@ module Middleman
|
||||||
raise "Tried to render a layout (calls yield) at #{path} like it was a template. Non-default layouts need to be in #{source}/layouts."
|
raise "Tried to render a layout (calls yield) at #{path} like it was a template. Non-default layouts need to be in #{source}/layouts."
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Certain output file types don't use layouts
|
# Certain output file types don't use layouts
|
||||||
needs_layout = !%w(.js .json .css .txt).include?(File.extname(path))
|
needs_layout = !%w(.js .json .css .txt).include?(File.extname(path))
|
||||||
|
|
||||||
# If we need a layout and have a layout, use it
|
# If we need a layout and have a layout, use it
|
||||||
if needs_layout && layout_path = fetch_layout(engine, opts)
|
if needs_layout && layout_path = fetch_layout(engine, opts)
|
||||||
content = render_individual_file(layout_path, locs, opts, context) { content }
|
content = render_individual_file(layout_path, locs, opts, context) { content }
|
||||||
end
|
end
|
||||||
|
|
||||||
# Return result
|
# Return result
|
||||||
content
|
content
|
||||||
ensure
|
ensure
|
||||||
# Pop all the saved variables from earlier as we may be returning to a
|
# Pop all the saved variables from earlier as we may be returning to a
|
||||||
# previous render (layouts, partials, nested layouts).
|
# previous render (layouts, partials, nested layouts).
|
||||||
@current_engine = engine_was
|
@current_engine = engine_was
|
||||||
@content_blocks = nil
|
@content_blocks = nil
|
||||||
@current_locs = nil
|
@current_locs = nil
|
||||||
@current_opts = nil
|
@current_opts = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
# Sinatra/Padrino compatible render method signature referenced by some view
|
# Sinatra/Padrino compatible render method signature referenced by some view
|
||||||
# helpers. Especially partials.
|
# helpers. Especially partials.
|
||||||
#
|
#
|
||||||
|
@ -179,7 +179,7 @@ module Middleman
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Look in the root for the partial with the current engine
|
# Look in the root for the partial with the current engine
|
||||||
if !found_partial && !engine.nil?
|
if !found_partial && !engine.nil?
|
||||||
found_partial, found_engine = resolve_template(data, :preferred_engine => engine, :try_without_underscore => true)
|
found_partial, found_engine = resolve_template(data, :preferred_engine => engine, :try_without_underscore => true)
|
||||||
|
@ -207,17 +207,17 @@ module Middleman
|
||||||
# @return [String]
|
# @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
|
path = path.to_s
|
||||||
|
|
||||||
# Save current buffer for later
|
# Save current buffer for later
|
||||||
@_out_buf, _buf_was = "", @_out_buf
|
@_out_buf, _buf_was = "", @_out_buf
|
||||||
|
|
||||||
# Read from disk or cache the contents of the file
|
# Read from disk or cache the contents of the file
|
||||||
body = if opts[:template_body]
|
body = if opts[:template_body]
|
||||||
opts.delete(:template_body)
|
opts.delete(:template_body)
|
||||||
else
|
else
|
||||||
template_data_for_file(path)
|
template_data_for_file(path)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Merge per-extension options from config
|
# Merge per-extension options from config
|
||||||
extension = File.extname(path)
|
extension = File.extname(path)
|
||||||
options = opts.merge(options_for_ext(extension))
|
options = opts.merge(options_for_ext(extension))
|
||||||
|
@ -234,15 +234,15 @@ module Middleman
|
||||||
# Reset stored buffer
|
# Reset stored buffer
|
||||||
@_out_buf = _buf_was
|
@_out_buf = _buf_was
|
||||||
end
|
end
|
||||||
|
|
||||||
# Get the template data from a path
|
# Get the template data from a path
|
||||||
# @param [String] path
|
# @param [String] path
|
||||||
# @return [String]
|
# @return [String]
|
||||||
def template_data_for_file(path)
|
def template_data_for_file(path)
|
||||||
File.read(File.expand_path(path, source_dir))
|
File.read(File.expand_path(path, source_dir))
|
||||||
end
|
end
|
||||||
|
|
||||||
# Get a hash of configuration options for a given file extension, from
|
# Get a hash of configuration options for a given file extension, from
|
||||||
# config.rb
|
# config.rb
|
||||||
#
|
#
|
||||||
# @param [String] ext
|
# @param [String] ext
|
||||||
|
@ -252,7 +252,7 @@ module Middleman
|
||||||
cache.fetch(:options_for_ext, ext) do
|
cache.fetch(:options_for_ext, ext) do
|
||||||
options = {}
|
options = {}
|
||||||
|
|
||||||
# Find all the engines which handle this extension in tilt. Look for
|
# Find all the engines which handle this extension in tilt. Look for
|
||||||
# config variables of that name and merge it
|
# config variables of that name and merge it
|
||||||
extension_class = ::Tilt[ext]
|
extension_class = ::Tilt[ext]
|
||||||
::Tilt.mappings.each do |ext, engines|
|
::Tilt.mappings.each do |ext, engines|
|
||||||
|
@ -264,7 +264,7 @@ module Middleman
|
||||||
options
|
options
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Find a layout for a given engine
|
# Find a layout for a given engine
|
||||||
#
|
#
|
||||||
# @param [Symbol] engine
|
# @param [Symbol] engine
|
||||||
|
@ -274,7 +274,7 @@ module Middleman
|
||||||
# The layout name comes from either the system default or the options
|
# The layout name comes from either the system default or the options
|
||||||
local_layout = opts.has_key?(:layout) ? opts[:layout] : layout
|
local_layout = opts.has_key?(:layout) ? opts[:layout] : layout
|
||||||
return false unless local_layout
|
return false unless local_layout
|
||||||
|
|
||||||
# Look for engine-specific options
|
# Look for engine-specific options
|
||||||
engine_options = respond_to?(engine) ? send(engine) : {}
|
engine_options = respond_to?(engine) ? send(engine) : {}
|
||||||
|
|
||||||
|
@ -303,7 +303,7 @@ module Middleman
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Find a layout on-disk, optionally using a specific engine
|
# Find a layout on-disk, optionally using a specific engine
|
||||||
# @param [String] name
|
# @param [String] name
|
||||||
# @param [Symbol] preferred_engine
|
# @param [Symbol] preferred_engine
|
||||||
|
@ -311,47 +311,47 @@ module Middleman
|
||||||
def locate_layout(name, preferred_engine=nil)
|
def locate_layout(name, preferred_engine=nil)
|
||||||
# Whether we've found the layout
|
# Whether we've found the layout
|
||||||
layout_path = false
|
layout_path = false
|
||||||
|
|
||||||
# If we prefer a specific engine
|
# If we prefer a specific engine
|
||||||
if !preferred_engine.nil?
|
if !preferred_engine.nil?
|
||||||
# Check root
|
# Check root
|
||||||
layout_path, layout_engine = resolve_template(name, :preferred_engine => preferred_engine)
|
layout_path, layout_engine = resolve_template(name, :preferred_engine => preferred_engine)
|
||||||
|
|
||||||
# Check layouts folder
|
# Check layouts folder
|
||||||
if !layout_path
|
if !layout_path
|
||||||
layout_path, layout_engine = resolve_template(File.join("layouts", name.to_s), :preferred_engine => preferred_engine)
|
layout_path, layout_engine = resolve_template(File.join("layouts", name.to_s), :preferred_engine => preferred_engine)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Check root, no preference
|
# Check root, no preference
|
||||||
if !layout_path
|
if !layout_path
|
||||||
layout_path, layout_engine = resolve_template(name)
|
layout_path, layout_engine = resolve_template(name)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Check layouts folder, no preference
|
# Check layouts folder, no preference
|
||||||
if !layout_path
|
if !layout_path
|
||||||
layout_path, layout_engine = resolve_template(File.join("layouts", name.to_s))
|
layout_path, layout_engine = resolve_template(File.join("layouts", name.to_s))
|
||||||
end
|
end
|
||||||
|
|
||||||
# Return the path
|
# Return the path
|
||||||
layout_path
|
layout_path
|
||||||
end
|
end
|
||||||
|
|
||||||
# Allow layouts to be wrapped in the contents of other layouts
|
# Allow layouts to be wrapped in the contents of other layouts
|
||||||
# @param [String, Symbol] layout_name
|
# @param [String, Symbol] layout_name
|
||||||
# @return [void]
|
# @return [void]
|
||||||
def wrap_layout(layout_name, &block)
|
def wrap_layout(layout_name, &block)
|
||||||
# Save current buffer for later
|
# Save current buffer for later
|
||||||
@_out_buf, _buf_was = "", @_out_buf
|
@_out_buf, _buf_was = "", @_out_buf
|
||||||
|
|
||||||
layout_path = locate_layout(layout_name, current_engine)
|
layout_path = locate_layout(layout_name, current_engine)
|
||||||
|
|
||||||
extension = File.extname(layout_path)
|
extension = File.extname(layout_path)
|
||||||
engine = extension[1..-1].to_sym
|
engine = extension[1..-1].to_sym
|
||||||
|
|
||||||
# Store last engine for later (could be inside nested renders)
|
# Store last engine for later (could be inside nested renders)
|
||||||
@current_engine, engine_was = engine, @current_engine
|
@current_engine, engine_was = engine, @current_engine
|
||||||
|
|
||||||
begin
|
begin
|
||||||
content = if block_given?
|
content = if block_given?
|
||||||
capture_html(&block)
|
capture_html(&block)
|
||||||
|
@ -362,18 +362,18 @@ module Middleman
|
||||||
# Reset stored buffer
|
# Reset stored buffer
|
||||||
@_out_buf = _buf_was
|
@_out_buf = _buf_was
|
||||||
end
|
end
|
||||||
|
|
||||||
concat_content render_individual_file(layout_path, @current_locs || {}, @current_opts || {}, self) { content }
|
concat_content render_individual_file(layout_path, @current_locs || {}, @current_opts || {}, self) { content }
|
||||||
ensure
|
ensure
|
||||||
@current_engine = engine_was
|
@current_engine = engine_was
|
||||||
end
|
end
|
||||||
|
|
||||||
# The currently rendering engine
|
# The currently rendering engine
|
||||||
# @return [Symbol, nil]
|
# @return [Symbol, nil]
|
||||||
def current_engine
|
def current_engine
|
||||||
@current_engine ||= nil
|
@current_engine ||= nil
|
||||||
end
|
end
|
||||||
|
|
||||||
# Find a template on disk given a output path
|
# Find a template on disk given a output path
|
||||||
# @param [String] request_path
|
# @param [String] request_path
|
||||||
# @param [Hash] options
|
# @param [Hash] options
|
||||||
|
@ -387,7 +387,7 @@ module Middleman
|
||||||
|
|
||||||
# By default, any engine will do
|
# By default, any engine will do
|
||||||
preferred_engine = "*"
|
preferred_engine = "*"
|
||||||
|
|
||||||
# Unless we're specifically looking for a preferred engine
|
# Unless we're specifically looking for a preferred engine
|
||||||
if options.has_key?(:preferred_engine)
|
if options.has_key?(:preferred_engine)
|
||||||
extension_class = ::Tilt[options[:preferred_engine]]
|
extension_class = ::Tilt[options[:preferred_engine]]
|
||||||
|
@ -410,12 +410,12 @@ module Middleman
|
||||||
|
|
||||||
# Look for files that match
|
# Look for files that match
|
||||||
path_with_ext = on_disk_path + "." + preferred_engine
|
path_with_ext = on_disk_path + "." + preferred_engine
|
||||||
|
|
||||||
found_path = Dir[path_with_ext].find do |path|
|
found_path = Dir[path_with_ext].find do |path|
|
||||||
::Tilt[path]
|
::Tilt[path]
|
||||||
end
|
end
|
||||||
|
|
||||||
if !found_path && options[:try_without_underscore] &&
|
if !found_path && options[:try_without_underscore] &&
|
||||||
path_no_underscore = path_with_ext.
|
path_no_underscore = path_with_ext.
|
||||||
sub(relative_path, relative_path.sub(/^_/, "").
|
sub(relative_path, relative_path.sub(/^_/, "").
|
||||||
sub(/\/_/, "/"))
|
sub(/\/_/, "/"))
|
||||||
|
@ -423,7 +423,7 @@ module Middleman
|
||||||
::Tilt[path]
|
::Tilt[path]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# If we found one, return it and the found engine
|
# If we found one, return it and the found engine
|
||||||
if found_path || (File.exists?(on_disk_path) && !File.directory?(on_disk_path))
|
if found_path || (File.exists?(on_disk_path) && !File.directory?(on_disk_path))
|
||||||
engine = found_path ? File.extname(found_path)[1..-1].to_sym : nil
|
engine = found_path ? File.extname(found_path)[1..-1].to_sym : nil
|
||||||
|
|
|
@ -4,33 +4,33 @@ require "rack/file"
|
||||||
|
|
||||||
module Middleman
|
module Middleman
|
||||||
module CoreExtensions
|
module CoreExtensions
|
||||||
|
|
||||||
# Base helper to manipulate asset paths
|
# Base helper to manipulate asset paths
|
||||||
module Request
|
module Request
|
||||||
|
|
||||||
# Extension registered
|
# Extension registered
|
||||||
class << self
|
class << self
|
||||||
# @private
|
# @private
|
||||||
def registered(app)
|
def registered(app)
|
||||||
|
|
||||||
# CSSPIE HTC File
|
# CSSPIE HTC File
|
||||||
::Rack::Mime::MIME_TYPES['.htc'] = 'text/x-component'
|
::Rack::Mime::MIME_TYPES['.htc'] = 'text/x-component'
|
||||||
|
|
||||||
# Let's serve all HTML as UTF-8
|
# Let's serve all HTML as UTF-8
|
||||||
::Rack::Mime::MIME_TYPES['.html'] = 'text/html; charset=utf-8'
|
::Rack::Mime::MIME_TYPES['.html'] = 'text/html; charset=utf-8'
|
||||||
::Rack::Mime::MIME_TYPES['.htm'] = 'text/html; charset=utf-8'
|
::Rack::Mime::MIME_TYPES['.htm'] = 'text/html; charset=utf-8'
|
||||||
|
|
||||||
app.extend ClassMethods
|
app.extend ClassMethods
|
||||||
app.extend ServerMethods
|
app.extend ServerMethods
|
||||||
|
|
||||||
Middleman.extend CompatibleClassMethods
|
Middleman.extend CompatibleClassMethods
|
||||||
|
|
||||||
# Include instance methods
|
# Include instance methods
|
||||||
app.send :include, InstanceMethods
|
app.send :include, InstanceMethods
|
||||||
end
|
end
|
||||||
alias :included :registered
|
alias :included :registered
|
||||||
end
|
end
|
||||||
|
|
||||||
module ClassMethods
|
module ClassMethods
|
||||||
# Reset Rack setup
|
# Reset Rack setup
|
||||||
#
|
#
|
||||||
|
@ -39,7 +39,7 @@ module Middleman
|
||||||
@app = nil
|
@app = nil
|
||||||
@prototype = nil
|
@prototype = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
# The shared Rack instance being build
|
# The shared Rack instance being build
|
||||||
#
|
#
|
||||||
# @private
|
# @private
|
||||||
|
@ -47,7 +47,7 @@ module Middleman
|
||||||
def app
|
def app
|
||||||
@app ||= ::Rack::Builder.new
|
@app ||= ::Rack::Builder.new
|
||||||
end
|
end
|
||||||
|
|
||||||
# Get the static instance
|
# Get the static instance
|
||||||
#
|
#
|
||||||
# @private
|
# @private
|
||||||
|
@ -59,7 +59,7 @@ module Middleman
|
||||||
mm
|
mm
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Set the shared instance
|
# Set the shared instance
|
||||||
#
|
#
|
||||||
# @private
|
# @private
|
||||||
|
@ -68,27 +68,27 @@ module Middleman
|
||||||
def inst=(inst)
|
def inst=(inst)
|
||||||
@inst = inst
|
@inst = inst
|
||||||
end
|
end
|
||||||
|
|
||||||
# Return built Rack app
|
# Return built Rack app
|
||||||
#
|
#
|
||||||
# @private
|
# @private
|
||||||
# @return [Rack::Builder]
|
# @return [Rack::Builder]
|
||||||
def to_rack_app(&block)
|
def to_rack_app(&block)
|
||||||
inner_app = inst(&block)
|
inner_app = inst(&block)
|
||||||
|
|
||||||
(@middleware || []).each do |m|
|
(@middleware || []).each do |m|
|
||||||
app.use(m[0], *m[1], &m[2])
|
app.use(m[0], *m[1], &m[2])
|
||||||
end
|
end
|
||||||
|
|
||||||
app.map("/") { run inner_app }
|
app.map("/") { run inner_app }
|
||||||
|
|
||||||
(@mappings || []).each do |m|
|
(@mappings || []).each do |m|
|
||||||
app.map(m[0], &m[1])
|
app.map(m[0], &m[1])
|
||||||
end
|
end
|
||||||
|
|
||||||
app
|
app
|
||||||
end
|
end
|
||||||
|
|
||||||
# Prototype app. Used in config.ru
|
# Prototype app. Used in config.ru
|
||||||
#
|
#
|
||||||
# @private
|
# @private
|
||||||
|
@ -103,7 +103,7 @@ module Middleman
|
||||||
def call(env)
|
def call(env)
|
||||||
prototype.call(env)
|
prototype.call(env)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Use Rack middleware
|
# Use Rack middleware
|
||||||
#
|
#
|
||||||
# @param [Class] middleware Middleware module
|
# @param [Class] middleware Middleware module
|
||||||
|
@ -112,7 +112,7 @@ module Middleman
|
||||||
@middleware ||= []
|
@middleware ||= []
|
||||||
@middleware << [middleware, args, block]
|
@middleware << [middleware, args, block]
|
||||||
end
|
end
|
||||||
|
|
||||||
# Add Rack App mapped to specific path
|
# Add Rack App mapped to specific path
|
||||||
#
|
#
|
||||||
# @param [String] map Path to map
|
# @param [String] map Path to map
|
||||||
|
@ -122,7 +122,7 @@ module Middleman
|
||||||
@mappings << [map, block]
|
@mappings << [map, block]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
module ServerMethods
|
module ServerMethods
|
||||||
# Create a new Class which is based on Middleman::Application
|
# Create a new Class which is based on Middleman::Application
|
||||||
# Used to create a safe sandbox into which extensions and
|
# Used to create a safe sandbox into which extensions and
|
||||||
|
@ -136,7 +136,7 @@ module Middleman
|
||||||
const_set("MiddlemanApplication#{@@servercounter}", Class.new(Middleman::Application))
|
const_set("MiddlemanApplication#{@@servercounter}", Class.new(Middleman::Application))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
module CompatibleClassMethods
|
module CompatibleClassMethods
|
||||||
# Create a new Class which is based on Middleman::Application
|
# Create a new Class which is based on Middleman::Application
|
||||||
# Used to create a safe sandbox into which extensions and
|
# Used to create a safe sandbox into which extensions and
|
||||||
|
@ -164,15 +164,15 @@ module Middleman
|
||||||
# @return [void]
|
# @return [void]
|
||||||
def current_path=(path)
|
def current_path=(path)
|
||||||
@current_path = path
|
@current_path = path
|
||||||
@request = ::Thor::CoreExt::HashWithIndifferentAccess.new({
|
@request = ::Thor::CoreExt::HashWithIndifferentAccess.new({
|
||||||
:path => path,
|
:path => path,
|
||||||
:params => req ? ::Thor::CoreExt::HashWithIndifferentAccess.new(req.params) : {}
|
:params => req ? ::Thor::CoreExt::HashWithIndifferentAccess.new(req.params) : {}
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
def use(*args, &block); self.class.use(*args, &block); end
|
def use(*args, &block); self.class.use(*args, &block); end
|
||||||
def map(*args, &block); self.class.map(*args, &block); end
|
def map(*args, &block); self.class.map(*args, &block); end
|
||||||
|
|
||||||
# Rack env
|
# Rack env
|
||||||
attr_accessor :env
|
attr_accessor :env
|
||||||
|
|
||||||
|
@ -187,7 +187,7 @@ module Middleman
|
||||||
def call(env)
|
def call(env)
|
||||||
dup.call!(env)
|
dup.call!(env)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Rack Interface
|
# Rack Interface
|
||||||
#
|
#
|
||||||
# @param env Rack environment
|
# @param env Rack environment
|
||||||
|
@ -215,8 +215,8 @@ module Middleman
|
||||||
def halt(response)
|
def halt(response)
|
||||||
throw :halt, response
|
throw :halt, response
|
||||||
end
|
end
|
||||||
|
|
||||||
# Core response method. We process the request, check with
|
# Core response method. We process the request, check with
|
||||||
# the sitemap, and return the correct file, response or status
|
# the sitemap, and return the correct file, response or status
|
||||||
# message.
|
# message.
|
||||||
#
|
#
|
||||||
|
@ -252,7 +252,7 @@ module Middleman
|
||||||
return send_file(resource.source_file, env, res) unless resource.template?
|
return send_file(resource.source_file, env, res) unless resource.template?
|
||||||
|
|
||||||
current_path = request_path.dup
|
current_path = request_path.dup
|
||||||
|
|
||||||
# Set a HTTP content type based on the request's extensions
|
# Set a HTTP content type based on the request's extensions
|
||||||
content_type(res, resource.mime_type)
|
content_type(res, resource.mime_type)
|
||||||
|
|
||||||
|
@ -275,7 +275,7 @@ module Middleman
|
||||||
logger.debug "== Finishing Request: #{request_path} (#{(Time.now - start_time).round(2)}s)"
|
logger.debug "== Finishing Request: #{request_path} (#{(Time.now - start_time).round(2)}s)"
|
||||||
halt res.finish
|
halt res.finish
|
||||||
end
|
end
|
||||||
|
|
||||||
# Add a new mime-type for a specific extension
|
# Add a new mime-type for a specific extension
|
||||||
#
|
#
|
||||||
# @param [Symbol] type File extension
|
# @param [Symbol] type File extension
|
||||||
|
|
|
@ -2,22 +2,22 @@
|
||||||
module Middleman
|
module Middleman
|
||||||
module CoreExtensions
|
module CoreExtensions
|
||||||
module Routing
|
module Routing
|
||||||
|
|
||||||
# Setup extension
|
# Setup extension
|
||||||
class << self
|
class << self
|
||||||
|
|
||||||
# Once registered
|
# Once registered
|
||||||
def registered(app)
|
def registered(app)
|
||||||
# Include methods
|
# Include methods
|
||||||
app.send :include, InstanceMethods
|
app.send :include, InstanceMethods
|
||||||
end
|
end
|
||||||
|
|
||||||
alias :included :registered
|
alias :included :registered
|
||||||
end
|
end
|
||||||
|
|
||||||
# Routing instance methods
|
# Routing instance methods
|
||||||
module InstanceMethods
|
module InstanceMethods
|
||||||
|
|
||||||
# Takes a block which allows many pages to have the same layout
|
# Takes a block which allows many pages to have the same layout
|
||||||
#
|
#
|
||||||
# with_layout :admin do
|
# with_layout :admin do
|
||||||
|
@ -29,13 +29,13 @@ module Middleman
|
||||||
# @return [void]
|
# @return [void]
|
||||||
def with_layout(layout_name, &block)
|
def with_layout(layout_name, &block)
|
||||||
old_layout = layout
|
old_layout = layout
|
||||||
|
|
||||||
set :layout, layout_name
|
set :layout, layout_name
|
||||||
instance_exec(&block) if block_given?
|
instance_exec(&block) if block_given?
|
||||||
ensure
|
ensure
|
||||||
set :layout, old_layout
|
set :layout, old_layout
|
||||||
end
|
end
|
||||||
|
|
||||||
# The page method allows the layout to be set on a specific path
|
# The page method allows the layout to be set on a specific path
|
||||||
#
|
#
|
||||||
# page "/about.html", :layout => false
|
# page "/about.html", :layout => false
|
||||||
|
@ -45,36 +45,36 @@ module Middleman
|
||||||
# @param [Hash] opts
|
# @param [Hash] opts
|
||||||
# @return [void]
|
# @return [void]
|
||||||
def page(url, opts={}, &block)
|
def page(url, opts={}, &block)
|
||||||
|
|
||||||
blocks = []
|
blocks = []
|
||||||
blocks << block if block_given?
|
blocks << block if block_given?
|
||||||
|
|
||||||
# Default layout
|
# Default layout
|
||||||
opts[:layout] = layout if opts[:layout].nil?
|
opts[:layout] = layout if opts[:layout].nil?
|
||||||
|
|
||||||
# If the url is a regexp
|
# If the url is a regexp
|
||||||
if url.is_a?(Regexp) || url.include?("*")
|
if url.is_a?(Regexp) || url.include?("*")
|
||||||
|
|
||||||
# Use the metadata loop for matching against paths at runtime
|
# Use the metadata loop for matching against paths at runtime
|
||||||
sitemap.provides_metadata_for_path url do |url|
|
sitemap.provides_metadata_for_path url do |url|
|
||||||
{ :options => opts, :blocks => blocks }
|
{ :options => opts, :blocks => blocks }
|
||||||
end
|
end
|
||||||
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
# Normalized path
|
# Normalized path
|
||||||
url = full_path(url)
|
url = full_path(url)
|
||||||
|
|
||||||
# Setup proxy
|
# Setup proxy
|
||||||
if opts.has_key?(:proxy)
|
if opts.has_key?(:proxy)
|
||||||
proxy(url, opts[:proxy])
|
proxy(url, opts[:proxy])
|
||||||
|
|
||||||
if opts.has_key?(:ignore) && opts[:ignore]
|
if opts.has_key?(:ignore) && opts[:ignore]
|
||||||
ignore(opts[:proxy])
|
ignore(opts[:proxy])
|
||||||
opts.delete(:ignore)
|
opts.delete(:ignore)
|
||||||
end
|
end
|
||||||
|
|
||||||
opts.delete(:proxy)
|
opts.delete(:proxy)
|
||||||
else
|
else
|
||||||
if opts.has_key?(:ignore) && opts[:ignore]
|
if opts.has_key?(:ignore) && opts[:ignore]
|
||||||
|
@ -82,7 +82,7 @@ module Middleman
|
||||||
opts.delete(:ignore)
|
opts.delete(:ignore)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Setup a metadata matcher for rendering those options
|
# Setup a metadata matcher for rendering those options
|
||||||
sitemap.provides_metadata_for_path url do |url|
|
sitemap.provides_metadata_for_path url do |url|
|
||||||
{ :options => opts, :blocks => blocks }
|
{ :options => opts, :blocks => blocks }
|
||||||
|
@ -91,4 +91,4 @@ module Middleman
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,7 +3,7 @@ module Middleman::CoreExtensions::RubyEncoding
|
||||||
|
|
||||||
# Setup extension
|
# Setup extension
|
||||||
class << self
|
class << self
|
||||||
|
|
||||||
# Once registerd
|
# Once registerd
|
||||||
def registered(app)
|
def registered(app)
|
||||||
app.send :include, InstanceMethods
|
app.send :include, InstanceMethods
|
||||||
|
|
|
@ -5,10 +5,10 @@ require 'rack/showexceptions'
|
||||||
module Middleman
|
module Middleman
|
||||||
module CoreExtensions
|
module CoreExtensions
|
||||||
module ShowExceptions
|
module ShowExceptions
|
||||||
|
|
||||||
# Setup extension
|
# Setup extension
|
||||||
class << self
|
class << self
|
||||||
|
|
||||||
# Once registered
|
# Once registered
|
||||||
def registered(app)
|
def registered(app)
|
||||||
# When in dev
|
# When in dev
|
||||||
|
@ -20,12 +20,12 @@ module Middleman
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Custom exception class
|
# Custom exception class
|
||||||
# TODO: Style this ourselves
|
# TODO: Style this ourselves
|
||||||
class Middleware < ::Rack::ShowExceptions
|
class Middleware < ::Rack::ShowExceptions
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -59,16 +59,16 @@ module Middleman
|
||||||
# @private
|
# @private
|
||||||
def load_extensions_in_path
|
def load_extensions_in_path
|
||||||
require "rubygems"
|
require "rubygems"
|
||||||
|
|
||||||
begin
|
begin
|
||||||
require "middleman-more"
|
require "middleman-more"
|
||||||
rescue LoadError
|
rescue LoadError
|
||||||
end
|
end
|
||||||
|
|
||||||
extensions = rubygems_latest_specs.select do |spec|
|
extensions = rubygems_latest_specs.select do |spec|
|
||||||
spec_has_file?(spec, EXTENSION_FILE)
|
spec_has_file?(spec, EXTENSION_FILE)
|
||||||
end
|
end
|
||||||
|
|
||||||
extensions.each do |spec|
|
extensions.each do |spec|
|
||||||
require spec.name
|
require spec.name
|
||||||
end
|
end
|
||||||
|
@ -100,4 +100,4 @@ module Middleman
|
||||||
File.exists?(full_path)
|
File.exists?(full_path)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -2,11 +2,11 @@
|
||||||
require "pathname"
|
require "pathname"
|
||||||
|
|
||||||
module Middleman
|
module Middleman
|
||||||
|
|
||||||
class << self
|
class << self
|
||||||
def setup_load_paths
|
def setup_load_paths
|
||||||
@_is_setup ||= begin
|
@_is_setup ||= begin
|
||||||
|
|
||||||
# Only look for config.rb if MM_ROOT isn't set
|
# Only look for config.rb if MM_ROOT isn't set
|
||||||
if !ENV["MM_ROOT"] && found_path = locate_root
|
if !ENV["MM_ROOT"] && found_path = locate_root
|
||||||
ENV["MM_ROOT"] = found_path
|
ENV["MM_ROOT"] = found_path
|
||||||
|
@ -39,18 +39,18 @@ module Middleman
|
||||||
else
|
else
|
||||||
::Middleman.load_extensions_in_path
|
::Middleman.load_extensions_in_path
|
||||||
end
|
end
|
||||||
|
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Recursive method to find config.rb
|
# 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 cwd.to_s if (cwd + 'config.rb').exist?
|
||||||
return false if cwd.root?
|
return false if cwd.root?
|
||||||
locate_root(cwd.parent)
|
locate_root(cwd.parent)
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,17 +3,17 @@ require 'active_support/core_ext/logger'
|
||||||
require "securerandom"
|
require "securerandom"
|
||||||
|
|
||||||
module Middleman
|
module Middleman
|
||||||
|
|
||||||
# The Middleman Logger
|
# The Middleman Logger
|
||||||
class Logger < ::Logger
|
class Logger < ::Logger
|
||||||
|
|
||||||
# Force output to STDOUT
|
# Force output to STDOUT
|
||||||
def initialize(log_level=1, is_instrumenting=false, target=STDOUT)
|
def initialize(log_level=1, is_instrumenting=false, target=STDOUT)
|
||||||
super(STDOUT)
|
super(STDOUT)
|
||||||
|
|
||||||
self.level = log_level
|
self.level = log_level
|
||||||
@instrumenting = is_instrumenting
|
@instrumenting = is_instrumenting
|
||||||
|
|
||||||
if @instrumenting != false
|
if @instrumenting != false
|
||||||
::ActiveSupport::Notifications.subscribe(/\.middleman$/, self)
|
::ActiveSupport::Notifications.subscribe(/\.middleman$/, self)
|
||||||
end
|
end
|
||||||
|
@ -26,4 +26,4 @@ module Middleman
|
||||||
self.info "== Instrument (#{evt.name.sub(/.middleman$/, '')}): #{evt.duration}ms"
|
self.info "== Instrument (#{evt.name.sub(/.middleman$/, '')}): #{evt.duration}ms"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,17 +1,17 @@
|
||||||
require "webrick"
|
require "webrick"
|
||||||
|
|
||||||
module Middleman
|
module Middleman
|
||||||
|
|
||||||
WINDOWS = !!(RUBY_PLATFORM =~ /(mingw|bccwin|wince|mswin32)/i) unless const_defined?(:WINDOWS)
|
WINDOWS = !!(RUBY_PLATFORM =~ /(mingw|bccwin|wince|mswin32)/i) unless const_defined?(:WINDOWS)
|
||||||
|
|
||||||
module PreviewServer
|
module PreviewServer
|
||||||
|
|
||||||
DEFAULT_PORT = 4567
|
DEFAULT_PORT = 4567
|
||||||
|
|
||||||
class << self
|
class << self
|
||||||
attr_reader :app
|
attr_reader :app
|
||||||
delegate :logger, :to => :app
|
delegate :logger, :to => :app
|
||||||
|
|
||||||
# Start an instance of Middleman::Application
|
# Start an instance of Middleman::Application
|
||||||
# @return [void]
|
# @return [void]
|
||||||
def start(options={})
|
def start(options={})
|
||||||
|
@ -19,12 +19,12 @@ module Middleman
|
||||||
if options[:environment]
|
if options[:environment]
|
||||||
set :environment, options[:environment].to_sym
|
set :environment, options[:environment].to_sym
|
||||||
end
|
end
|
||||||
|
|
||||||
logger(options[:debug] ? 0 : 1, options[:instrumenting] || false)
|
logger(options[:debug] ? 0 : 1, options[:instrumenting] || false)
|
||||||
end
|
end
|
||||||
|
|
||||||
port = options[:port] || DEFAULT_PORT
|
port = options[:port] || DEFAULT_PORT
|
||||||
|
|
||||||
logger.info "== The Middleman is standing watch on port #{port}"
|
logger.info "== The Middleman is standing watch on port #{port}"
|
||||||
|
|
||||||
@webrick ||= setup_webrick(
|
@webrick ||= setup_webrick(
|
||||||
|
@ -32,17 +32,17 @@ module Middleman
|
||||||
port,
|
port,
|
||||||
options[:debug] || false
|
options[:debug] || false
|
||||||
)
|
)
|
||||||
|
|
||||||
mount_instance(app)
|
mount_instance(app)
|
||||||
|
|
||||||
start_file_watcher unless options[:"disable-watcher"]
|
start_file_watcher unless options[:"disable-watcher"]
|
||||||
|
|
||||||
@initialized ||= false
|
@initialized ||= false
|
||||||
unless @initialized
|
unless @initialized
|
||||||
@initialized = true
|
@initialized = true
|
||||||
|
|
||||||
register_signal_handlers unless ::Middleman::WINDOWS
|
register_signal_handlers unless ::Middleman::WINDOWS
|
||||||
|
|
||||||
# Save the last-used options so it may be re-used when
|
# Save the last-used options so it may be re-used when
|
||||||
# reloading later on.
|
# reloading later on.
|
||||||
@last_options = options
|
@last_options = options
|
||||||
|
@ -62,7 +62,7 @@ module Middleman
|
||||||
end
|
end
|
||||||
unmount_instance
|
unmount_instance
|
||||||
end
|
end
|
||||||
|
|
||||||
# Simply stop, then start the server
|
# Simply stop, then start the server
|
||||||
# @return [void]
|
# @return [void]
|
||||||
def reload
|
def reload
|
||||||
|
@ -76,17 +76,17 @@ module Middleman
|
||||||
stop
|
stop
|
||||||
@webrick.shutdown
|
@webrick.shutdown
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def start_file_watcher
|
def start_file_watcher
|
||||||
# Watcher Library
|
# Watcher Library
|
||||||
require "listen"
|
require "listen"
|
||||||
|
|
||||||
return if @listener
|
return if @listener
|
||||||
|
|
||||||
@listener = Listen.to(Dir.pwd, :relative_paths => true)
|
@listener = Listen.to(Dir.pwd, :relative_paths => true)
|
||||||
|
|
||||||
@listener.change do |modified, added, removed|
|
@listener.change do |modified, added, removed|
|
||||||
added_and_modified = (modified + added)
|
added_and_modified = (modified + added)
|
||||||
|
|
||||||
|
@ -102,7 +102,7 @@ module Middleman
|
||||||
@app.files.did_change(path)
|
@app.files.did_change(path)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
unless removed.empty?
|
unless removed.empty?
|
||||||
# See if the changed file is config.rb or lib/*.rb
|
# See if the changed file is config.rb or lib/*.rb
|
||||||
if needs_to_reload?(removed)
|
if needs_to_reload?(removed)
|
||||||
|
@ -116,11 +116,11 @@ module Middleman
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Don't block this thread
|
# Don't block this thread
|
||||||
@listener.start(false)
|
@listener.start(false)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Trap the interupt signal and shut down smoothly
|
# Trap the interupt signal and shut down smoothly
|
||||||
# @return [void]
|
# @return [void]
|
||||||
def register_signal_handlers
|
def register_signal_handlers
|
||||||
|
@ -128,28 +128,28 @@ module Middleman
|
||||||
trap("TERM") { shutdown }
|
trap("TERM") { shutdown }
|
||||||
trap("QUIT") { shutdown }
|
trap("QUIT") { shutdown }
|
||||||
end
|
end
|
||||||
|
|
||||||
# Initialize webrick
|
# Initialize webrick
|
||||||
# @return [void]
|
# @return [void]
|
||||||
def setup_webrick(host, port, is_logging)
|
def setup_webrick(host, port, is_logging)
|
||||||
@host = host
|
@host = host
|
||||||
@port = port
|
@port = port
|
||||||
|
|
||||||
http_opts = {
|
http_opts = {
|
||||||
:BindAddress => @host,
|
:BindAddress => @host,
|
||||||
:Port => @port,
|
:Port => @port,
|
||||||
:AccessLog => []
|
:AccessLog => []
|
||||||
}
|
}
|
||||||
|
|
||||||
if is_logging
|
if is_logging
|
||||||
http_opts[:Logger] = FilteredWebrickLog.new
|
http_opts[:Logger] = FilteredWebrickLog.new
|
||||||
else
|
else
|
||||||
http_opts[:Logger] = ::WEBrick::Log.new(nil, 0)
|
http_opts[:Logger] = ::WEBrick::Log.new(nil, 0)
|
||||||
end
|
end
|
||||||
|
|
||||||
::WEBrick::HTTPServer.new(http_opts)
|
::WEBrick::HTTPServer.new(http_opts)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Attach a new Middleman::Application instance
|
# Attach a new Middleman::Application instance
|
||||||
# @param [Middleman::Application] app
|
# @param [Middleman::Application] app
|
||||||
# @return [void]
|
# @return [void]
|
||||||
|
@ -157,7 +157,7 @@ module Middleman
|
||||||
@app = app
|
@app = app
|
||||||
@webrick.mount "/", ::Rack::Handler::WEBrick, @app.class.to_rack_app
|
@webrick.mount "/", ::Rack::Handler::WEBrick, @app.class.to_rack_app
|
||||||
end
|
end
|
||||||
|
|
||||||
# Detach the current Middleman::Application instance
|
# Detach the current Middleman::Application instance
|
||||||
# @return [void]
|
# @return [void]
|
||||||
def unmount_instance
|
def unmount_instance
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
module Middleman
|
module Middleman
|
||||||
module Profiling
|
module Profiling
|
||||||
|
|
||||||
# The profiler instance. There can only be one!
|
# The profiler instance. There can only be one!
|
||||||
def self.profiler=(prof)
|
def self.profiler=(prof)
|
||||||
@profiler = prof
|
@profiler = prof
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
# Require gem
|
# Require gem
|
||||||
require "coffee_script"
|
require "coffee_script"
|
||||||
|
|
||||||
module Middleman
|
module Middleman
|
||||||
module Renderers
|
module Renderers
|
||||||
|
|
||||||
# CoffeeScript Renderer
|
# CoffeeScript Renderer
|
||||||
module CoffeeScript
|
module CoffeeScript
|
||||||
|
|
||||||
# Setup extension
|
# Setup extension
|
||||||
class << self
|
class << self
|
||||||
# Once registered
|
# Once registered
|
||||||
|
@ -14,14 +14,14 @@ module Middleman
|
||||||
app.before_configuration do
|
app.before_configuration do
|
||||||
template_extensions :coffee => :js
|
template_extensions :coffee => :js
|
||||||
end
|
end
|
||||||
|
|
||||||
# Tell Tilt to use it as well (for inline scss blocks)
|
# Tell Tilt to use it as well (for inline scss blocks)
|
||||||
::Tilt.register 'coffee', DebuggingCoffeeScriptTemplate
|
::Tilt.register 'coffee', DebuggingCoffeeScriptTemplate
|
||||||
::Tilt.prefer(DebuggingCoffeeScriptTemplate)
|
::Tilt.prefer(DebuggingCoffeeScriptTemplate)
|
||||||
end
|
end
|
||||||
alias :included :registered
|
alias :included :registered
|
||||||
end
|
end
|
||||||
|
|
||||||
# A Template for Tilt which outputs debug messages
|
# A Template for Tilt which outputs debug messages
|
||||||
class DebuggingCoffeeScriptTemplate < ::Tilt::CoffeeScriptTemplate
|
class DebuggingCoffeeScriptTemplate < ::Tilt::CoffeeScriptTemplate
|
||||||
# Add exception messaging
|
# Add exception messaging
|
||||||
|
@ -30,7 +30,7 @@ module Middleman
|
||||||
# @return [String]
|
# @return [String]
|
||||||
def evaluate(context, locals, &block)
|
def evaluate(context, locals, &block)
|
||||||
return super if context.build?
|
return super if context.build?
|
||||||
|
|
||||||
begin
|
begin
|
||||||
super
|
super
|
||||||
rescue ::ExecJS::RuntimeError => e
|
rescue ::ExecJS::RuntimeError => e
|
||||||
|
@ -42,4 +42,4 @@ module Middleman
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -4,17 +4,17 @@ module Middleman
|
||||||
module ERb
|
module ERb
|
||||||
# Setup extension
|
# Setup extension
|
||||||
class << self
|
class << self
|
||||||
|
|
||||||
# once registered
|
# once registered
|
||||||
def registered(app)
|
def registered(app)
|
||||||
# Setup a default ERb engine
|
# Setup a default ERb engine
|
||||||
app.set :erb_engine, :erb
|
app.set :erb_engine, :erb
|
||||||
app.set :erb_engine_prefix, ::Tilt
|
app.set :erb_engine_prefix, ::Tilt
|
||||||
|
|
||||||
app.before_configuration do
|
app.before_configuration do
|
||||||
template_extensions :erb => :html
|
template_extensions :erb => :html
|
||||||
end
|
end
|
||||||
|
|
||||||
# After config
|
# After config
|
||||||
app.after_configuration do
|
app.after_configuration do
|
||||||
# Find the user's prefered engine
|
# Find the user's prefered engine
|
||||||
|
@ -24,7 +24,7 @@ module Middleman
|
||||||
engine = engine == "erb" ? "ERB" : engine.camelize
|
engine = engine == "erb" ? "ERB" : engine.camelize
|
||||||
erb_engine = erb_engine_prefix.const_get("#{engine}Template")
|
erb_engine = erb_engine_prefix.const_get("#{engine}Template")
|
||||||
end
|
end
|
||||||
|
|
||||||
# Tell Tilt to use the preferred engine
|
# Tell Tilt to use the preferred engine
|
||||||
::Tilt.prefer(erb_engine)
|
::Tilt.prefer(erb_engine)
|
||||||
end
|
end
|
||||||
|
@ -33,4 +33,4 @@ module Middleman
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,10 +3,10 @@ require "haml"
|
||||||
|
|
||||||
module Middleman
|
module Middleman
|
||||||
module Renderers
|
module Renderers
|
||||||
|
|
||||||
# Haml Renderer
|
# Haml Renderer
|
||||||
module Haml
|
module Haml
|
||||||
|
|
||||||
# Setup extension
|
# Setup extension
|
||||||
class << self
|
class << self
|
||||||
# Once registered
|
# Once registered
|
||||||
|
@ -14,10 +14,10 @@ module Middleman
|
||||||
app.before_configuration do
|
app.before_configuration do
|
||||||
template_extensions :haml => :html
|
template_extensions :haml => :html
|
||||||
end
|
end
|
||||||
|
|
||||||
# Add haml helpers to context
|
# Add haml helpers to context
|
||||||
app.send :include, ::Haml::Helpers
|
app.send :include, ::Haml::Helpers
|
||||||
|
|
||||||
# Setup haml helper paths
|
# Setup haml helper paths
|
||||||
app.ready do
|
app.ready do
|
||||||
init_haml_helpers
|
init_haml_helpers
|
||||||
|
@ -27,4 +27,4 @@ module Middleman
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -2,22 +2,22 @@ require "less"
|
||||||
|
|
||||||
module Middleman
|
module Middleman
|
||||||
module Renderers
|
module Renderers
|
||||||
|
|
||||||
# Sass renderer
|
# Sass renderer
|
||||||
module Less
|
module Less
|
||||||
|
|
||||||
# Setup extension
|
# Setup extension
|
||||||
class << self
|
class << self
|
||||||
|
|
||||||
# Once registered
|
# Once registered
|
||||||
def registered(app)
|
def registered(app)
|
||||||
# Default sass options
|
# Default sass options
|
||||||
app.set :less, {}
|
app.set :less, {}
|
||||||
|
|
||||||
app.before_configuration do
|
app.before_configuration do
|
||||||
template_extensions :less => :css
|
template_extensions :less => :css
|
||||||
end
|
end
|
||||||
|
|
||||||
app.after_configuration do
|
app.after_configuration do
|
||||||
::Less.paths << File.expand_path(css_dir, source_dir)
|
::Less.paths << File.expand_path(css_dir, source_dir)
|
||||||
end
|
end
|
||||||
|
@ -26,13 +26,13 @@ module Middleman
|
||||||
::Tilt.register 'less', LocalLoadingLessTemplate
|
::Tilt.register 'less', LocalLoadingLessTemplate
|
||||||
::Tilt.prefer(LocalLoadingLessTemplate)
|
::Tilt.prefer(LocalLoadingLessTemplate)
|
||||||
end
|
end
|
||||||
|
|
||||||
alias :included :registered
|
alias :included :registered
|
||||||
end
|
end
|
||||||
|
|
||||||
# A SassTemplate for Tilt which outputs debug messages
|
# A SassTemplate for Tilt which outputs debug messages
|
||||||
class LocalLoadingLessTemplate < ::Tilt::LessTemplate
|
class LocalLoadingLessTemplate < ::Tilt::LessTemplate
|
||||||
|
|
||||||
def prepare
|
def prepare
|
||||||
if ::Less.const_defined? :Engine
|
if ::Less.const_defined? :Engine
|
||||||
@engine = ::Less::Engine.new(data)
|
@engine = ::Less::Engine.new(data)
|
||||||
|
@ -41,9 +41,9 @@ module Middleman
|
||||||
@engine = parser.parse(data)
|
@engine = parser.parse(data)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -6,30 +6,30 @@ module Middleman
|
||||||
|
|
||||||
# Liquid Renderer
|
# Liquid Renderer
|
||||||
module Liquid
|
module Liquid
|
||||||
|
|
||||||
# Setup extension
|
# Setup extension
|
||||||
class << self
|
class << self
|
||||||
|
|
||||||
# Once registerd
|
# Once registerd
|
||||||
def registered(app)
|
def registered(app)
|
||||||
app.before_configuration do
|
app.before_configuration do
|
||||||
template_extensions :liquid => :html
|
template_extensions :liquid => :html
|
||||||
end
|
end
|
||||||
|
|
||||||
# After config, setup liquid partial paths
|
# After config, setup liquid partial paths
|
||||||
app.after_configuration do
|
app.after_configuration do
|
||||||
::Liquid::Template.file_system = ::Liquid::LocalFileSystem.new(source_dir)
|
::Liquid::Template.file_system = ::Liquid::LocalFileSystem.new(source_dir)
|
||||||
|
|
||||||
# Convert data object into a hash for liquid
|
# Convert data object into a hash for liquid
|
||||||
sitemap.provides_metadata %r{\.liquid$} do |path|
|
sitemap.provides_metadata %r{\.liquid$} do |path|
|
||||||
{ :locals => { :data => data.to_h } }
|
{ :locals => { :data => data.to_h } }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
alias :included :registered
|
alias :included :registered
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,18 +1,18 @@
|
||||||
module Middleman
|
module Middleman
|
||||||
module Renderers
|
module Renderers
|
||||||
|
|
||||||
# Markdown renderer
|
# Markdown renderer
|
||||||
module Markdown
|
module Markdown
|
||||||
|
|
||||||
# Setup extension
|
# Setup extension
|
||||||
class << self
|
class << self
|
||||||
|
|
||||||
# Once registered
|
# Once registered
|
||||||
def registered(app)
|
def registered(app)
|
||||||
# Set our preference for a markdown engine
|
# Set our preference for a markdown engine
|
||||||
app.set :markdown_engine, :maruku
|
app.set :markdown_engine, :maruku
|
||||||
app.set :markdown_engine_prefix, ::Tilt
|
app.set :markdown_engine_prefix, ::Tilt
|
||||||
|
|
||||||
app.before_configuration do
|
app.before_configuration do
|
||||||
template_extensions :markdown => :html,
|
template_extensions :markdown => :html,
|
||||||
:mdown => :html,
|
:mdown => :html,
|
||||||
|
@ -20,10 +20,10 @@ module Middleman
|
||||||
:mkd => :html,
|
:mkd => :html,
|
||||||
:mkdn => :html
|
:mkdn => :html
|
||||||
end
|
end
|
||||||
|
|
||||||
# Once configuration is parsed
|
# Once configuration is parsed
|
||||||
app.after_configuration do
|
app.after_configuration do
|
||||||
|
|
||||||
begin
|
begin
|
||||||
# Look for the user's preferred engine
|
# Look for the user's preferred engine
|
||||||
if markdown_engine == :redcarpet
|
if markdown_engine == :redcarpet
|
||||||
|
@ -35,22 +35,22 @@ module Middleman
|
||||||
engine = markdown_engine.to_s
|
engine = markdown_engine.to_s
|
||||||
engine = engine == "rdiscount" ? "RDiscount" : engine.camelize
|
engine = engine == "rdiscount" ? "RDiscount" : engine.camelize
|
||||||
markdown_engine_prefix.const_get("#{engine}Template")
|
markdown_engine_prefix.const_get("#{engine}Template")
|
||||||
else
|
else
|
||||||
markdown_engine_prefix
|
markdown_engine_prefix
|
||||||
end
|
end
|
||||||
|
|
||||||
# Tell tilt to use that engine
|
# Tell tilt to use that engine
|
||||||
::Tilt.prefer(markdown_engine_klass)
|
::Tilt.prefer(markdown_engine_klass)
|
||||||
end
|
end
|
||||||
rescue LoadError
|
rescue LoadError
|
||||||
logger.warn "Requested Markdown engine (#{markdown_engine}) not found. Maybe the gem needs to be installed and required?"
|
logger.warn "Requested Markdown engine (#{markdown_engine}) not found. Maybe the gem needs to be installed and required?"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
alias :included :registered
|
alias :included :registered
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -4,26 +4,26 @@ module Middleman
|
||||||
module Renderers
|
module Renderers
|
||||||
|
|
||||||
class RedcarpetTemplate < ::Tilt::RedcarpetTemplate::Redcarpet2
|
class RedcarpetTemplate < ::Tilt::RedcarpetTemplate::Redcarpet2
|
||||||
|
|
||||||
# Overwrite built-in Tilt version.
|
# Overwrite built-in Tilt version.
|
||||||
# Don't overload :renderer option with smartypants
|
# Don't overload :renderer option with smartypants
|
||||||
# Support renderer-level options
|
# Support renderer-level options
|
||||||
def generate_renderer
|
def generate_renderer
|
||||||
return options.delete(:renderer) if options.has_key?(:renderer)
|
return options.delete(:renderer) if options.has_key?(:renderer)
|
||||||
|
|
||||||
# Pick a renderer
|
# Pick a renderer
|
||||||
renderer = MiddlemanRedcarpetHTML
|
renderer = MiddlemanRedcarpetHTML
|
||||||
|
|
||||||
# Support SmartyPants
|
# Support SmartyPants
|
||||||
if options.delete(:smartypants)
|
if options.delete(:smartypants)
|
||||||
renderer = Class.new(renderer) do
|
renderer = Class.new(renderer) do
|
||||||
include ::Redcarpet::Render::SmartyPants
|
include ::Redcarpet::Render::SmartyPants
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Renderer Options
|
# Renderer Options
|
||||||
possible_render_opts = [:filter_html, :no_images, :no_links, :no_styles, :safe_links_only, :with_toc_data, :hard_wrap, :xhtml]
|
possible_render_opts = [:filter_html, :no_images, :no_links, :no_styles, :safe_links_only, :with_toc_data, :hard_wrap, :xhtml]
|
||||||
|
|
||||||
render_options = possible_render_opts.inject({}) do |sum, opt|
|
render_options = possible_render_opts.inject({}) do |sum, opt|
|
||||||
sum[opt] = options.delete(opt) if options.has_key?(opt)
|
sum[opt] = options.delete(opt) if options.has_key?(opt)
|
||||||
sum
|
sum
|
||||||
|
@ -52,7 +52,7 @@ module Middleman
|
||||||
middleman_app.link_to(content, link, :title => title)
|
middleman_app.link_to(content, link, :title => title)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
::Tilt.register RedcarpetTemplate, 'markdown', 'mkd', 'md'
|
::Tilt.register RedcarpetTemplate, 'markdown', 'mkd', 'md'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -2,23 +2,23 @@ require "sass"
|
||||||
|
|
||||||
module Middleman
|
module Middleman
|
||||||
module Renderers
|
module Renderers
|
||||||
|
|
||||||
# Sass renderer
|
# Sass renderer
|
||||||
module Sass
|
module Sass
|
||||||
|
|
||||||
# Setup extension
|
# Setup extension
|
||||||
class << self
|
class << self
|
||||||
|
|
||||||
# Once registered
|
# Once registered
|
||||||
def registered(app)
|
def registered(app)
|
||||||
# Default sass options
|
# Default sass options
|
||||||
app.set :sass, {}
|
app.set :sass, {}
|
||||||
|
|
||||||
# Location of SASS .sass_cache directory.
|
# Location of SASS .sass_cache directory.
|
||||||
# @return [String]
|
# @return [String]
|
||||||
# set :sass_cache_path, "/tmp/middleman-app-name/sass_cache"
|
# set :sass_cache_path, "/tmp/middleman-app-name/sass_cache"
|
||||||
app.set(:sass_cache_path) { File.join(app.root_path, '.sass_cache') } # runtime compile of path
|
app.set(:sass_cache_path) { File.join(app.root_path, '.sass_cache') } # runtime compile of path
|
||||||
|
|
||||||
app.before_configuration do
|
app.before_configuration do
|
||||||
template_extensions :scss => :css,
|
template_extensions :scss => :css,
|
||||||
:sass => :css
|
:sass => :css
|
||||||
|
@ -32,19 +32,19 @@ module Middleman
|
||||||
::Tilt.register 'scss', ScssPlusCSSFilenameTemplate
|
::Tilt.register 'scss', ScssPlusCSSFilenameTemplate
|
||||||
::Tilt.prefer(ScssPlusCSSFilenameTemplate)
|
::Tilt.prefer(ScssPlusCSSFilenameTemplate)
|
||||||
end
|
end
|
||||||
|
|
||||||
alias :included :registered
|
alias :included :registered
|
||||||
end
|
end
|
||||||
|
|
||||||
# A SassTemplate for Tilt which outputs debug messages
|
# A SassTemplate for Tilt which outputs debug messages
|
||||||
class SassPlusCSSFilenameTemplate < ::Tilt::SassTemplate
|
class SassPlusCSSFilenameTemplate < ::Tilt::SassTemplate
|
||||||
|
|
||||||
# Define the expected syntax for the template
|
# Define the expected syntax for the template
|
||||||
# @return [Symbol]
|
# @return [Symbol]
|
||||||
def syntax
|
def syntax
|
||||||
:sass
|
:sass
|
||||||
end
|
end
|
||||||
|
|
||||||
def prepare; end
|
def prepare; end
|
||||||
|
|
||||||
# Add exception messaging
|
# Add exception messaging
|
||||||
|
@ -54,31 +54,31 @@ module Middleman
|
||||||
def evaluate(context, locals, &block)
|
def evaluate(context, locals, &block)
|
||||||
@context = context
|
@context = context
|
||||||
@engine = ::Sass::Engine.new(data, sass_options)
|
@engine = ::Sass::Engine.new(data, sass_options)
|
||||||
|
|
||||||
begin
|
begin
|
||||||
@engine.render
|
@engine.render
|
||||||
rescue ::Sass::SyntaxError => e
|
rescue ::Sass::SyntaxError => e
|
||||||
::Sass::SyntaxError.exception_to_css(e, :full_exception => true)
|
::Sass::SyntaxError.exception_to_css(e, :full_exception => true)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
# Change Sass path, for url functions, to the build folder if we're building
|
# Change Sass path, for url functions, to the build folder if we're building
|
||||||
# @return [Hash]
|
# @return [Hash]
|
||||||
def sass_options
|
def sass_options
|
||||||
location_of_sass_file = File.expand_path(@context.source, @context.root)
|
location_of_sass_file = File.expand_path(@context.source, @context.root)
|
||||||
|
|
||||||
parts = basename.split('.')
|
parts = basename.split('.')
|
||||||
parts.pop
|
parts.pop
|
||||||
css_filename = File.join(location_of_sass_file, @context.css_dir, parts.join("."))
|
css_filename = File.join(location_of_sass_file, @context.css_dir, parts.join("."))
|
||||||
|
|
||||||
options.merge(:filename => eval_file, :line => line, :syntax => syntax, :css_filename => css_filename)
|
options.merge(:filename => eval_file, :line => line, :syntax => syntax, :css_filename => css_filename)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# SCSS version of the above template
|
# SCSS version of the above template
|
||||||
class ScssPlusCSSFilenameTemplate < SassPlusCSSFilenameTemplate
|
class ScssPlusCSSFilenameTemplate < SassPlusCSSFilenameTemplate
|
||||||
|
|
||||||
# Define the expected syntax for the template
|
# Define the expected syntax for the template
|
||||||
# @return [Symbol]
|
# @return [Symbol]
|
||||||
def syntax
|
def syntax
|
||||||
|
@ -87,4 +87,4 @@ module Middleman
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,28 +3,28 @@ require "slim"
|
||||||
|
|
||||||
module Middleman
|
module Middleman
|
||||||
module Renderers
|
module Renderers
|
||||||
|
|
||||||
# Slim renderer
|
# Slim renderer
|
||||||
module Slim
|
module Slim
|
||||||
|
|
||||||
# Setup extension
|
# Setup extension
|
||||||
class << self
|
class << self
|
||||||
|
|
||||||
# Once registered
|
# Once registered
|
||||||
def registered(app)
|
def registered(app)
|
||||||
app.before_configuration do
|
app.before_configuration do
|
||||||
template_extensions :slim => :html
|
template_extensions :slim => :html
|
||||||
end
|
end
|
||||||
|
|
||||||
# Setup Slim options to work with partials
|
# Setup Slim options to work with partials
|
||||||
::Slim::Engine.set_default_options(
|
::Slim::Engine.set_default_options(
|
||||||
:buffer => '@_out_buf',
|
:buffer => '@_out_buf',
|
||||||
:generator => ::Temple::Generators::StringBuffer
|
:generator => ::Temple::Generators::StringBuffer
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
alias :included :registered
|
alias :included :registered
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -7,72 +7,72 @@ require "middleman-core/sitemap/extensions/ignores"
|
||||||
|
|
||||||
# Core Sitemap Extensions
|
# Core Sitemap Extensions
|
||||||
module Middleman
|
module Middleman
|
||||||
|
|
||||||
module Sitemap
|
module Sitemap
|
||||||
|
|
||||||
# Setup Extension
|
# Setup Extension
|
||||||
class << self
|
class << self
|
||||||
|
|
||||||
# Once registered
|
# Once registered
|
||||||
def registered(app)
|
def registered(app)
|
||||||
|
|
||||||
app.register Middleman::Sitemap::Extensions::Proxies
|
app.register Middleman::Sitemap::Extensions::Proxies
|
||||||
app.register Middleman::Sitemap::Extensions::Ignores
|
app.register Middleman::Sitemap::Extensions::Ignores
|
||||||
|
|
||||||
# Set to automatically convert some characters into a directory
|
# Set to automatically convert some characters into a directory
|
||||||
app.set :automatic_directory_matcher, nil
|
app.set :automatic_directory_matcher, nil
|
||||||
|
|
||||||
# Setup callbacks which can exclude paths from the sitemap
|
# Setup callbacks which can exclude paths from the sitemap
|
||||||
app.set :ignored_sitemap_matchers, {
|
app.set :ignored_sitemap_matchers, {
|
||||||
# dotfiles and folders in the root
|
# dotfiles and folders in the root
|
||||||
:root_dotfiles => proc { |file| file.match(%r{^\.}) },
|
:root_dotfiles => proc { |file| file.match(%r{^\.}) },
|
||||||
|
|
||||||
# Files starting with an dot, but not .htaccess
|
# Files starting with an dot, but not .htaccess
|
||||||
:source_dotfiles => proc { |file|
|
:source_dotfiles => proc { |file|
|
||||||
file.match(%r{/\.}) && !file.match(%r{/\.htaccess})
|
file.match(%r{/\.}) && !file.match(%r{/\.htaccess})
|
||||||
},
|
},
|
||||||
|
|
||||||
# Files starting with an underscore, but not a double-underscore
|
# Files starting with an underscore, but not a double-underscore
|
||||||
:partials => proc { |file| file.match(%r{/_}) && !file.match(%r{/__}) },
|
:partials => proc { |file| file.match(%r{/_}) && !file.match(%r{/__}) },
|
||||||
|
|
||||||
:layout => proc { |file|
|
:layout => proc { |file|
|
||||||
file.match(%r{^source/layout\.}) || file.match(%r{^source/layouts/})
|
file.match(%r{^source/layout\.}) || file.match(%r{^source/layouts/})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# Include instance methods
|
# Include instance methods
|
||||||
app.send :include, InstanceMethods
|
app.send :include, InstanceMethods
|
||||||
|
|
||||||
# Initialize Sitemap
|
# Initialize Sitemap
|
||||||
app.before_configuration do
|
app.before_configuration do
|
||||||
sitemap
|
sitemap
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
alias :included :registered
|
alias :included :registered
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Sitemap instance methods
|
# Sitemap instance methods
|
||||||
module InstanceMethods
|
module InstanceMethods
|
||||||
|
|
||||||
# Get the sitemap class instance
|
# Get the sitemap class instance
|
||||||
# @return [Middleman::Sitemap::Store]
|
# @return [Middleman::Sitemap::Store]
|
||||||
def sitemap
|
def sitemap
|
||||||
@_sitemap ||= Store.new(self)
|
@_sitemap ||= Store.new(self)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Get the resource object for the current path
|
# Get the resource object for the current path
|
||||||
# @return [Middleman::Sitemap::Resource]
|
# @return [Middleman::Sitemap::Resource]
|
||||||
def current_page
|
def current_page
|
||||||
current_resource
|
current_resource
|
||||||
end
|
end
|
||||||
|
|
||||||
# Get the resource object for the current path
|
# Get the resource object for the current path
|
||||||
# @return [Middleman::Sitemap::Resource]
|
# @return [Middleman::Sitemap::Resource]
|
||||||
def current_resource
|
def current_resource
|
||||||
sitemap.find_resource_by_destination_path(current_path)
|
sitemap.find_resource_by_destination_path(current_path)
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,42 +3,42 @@ module Middleman
|
||||||
module Sitemap
|
module Sitemap
|
||||||
|
|
||||||
module Extensions
|
module Extensions
|
||||||
|
|
||||||
module Ignores
|
module Ignores
|
||||||
|
|
||||||
# Setup extension
|
# Setup extension
|
||||||
class << self
|
class << self
|
||||||
|
|
||||||
# Once registered
|
# Once registered
|
||||||
def registered(app)
|
def registered(app)
|
||||||
# Include methods
|
# Include methods
|
||||||
app.send :include, InstanceMethods
|
app.send :include, InstanceMethods
|
||||||
|
|
||||||
::Middleman::Sitemap::Resource.send :include, ResourceInstanceMethods
|
::Middleman::Sitemap::Resource.send :include, ResourceInstanceMethods
|
||||||
end
|
end
|
||||||
|
|
||||||
alias :included :registered
|
alias :included :registered
|
||||||
end
|
end
|
||||||
|
|
||||||
# Helpers methods for Resources
|
# Helpers methods for Resources
|
||||||
module ResourceInstanceMethods
|
module ResourceInstanceMethods
|
||||||
|
|
||||||
# Whether the Resource is ignored
|
# Whether the Resource is ignored
|
||||||
# @return [Boolean]
|
# @return [Boolean]
|
||||||
def ignored?
|
def ignored?
|
||||||
@app.ignore_manager.ignored?(path) ||
|
@app.ignore_manager.ignored?(path) ||
|
||||||
(!proxy? &&
|
(!proxy? &&
|
||||||
@app.ignore_manager.ignored?(source_file.sub("#{@app.source_dir}/", ""))
|
@app.ignore_manager.ignored?(source_file.sub("#{@app.source_dir}/", ""))
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Ignore-related instance methods
|
# Ignore-related instance methods
|
||||||
module InstanceMethods
|
module InstanceMethods
|
||||||
def ignore_manager
|
def ignore_manager
|
||||||
@_ignore_manager ||= IgnoreManager.new(self)
|
@_ignore_manager ||= IgnoreManager.new(self)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Ignore a path or add an ignore callback
|
# Ignore a path or add an ignore callback
|
||||||
# @param [String, Regexp] path Path glob expression, or path regex
|
# @param [String, Regexp] path Path glob expression, or path regex
|
||||||
# @return [void]
|
# @return [void]
|
||||||
|
@ -46,7 +46,7 @@ module Middleman
|
||||||
ignore_manager.ignore(path, &block)
|
ignore_manager.ignore(path, &block)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Class to handle managing ignores
|
# Class to handle managing ignores
|
||||||
class IgnoreManager
|
class IgnoreManager
|
||||||
def initialize(app)
|
def initialize(app)
|
||||||
|
@ -55,7 +55,7 @@ module Middleman
|
||||||
# Array of callbacks which can ass ignored
|
# Array of callbacks which can ass ignored
|
||||||
@ignored_callbacks = []
|
@ignored_callbacks = []
|
||||||
end
|
end
|
||||||
|
|
||||||
# Ignore a path or add an ignore callback
|
# Ignore a path or add an ignore callback
|
||||||
# @param [String, Regexp] path Path glob expression, or path regex
|
# @param [String, Regexp] path Path glob expression, or path regex
|
||||||
# @return [void]
|
# @return [void]
|
||||||
|
@ -88,4 +88,4 @@ module Middleman
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
require 'set'
|
require 'set'
|
||||||
|
|
||||||
module Middleman
|
module Middleman
|
||||||
|
|
||||||
module Sitemap
|
module Sitemap
|
||||||
|
|
||||||
module Extensions
|
module Extensions
|
||||||
|
|
||||||
class OnDisk
|
class OnDisk
|
||||||
|
|
||||||
attr_accessor :sitemap
|
attr_accessor :sitemap
|
||||||
|
@ -14,22 +14,22 @@ module Middleman
|
||||||
def initialize(sitemap)
|
def initialize(sitemap)
|
||||||
@sitemap = sitemap
|
@sitemap = sitemap
|
||||||
@app = @sitemap.app
|
@app = @sitemap.app
|
||||||
|
|
||||||
@file_paths_on_disk = Set.new
|
@file_paths_on_disk = Set.new
|
||||||
|
|
||||||
scoped_self = self
|
scoped_self = self
|
||||||
@waiting_for_ready = true
|
@waiting_for_ready = true
|
||||||
|
|
||||||
# Register file change callback
|
# Register file change callback
|
||||||
@app.files.changed do |file|
|
@app.files.changed do |file|
|
||||||
scoped_self.touch_file(file, !scoped_self.waiting_for_ready)
|
scoped_self.touch_file(file, !scoped_self.waiting_for_ready)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Register file delete callback
|
# Register file delete callback
|
||||||
@app.files.deleted do |file|
|
@app.files.deleted do |file|
|
||||||
scoped_self.remove_file(file, !scoped_self.waiting_for_ready)
|
scoped_self.remove_file(file, !scoped_self.waiting_for_ready)
|
||||||
end
|
end
|
||||||
|
|
||||||
@app.ready do
|
@app.ready do
|
||||||
scoped_self.waiting_for_ready = false
|
scoped_self.waiting_for_ready = false
|
||||||
scoped_self.sitemap.rebuild_resource_list!(:on_disk_ready)
|
scoped_self.sitemap.rebuild_resource_list!(:on_disk_ready)
|
||||||
|
@ -57,7 +57,7 @@ module Middleman
|
||||||
# whether or not it belongs in the sitemap (like a partial)
|
# whether or not it belongs in the sitemap (like a partial)
|
||||||
@sitemap.rebuild_resource_list!(:touched_file) if rebuild
|
@sitemap.rebuild_resource_list!(:touched_file) if rebuild
|
||||||
end
|
end
|
||||||
|
|
||||||
# Remove a file from the store
|
# Remove a file from the store
|
||||||
# @param [String] file
|
# @param [String] file
|
||||||
# @return [void]
|
# @return [void]
|
||||||
|
@ -66,7 +66,7 @@ module Middleman
|
||||||
@sitemap.rebuild_resource_list!(:removed_file) if rebuild
|
@sitemap.rebuild_resource_list!(:removed_file) if rebuild
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Update the main sitemap resource list
|
# Update the main sitemap resource list
|
||||||
# @return [void]
|
# @return [void]
|
||||||
def manipulate_resource_list(resources)
|
def manipulate_resource_list(resources)
|
||||||
|
|
|
@ -1,32 +1,32 @@
|
||||||
module Middleman
|
module Middleman
|
||||||
|
|
||||||
module Sitemap
|
module Sitemap
|
||||||
|
|
||||||
module Extensions
|
module Extensions
|
||||||
|
|
||||||
module Proxies
|
module Proxies
|
||||||
|
|
||||||
# Setup extension
|
# Setup extension
|
||||||
class << self
|
class << self
|
||||||
|
|
||||||
# Once registered
|
# Once registered
|
||||||
def registered(app)
|
def registered(app)
|
||||||
::Middleman::Sitemap::Resource.send :include, ResourceInstanceMethods
|
::Middleman::Sitemap::Resource.send :include, ResourceInstanceMethods
|
||||||
|
|
||||||
# Include methods
|
# Include methods
|
||||||
app.send :include, InstanceMethods
|
app.send :include, InstanceMethods
|
||||||
end
|
end
|
||||||
|
|
||||||
alias :included :registered
|
alias :included :registered
|
||||||
end
|
end
|
||||||
|
|
||||||
module ResourceInstanceMethods
|
module ResourceInstanceMethods
|
||||||
# Whether this page is a proxy
|
# Whether this page is a proxy
|
||||||
# @return [Boolean]
|
# @return [Boolean]
|
||||||
def proxy?
|
def proxy?
|
||||||
!!@proxied_to
|
!!@proxied_to
|
||||||
end
|
end
|
||||||
|
|
||||||
# Set this page to proxy to a target path
|
# Set this page to proxy to a target path
|
||||||
# @param [String] target
|
# @param [String] target
|
||||||
# @return [void]
|
# @return [void]
|
||||||
|
@ -35,13 +35,13 @@ module Middleman
|
||||||
raise "You can't proxy #{path} to itself!" if target == path
|
raise "You can't proxy #{path} to itself!" if target == path
|
||||||
@proxied_to = target
|
@proxied_to = target
|
||||||
end
|
end
|
||||||
|
|
||||||
# The path of the page this page is proxied to, or nil if it's not proxied.
|
# The path of the page this page is proxied to, or nil if it's not proxied.
|
||||||
# @return [String]
|
# @return [String]
|
||||||
def proxied_to
|
def proxied_to
|
||||||
@proxied_to
|
@proxied_to
|
||||||
end
|
end
|
||||||
|
|
||||||
# Whether this page has a template file
|
# Whether this page has a template file
|
||||||
# @return [Boolean]
|
# @return [Boolean]
|
||||||
def template?
|
def template?
|
||||||
|
@ -51,15 +51,15 @@ module Middleman
|
||||||
super
|
super
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_source_file
|
def get_source_file
|
||||||
if proxy?
|
if proxy?
|
||||||
proxy_resource = store.find_resource_by_path(proxied_to)
|
proxy_resource = store.find_resource_by_path(proxied_to)
|
||||||
|
|
||||||
unless proxy_resource
|
unless proxy_resource
|
||||||
raise "Path #{path} proxies to unknown file #{proxied_to}:#{store.resources.map(&:path)}"
|
raise "Path #{path} proxies to unknown file #{proxied_to}:#{store.resources.map(&:path)}"
|
||||||
end
|
end
|
||||||
|
|
||||||
if proxy_resource.proxy?
|
if proxy_resource.proxy?
|
||||||
raise "You can't proxy #{path} to #{proxied_to} which is itself a proxy."
|
raise "You can't proxy #{path} to #{proxied_to} which is itself a proxy."
|
||||||
end
|
end
|
||||||
|
@ -68,24 +68,24 @@ module Middleman
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
module InstanceMethods
|
module InstanceMethods
|
||||||
def proxy_manager
|
def proxy_manager
|
||||||
@_proxy_manager ||= ProxyManager.new(self)
|
@_proxy_manager ||= ProxyManager.new(self)
|
||||||
end
|
end
|
||||||
|
|
||||||
def proxy(*args)
|
def proxy(*args)
|
||||||
proxy_manager.proxy(*args)
|
proxy_manager.proxy(*args)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class ProxyManager
|
class ProxyManager
|
||||||
def initialize(app)
|
def initialize(app)
|
||||||
@app = app
|
@app = app
|
||||||
|
|
||||||
@proxy_paths = {}
|
@proxy_paths = {}
|
||||||
end
|
end
|
||||||
|
|
||||||
# Setup a proxy from a path to a target
|
# Setup a proxy from a path to a target
|
||||||
# @param [String] path
|
# @param [String] path
|
||||||
# @param [String] target
|
# @param [String] target
|
||||||
|
|
|
@ -1,23 +1,23 @@
|
||||||
module Middleman
|
module Middleman
|
||||||
|
|
||||||
module Sitemap
|
module Sitemap
|
||||||
|
|
||||||
module Extensions
|
module Extensions
|
||||||
|
|
||||||
module Traversal
|
module Traversal
|
||||||
# This resource's parent resource
|
# This resource's parent resource
|
||||||
# @return [Middleman::Sitemap::Resource, nil]
|
# @return [Middleman::Sitemap::Resource, nil]
|
||||||
def parent
|
def parent
|
||||||
parts = path.split("/")
|
parts = path.split("/")
|
||||||
parts.pop if path.include?(app.index_file)
|
parts.pop if path.include?(app.index_file)
|
||||||
|
|
||||||
return nil if parts.length < 1
|
return nil if parts.length < 1
|
||||||
|
|
||||||
parts.pop
|
parts.pop
|
||||||
parts << app.index_file
|
parts << app.index_file
|
||||||
|
|
||||||
parent_path = "/" + parts.join("/")
|
parent_path = "/" + parts.join("/")
|
||||||
|
|
||||||
store.find_resource_by_destination_path(parent_path)
|
store.find_resource_by_destination_path(parent_path)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -57,13 +57,13 @@ module Middleman
|
||||||
return [] unless parent
|
return [] unless parent
|
||||||
parent.children.reject { |p| p == self }
|
parent.children.reject { |p| p == self }
|
||||||
end
|
end
|
||||||
|
|
||||||
# Whether this resource either a directory index, or has the same name as an existing directory in the source
|
# Whether this resource either a directory index, or has the same name as an existing directory in the source
|
||||||
# @return [Boolean]
|
# @return [Boolean]
|
||||||
def directory_index?
|
def directory_index?
|
||||||
path.include?(app.index_file) || path =~ /\/$/ || eponymous_directory?
|
path.include?(app.index_file) || path =~ /\/$/ || eponymous_directory?
|
||||||
end
|
end
|
||||||
|
|
||||||
# Whether the resource has the same name as a directory in the source
|
# Whether the resource has the same name as a directory in the source
|
||||||
# (e.g., if the resource is named 'gallery.html' and a path exists named 'gallery/', this would return true)
|
# (e.g., if the resource is named 'gallery.html' and a path exists named 'gallery/', this would return true)
|
||||||
# @return [Boolean]
|
# @return [Boolean]
|
||||||
|
@ -71,7 +71,7 @@ module Middleman
|
||||||
full_path = File.join(app.source_dir, eponymous_directory_path)
|
full_path = File.join(app.source_dir, eponymous_directory_path)
|
||||||
!!(File.exists?(full_path) && File.directory?(full_path))
|
!!(File.exists?(full_path) && File.directory?(full_path))
|
||||||
end
|
end
|
||||||
|
|
||||||
# The path for this resource if it were a directory, and not a file
|
# The path for this resource if it were a directory, and not a file
|
||||||
# (e.g., for 'gallery.html' this would return 'gallery/')
|
# (e.g., for 'gallery.html' this would return 'gallery/')
|
||||||
# @return [String]
|
# @return [String]
|
||||||
|
@ -81,4 +81,4 @@ module Middleman
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -2,33 +2,33 @@ require "middleman-core/sitemap/extensions/traversal"
|
||||||
|
|
||||||
module Middleman
|
module Middleman
|
||||||
|
|
||||||
# Sitemap namespace
|
# Sitemap namespace
|
||||||
module Sitemap
|
module Sitemap
|
||||||
|
|
||||||
# Sitemap Resource class
|
# Sitemap Resource class
|
||||||
class Resource
|
class Resource
|
||||||
include Middleman::Sitemap::Extensions::Traversal
|
include Middleman::Sitemap::Extensions::Traversal
|
||||||
|
|
||||||
# @return [Middleman::Application]
|
# @return [Middleman::Application]
|
||||||
attr_reader :app
|
attr_reader :app
|
||||||
delegate :logger, :instrument, :to => :app
|
delegate :logger, :instrument, :to => :app
|
||||||
|
|
||||||
# @return [Middleman::Sitemap::Store]
|
# @return [Middleman::Sitemap::Store]
|
||||||
attr_reader :store
|
attr_reader :store
|
||||||
|
|
||||||
# The source path of this resource (relative to the source directory,
|
# The source path of this resource (relative to the source directory,
|
||||||
# without template extensions)
|
# without template extensions)
|
||||||
# @return [String]
|
# @return [String]
|
||||||
attr_reader :path
|
attr_reader :path
|
||||||
|
|
||||||
# Set the on-disk source file for this resource
|
# Set the on-disk source file for this resource
|
||||||
# @return [String]
|
# @return [String]
|
||||||
# attr_reader :source_file
|
# attr_reader :source_file
|
||||||
|
|
||||||
def source_file
|
def source_file
|
||||||
@source_file || get_source_file
|
@source_file || get_source_file
|
||||||
end
|
end
|
||||||
|
|
||||||
# Initialize resource with parent store and URL
|
# Initialize resource with parent store and URL
|
||||||
# @param [Middleman::Sitemap::Store] store
|
# @param [Middleman::Sitemap::Store] store
|
||||||
# @param [String] path
|
# @param [String] path
|
||||||
|
@ -38,24 +38,24 @@ module Middleman
|
||||||
@app = @store.app
|
@app = @store.app
|
||||||
@path = path
|
@path = path
|
||||||
@source_file = source_file
|
@source_file = source_file
|
||||||
|
|
||||||
@destination_paths = [@path]
|
@destination_paths = [@path]
|
||||||
|
|
||||||
@local_metadata = { :options => {}, :locals => {}, :page => {}, :blocks => [] }
|
@local_metadata = { :options => {}, :locals => {}, :page => {}, :blocks => [] }
|
||||||
end
|
end
|
||||||
|
|
||||||
# Whether this resource has a template file
|
# Whether this resource has a template file
|
||||||
# @return [Boolean]
|
# @return [Boolean]
|
||||||
def template?
|
def template?
|
||||||
return false if source_file.nil?
|
return false if source_file.nil?
|
||||||
!::Tilt[source_file].nil?
|
!::Tilt[source_file].nil?
|
||||||
end
|
end
|
||||||
|
|
||||||
# Get the metadata for both the current source_file and the current path
|
# Get the metadata for both the current source_file and the current path
|
||||||
# @return [Hash]
|
# @return [Hash]
|
||||||
def metadata
|
def metadata
|
||||||
result = store.metadata_for_path(path).dup
|
result = store.metadata_for_path(path).dup
|
||||||
|
|
||||||
file_meta = store.metadata_for_file(source_file).dup
|
file_meta = store.metadata_for_file(source_file).dup
|
||||||
if file_meta.has_key?(:blocks)
|
if file_meta.has_key?(:blocks)
|
||||||
result[:blocks] << file_meta.delete(:blocks)
|
result[:blocks] << file_meta.delete(:blocks)
|
||||||
|
@ -69,7 +69,7 @@ module Middleman
|
||||||
result.deep_merge!(local_meta)
|
result.deep_merge!(local_meta)
|
||||||
|
|
||||||
result[:blocks] = result[:blocks].flatten.compact
|
result[:blocks] = result[:blocks].flatten.compact
|
||||||
|
|
||||||
result
|
result
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -82,32 +82,32 @@ module Middleman
|
||||||
@local_metadata.deep_merge!(metadata)
|
@local_metadata.deep_merge!(metadata)
|
||||||
@local_metadata[:blocks] << block if block_given?
|
@local_metadata[:blocks] << block if block_given?
|
||||||
end
|
end
|
||||||
|
|
||||||
# Get the output/preview URL for this resource
|
# Get the output/preview URL for this resource
|
||||||
# @return [String]
|
# @return [String]
|
||||||
def destination_path
|
def destination_path
|
||||||
@destination_paths.last
|
@destination_paths.last
|
||||||
end
|
end
|
||||||
|
|
||||||
# Set the output/preview URL for this resource
|
# Set the output/preview URL for this resource
|
||||||
# @param [String] path
|
# @param [String] path
|
||||||
# @return [void]
|
# @return [void]
|
||||||
def destination_path=(path)
|
def destination_path=(path)
|
||||||
@destination_paths << path
|
@destination_paths << path
|
||||||
end
|
end
|
||||||
|
|
||||||
# Extension of the path (i.e. '.js')
|
# Extension of the path (i.e. '.js')
|
||||||
# @return [String]
|
# @return [String]
|
||||||
def ext
|
def ext
|
||||||
File.extname(path)
|
File.extname(path)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Mime type of the path
|
# Mime type of the path
|
||||||
# @return [String]
|
# @return [String]
|
||||||
def mime_type
|
def mime_type
|
||||||
app.mime_type ext
|
app.mime_type ext
|
||||||
end
|
end
|
||||||
|
|
||||||
# Render this resource
|
# Render this resource
|
||||||
# @return [String]
|
# @return [String]
|
||||||
def render(opts={}, locs={}, &block)
|
def render(opts={}, locs={}, &block)
|
||||||
|
@ -124,7 +124,7 @@ module Middleman
|
||||||
if md.has_key?(:page)
|
if md.has_key?(:page)
|
||||||
app.data.store("page", md[:page])
|
app.data.store("page", md[:page])
|
||||||
end
|
end
|
||||||
|
|
||||||
blocks = md[:blocks].dup rescue []
|
blocks = md[:blocks].dup rescue []
|
||||||
blocks << block if block_given?
|
blocks << block if block_given?
|
||||||
|
|
||||||
|
@ -132,7 +132,7 @@ module Middleman
|
||||||
app.render_template(source_file, locs, opts, blocks)
|
app.render_template(source_file, locs, opts, blocks)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# A path without the directory index - so foo/index.html becomes
|
# A path without the directory index - so foo/index.html becomes
|
||||||
# just foo. Best for linking.
|
# just foo. Best for linking.
|
||||||
# @return [String]
|
# @return [String]
|
||||||
|
|
|
@ -2,10 +2,10 @@
|
||||||
require "active_support/core_ext/hash/deep_merge"
|
require "active_support/core_ext/hash/deep_merge"
|
||||||
|
|
||||||
module Middleman
|
module Middleman
|
||||||
|
|
||||||
# Sitemap namespace
|
# Sitemap namespace
|
||||||
module Sitemap
|
module Sitemap
|
||||||
|
|
||||||
# The Store class
|
# The Store class
|
||||||
#
|
#
|
||||||
# The Store manages a collection of Resource objects, which represent
|
# The Store manages a collection of Resource objects, which represent
|
||||||
|
@ -13,10 +13,10 @@ module Middleman
|
||||||
# which is the path relative to the source directory, minus any template
|
# which is the path relative to the source directory, minus any template
|
||||||
# extensions. All "path" parameters used in this class are source paths.
|
# extensions. All "path" parameters used in this class are source paths.
|
||||||
class Store
|
class Store
|
||||||
|
|
||||||
# @return [Middleman::Application]
|
# @return [Middleman::Application]
|
||||||
attr_accessor :app
|
attr_accessor :app
|
||||||
|
|
||||||
# Initialize with parent app
|
# Initialize with parent app
|
||||||
# @param [Middleman::Application] app
|
# @param [Middleman::Application] app
|
||||||
def initialize(app)
|
def initialize(app)
|
||||||
|
@ -25,10 +25,10 @@ module Middleman
|
||||||
@_cached_metadata = {}
|
@_cached_metadata = {}
|
||||||
@_lookup_cache = { :path => {}, :destination_path => {} }
|
@_lookup_cache = { :path => {}, :destination_path => {} }
|
||||||
@resource_list_manipulators = []
|
@resource_list_manipulators = []
|
||||||
|
|
||||||
# Register classes which can manipulate the main site map list
|
# Register classes which can manipulate the main site map list
|
||||||
register_resource_list_manipulator(:on_disk, Middleman::Sitemap::Extensions::OnDisk.new(self), false)
|
register_resource_list_manipulator(:on_disk, Middleman::Sitemap::Extensions::OnDisk.new(self), false)
|
||||||
|
|
||||||
# Proxies
|
# Proxies
|
||||||
register_resource_list_manipulator(:proxies, @app.proxy_manager, false)
|
register_resource_list_manipulator(:proxies, @app.proxy_manager, false)
|
||||||
end
|
end
|
||||||
|
@ -42,7 +42,7 @@ module Middleman
|
||||||
@resource_list_manipulators << [name, inst]
|
@resource_list_manipulators << [name, inst]
|
||||||
rebuild_resource_list!(:registered_new) if immediately_rebuild
|
rebuild_resource_list!(:registered_new) if immediately_rebuild
|
||||||
end
|
end
|
||||||
|
|
||||||
# Rebuild the list of resources from scratch, using registed manipulators
|
# Rebuild the list of resources from scratch, using registed manipulators
|
||||||
# @return [void]
|
# @return [void]
|
||||||
def rebuild_resource_list!(reason=nil)
|
def rebuild_resource_list!(reason=nil)
|
||||||
|
@ -59,7 +59,7 @@ module Middleman
|
||||||
newres
|
newres
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Find a resource given its original path
|
# Find a resource given its original path
|
||||||
# @param [String] request_path The original path of a resource.
|
# @param [String] request_path The original path of a resource.
|
||||||
# @return [Middleman::Sitemap::Resource]
|
# @return [Middleman::Sitemap::Resource]
|
||||||
|
@ -67,7 +67,7 @@ module Middleman
|
||||||
request_path = ::Middleman::Util.normalize_path(request_path)
|
request_path = ::Middleman::Util.normalize_path(request_path)
|
||||||
@_lookup_cache[:path][request_path]
|
@_lookup_cache[:path][request_path]
|
||||||
end
|
end
|
||||||
|
|
||||||
# Find a resource given its destination path
|
# Find a resource given its destination path
|
||||||
# @param [String] request_path The destination (output) path of a resource.
|
# @param [String] request_path The destination (output) path of a resource.
|
||||||
# @return [Middleman::Sitemap::Resource]
|
# @return [Middleman::Sitemap::Resource]
|
||||||
|
@ -75,7 +75,7 @@ module Middleman
|
||||||
request_path = ::Middleman::Util.normalize_path(request_path)
|
request_path = ::Middleman::Util.normalize_path(request_path)
|
||||||
@_lookup_cache[:destination_path][request_path]
|
@_lookup_cache[:destination_path][request_path]
|
||||||
end
|
end
|
||||||
|
|
||||||
# Get the array of all resources
|
# Get the array of all resources
|
||||||
# @param [Boolean] include_ignored Whether to include ignored resources
|
# @param [Boolean] include_ignored Whether to include ignored resources
|
||||||
# @return [Array<Middleman::Sitemap::Resource>]
|
# @return [Array<Middleman::Sitemap::Resource>]
|
||||||
|
@ -86,7 +86,7 @@ module Middleman
|
||||||
@resources.reject(&:ignored?)
|
@resources.reject(&:ignored?)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Register a handler to provide metadata on a file path
|
# Register a handler to provide metadata on a file path
|
||||||
# @param [Regexp] matcher
|
# @param [Regexp] matcher
|
||||||
# @return [Array<Array<Proc, Regexp>>]
|
# @return [Array<Array<Proc, Regexp>>]
|
||||||
|
@ -95,16 +95,16 @@ module Middleman
|
||||||
@_provides_metadata << [block, matcher] if block_given?
|
@_provides_metadata << [block, matcher] if block_given?
|
||||||
@_provides_metadata
|
@_provides_metadata
|
||||||
end
|
end
|
||||||
|
|
||||||
# Get the metadata for a specific file
|
# Get the metadata for a specific file
|
||||||
# @param [String] source_file
|
# @param [String] source_file
|
||||||
# @return [Hash]
|
# @return [Hash]
|
||||||
def metadata_for_file(source_file)
|
def metadata_for_file(source_file)
|
||||||
blank_metadata = { :options => {}, :locals => {}, :page => {}, :blocks => [] }
|
blank_metadata = { :options => {}, :locals => {}, :page => {}, :blocks => [] }
|
||||||
|
|
||||||
provides_metadata.inject(blank_metadata) do |result, (callback, matcher)|
|
provides_metadata.inject(blank_metadata) do |result, (callback, matcher)|
|
||||||
next result if !matcher.nil? && !source_file.match(matcher)
|
next result if !matcher.nil? && !source_file.match(matcher)
|
||||||
|
|
||||||
metadata = callback.call(source_file)
|
metadata = callback.call(source_file)
|
||||||
|
|
||||||
if metadata.has_key?(:blocks)
|
if metadata.has_key?(:blocks)
|
||||||
|
@ -115,10 +115,10 @@ module Middleman
|
||||||
result.deep_merge(metadata)
|
result.deep_merge(metadata)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Register a handler to provide metadata on a url path
|
# Register a handler to provide metadata on a url path
|
||||||
# @param [Regexp] matcher
|
# @param [Regexp] matcher
|
||||||
# @param [Symbol] origin an indicator of where this metadata came from - only one
|
# @param [Symbol] origin an indicator of where this metadata came from - only one
|
||||||
# block per [matcher, origin] pair may exist.
|
# block per [matcher, origin] pair may exist.
|
||||||
# @return [Array<Array<Proc, Regexp>>]
|
# @return [Array<Array<Proc, Regexp>>]
|
||||||
def provides_metadata_for_path(matcher=nil, origin=nil, &block)
|
def provides_metadata_for_path(matcher=nil, origin=nil, &block)
|
||||||
|
@ -138,7 +138,7 @@ module Middleman
|
||||||
end
|
end
|
||||||
@_provides_metadata_for_path
|
@_provides_metadata_for_path
|
||||||
end
|
end
|
||||||
|
|
||||||
# Get the metadata for a specific URL
|
# Get the metadata for a specific URL
|
||||||
# @param [String] request_path
|
# @param [String] request_path
|
||||||
# @return [Hash]
|
# @return [Hash]
|
||||||
|
@ -146,7 +146,7 @@ module Middleman
|
||||||
return @_cached_metadata[request_path] if @_cached_metadata[request_path]
|
return @_cached_metadata[request_path] if @_cached_metadata[request_path]
|
||||||
|
|
||||||
blank_metadata = { :options => {}, :locals => {}, :page => {}, :blocks => [] }
|
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.inject(blank_metadata) do |result, (callback, matcher)|
|
||||||
case matcher
|
case matcher
|
||||||
when Regexp
|
when Regexp
|
||||||
|
@ -154,9 +154,9 @@ module Middleman
|
||||||
when String
|
when String
|
||||||
next result unless File.fnmatch("/" + matcher.sub(%r{^/}, ''), "/#{request_path}")
|
next result unless File.fnmatch("/" + matcher.sub(%r{^/}, ''), "/#{request_path}")
|
||||||
end
|
end
|
||||||
|
|
||||||
metadata = callback.call(request_path)
|
metadata = callback.call(request_path)
|
||||||
|
|
||||||
if metadata.has_key?(:blocks)
|
if metadata.has_key?(:blocks)
|
||||||
result[:blocks] << metadata[:blocks]
|
result[:blocks] << metadata[:blocks]
|
||||||
metadata.delete(:blocks)
|
metadata.delete(:blocks)
|
||||||
|
@ -165,26 +165,26 @@ module Middleman
|
||||||
result.deep_merge(metadata)
|
result.deep_merge(metadata)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Get the URL path for an on-disk file
|
# Get the URL path for an on-disk file
|
||||||
# @param [String] file
|
# @param [String] file
|
||||||
# @return [String]
|
# @return [String]
|
||||||
def file_to_path(file)
|
def file_to_path(file)
|
||||||
file = File.expand_path(file, @app.root)
|
file = File.expand_path(file, @app.root)
|
||||||
|
|
||||||
prefix = @app.source_dir.sub(/\/$/, "") + "/"
|
prefix = @app.source_dir.sub(/\/$/, "") + "/"
|
||||||
return false unless file.start_with?(prefix)
|
return false unless file.start_with?(prefix)
|
||||||
|
|
||||||
path = file.sub(prefix, "")
|
path = file.sub(prefix, "")
|
||||||
|
|
||||||
# Replace a file name containing automatic_directory_matcher with a folder
|
# Replace a file name containing automatic_directory_matcher with a folder
|
||||||
unless @app.automatic_directory_matcher.nil?
|
unless @app.automatic_directory_matcher.nil?
|
||||||
path = path.gsub(@app.automatic_directory_matcher, "/")
|
path = path.gsub(@app.automatic_directory_matcher, "/")
|
||||||
end
|
end
|
||||||
|
|
||||||
extensionless_path(path)
|
extensionless_path(path)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Get a path without templating extensions
|
# Get a path without templating extensions
|
||||||
# @param [String] file
|
# @param [String] file
|
||||||
# @return [String]
|
# @return [String]
|
||||||
|
|
|
@ -9,4 +9,4 @@ require "middleman-core/step_definitions/server_steps"
|
||||||
|
|
||||||
Before do
|
Before do
|
||||||
@aruba_timeout_seconds = 30
|
@aruba_timeout_seconds = 30
|
||||||
end
|
end
|
||||||
|
|
|
@ -21,7 +21,7 @@ Given /^a fixture app "([^\"]*)"$/ do |path|
|
||||||
|
|
||||||
target_path = File.join(PROJECT_ROOT_PATH, "fixtures", path)
|
target_path = File.join(PROJECT_ROOT_PATH, "fixtures", path)
|
||||||
FileUtils.cp_r(target_path, current_dir)
|
FileUtils.cp_r(target_path, current_dir)
|
||||||
|
|
||||||
step %Q{I cd to "#{path}"}
|
step %Q{I cd to "#{path}"}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@ end
|
||||||
|
|
||||||
Given /^"([^\"]*)" feature is "([^\"]*)"$/ do |feature, state|
|
Given /^"([^\"]*)" feature is "([^\"]*)"$/ do |feature, state|
|
||||||
@initialize_commands ||= []
|
@initialize_commands ||= []
|
||||||
|
|
||||||
if state == "enabled"
|
if state == "enabled"
|
||||||
@initialize_commands << lambda { activate(feature.to_sym) }
|
@initialize_commands << lambda { activate(feature.to_sym) }
|
||||||
end
|
end
|
||||||
|
@ -16,7 +16,7 @@ end
|
||||||
|
|
||||||
Given /^"([^\"]*)" feature is "enabled" with "([^\"]*)"$/ do |feature, options_str|
|
Given /^"([^\"]*)" feature is "enabled" with "([^\"]*)"$/ do |feature, options_str|
|
||||||
@initialize_commands ||= []
|
@initialize_commands ||= []
|
||||||
|
|
||||||
options = eval("{#{options_str}}")
|
options = eval("{#{options_str}}")
|
||||||
|
|
||||||
@initialize_commands << lambda { activate(feature.to_sym, options) }
|
@initialize_commands << lambda { activate(feature.to_sym, options) }
|
||||||
|
@ -39,20 +39,20 @@ Given /^the Server is running$/ do
|
||||||
else
|
else
|
||||||
ENV["MM_SOURCE"] = ""
|
ENV["MM_SOURCE"] = ""
|
||||||
end
|
end
|
||||||
|
|
||||||
initialize_commands = @initialize_commands || []
|
initialize_commands = @initialize_commands || []
|
||||||
initialize_commands.unshift lambda {
|
initialize_commands.unshift lambda {
|
||||||
set :root, root_dir
|
set :root, root_dir
|
||||||
set :environment, @current_env || :development
|
set :environment, @current_env || :development
|
||||||
set :show_exceptions, false
|
set :show_exceptions, false
|
||||||
}
|
}
|
||||||
|
|
||||||
@server_inst = Middleman::Application.server.inst do
|
@server_inst = Middleman::Application.server.inst do
|
||||||
initialize_commands.each do |p|
|
initialize_commands.each do |p|
|
||||||
instance_exec(&p)
|
instance_exec(&p)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
app_rack = @server_inst.class.to_rack_app
|
app_rack = @server_inst.class.to_rack_app
|
||||||
@browser = ::Rack::Test::Session.new(::Rack::MockSession.new(app_rack))
|
@browser = ::Rack::Test::Session.new(::Rack::MockSession.new(app_rack))
|
||||||
end
|
end
|
||||||
|
|
|
@ -4,12 +4,12 @@ require "thor/group"
|
||||||
|
|
||||||
# Templates namespace
|
# Templates namespace
|
||||||
module Middleman::Templates
|
module Middleman::Templates
|
||||||
|
|
||||||
# Static methods
|
# Static methods
|
||||||
class << self
|
class << self
|
||||||
|
|
||||||
# Get list of registered templates and add new ones
|
# Get list of registered templates and add new ones
|
||||||
#
|
#
|
||||||
# Middleman::Templates.register(:ext_name, klass)
|
# Middleman::Templates.register(:ext_name, klass)
|
||||||
#
|
#
|
||||||
# @param [Symbol] name The name of the template
|
# @param [Symbol] name The name of the template
|
||||||
|
@ -20,15 +20,15 @@ module Middleman::Templates
|
||||||
@_template_mappings[name] = klass if name && klass
|
@_template_mappings[name] = klass if name && klass
|
||||||
@_template_mappings
|
@_template_mappings
|
||||||
end
|
end
|
||||||
|
|
||||||
# Middleman::Templates.register(name, klass)
|
# Middleman::Templates.register(name, klass)
|
||||||
alias :registered :register
|
alias :registered :register
|
||||||
end
|
end
|
||||||
|
|
||||||
# Base Template class. Handles basic options and paths.
|
# Base Template class. Handles basic options and paths.
|
||||||
class Base < ::Thor::Group
|
class Base < ::Thor::Group
|
||||||
include Thor::Actions
|
include Thor::Actions
|
||||||
|
|
||||||
def initialize(names, options)
|
def initialize(names, options)
|
||||||
super
|
super
|
||||||
source_paths << File.join(File.dirname(__FILE__), 'templates')
|
source_paths << File.join(File.dirname(__FILE__), 'templates')
|
||||||
|
@ -36,25 +36,25 @@ module Middleman::Templates
|
||||||
|
|
||||||
# Required path for the new project to be generated
|
# Required path for the new project to be generated
|
||||||
argument :location, :type => :string
|
argument :location, :type => :string
|
||||||
|
|
||||||
# Name of the template being used to generate the project.
|
# Name of the template being used to generate the project.
|
||||||
class_option :template, :default => "default"
|
class_option :template, :default => "default"
|
||||||
|
|
||||||
# Output a config.ru file for Rack if --rack is passed
|
# Output a config.ru file for Rack if --rack is passed
|
||||||
class_option :rack, :type => :boolean, :default => false
|
class_option :rack, :type => :boolean, :default => false
|
||||||
|
|
||||||
# Write a Rack config.ru file for project
|
# Write a Rack config.ru file for project
|
||||||
# @return [void]
|
# @return [void]
|
||||||
def generate_rack!
|
def generate_rack!
|
||||||
return unless options[:rack]
|
return unless options[:rack]
|
||||||
template "shared/config.ru", File.join(location, "config.ru")
|
template "shared/config.ru", File.join(location, "config.ru")
|
||||||
end
|
end
|
||||||
|
|
||||||
# Write a Bundler Gemfile file for project
|
# Write a Bundler Gemfile file for project
|
||||||
# @return [void]
|
# @return [void]
|
||||||
def generate_bundler!
|
def generate_bundler!
|
||||||
template "shared/Gemfile.tt", File.join(location, "Gemfile")
|
template "shared/Gemfile.tt", File.join(location, "Gemfile")
|
||||||
|
|
||||||
inside(location) do
|
inside(location) do
|
||||||
::Middleman::Cli::Bundle.new.invoke(:bundle)
|
::Middleman::Cli::Bundle.new.invoke(:bundle)
|
||||||
end unless ENV["TEST"]
|
end unless ENV["TEST"]
|
||||||
|
@ -62,7 +62,7 @@ module Middleman::Templates
|
||||||
|
|
||||||
# Output a .gitignore file
|
# Output a .gitignore file
|
||||||
class_option :git, :type => :boolean, :default => true
|
class_option :git, :type => :boolean, :default => true
|
||||||
|
|
||||||
# Write a .gitignore file for project
|
# Write a .gitignore file for project
|
||||||
# @return [void]
|
# @return [void]
|
||||||
def generate_gitignore!
|
def generate_gitignore!
|
||||||
|
|
|
@ -1,22 +1,22 @@
|
||||||
# Default Middleman template
|
# Default Middleman template
|
||||||
class Middleman::Templates::Default < Middleman::Templates::Base
|
class Middleman::Templates::Default < Middleman::Templates::Base
|
||||||
|
|
||||||
class_option "css_dir",
|
class_option "css_dir",
|
||||||
:default => "stylesheets",
|
:default => "stylesheets",
|
||||||
:desc => 'The path to the css files'
|
:desc => 'The path to the css files'
|
||||||
class_option "js_dir",
|
class_option "js_dir",
|
||||||
:default => "javascripts",
|
:default => "javascripts",
|
||||||
:desc => 'The path to the javascript files'
|
:desc => 'The path to the javascript files'
|
||||||
class_option "images_dir",
|
class_option "images_dir",
|
||||||
:default => "images",
|
:default => "images",
|
||||||
:desc => 'The path to the image files'
|
:desc => 'The path to the image files'
|
||||||
|
|
||||||
# Template files are relative to this file
|
# Template files are relative to this file
|
||||||
# @return [String]
|
# @return [String]
|
||||||
def self.source_root
|
def self.source_root
|
||||||
File.dirname(__FILE__)
|
File.dirname(__FILE__)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Actually output the files
|
# Actually output the files
|
||||||
# @return [void]
|
# @return [void]
|
||||||
def build_scaffold!
|
def build_scaffold!
|
||||||
|
@ -31,8 +31,8 @@ class Middleman::Templates::Default < Middleman::Templates::Base
|
||||||
empty_directory File.join(location, "source", options[:images_dir])
|
empty_directory File.join(location, "source", options[:images_dir])
|
||||||
copy_file "default/source/images/background.png", File.join(location, "source", options[:images_dir], "background.png")
|
copy_file "default/source/images/background.png", File.join(location, "source", options[:images_dir], "background.png")
|
||||||
copy_file "default/source/images/middleman.png", File.join(location, "source", options[:images_dir], "middleman.png")
|
copy_file "default/source/images/middleman.png", File.join(location, "source", options[:images_dir], "middleman.png")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Register this template
|
# Register this template
|
||||||
Middleman::Templates.register(:default, Middleman::Templates::Default)
|
Middleman::Templates.register(:default, Middleman::Templates::Default)
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
PROJECT_ROOT_PATH = File.dirname(File.dirname(File.dirname(__FILE__)))
|
PROJECT_ROOT_PATH = File.dirname(File.dirname(File.dirname(__FILE__)))
|
||||||
require "middleman-core"
|
require "middleman-core"
|
||||||
require "middleman-core/step_definitions"
|
require "middleman-core/step_definitions"
|
||||||
require File.join(PROJECT_ROOT_PATH, 'lib', '<%= name %>')
|
require File.join(PROJECT_ROOT_PATH, 'lib', '<%= name %>')
|
||||||
|
|
|
@ -4,22 +4,22 @@ require "middleman-core"
|
||||||
# Extension namespace
|
# Extension namespace
|
||||||
module MyExtension
|
module MyExtension
|
||||||
class << self
|
class << self
|
||||||
|
|
||||||
# Called when user `activate`s your extension
|
# Called when user `activate`s your extension
|
||||||
def registered(app, options={})
|
def registered(app, options={})
|
||||||
# Setup extension-specific config
|
# Setup extension-specific config
|
||||||
app.set :config_variable, false
|
app.set :config_variable, false
|
||||||
|
|
||||||
# Include class methods
|
# Include class methods
|
||||||
# app.extend ClassMethods
|
# app.extend ClassMethods
|
||||||
|
|
||||||
# Include instance methods
|
# Include instance methods
|
||||||
# app.send :include, InstanceMethods
|
# app.send :include, InstanceMethods
|
||||||
|
|
||||||
app.after_configuration do
|
app.after_configuration do
|
||||||
# Do something
|
# Do something
|
||||||
|
|
||||||
# config_variable is now either the default or the user's
|
# config_variable is now either the default or the user's
|
||||||
# setting from config.rb
|
# setting from config.rb
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -30,20 +30,20 @@ module MyExtension
|
||||||
# def a_class_method
|
# def a_class_method
|
||||||
# end
|
# end
|
||||||
# end
|
# end
|
||||||
|
|
||||||
# module InstanceMethods
|
# module InstanceMethods
|
||||||
# def an_instance_method
|
# def an_instance_method
|
||||||
# end
|
# end
|
||||||
# end
|
# end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
# Register extensions which can be activated
|
# Register extensions which can be activated
|
||||||
# Make sure we have the version of Middleman we expect
|
# Make sure we have the version of Middleman we expect
|
||||||
# ::Middleman::Extensions.register(:extension_name) do
|
# ::Middleman::Extensions.register(:extension_name) do
|
||||||
#
|
#
|
||||||
# # Return the extension module
|
# # Return the extension module
|
||||||
# ::MyExtension
|
# ::MyExtension
|
||||||
#
|
#
|
||||||
# end
|
# end
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
require "<%= name %>"
|
require "<%= name %>"
|
||||||
|
|
|
@ -1,22 +1,22 @@
|
||||||
# HTML5 Boilerplate template
|
# HTML5 Boilerplate template
|
||||||
class Middleman::Templates::Html5 < Middleman::Templates::Base
|
class Middleman::Templates::Html5 < Middleman::Templates::Base
|
||||||
|
|
||||||
class_option "css_dir",
|
class_option "css_dir",
|
||||||
:default => "css",
|
:default => "css",
|
||||||
:desc => 'The path to the css files'
|
:desc => 'The path to the css files'
|
||||||
class_option "js_dir",
|
class_option "js_dir",
|
||||||
:default => "js",
|
:default => "js",
|
||||||
:desc => 'The path to the javascript files'
|
:desc => 'The path to the javascript files'
|
||||||
class_option "images_dir",
|
class_option "images_dir",
|
||||||
:default => "img",
|
:default => "img",
|
||||||
:desc => 'The path to the image files'
|
:desc => 'The path to the image files'
|
||||||
|
|
||||||
# Templates are relative to this file
|
# Templates are relative to this file
|
||||||
# @return [String]
|
# @return [String]
|
||||||
def self.source_root
|
def self.source_root
|
||||||
File.dirname(__FILE__)
|
File.dirname(__FILE__)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Output the files
|
# Output the files
|
||||||
# @return [void]
|
# @return [void]
|
||||||
def build_scaffold!
|
def build_scaffold!
|
||||||
|
@ -27,4 +27,4 @@ class Middleman::Templates::Html5 < Middleman::Templates::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
# Register the template
|
# Register the template
|
||||||
Middleman::Templates.register(:html5, Middleman::Templates::Html5)
|
Middleman::Templates.register(:html5, Middleman::Templates::Html5)
|
||||||
|
|
0
middleman-core/lib/middleman-core/templates/html5/source/humans.txt
Executable file → Normal file
0
middleman-core/lib/middleman-core/templates/html5/source/humans.txt
Executable file → Normal file
0
middleman-core/lib/middleman-core/templates/html5/source/robots.txt
Executable file → Normal file
0
middleman-core/lib/middleman-core/templates/html5/source/robots.txt
Executable file → Normal file
|
@ -1,6 +1,6 @@
|
||||||
# Local templates
|
# Local templates
|
||||||
class Middleman::Templates::Local < Middleman::Templates::Base
|
class Middleman::Templates::Local < Middleman::Templates::Base
|
||||||
|
|
||||||
# Look for templates in ~/.middleman
|
# Look for templates in ~/.middleman
|
||||||
# @return [String]
|
# @return [String]
|
||||||
def self.source_root
|
def self.source_root
|
||||||
|
@ -11,15 +11,15 @@ class Middleman::Templates::Local < Middleman::Templates::Base
|
||||||
# @return [void]
|
# @return [void]
|
||||||
def build_scaffold!
|
def build_scaffold!
|
||||||
directory options[:template].to_s, location
|
directory options[:template].to_s, location
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Iterate over the directories in the templates path and register each one.
|
# Iterate over the directories in the templates path and register each one.
|
||||||
Dir[File.join(Middleman::Templates::Local.source_root, "*")].each do |dir|
|
Dir[File.join(Middleman::Templates::Local.source_root, "*")].each do |dir|
|
||||||
next unless File.directory?(dir)
|
next unless File.directory?(dir)
|
||||||
|
|
||||||
template_file = File.join(dir, "template.rb")
|
template_file = File.join(dir, "template.rb")
|
||||||
|
|
||||||
if File.exists?(template_file)
|
if File.exists?(template_file)
|
||||||
require template_file
|
require template_file
|
||||||
else
|
else
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
# Mobile HTML5 Boilerplate
|
# Mobile HTML5 Boilerplate
|
||||||
class Middleman::Templates::Mobile < Middleman::Templates::Base
|
class Middleman::Templates::Mobile < Middleman::Templates::Base
|
||||||
|
|
||||||
# Slightly different paths
|
# Slightly different paths
|
||||||
class_option :css_dir, :default => "css"
|
class_option :css_dir, :default => "css"
|
||||||
class_option :js_dir, :default => "js"
|
class_option :js_dir, :default => "js"
|
||||||
|
@ -11,7 +11,7 @@ class Middleman::Templates::Mobile < Middleman::Templates::Base
|
||||||
def self.source_root
|
def self.source_root
|
||||||
File.dirname(__FILE__)
|
File.dirname(__FILE__)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Output the files
|
# Output the files
|
||||||
# @return [void]
|
# @return [void]
|
||||||
def build_scaffold!
|
def build_scaffold!
|
||||||
|
@ -22,4 +22,4 @@ class Middleman::Templates::Mobile < Middleman::Templates::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
# Register the template
|
# Register the template
|
||||||
Middleman::Templates.register(:mobile, Middleman::Templates::Mobile)
|
Middleman::Templates.register(:mobile, Middleman::Templates::Mobile)
|
||||||
|
|
0
middleman-core/lib/middleman-core/templates/mobile/source/humans.txt
Executable file → Normal file
0
middleman-core/lib/middleman-core/templates/mobile/source/humans.txt
Executable file → Normal file
0
middleman-core/lib/middleman-core/templates/mobile/source/robots.txt
Executable file → Normal file
0
middleman-core/lib/middleman-core/templates/mobile/source/robots.txt
Executable file → Normal file
|
@ -11,7 +11,7 @@ require "thor"
|
||||||
require "pathname"
|
require "pathname"
|
||||||
|
|
||||||
module Middleman
|
module Middleman
|
||||||
|
|
||||||
module Util
|
module Util
|
||||||
|
|
||||||
# The logger
|
# The logger
|
||||||
|
@ -21,16 +21,16 @@ module Middleman
|
||||||
if !@_logger || args.length > 0
|
if !@_logger || args.length > 0
|
||||||
@_logger = ::Middleman::Logger.new(*args)
|
@_logger = ::Middleman::Logger.new(*args)
|
||||||
end
|
end
|
||||||
|
|
||||||
@_logger
|
@_logger
|
||||||
end
|
end
|
||||||
|
|
||||||
# Facade for ActiveSupport/Notification
|
# Facade for ActiveSupport/Notification
|
||||||
def self.instrument(name, payload={}, &block)
|
def self.instrument(name, payload={}, &block)
|
||||||
name << ".middleman" unless name =~ /\.middleman$/
|
name << ".middleman" unless name =~ /\.middleman$/
|
||||||
::ActiveSupport::Notifications.instrument(name, payload, &block)
|
::ActiveSupport::Notifications.instrument(name, payload, &block)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Recursively convert a normal Hash into a HashWithIndifferentAccess
|
# Recursively convert a normal Hash into a HashWithIndifferentAccess
|
||||||
#
|
#
|
||||||
# @private
|
# @private
|
||||||
|
@ -52,13 +52,13 @@ module Middleman
|
||||||
data
|
data
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Normalize a path to not include a leading slash
|
# Normalize a path to not include a leading slash
|
||||||
# @param [String] path
|
# @param [String] path
|
||||||
# @return [String]
|
# @return [String]
|
||||||
def self.normalize_path(path)
|
def self.normalize_path(path)
|
||||||
# The tr call works around a bug in Ruby's Unicode handling
|
# The tr call works around a bug in Ruby's Unicode handling
|
||||||
path.sub(/^\//, "").tr('','')
|
path.sub(/^\//, "").tr('','')
|
||||||
end
|
end
|
||||||
|
|
||||||
# Extract the text of a Rack response as a string.
|
# Extract the text of a Rack response as a string.
|
||||||
|
@ -79,7 +79,7 @@ module Middleman
|
||||||
response.to_s
|
response.to_s
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Takes a matcher, which can be a literal string
|
# Takes a matcher, which can be a literal string
|
||||||
# or a string containing glob expressions, or a
|
# or a string containing glob expressions, or a
|
||||||
# regexp, or a proc, or anything else that responds
|
# regexp, or a proc, or anything else that responds
|
||||||
|
@ -98,7 +98,7 @@ module Middleman
|
||||||
File.fnmatch(matcher.to_s, path)
|
File.fnmatch(matcher.to_s, path)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Get a recusive list of files inside a set of paths.
|
# Get a recusive list of files inside a set of paths.
|
||||||
# Works with symlinks.
|
# Works with symlinks.
|
||||||
#
|
#
|
||||||
|
@ -129,7 +129,7 @@ module Middleman
|
||||||
end
|
end
|
||||||
|
|
||||||
# Whether the key is in the cache
|
# Whether the key is in the cache
|
||||||
#
|
#
|
||||||
# @param key Anything Hash can use as a key
|
# @param key Anything Hash can use as a key
|
||||||
# @return [Boolean]
|
# @return [Boolean]
|
||||||
def has_key?(key)
|
def has_key?(key)
|
||||||
|
|
|
@ -11,50 +11,50 @@ require File.join(File.dirname(__FILE__), "hooks/inheritable_attribute")
|
||||||
#
|
#
|
||||||
# after_dinner do puts "Ice cream!" end
|
# after_dinner do puts "Ice cream!" end
|
||||||
# after_dinner :have_a_desert # => refers to CatWidget#have_a_desert
|
# after_dinner :have_a_desert # => refers to CatWidget#have_a_desert
|
||||||
#
|
#
|
||||||
# Running the callbacks happens on instances. It will run the block and #have_a_desert from above.
|
# Running the callbacks happens on instances. It will run the block and #have_a_desert from above.
|
||||||
#
|
#
|
||||||
# cat.run_hook :after_dinner
|
# cat.run_hook :after_dinner
|
||||||
module Hooks
|
module Hooks
|
||||||
VERSION = "0.2.0"
|
VERSION = "0.2.0"
|
||||||
|
|
||||||
def self.included(base)
|
def self.included(base)
|
||||||
base.extend InheritableAttribute
|
base.extend InheritableAttribute
|
||||||
base.extend ClassMethods
|
base.extend ClassMethods
|
||||||
end
|
end
|
||||||
|
|
||||||
module ClassMethods
|
module ClassMethods
|
||||||
def define_hook(name)
|
def define_hook(name)
|
||||||
accessor_name = "_#{name}_callbacks"
|
accessor_name = "_#{name}_callbacks"
|
||||||
|
|
||||||
setup_hook_accessors(accessor_name)
|
setup_hook_accessors(accessor_name)
|
||||||
define_hook_writer(name, accessor_name)
|
define_hook_writer(name, accessor_name)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Like Hooks#run_hook but for the class. Note that +:callbacks+ must be class methods.
|
# Like Hooks#run_hook but for the class. Note that +:callbacks+ must be class methods.
|
||||||
#
|
#
|
||||||
# Example:
|
# Example:
|
||||||
#
|
#
|
||||||
# class Cat
|
# class Cat
|
||||||
# after_eight :grab_a_beer
|
# after_eight :grab_a_beer
|
||||||
#
|
#
|
||||||
# def self.grab_a_beer(*) # and so on...
|
# def self.grab_a_beer(*) # and so on...
|
||||||
#
|
#
|
||||||
# where <tt>Cat.run_hook :after_eight</tt> will call the class method +grab_a_beer+.
|
# where <tt>Cat.run_hook :after_eight</tt> will call the class method +grab_a_beer+.
|
||||||
def run_hook(name, *args)
|
def run_hook(name, *args)
|
||||||
run_hook_for(name, self, *args)
|
run_hook_for(name, self, *args)
|
||||||
end
|
end
|
||||||
|
|
||||||
def run_hook_for(name, scope, *args)
|
def run_hook_for(name, scope, *args)
|
||||||
callbacks_for_hook(name).each do |callback|
|
callbacks_for_hook(name).each do |callback|
|
||||||
if callback.kind_of? Symbol
|
if callback.kind_of? Symbol
|
||||||
scope.send(callback, *args)
|
scope.send(callback, *args)
|
||||||
else
|
else
|
||||||
scope.instance_exec(*args, &callback)
|
scope.instance_exec(*args, &callback)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns the callbacks for +name+. Handy if you want to run the callbacks yourself, say when
|
# Returns the callbacks for +name+. Handy if you want to run the callbacks yourself, say when
|
||||||
# they should be executed in another context.
|
# they should be executed in another context.
|
||||||
#
|
#
|
||||||
|
@ -69,30 +69,30 @@ module Hooks
|
||||||
def callbacks_for_hook(name)
|
def callbacks_for_hook(name)
|
||||||
send("_#{name}_callbacks")
|
send("_#{name}_callbacks")
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def define_hook_writer(hook, accessor_name)
|
def define_hook_writer(hook, accessor_name)
|
||||||
self.send(:define_method, hook.to_sym) do |&block|
|
self.send(:define_method, hook.to_sym) do |&block|
|
||||||
if self.class.respond_to?(hook)
|
if self.class.respond_to?(hook)
|
||||||
self.class.send(hook.to_sym, &block)
|
self.class.send(hook.to_sym, &block)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
instance_eval <<-RUBY_EVAL, __FILE__, __LINE__ + 1
|
instance_eval <<-RUBY_EVAL, __FILE__, __LINE__ + 1
|
||||||
def #{hook}(method=nil, &block)
|
def #{hook}(method=nil, &block)
|
||||||
#{accessor_name} << (block || method)
|
#{accessor_name} << (block || method)
|
||||||
end
|
end
|
||||||
RUBY_EVAL
|
RUBY_EVAL
|
||||||
end
|
end
|
||||||
|
|
||||||
def setup_hook_accessors(accessor_name)
|
def setup_hook_accessors(accessor_name)
|
||||||
inheritable_attr(accessor_name)
|
inheritable_attr(accessor_name)
|
||||||
send("#{accessor_name}=", []) # initialize ivar.
|
send("#{accessor_name}=", []) # initialize ivar.
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Runs the callbacks (method/block) for the specified hook +name+. Additional arguments will
|
# Runs the callbacks (method/block) for the specified hook +name+. Additional arguments will
|
||||||
# be passed to the callback.
|
# be passed to the callback.
|
||||||
#
|
#
|
||||||
# Example:
|
# Example:
|
||||||
|
@ -100,7 +100,7 @@ module Hooks
|
||||||
# cat.run_hook :after_dinner, "i want ice cream!"
|
# cat.run_hook :after_dinner, "i want ice cream!"
|
||||||
#
|
#
|
||||||
# will invoke the callbacks like
|
# will invoke the callbacks like
|
||||||
#
|
#
|
||||||
# desert("i want ice cream!")
|
# desert("i want ice cream!")
|
||||||
# block.call("i want ice cream!")
|
# block.call("i want ice cream!")
|
||||||
def run_hook(name, *args)
|
def run_hook(name, *args)
|
||||||
|
|
|
@ -22,12 +22,12 @@ module Hooks
|
||||||
def #{name}=(v)
|
def #{name}=(v)
|
||||||
@#{name} = v
|
@#{name} = v
|
||||||
end
|
end
|
||||||
|
|
||||||
def #{name}
|
def #{name}
|
||||||
return @#{name} unless superclass.respond_to?(:#{name}) and value = superclass.#{name}
|
return @#{name} unless superclass.respond_to?(:#{name}) and value = superclass.#{name}
|
||||||
@#{name} ||= value.clone # only do this once.
|
@#{name} ||= value.clone # only do this once.
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,76 +3,76 @@ require 'test_helper'
|
||||||
class HooksTest < Test::Unit::TestCase
|
class HooksTest < Test::Unit::TestCase
|
||||||
class TestClass
|
class TestClass
|
||||||
include Hooks
|
include Hooks
|
||||||
|
|
||||||
def executed
|
def executed
|
||||||
@executed ||= [];
|
@executed ||= [];
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
context "Hooks.define_hook" do
|
context "Hooks.define_hook" do
|
||||||
setup do
|
setup do
|
||||||
@klass = Class.new(TestClass)
|
@klass = Class.new(TestClass)
|
||||||
|
|
||||||
@mum = @klass.new
|
@mum = @klass.new
|
||||||
@mum.class.define_hook :after_eight
|
@mum.class.define_hook :after_eight
|
||||||
end
|
end
|
||||||
|
|
||||||
should "provide accessors to the stored callbacks" do
|
should "provide accessors to the stored callbacks" do
|
||||||
assert_equal [], @klass._after_eight_callbacks
|
assert_equal [], @klass._after_eight_callbacks
|
||||||
@klass._after_eight_callbacks << :dine
|
@klass._after_eight_callbacks << :dine
|
||||||
assert_equal [:dine], @klass._after_eight_callbacks
|
assert_equal [:dine], @klass._after_eight_callbacks
|
||||||
end
|
end
|
||||||
|
|
||||||
should "respond to Class.callbacks_for_hook" do
|
should "respond to Class.callbacks_for_hook" do
|
||||||
assert_equal [], @klass.callbacks_for_hook(:after_eight)
|
assert_equal [], @klass.callbacks_for_hook(:after_eight)
|
||||||
@klass.after_eight :dine
|
@klass.after_eight :dine
|
||||||
assert_equal [:dine], @klass.callbacks_for_hook(:after_eight)
|
assert_equal [:dine], @klass.callbacks_for_hook(:after_eight)
|
||||||
end
|
end
|
||||||
|
|
||||||
context "creates a public writer for the hook that" do
|
context "creates a public writer for the hook that" do
|
||||||
should "accepts method names" do
|
should "accepts method names" do
|
||||||
@klass.after_eight :dine
|
@klass.after_eight :dine
|
||||||
assert_equal [:dine], @klass._after_eight_callbacks
|
assert_equal [:dine], @klass._after_eight_callbacks
|
||||||
end
|
end
|
||||||
|
|
||||||
should "accepts blocks" do
|
should "accepts blocks" do
|
||||||
@klass.after_eight do true; end
|
@klass.after_eight do true; end
|
||||||
assert @klass._after_eight_callbacks.first.kind_of? Proc
|
assert @klass._after_eight_callbacks.first.kind_of? Proc
|
||||||
end
|
end
|
||||||
|
|
||||||
should "be inherited" do
|
should "be inherited" do
|
||||||
@klass.after_eight :dine
|
@klass.after_eight :dine
|
||||||
subklass = Class.new(@klass)
|
subklass = Class.new(@klass)
|
||||||
|
|
||||||
assert_equal [:dine], subklass._after_eight_callbacks
|
assert_equal [:dine], subklass._after_eight_callbacks
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "Hooks#run_hook" do
|
context "Hooks#run_hook" do
|
||||||
should "run without parameters" do
|
should "run without parameters" do
|
||||||
@mum.instance_eval do
|
@mum.instance_eval do
|
||||||
def a; executed << :a; nil; end
|
def a; executed << :a; nil; end
|
||||||
def b; executed << :b; end
|
def b; executed << :b; end
|
||||||
|
|
||||||
self.class.after_eight :b
|
self.class.after_eight :b
|
||||||
self.class.after_eight :a
|
self.class.after_eight :a
|
||||||
end
|
end
|
||||||
|
|
||||||
@mum.run_hook(:after_eight)
|
@mum.run_hook(:after_eight)
|
||||||
|
|
||||||
assert_equal [:b, :a], @mum.executed
|
assert_equal [:b, :a], @mum.executed
|
||||||
end
|
end
|
||||||
|
|
||||||
should "accept arbitrary parameters" do
|
should "accept arbitrary parameters" do
|
||||||
@mum.instance_eval do
|
@mum.instance_eval do
|
||||||
def a(me, arg); executed << arg+1; end
|
def a(me, arg); executed << arg+1; end
|
||||||
end
|
end
|
||||||
@mum.class.after_eight :a
|
@mum.class.after_eight :a
|
||||||
@mum.class.after_eight lambda { |me, arg| me.executed << arg-1 }
|
@mum.class.after_eight lambda { |me, arg| me.executed << arg-1 }
|
||||||
|
|
||||||
@mum.run_hook(:after_eight, @mum, 1)
|
@mum.run_hook(:after_eight, @mum, 1)
|
||||||
|
|
||||||
assert_equal [2, 0], @mum.executed
|
assert_equal [2, 0], @mum.executed
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -82,7 +82,7 @@ class HooksTest < Test::Unit::TestCase
|
||||||
assert_equal [:c], @mum.executed
|
assert_equal [:c], @mum.executed
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "in class context" do
|
context "in class context" do
|
||||||
should "run a callback block" do
|
should "run a callback block" do
|
||||||
executed = []
|
executed = []
|
||||||
|
@ -90,51 +90,51 @@ class HooksTest < Test::Unit::TestCase
|
||||||
executed << :klass
|
executed << :klass
|
||||||
end
|
end
|
||||||
@klass.run_hook :after_eight
|
@klass.run_hook :after_eight
|
||||||
|
|
||||||
assert_equal [:klass], executed
|
assert_equal [:klass], executed
|
||||||
end
|
end
|
||||||
|
|
||||||
should "run a class methods" do
|
should "run a class methods" do
|
||||||
executed = []
|
executed = []
|
||||||
@klass.instance_eval do
|
@klass.instance_eval do
|
||||||
after_eight :have_dinner
|
after_eight :have_dinner
|
||||||
|
|
||||||
def have_dinner(executed)
|
def have_dinner(executed)
|
||||||
executed << :have_dinner
|
executed << :have_dinner
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@klass.run_hook :after_eight, executed
|
@klass.run_hook :after_eight, executed
|
||||||
|
|
||||||
assert_equal [:have_dinner], executed
|
assert_equal [:have_dinner], executed
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "Deriving" do
|
context "Deriving" do
|
||||||
setup do
|
setup do
|
||||||
@klass = Class.new(TestClass)
|
@klass = Class.new(TestClass)
|
||||||
|
|
||||||
@mum = @klass.new
|
@mum = @klass.new
|
||||||
@mum.class.define_hook :after_eight
|
@mum.class.define_hook :after_eight
|
||||||
end
|
end
|
||||||
|
|
||||||
should "inherit the hook" do
|
should "inherit the hook" do
|
||||||
@klass.class_eval do
|
@klass.class_eval do
|
||||||
after_eight :take_shower
|
after_eight :take_shower
|
||||||
|
|
||||||
def take_shower
|
def take_shower
|
||||||
executed << :take_shower
|
executed << :take_shower
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@kid = Class.new(@klass) do
|
@kid = Class.new(@klass) do
|
||||||
after_eight :have_dinner
|
after_eight :have_dinner
|
||||||
|
|
||||||
def have_dinner
|
def have_dinner
|
||||||
executed << :have_dinner
|
executed << :have_dinner
|
||||||
end
|
end
|
||||||
end.new
|
end.new
|
||||||
|
|
||||||
assert_equal [:take_shower, :have_dinner], @kid.run_hook(:after_eight)
|
assert_equal [:take_shower, :have_dinner], @kid.run_hook(:after_eight)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -6,48 +6,48 @@ class HooksTest < Test::Unit::TestCase
|
||||||
@klass = Class.new(Object) do
|
@klass = Class.new(Object) do
|
||||||
extend Hooks::InheritableAttribute
|
extend Hooks::InheritableAttribute
|
||||||
end
|
end
|
||||||
|
|
||||||
@mum = @klass.new
|
@mum = @klass.new
|
||||||
@klass.inheritable_attr :drinks
|
@klass.inheritable_attr :drinks
|
||||||
end
|
end
|
||||||
|
|
||||||
should "provide a reader with empty inherited attributes, already" do
|
should "provide a reader with empty inherited attributes, already" do
|
||||||
assert_equal nil, @klass.drinks
|
assert_equal nil, @klass.drinks
|
||||||
end
|
end
|
||||||
|
|
||||||
should "provide a reader with empty inherited attributes in a derived class" do
|
should "provide a reader with empty inherited attributes in a derived class" do
|
||||||
assert_equal nil, Class.new(@klass).drinks
|
assert_equal nil, Class.new(@klass).drinks
|
||||||
#@klass.drinks = true
|
#@klass.drinks = true
|
||||||
#Class.new(@klass).drinks # TODO: crashes.
|
#Class.new(@klass).drinks # TODO: crashes.
|
||||||
end
|
end
|
||||||
|
|
||||||
should "provide an attribute copy in subclasses" do
|
should "provide an attribute copy in subclasses" do
|
||||||
@klass.drinks = []
|
@klass.drinks = []
|
||||||
assert @klass.drinks.object_id != Class.new(@klass).drinks.object_id
|
assert @klass.drinks.object_id != Class.new(@klass).drinks.object_id
|
||||||
end
|
end
|
||||||
|
|
||||||
should "provide a writer" do
|
should "provide a writer" do
|
||||||
@klass.drinks = [:cabernet]
|
@klass.drinks = [:cabernet]
|
||||||
assert_equal [:cabernet], @klass.drinks
|
assert_equal [:cabernet], @klass.drinks
|
||||||
end
|
end
|
||||||
|
|
||||||
should "inherit attributes" do
|
should "inherit attributes" do
|
||||||
@klass.drinks = [:cabernet]
|
@klass.drinks = [:cabernet]
|
||||||
|
|
||||||
subklass_a = Class.new(@klass)
|
subklass_a = Class.new(@klass)
|
||||||
subklass_a.drinks << :becks
|
subklass_a.drinks << :becks
|
||||||
|
|
||||||
subklass_b = Class.new(@klass)
|
subklass_b = Class.new(@klass)
|
||||||
|
|
||||||
assert_equal [:cabernet], @klass.drinks
|
assert_equal [:cabernet], @klass.drinks
|
||||||
assert_equal [:cabernet, :becks], subklass_a.drinks
|
assert_equal [:cabernet, :becks], subklass_a.drinks
|
||||||
assert_equal [:cabernet], subklass_b.drinks
|
assert_equal [:cabernet], subklass_b.drinks
|
||||||
end
|
end
|
||||||
|
|
||||||
should "not inherit attributes if we set explicitely" do
|
should "not inherit attributes if we set explicitely" do
|
||||||
@klass.drinks = [:cabernet]
|
@klass.drinks = [:cabernet]
|
||||||
subklass = Class.new(@klass)
|
subklass = Class.new(@klass)
|
||||||
|
|
||||||
subklass.drinks = [:merlot] # we only want merlot explicitely.
|
subklass.drinks = [:merlot] # we only want merlot explicitely.
|
||||||
assert_equal [:merlot], subklass.drinks # no :cabernet, here
|
assert_equal [:merlot], subklass.drinks # no :cabernet, here
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
require "middleman-core/load_paths"
|
require "middleman-core/load_paths"
|
||||||
::Middleman.setup_load_paths
|
::Middleman.setup_load_paths
|
||||||
|
|
||||||
require "middleman-core"
|
require "middleman-core"
|
||||||
|
|
2
middleman-more/.cane
Normal file
2
middleman-more/.cane
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
--exclusions-file .cane-exclusions.yml
|
||||||
|
--no-doc
|
3
middleman-more/.cane-exclusions.yml
Normal file
3
middleman-more/.cane-exclusions.yml
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
style:
|
||||||
|
- lib/middleman-more/extensions/minify_css/rainpress.rb
|
||||||
|
- lib/middleman-more/extensions/automatic_image_sizes/fastimage.rb
|
|
@ -6,5 +6,5 @@ PROJECT_ROOT_PATH = File.dirname(File.dirname(File.dirname(__FILE__)))
|
||||||
core_root = File.expand_path("../../../../middleman-core/lib/middleman-core", __FILE__)
|
core_root = File.expand_path("../../../../middleman-core/lib/middleman-core", __FILE__)
|
||||||
|
|
||||||
require core_root
|
require core_root
|
||||||
require File.join(core_root, "step_definitions")
|
require File.join(core_root, "step_definitions")
|
||||||
require File.join(PROJECT_ROOT_PATH, 'lib', 'middleman-more')
|
require File.join(PROJECT_ROOT_PATH, 'lib', 'middleman-more')
|
||||||
|
|
|
@ -3,4 +3,4 @@ set :layout, false
|
||||||
activate :asset_host
|
activate :asset_host
|
||||||
set :asset_host do |asset|
|
set :asset_host do |asset|
|
||||||
"http://assets%d.example.com" % (asset.hash % 4)
|
"http://assets%d.example.com" % (asset.hash % 4)
|
||||||
end
|
end
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Reference in a new issue