fix slickmap, change to config.rb, rename Base to Server
This commit is contained in:
parent
b5697d9b0d
commit
8b00e830f9
2
LICENSE
2
LICENSE
|
@ -1,4 +1,4 @@
|
||||||
Copyright (c) 2009 Thomas Reynolds
|
Copyright (c) 2010 Thomas Reynolds
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining
|
Permission is hereby granted, free of charge, to any person obtaining
|
||||||
a copy of this software and associated documentation files (the
|
a copy of this software and associated documentation files (the
|
||||||
|
|
2
Rakefile
2
Rakefile
|
@ -25,7 +25,7 @@ begin
|
||||||
gem.add_dependency("compass", "~>0.10.0")
|
gem.add_dependency("compass", "~>0.10.0")
|
||||||
gem.add_dependency("json_pure", "~>1.4.0")
|
gem.add_dependency("json_pure", "~>1.4.0")
|
||||||
gem.add_dependency("smusher", "~>0.4.5")
|
gem.add_dependency("smusher", "~>0.4.5")
|
||||||
gem.add_dependency("compass-slickmap", "~>0.3.0")
|
gem.add_dependency("compass-slickmap", "~>0.4.0")
|
||||||
# gem.add_dependency("livereload", "~>1.4.0")
|
# gem.add_dependency("livereload", "~>1.4.0")
|
||||||
|
|
||||||
gem.add_development_dependency("rspec")
|
gem.add_development_dependency("rspec")
|
||||||
|
|
|
@ -6,7 +6,7 @@ ENV['MM_ENV'] = "build"
|
||||||
require File.join(File.dirname(__FILE__), "..", "lib", "middleman")
|
require File.join(File.dirname(__FILE__), "..", "lib", "middleman")
|
||||||
require 'middleman/builder'
|
require 'middleman/builder'
|
||||||
|
|
||||||
# Middleman::Base.init!
|
# Middleman::Server.init!
|
||||||
Middleman::Builder.init!
|
Middleman::Builder.init!
|
||||||
|
|
||||||
Middleman::Generators.run_cli(Dir.pwd, 'mm-build', 1, %w(build --force).concat(ARGV))
|
Middleman::Generators.run_cli(Dir.pwd, 'mm-build', 1, %w(build --force).concat(ARGV))
|
|
@ -22,7 +22,7 @@ module Generators
|
||||||
File.join(File.dirname(__FILE__), '..', 'lib', 'middleman', 'template')
|
File.join(File.dirname(__FILE__), '..', 'lib', 'middleman', 'template')
|
||||||
end
|
end
|
||||||
|
|
||||||
template :init, "init.rb"
|
template :config, "config.rb"
|
||||||
glob! :views
|
glob! :views
|
||||||
glob! :public
|
glob! :public
|
||||||
|
|
||||||
|
|
|
@ -36,7 +36,7 @@ OptionParser.new { |opts|
|
||||||
env = e
|
env = e
|
||||||
}
|
}
|
||||||
opts.on("--debug", "Debug mode") {
|
opts.on("--debug", "Debug mode") {
|
||||||
::Middleman::Base.set :logging, true
|
::Middleman::Server.set :logging, true
|
||||||
}
|
}
|
||||||
|
|
||||||
opts.parse! ARGV
|
opts.parse! ARGV
|
||||||
|
@ -44,13 +44,13 @@ OptionParser.new { |opts|
|
||||||
|
|
||||||
ENV['RACK_ENV'] = env
|
ENV['RACK_ENV'] = env
|
||||||
|
|
||||||
class Middleman::Base
|
class Middleman::Server
|
||||||
set :root, Dir.pwd
|
set :root, Dir.pwd
|
||||||
end
|
end
|
||||||
|
|
||||||
require 'shotgun'
|
require 'shotgun'
|
||||||
config = File.join(File.dirname(__FILE__), '..', 'lib', 'middleman', 'config.ru')
|
config = File.join(File.dirname(__FILE__), '..', 'lib', 'middleman', 'config.ru')
|
||||||
app = Shotgun.new(config, &lambda { |inner_app| Middleman::Base })
|
app = Shotgun.new(config, &lambda { |inner_app| Middleman::Server })
|
||||||
|
|
||||||
require 'rubygems'
|
require 'rubygems'
|
||||||
require 'thin'
|
require 'thin'
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
Given /^I am using an asset host$/ do
|
Given /^I am using an asset host$/ do
|
||||||
Middleman::Base.enable :asset_host
|
Middleman::Server.enable :asset_host
|
||||||
Middleman::Base.set :asset_host do |asset|
|
Middleman::Server.set :asset_host do |asset|
|
||||||
"http://assets%d.example.com" % (asset.hash % 4)
|
"http://assets%d.example.com" % (asset.hash % 4)
|
||||||
end
|
end
|
||||||
@browser = Rack::Test::Session.new(Rack::MockSession.new(Middleman::Base.new))
|
@browser = Rack::Test::Session.new(Rack::MockSession.new(Middleman::Server.new))
|
||||||
end
|
end
|
|
@ -1,7 +1,7 @@
|
||||||
Given /^"([^\"]*)" feature is "([^\"]*)"$/ do |feature, state|
|
Given /^"([^\"]*)" feature is "([^\"]*)"$/ do |feature, state|
|
||||||
enable_or_disable = (state == "enabled") ? :enable : :disable
|
enable_or_disable = (state == "enabled") ? :enable : :disable
|
||||||
Middleman::Base.send(enable_or_disable, feature.to_sym)
|
Middleman::Server.send(enable_or_disable, feature.to_sym)
|
||||||
@browser = Rack::Test::Session.new(Rack::MockSession.new(Middleman::Base.new))
|
@browser = Rack::Test::Session.new(Rack::MockSession.new(Middleman::Server.new))
|
||||||
end
|
end
|
||||||
|
|
||||||
Given /^generated directory at "([^\"]*)"$/ do |dirname|
|
Given /^generated directory at "([^\"]*)"$/ do |dirname|
|
||||||
|
@ -23,6 +23,5 @@ Then /^I should not see "([^\"]*)"$/ do |expected|
|
||||||
end
|
end
|
||||||
|
|
||||||
Then /^I should see "([^\"]*)" lines$/ do |lines|
|
Then /^I should see "([^\"]*)" lines$/ do |lines|
|
||||||
$stderr.puts @browser.last_response.body
|
|
||||||
@browser.last_response.body.chomp.split($/).length.should == lines.to_i
|
@browser.last_response.body.chomp.split($/).length.should == lines.to_i
|
||||||
end
|
end
|
|
@ -1,13 +1,13 @@
|
||||||
Given /^page "([^\"]*)" has layout "([^\"]*)"$/ do |url, layout|
|
Given /^page "([^\"]*)" has layout "([^\"]*)"$/ do |url, layout|
|
||||||
Middleman::Base.set :root, File.join(File.dirname(File.dirname(File.dirname(__FILE__))), "spec", "fixtures", "sample")
|
Middleman::Server.set :root, File.join(File.dirname(File.dirname(File.dirname(__FILE__))), "spec", "fixtures", "sample")
|
||||||
Middleman::Base.page(url, :layout => layout.to_sym)
|
Middleman::Server.page(url, :layout => layout.to_sym)
|
||||||
@browser = Rack::Test::Session.new(Rack::MockSession.new(Middleman::Base.new))
|
@browser = Rack::Test::Session.new(Rack::MockSession.new(Middleman::Server.new))
|
||||||
end
|
end
|
||||||
|
|
||||||
Given /^"([^\"]*)" with_layout block has layout "([^\"]*)"$/ do |url, layout|
|
Given /^"([^\"]*)" with_layout block has layout "([^\"]*)"$/ do |url, layout|
|
||||||
Middleman::Base.set :root, File.join(File.dirname(File.dirname(File.dirname(__FILE__))), "spec", "fixtures", "sample")
|
Middleman::Server.set :root, File.join(File.dirname(File.dirname(File.dirname(__FILE__))), "spec", "fixtures", "sample")
|
||||||
Middleman::Base.with_layout(:layout => layout.to_sym) do
|
Middleman::Server.with_layout(:layout => layout.to_sym) do
|
||||||
page(url)
|
page(url)
|
||||||
end
|
end
|
||||||
@browser = Rack::Test::Session.new(Rack::MockSession.new(Middleman::Base.new))
|
@browser = Rack::Test::Session.new(Rack::MockSession.new(Middleman::Server.new))
|
||||||
end
|
end
|
|
@ -4,5 +4,5 @@ $LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir)
|
||||||
require 'rubygems'
|
require 'rubygems'
|
||||||
|
|
||||||
module Middleman
|
module Middleman
|
||||||
autoload :Base, "middleman/base"
|
autoload :Server, "middleman/server"
|
||||||
end
|
end
|
||||||
|
|
|
@ -29,5 +29,5 @@ module Middleman
|
||||||
end
|
end
|
||||||
|
|
||||||
Middleman::Assets.register :base do |path, prefix, request|
|
Middleman::Assets.register :base do |path, prefix, request|
|
||||||
path.include?("://") ? path : File.join(Middleman::Base.http_prefix || "/", prefix, path)
|
path.include?("://") ? path : File.join(Middleman::Server.http_prefix || "/", prefix, path)
|
||||||
end
|
end
|
|
@ -1,147 +0,0 @@
|
||||||
# We're riding on Sinatra, so let's include it
|
|
||||||
require "sinatra/base"
|
|
||||||
require "sinatra/content_for"
|
|
||||||
|
|
||||||
class Sinatra::Request
|
|
||||||
attr_accessor :layout
|
|
||||||
end
|
|
||||||
|
|
||||||
module Middleman
|
|
||||||
class Base < Sinatra::Base
|
|
||||||
set :app_file, __FILE__
|
|
||||||
set :root, ENV["MM_DIR"] || Dir.pwd
|
|
||||||
set :reload, false
|
|
||||||
set :sessions, false
|
|
||||||
set :logging, false
|
|
||||||
set :environment, ENV['MM_ENV'] || :development
|
|
||||||
set :index_file, "index.html"
|
|
||||||
set :js_dir, "javascripts"
|
|
||||||
set :css_dir, "stylesheets"
|
|
||||||
set :images_dir, "images"
|
|
||||||
set :fonts_dir, "fonts"
|
|
||||||
set :build_dir, "build"
|
|
||||||
set :http_prefix, nil
|
|
||||||
|
|
||||||
helpers Sinatra::ContentFor
|
|
||||||
|
|
||||||
set :features, []
|
|
||||||
def self.enable(*opts)
|
|
||||||
set :features, (self.features << opts).flatten
|
|
||||||
super
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.disable(*opts)
|
|
||||||
current = self.features
|
|
||||||
current -= opts.flatten
|
|
||||||
set :features, current
|
|
||||||
super
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.set(option, value=self, &block)
|
|
||||||
if block_given?
|
|
||||||
value = Proc.new { block }
|
|
||||||
end
|
|
||||||
|
|
||||||
super(option, value, &nil)
|
|
||||||
end
|
|
||||||
|
|
||||||
@@afters = []
|
|
||||||
def self.after_feature_init(&block)
|
|
||||||
@@afters << block
|
|
||||||
end
|
|
||||||
|
|
||||||
# Rack helper for adding mime-types during local preview
|
|
||||||
def self.mime(ext, type)
|
|
||||||
ext = ".#{ext}" unless ext.to_s[0] == ?.
|
|
||||||
::Rack::Mime::MIME_TYPES[ext.to_s] = type
|
|
||||||
end
|
|
||||||
|
|
||||||
@@layout = nil
|
|
||||||
def self.page(url, options={}, &block)
|
|
||||||
layout = @@layout
|
|
||||||
layout = options[:layout] if !options[:layout].nil?
|
|
||||||
|
|
||||||
get(url) do
|
|
||||||
return yield if block_given?
|
|
||||||
process_request(layout)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.with_layout(layout, &block)
|
|
||||||
@@layout = layout
|
|
||||||
class_eval(&block) if block_given?
|
|
||||||
ensure
|
|
||||||
@@layout = nil
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.enabled?(name)
|
|
||||||
name = (name.to_s << "?").to_sym
|
|
||||||
self.respond_to?(name) && self.send(name)
|
|
||||||
end
|
|
||||||
|
|
||||||
def enabled?(name)
|
|
||||||
self.class.enabled?(name)
|
|
||||||
end
|
|
||||||
|
|
||||||
# This will match all requests not overridden in the project's init.rb
|
|
||||||
not_found do
|
|
||||||
process_request
|
|
||||||
end
|
|
||||||
|
|
||||||
private
|
|
||||||
def process_request(layout = :layout)
|
|
||||||
# Normalize the path and add index if we're looking at a directory
|
|
||||||
path = request.path
|
|
||||||
path << settings.index_file if path.match(%r{/$})
|
|
||||||
path.gsub!(%r{^/}, '')
|
|
||||||
|
|
||||||
template_path = locate_template_file(path)
|
|
||||||
if template_path
|
|
||||||
content_type mime_type(File.extname(path)), :charset => 'utf-8'
|
|
||||||
|
|
||||||
renderer = Middleman::Renderers.get_method(template_path)
|
|
||||||
if respond_to? renderer
|
|
||||||
status 200
|
|
||||||
return send(renderer, path.to_sym, { :layout => layout })
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
status 404
|
|
||||||
end
|
|
||||||
|
|
||||||
def locate_template_file(path)
|
|
||||||
template_path = File.join(settings.views, "#{path}.*")
|
|
||||||
Dir.glob(template_path).first
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
require "middleman/assets"
|
|
||||||
require "middleman/renderers"
|
|
||||||
require "middleman/features"
|
|
||||||
|
|
||||||
# The Rack App
|
|
||||||
class Middleman::Base
|
|
||||||
def self.new(*args, &block)
|
|
||||||
# Check for and evaluate local configuration
|
|
||||||
local_config = File.join(self.root, "init.rb")
|
|
||||||
if File.exists? local_config
|
|
||||||
puts "== Reading: Local config" if logging?
|
|
||||||
Middleman::Base.class_eval File.read(local_config)
|
|
||||||
set :app_file, File.expand_path(local_config)
|
|
||||||
end
|
|
||||||
|
|
||||||
# loop over enabled feature
|
|
||||||
features.flatten.each do |feature_name|
|
|
||||||
next unless send(:"#{feature_name}?")
|
|
||||||
$stderr.puts "== Enabling: #{feature_name.to_s.capitalize}" if logging?
|
|
||||||
Middleman::Features.run(feature_name, self)
|
|
||||||
end
|
|
||||||
|
|
||||||
use ::Rack::ConditionalGet if environment == :development
|
|
||||||
|
|
||||||
@@afters.each { |block| class_eval(&block) }
|
|
||||||
|
|
||||||
super
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -1,4 +1,4 @@
|
||||||
require 'middleman/base'
|
require 'middleman/server'
|
||||||
require 'templater'
|
require 'templater'
|
||||||
require 'middleman/templater+dynamic_renderer.rb'
|
require 'middleman/templater+dynamic_renderer.rb'
|
||||||
|
|
||||||
|
@ -6,11 +6,12 @@ require 'middleman/templater+dynamic_renderer.rb'
|
||||||
module Middleman
|
module Middleman
|
||||||
class Builder < ::Templater::Generator
|
class Builder < ::Templater::Generator
|
||||||
|
|
||||||
|
# Support all Tilt-enabled templates and treat js like a template
|
||||||
@@template_extensions = ::Tilt.mappings.keys << "js"
|
@@template_extensions = ::Tilt.mappings.keys << "js"
|
||||||
|
|
||||||
# Define source and desintation
|
# Define source and desintation
|
||||||
def self.source_root; Dir.pwd; end
|
def self.source_root; Dir.pwd; end
|
||||||
def destination_root; File.join(Dir.pwd, Middleman::Base.build_dir); end
|
def destination_root; File.join(Dir.pwd, Middleman::Server.build_dir); end
|
||||||
|
|
||||||
# Override template to ask middleman for the correct extension to output
|
# Override template to ask middleman for the correct extension to output
|
||||||
def self.template(name, *args, &block)
|
def self.template(name, *args, &block)
|
||||||
|
@ -21,7 +22,7 @@ module Middleman
|
||||||
end
|
end
|
||||||
|
|
||||||
if (args[0] === args[1])
|
if (args[0] === args[1])
|
||||||
args[1] = args[0].gsub("#{File.basename(Middleman::Base.views)}/", "").gsub("#{File.basename(Middleman::Base.public)}/", "")
|
args[1] = args[0].gsub("#{File.basename(Middleman::Server.views)}/", "").gsub("#{File.basename(Middleman::Server.public)}/", "")
|
||||||
if File.extname(args[1]) != ".js"
|
if File.extname(args[1]) != ".js"
|
||||||
args[1] = args[1].gsub!(File.extname(args[1]), "") if File.basename(args[1]).split('.').length > 2
|
args[1] = args[1].gsub!(File.extname(args[1]), "") if File.basename(args[1]).split('.').length > 2
|
||||||
end
|
end
|
||||||
|
@ -36,14 +37,14 @@ module Middleman
|
||||||
return unless ::Tilt[file_ext].nil?
|
return unless ::Tilt[file_ext].nil?
|
||||||
|
|
||||||
if (args[0] === args[1])
|
if (args[0] === args[1])
|
||||||
args[1] = args[0].gsub("#{File.basename(Middleman::Base.views)}/", "").gsub("#{File.basename(Middleman::Base.public)}/", "")
|
args[1] = args[0].gsub("#{File.basename(Middleman::Server.views)}/", "").gsub("#{File.basename(Middleman::Server.public)}/", "")
|
||||||
end
|
end
|
||||||
super(name, *args, &block)
|
super(name, *args, &block)
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.init!
|
def self.init!
|
||||||
glob! File.basename(Middleman::Base.public), @@template_extensions
|
glob! File.basename(Middleman::Server.public), @@template_extensions
|
||||||
glob! File.basename(Middleman::Base.views), @@template_extensions
|
glob! File.basename(Middleman::Server.views), @@template_extensions
|
||||||
end
|
end
|
||||||
|
|
||||||
def after_run
|
def after_run
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
require 'middleman'
|
require 'middleman'
|
||||||
run Middleman::Base
|
run Middleman::Server
|
|
@ -7,14 +7,16 @@ module Middleman
|
||||||
|
|
||||||
# Default to disabled, unless the class asks to auto-enable
|
# Default to disabled, unless the class asks to auto-enable
|
||||||
activate_method = (options.has_key?(:auto_enable) && options[:auto_enable]) ? :enable : :disable
|
activate_method = (options.has_key?(:auto_enable) && options[:auto_enable]) ? :enable : :disable
|
||||||
Middleman::Base.send(activate_method, feature_name)
|
Middleman::Server.send(activate_method, feature_name)
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.run(feature_name, scope)
|
# Initialize a feature
|
||||||
|
def self.run(feature_name, feature_config, scope)
|
||||||
feature_class = @@features[feature_name]
|
feature_class = @@features[feature_name]
|
||||||
feature_class.new(scope) unless feature_class.nil?
|
feature_class.new(scope, feature_config) unless feature_class.nil?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Get a list of all features
|
||||||
def self.all
|
def self.all
|
||||||
@@features
|
@@features
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
class Middleman::Features::AssetHost
|
class Middleman::Features::AssetHost
|
||||||
def initialize(app)
|
def initialize(app, config)
|
||||||
Middleman::Base.after_feature_init do
|
Middleman::Server.after_feature_init do
|
||||||
if Middleman::Base.asset_host.is_a?(Proc)
|
if Middleman::Server.asset_host.is_a?(Proc)
|
||||||
::Compass.configuration.asset_host(&Middleman::Base.asset_host)
|
::Compass.configuration.asset_host(&Middleman::Server.asset_host)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -11,7 +11,7 @@ class Middleman::Features::AssetHost
|
||||||
|
|
||||||
valid_extensions = %w(.png .gif .jpg .jpeg .js .css)
|
valid_extensions = %w(.png .gif .jpg .jpeg .js .css)
|
||||||
|
|
||||||
asset_prefix = Middleman::Base.asset_host.call(original_output)
|
asset_prefix = Middleman::Server.asset_host.call(original_output)
|
||||||
|
|
||||||
File.join(asset_prefix, original_output)
|
File.join(asset_prefix, original_output)
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
class Middleman::Features::AutomaticImageSizes
|
class Middleman::Features::AutomaticImageSizes
|
||||||
def initialize(app)
|
def initialize(app, config)
|
||||||
require "middleman/features/automatic_image_sizes/fastimage"
|
require "middleman/features/automatic_image_sizes/fastimage"
|
||||||
|
|
||||||
Middleman::Base.send :alias_method, :pre_automatic_image_tag, :image_tag
|
Middleman::Server.send :alias_method, :pre_automatic_image_tag, :image_tag
|
||||||
Middleman::Base.helpers do
|
Middleman::Server.helpers do
|
||||||
def image_tag(path, params={})
|
def image_tag(path, params={})
|
||||||
if (!params[:width] || !params[:height]) && !path.include?("://")
|
if (!params[:width] || !params[:height]) && !path.include?("://")
|
||||||
params[:alt] ||= ""
|
params[:alt] ||= ""
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
class Middleman::Features::CacheBuster
|
class Middleman::Features::CacheBuster
|
||||||
def initialize(app)
|
def initialize(app, config)
|
||||||
Middleman::Assets.register :cache_buster do |path, prefix, request|
|
Middleman::Assets.register :cache_buster do |path, prefix, request|
|
||||||
http_path = Middleman::Assets.before(:cache_buster, path, prefix, request)
|
http_path = Middleman::Assets.before(:cache_buster, path, prefix, request)
|
||||||
|
|
||||||
|
@ -7,16 +7,16 @@ class Middleman::Features::CacheBuster
|
||||||
http_path
|
http_path
|
||||||
else
|
else
|
||||||
begin
|
begin
|
||||||
prefix = Middleman::Base.images_dir if prefix == Middleman::Base.http_images_path
|
prefix = Middleman::Server.images_dir if prefix == Middleman::Server.http_images_path
|
||||||
rescue
|
rescue
|
||||||
end
|
end
|
||||||
|
|
||||||
real_path_static = File.join(Middleman::Base.public, prefix, path)
|
real_path_static = File.join(Middleman::Server.public, prefix, path)
|
||||||
|
|
||||||
if File.readable?(real_path_static)
|
if File.readable?(real_path_static)
|
||||||
http_path << "?" + File.mtime(real_path_static).strftime("%s")
|
http_path << "?" + File.mtime(real_path_static).strftime("%s")
|
||||||
elsif Middleman::Base.environment == "build"
|
elsif Middleman::Server.environment == :build
|
||||||
real_path_dynamic = File.join(Middleman::Base.root, Middleman::Base.build_dir, prefix, path)
|
real_path_dynamic = File.join(Middleman::Server.root, Middleman::Server.build_dir, prefix, path)
|
||||||
http_path << "?" + File.mtime(real_path_dynamic).strftime("%s") if File.readable?(real_path_dynamic)
|
http_path << "?" + File.mtime(real_path_dynamic).strftime("%s") if File.readable?(real_path_dynamic)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -24,11 +24,11 @@ class Middleman::Features::CacheBuster
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
Middleman::Base.after_feature_init do
|
Middleman::Server.after_feature_init do
|
||||||
::Compass.configuration do |config|
|
::Compass.configuration do |config|
|
||||||
config.asset_cache_buster do |path, real_path|
|
config.asset_cache_buster do |path, real_path|
|
||||||
real_path = real_path.path if real_path.is_a? File
|
real_path = real_path.path if real_path.is_a? File
|
||||||
real_path = real_path.gsub(File.join(Middleman::Base.root, Middleman::Base.build_dir), Middleman::Base.public)
|
real_path = real_path.gsub(File.join(Middleman::Server.root, Middleman::Server.build_dir), Middleman::Server.public)
|
||||||
if File.readable?(real_path)
|
if File.readable?(real_path)
|
||||||
File.mtime(real_path).strftime("%s")
|
File.mtime(real_path).strftime("%s")
|
||||||
else
|
else
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
class Middleman::Features::DefaultHelpers
|
class Middleman::Features::DefaultHelpers
|
||||||
def initialize(app)
|
def initialize(app, config)
|
||||||
Middleman::Base.helpers Helpers
|
Middleman::Server.helpers Helpers
|
||||||
end
|
end
|
||||||
|
|
||||||
module Helpers
|
module Helpers
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
class Middleman::Features::LiveReload
|
class Middleman::Features::LiveReload
|
||||||
def initialize(app)
|
def initialize(app, config)
|
||||||
return unless Middleman::Base.environment == :development
|
return unless Middleman::Server.environment == :development
|
||||||
|
|
||||||
begin
|
begin
|
||||||
require 'livereload'
|
require 'livereload'
|
||||||
|
@ -12,7 +12,7 @@ class Middleman::Features::LiveReload
|
||||||
config.exts = %w(haml sass scss coffee less builder)
|
config.exts = %w(haml sass scss coffee less builder)
|
||||||
end
|
end
|
||||||
|
|
||||||
::LiveReload.run [Middleman::Base.public, Middleman::Base.views], new_config
|
::LiveReload.run [Middleman::Server.public, Middleman::Server.views], new_config
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
class Middleman::Features::MinifyCSS
|
class Middleman::Features::MinifyCSS
|
||||||
def initialize(app)
|
def initialize(app, config)
|
||||||
Middleman::Base.after_feature_init do
|
Middleman::Server.after_feature_init do
|
||||||
::Compass.configuration.output_style = :compressed
|
::Compass.configuration.output_style = :compressed
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
class Middleman::Features::MinifyJavascript
|
class Middleman::Features::MinifyJavascript
|
||||||
def initialize(app)
|
def initialize(app, config)
|
||||||
Haml::Javascript.send :include, ::Haml::Filters::Base
|
Haml::Javascript.send :include, ::Haml::Filters::Base
|
||||||
|
|
||||||
require "middleman/features/minify_javascript/rack"
|
require "middleman/features/minify_javascript/rack"
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
class Middleman::Features::RelativeAssets
|
class Middleman::Features::RelativeAssets
|
||||||
def initialize(app)
|
def initialize(app, config)
|
||||||
::Compass.configuration.relative_assets = true
|
::Compass.configuration.relative_assets = true
|
||||||
|
|
||||||
Middleman::Assets.register :relative_assets do |path, prefix, request|
|
Middleman::Assets.register :relative_assets do |path, prefix, request|
|
||||||
begin
|
begin
|
||||||
prefix = Middleman::Base.images_dir if prefix == Middleman::Base.http_images_path
|
prefix = Middleman::Server.images_dir if prefix == Middleman::Server.http_images_path
|
||||||
rescue
|
rescue
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@ class Middleman::Features::RelativeAssets
|
||||||
else
|
else
|
||||||
path = File.join(prefix, path) if prefix.length > 0
|
path = File.join(prefix, path) if prefix.length > 0
|
||||||
request_path = request.path_info.dup
|
request_path = request.path_info.dup
|
||||||
request_path << Middleman::Base.index_file if path.match(%r{/$})
|
request_path << Middleman::Server.index_file if path.match(%r{/$})
|
||||||
request_path.gsub!(%r{^/}, '')
|
request_path.gsub!(%r{^/}, '')
|
||||||
parts = request_path.split('/')
|
parts = request_path.split('/')
|
||||||
|
|
||||||
|
|
|
@ -1,44 +1,16 @@
|
||||||
Entry = Struct.new(:dir, :children)
|
Entry = Struct.new(:dir, :children)
|
||||||
|
|
||||||
class Middleman::Features::Slickmap
|
class Middleman::Features::Slickmap
|
||||||
def initialize(app)
|
def initialize(app, config)
|
||||||
require 'slickmap'
|
require 'slickmap'
|
||||||
|
|
||||||
if Middleman::Base.environment == "build"
|
@sitemap_url = config[:url] || "sitemap.html"
|
||||||
Middleman::Builder.template :slickmap, "sitemap.html", "sitemap.html"
|
|
||||||
|
if Middleman::Server.environment == :build
|
||||||
|
Middleman::Builder.template :slickmap, @sitemap_url, @sitemap_url
|
||||||
end
|
end
|
||||||
|
|
||||||
def build_sitemap(&block)
|
Middleman::Server.helpers do
|
||||||
@@utility = []
|
|
||||||
[recurse_sitemap(Middleman::Base.views, &block), @@utility]
|
|
||||||
end
|
|
||||||
|
|
||||||
def recurse_sitemap(path, &block)
|
|
||||||
bad_ext = path.split('.html')[1]
|
|
||||||
path = path.gsub(bad_ext, '') if bad_ext
|
|
||||||
entry = Entry.new(path, [])
|
|
||||||
|
|
||||||
#no "." or ".." dirs
|
|
||||||
Dir[File.join(path, "*")].each do |e|
|
|
||||||
next if !File.directory?(e) && !e.include?(".html")
|
|
||||||
if File.directory?(e)
|
|
||||||
entry.children << recurse_sitemap(e, &block)
|
|
||||||
elsif block_given?
|
|
||||||
how_to_handle = block.call(e)
|
|
||||||
if how_to_handle == :valid
|
|
||||||
entry.children << recurse_sitemap(e, &block)
|
|
||||||
elsif how_to_handle == :utility
|
|
||||||
bad_ext = e.split('.html')[1]
|
|
||||||
e = e.gsub(bad_ext, '') if bad_ext
|
|
||||||
@@utility << e.gsub(Middleman::Base.views + "/", '')
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
entry
|
|
||||||
end
|
|
||||||
|
|
||||||
Middleman::Base.helpers do
|
|
||||||
def sitemap_node(n, first=false)
|
def sitemap_node(n, first=false)
|
||||||
if n.children.length < 1
|
if n.children.length < 1
|
||||||
if !first && File.extname(n.dir).length > 0
|
if !first && File.extname(n.dir).length > 0
|
||||||
|
@ -72,47 +44,45 @@ class Middleman::Features::Slickmap
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
Middleman::Base.get '/sitemap.html' do
|
Middleman::Server.get "/#{@sitemap_url}" do
|
||||||
# Return :utility to put it util top menu. False to ignore
|
# Return :utility to put it util top menu. False to ignore
|
||||||
@tree, @utility = build_sitemap do |file_name|
|
@tree, @utility = Middleman::Features::Slickmap.build_sitemap do |file_name|
|
||||||
:valid
|
:valid
|
||||||
end
|
end
|
||||||
haml :sitemap, :layout => false
|
|
||||||
|
haml "template.html".to_sym, :layout => false, :views => File.expand_path(File.join(File.dirname(__FILE__), "slickmap"))
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
Middleman::Base.use_in_file_templates!
|
def self.build_sitemap(&block)
|
||||||
|
@@utility = []
|
||||||
|
[recurse_sitemap(Middleman::Server.views, &block), @@utility]
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.recurse_sitemap(path, &block)
|
||||||
|
bad_ext = path.split('.html')[1]
|
||||||
|
path = path.gsub(bad_ext, '') if bad_ext
|
||||||
|
entry = Entry.new(path, [])
|
||||||
|
|
||||||
|
#no "." or ".." dirs
|
||||||
|
Dir[File.join(path, "*")].each do |e|
|
||||||
|
next if !File.directory?(e) && !e.include?(".html")
|
||||||
|
if File.directory?(e)
|
||||||
|
entry.children << recurse_sitemap(e, &block)
|
||||||
|
elsif block_given?
|
||||||
|
how_to_handle = block.call(e)
|
||||||
|
if how_to_handle == :valid
|
||||||
|
entry.children << recurse_sitemap(e, &block)
|
||||||
|
elsif how_to_handle == :utility
|
||||||
|
bad_ext = e.split('.html')[1]
|
||||||
|
e = e.gsub(bad_ext, '') if bad_ext
|
||||||
|
@@utility << e.gsub(Middleman::Server.views + "/", '')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
entry
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
Middleman::Features.register :slickmap, Middleman::Features::Slickmap
|
Middleman::Features.register :slickmap, Middleman::Features::Slickmap
|
||||||
|
|
||||||
__END__
|
|
||||||
|
|
||||||
@@ sitemap
|
|
||||||
!!!
|
|
||||||
%html{ :xmlns => "http://www.w3.org/1999/xhtml" }
|
|
||||||
%head
|
|
||||||
%meta{ :content => "text/html; charset=utf-8", "http-equiv" => "Content-type" }
|
|
||||||
%title Sitemap
|
|
||||||
%style{ :type => "text/css" }
|
|
||||||
:sass
|
|
||||||
@import "slickmap"
|
|
||||||
+slickmap
|
|
||||||
:javascript
|
|
||||||
window.onload = function() {
|
|
||||||
document.getElementById('primaryNav').className = "col" + document.querySelectorAll("#primaryNav > li:not(#home)").length;
|
|
||||||
};
|
|
||||||
|
|
||||||
%body
|
|
||||||
.logo
|
|
||||||
%h1= @project_name || "Sitemap"
|
|
||||||
- if @project_subtitle
|
|
||||||
%h2= @project_subtitle
|
|
||||||
|
|
||||||
- if @utility.length > 0
|
|
||||||
%ul#utilityNav
|
|
||||||
- @utility.each do |u|
|
|
||||||
%li= link_to u, u
|
|
||||||
|
|
||||||
%ul#primaryNav
|
|
||||||
- sitemap_node(@tree, true)
|
|
27
lib/middleman/features/slickmap/template.html.haml
Normal file
27
lib/middleman/features/slickmap/template.html.haml
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
!!!
|
||||||
|
%html{ :xmlns => "http://www.w3.org/1999/xhtml" }
|
||||||
|
%head
|
||||||
|
%meta{ :content => "text/html; charset=utf-8", "http-equiv" => "Content-type" }
|
||||||
|
%title Sitemap
|
||||||
|
%style{ :type => "text/css" }
|
||||||
|
:sass
|
||||||
|
@import "slickmap"
|
||||||
|
+slickmap
|
||||||
|
:javascript
|
||||||
|
window.onload = function() {
|
||||||
|
document.getElementById('primaryNav').className = "col" + document.querySelectorAll("#primaryNav > li:not(#home)").length;
|
||||||
|
};
|
||||||
|
|
||||||
|
%body
|
||||||
|
.logo
|
||||||
|
%h1= @project_name || "Sitemap"
|
||||||
|
- if @project_subtitle
|
||||||
|
%h2= @project_subtitle
|
||||||
|
|
||||||
|
- if @utility.length > 0
|
||||||
|
%ul#utilityNav
|
||||||
|
- @utility.each do |u|
|
||||||
|
%li= link_to u, u
|
||||||
|
|
||||||
|
%ul#primaryNav
|
||||||
|
- sitemap_node(@tree, true)
|
|
@ -1,14 +1,14 @@
|
||||||
class Middleman::Features::SmushPngs
|
class Middleman::Features::SmushPngs
|
||||||
def initialize(app)
|
def initialize(app, config)
|
||||||
require "middleman/builder"
|
require "middleman/builder"
|
||||||
|
|
||||||
Middleman::Base.alias_method :pre_smush_after_run, :after_run
|
Middleman::Server.alias_method :pre_smush_after_run, :after_run
|
||||||
Middleman::Base.define_method :after_run do
|
Middleman::Server.define_method :after_run do
|
||||||
pre_smush_after_run
|
pre_smush_after_run
|
||||||
smush_dir = File.join(Middleman::Base.build_dir, Middleman::Base.images_dir)
|
smush_dir = File.join(Middleman::Server.build_dir, Middleman::Server.images_dir)
|
||||||
|
|
||||||
# Read cache
|
# Read cache
|
||||||
cache_file = File.join(Middleman::Base.root, ".smush-cache")
|
cache_file = File.join(Middleman::Server.root, ".smush-cache")
|
||||||
cache_data = if File.exists?(cache_file)
|
cache_data = if File.exists?(cache_file)
|
||||||
Marshal.restore(File.read(cache_file))
|
Marshal.restore(File.read(cache_file))
|
||||||
else
|
else
|
||||||
|
@ -27,7 +27,7 @@ class Middleman::Features::SmushPngs
|
||||||
write_optimized_data(file)
|
write_optimized_data(file)
|
||||||
cache_data[file] = size(file) # Add or update cache
|
cache_data[file] = size(file) # Add or update cache
|
||||||
File.open(cache_file, "w") { |f| f.write Marshal.dump(cache_data) } # Write cache
|
File.open(cache_file, "w") { |f| f.write Marshal.dump(cache_data) } # Write cache
|
||||||
say "<%= color('#{"[SMUSHED]".rjust(12)}', :yellow) %> " + file.gsub(Middleman::Base.build_dir+"/", '')
|
say "<%= color('#{"[SMUSHED]".rjust(12)}', :yellow) %> " + file.gsub(Middleman::Server.build_dir+"/", '')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
class Middleman::Features::UglyHaml
|
class Middleman::Features::UglyHaml
|
||||||
def initialize(app)
|
def initialize(app, config)
|
||||||
Middleman::Base.set :haml, Middleman::Base.settings.haml.merge({ :ugly_haml => true })
|
Middleman::Server.set :haml, Middleman::Server.settings.haml.merge({ :ugly_haml => true })
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
class Middleman::Base
|
class Middleman::Server
|
||||||
def coffee(template, options={}, locals={})
|
def coffee(template, options={}, locals={})
|
||||||
options[:layout] = false
|
options[:layout] = false
|
||||||
render :coffee, template, options, locals
|
render :coffee, template, options, locals
|
||||||
|
|
|
@ -42,6 +42,6 @@ module Middleman
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class Middleman::Base
|
class Middleman::Server
|
||||||
helpers Middleman::Haml::Helpers
|
helpers Middleman::Haml::Helpers
|
||||||
end
|
end
|
|
@ -1,7 +1,7 @@
|
||||||
require "sass"
|
require "sass"
|
||||||
require "compass"
|
require "compass"
|
||||||
|
|
||||||
class Middleman::Base
|
class Middleman::Server
|
||||||
def scss(template, options={}, locals={})
|
def scss(template, options={}, locals={})
|
||||||
options[:layout] = false
|
options[:layout] = false
|
||||||
render :scss, template, options, locals
|
render :scss, template, options, locals
|
||||||
|
@ -34,13 +34,13 @@ end
|
||||||
|
|
||||||
class Tilt::SassPlusCSSFilenameTemplate < Tilt::SassTemplate
|
class Tilt::SassPlusCSSFilenameTemplate < Tilt::SassTemplate
|
||||||
def sass_options
|
def sass_options
|
||||||
location_of_sass_file = Middleman::Base.environment == "build" ?
|
location_of_sass_file = Middleman::Server.environment == :build ?
|
||||||
File.join(Middleman::Base.root, Middleman::Base.build_dir) :
|
File.join(Middleman::Server.root, Middleman::Server.build_dir) :
|
||||||
Middleman::Base.public
|
Middleman::Server.public
|
||||||
|
|
||||||
parts = basename.split('.')
|
parts = basename.split('.')
|
||||||
parts.pop
|
parts.pop
|
||||||
css_filename = File.join(location_of_sass_file, Middleman::Base.css_dir, parts.join("."))
|
css_filename = File.join(location_of_sass_file, Middleman::Server.css_dir, parts.join("."))
|
||||||
super.merge(::Compass.configuration.to_sass_engine_options).merge(:css_filename => css_filename)
|
super.merge(::Compass.configuration.to_sass_engine_options).merge(:css_filename => css_filename)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
168
lib/middleman/server.rb
Normal file
168
lib/middleman/server.rb
Normal file
|
@ -0,0 +1,168 @@
|
||||||
|
# We're riding on Sinatra, so let's include it.
|
||||||
|
require "sinatra/base"
|
||||||
|
|
||||||
|
# The content_for plugin allows Sinatra to use the throw/yield block
|
||||||
|
# system similar to Rails views.
|
||||||
|
require "sinatra/content_for"
|
||||||
|
|
||||||
|
# Monkey-patch Sinatra to expose the layout parameter
|
||||||
|
class Sinatra::Request
|
||||||
|
attr_accessor :layout
|
||||||
|
end
|
||||||
|
|
||||||
|
module Middleman
|
||||||
|
class Server < Sinatra::Base
|
||||||
|
# Basic Sinatra config
|
||||||
|
set :app_file, __FILE__
|
||||||
|
set :root, ENV["MM_DIR"] || Dir.pwd
|
||||||
|
set :reload, false
|
||||||
|
set :sessions, false
|
||||||
|
set :logging, false
|
||||||
|
set :environment, (ENV['MM_ENV'] && ENV['MM_ENV'].to_sym) || :development
|
||||||
|
|
||||||
|
# Import content_for methods
|
||||||
|
helpers Sinatra::ContentFor
|
||||||
|
|
||||||
|
# Middleman-specific options
|
||||||
|
set :index_file, "index.html" # What file responds to folder requests
|
||||||
|
# Such as the homepage (/) or subfolders (/about/)
|
||||||
|
|
||||||
|
# These directories are passed directly to Compass
|
||||||
|
set :js_dir, "javascripts" # Where to look for javascript files
|
||||||
|
set :css_dir, "stylesheets" # Where to look for CSS files
|
||||||
|
set :images_dir, "images" # Where to look for images
|
||||||
|
set :fonts_dir, "fonts" # Where to look for fonts
|
||||||
|
|
||||||
|
set :build_dir, "build" # Which folder are builds output to
|
||||||
|
set :http_prefix, nil # During build, add a prefix for absolute paths
|
||||||
|
|
||||||
|
# A hash of enabled features
|
||||||
|
@@enabled_features = {}
|
||||||
|
|
||||||
|
# Override Sinatra's enable to keep track of enabled features
|
||||||
|
def self.enable(feature_name, config={})
|
||||||
|
@@enabled_features[feature_name] = config
|
||||||
|
super(feature_name)
|
||||||
|
end
|
||||||
|
|
||||||
|
# Disable a feature, then pass to Sinatra's method
|
||||||
|
def self.disable(feature_name)
|
||||||
|
@@enabled_features.delete(feature_name)
|
||||||
|
super(feature_name)
|
||||||
|
end
|
||||||
|
|
||||||
|
# Override Sinatra's set to accept a block
|
||||||
|
def self.set(option, value=self, &block)
|
||||||
|
if block_given?
|
||||||
|
value = Proc.new { block }
|
||||||
|
end
|
||||||
|
|
||||||
|
super(option, value, &nil)
|
||||||
|
end
|
||||||
|
|
||||||
|
# An array of callback procs to run after all features have been setup
|
||||||
|
@@run_after_features = []
|
||||||
|
|
||||||
|
# Add a block/proc to be run after features have been setup
|
||||||
|
def self.after_feature_init(&block)
|
||||||
|
@@run_after_features << block
|
||||||
|
end
|
||||||
|
|
||||||
|
# Rack helper for adding mime-types during local preview
|
||||||
|
def self.mime(ext, type)
|
||||||
|
ext = ".#{ext}" unless ext.to_s[0] == ?.
|
||||||
|
::Rack::Mime::MIME_TYPES[ext.to_s] = type
|
||||||
|
end
|
||||||
|
|
||||||
|
# Keep track of a block-specific layout
|
||||||
|
@@layout = nil
|
||||||
|
|
||||||
|
# Takes a block which allows many pages to have the same layout
|
||||||
|
# with_layout :admin do
|
||||||
|
# page "/admin/"
|
||||||
|
# page "/admin/login.html"
|
||||||
|
# end
|
||||||
|
def self.with_layout(layout, &block)
|
||||||
|
@@layout = layout
|
||||||
|
class_eval(&block) if block_given?
|
||||||
|
ensure
|
||||||
|
@@layout = nil
|
||||||
|
end
|
||||||
|
|
||||||
|
# The page method allows the layout to be set on a specific path
|
||||||
|
# page "/about.html", :layout => false
|
||||||
|
# page "/", :layout => :homepage_layout
|
||||||
|
def self.page(url, options={}, &block)
|
||||||
|
layout = @@layout
|
||||||
|
layout = options[:layout] if !options[:layout].nil?
|
||||||
|
|
||||||
|
get(url) do
|
||||||
|
return yield if block_given?
|
||||||
|
process_request(layout)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# This will match all requests not overridden in the project's config.rb
|
||||||
|
not_found do
|
||||||
|
process_request
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
# Internal method to look for templates and evaluate them if found
|
||||||
|
def process_request(layout = :layout)
|
||||||
|
# Normalize the path and add index if we're looking at a directory
|
||||||
|
path = request.path
|
||||||
|
path << settings.index_file if path.match(%r{/$})
|
||||||
|
path.gsub!(%r{^/}, '')
|
||||||
|
|
||||||
|
if template_path = Dir.glob(File.join(settings.views, "#{path}.*")).first
|
||||||
|
content_type mime_type(File.extname(path)), :charset => 'utf-8'
|
||||||
|
|
||||||
|
renderer = Middleman::Renderers.get_method(template_path)
|
||||||
|
if respond_to? renderer
|
||||||
|
status 200
|
||||||
|
return send(renderer, path.to_sym, { :layout => layout })
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
status 404
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
require "middleman/assets"
|
||||||
|
require "middleman/renderers"
|
||||||
|
require "middleman/features"
|
||||||
|
|
||||||
|
# The Rack App
|
||||||
|
class Middleman::Server
|
||||||
|
def self.new(*args, &block)
|
||||||
|
# If the old init.rb exists, use it, but issue warning
|
||||||
|
old_config = File.join(self.root, "init.rb")
|
||||||
|
if File.exists? old_config
|
||||||
|
$stderr.puts "== Warning: The init.rb file has been renamed to config.rb"
|
||||||
|
local_config = old_config
|
||||||
|
end
|
||||||
|
|
||||||
|
# Check for and evaluate local configuration
|
||||||
|
local_config ||= File.join(self.root, "config.rb")
|
||||||
|
if File.exists? local_config
|
||||||
|
$stderr.puts "== Reading: Local config" if logging?
|
||||||
|
Middleman::Server.class_eval File.read(local_config)
|
||||||
|
set :app_file, File.expand_path(local_config)
|
||||||
|
end
|
||||||
|
|
||||||
|
# loop over enabled feature
|
||||||
|
@@enabled_features.each do |feature_name, feature_config|
|
||||||
|
next unless send(:"#{feature_name}?")
|
||||||
|
$stderr.puts "== Enabling: #{feature_name.to_s.capitalize}" if logging?
|
||||||
|
Middleman::Features.run(feature_name, feature_config, self)
|
||||||
|
end
|
||||||
|
|
||||||
|
use ::Rack::ConditionalGet if environment == :development
|
||||||
|
|
||||||
|
@@run_after_features.each { |block| class_eval(&block) }
|
||||||
|
|
||||||
|
super
|
||||||
|
end
|
||||||
|
end
|
|
@ -14,11 +14,11 @@ end
|
||||||
|
|
||||||
class Templater::Actions::Template
|
class Templater::Actions::Template
|
||||||
def render
|
def render
|
||||||
@@rack_test ||= Rack::Test::Session.new(Rack::MockSession.new(Middleman::Base))
|
@@rack_test ||= Rack::Test::Session.new(Rack::MockSession.new(Middleman::Server))
|
||||||
|
|
||||||
@render_cache ||= begin
|
@render_cache ||= begin
|
||||||
# The default render just requests the page over Rack and writes the response
|
# The default render just requests the page over Rack and writes the response
|
||||||
request_path = destination.gsub(File.join(Dir.pwd, Middleman::Base.build_dir), "")
|
request_path = destination.gsub(File.join(Dir.pwd, Middleman::Server.build_dir), "")
|
||||||
@@rack_test.get(request_path)
|
@@rack_test.get(request_path)
|
||||||
@@rack_test.last_response.body
|
@@rack_test.last_response.body
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
require File.join(File.dirname(__FILE__), "spec_helper")
|
require File.join(File.dirname(__FILE__), "spec_helper")
|
||||||
|
|
||||||
base = ::Middleman::Base
|
base = ::Middleman::Server
|
||||||
|
|
||||||
describe "page_classes helper" do
|
describe "page_classes helper" do
|
||||||
it "should generate root paths correctly" do
|
it "should generate root paths correctly" do
|
||||||
|
|
Loading…
Reference in a new issue