This commit is contained in:
tdreyno 2010-03-02 22:00:46 -08:00
parent 65925fc0e5
commit 25ce57017b
5 changed files with 57 additions and 72 deletions

View file

@ -2,4 +2,17 @@ libdir = File.dirname(__FILE__)
$LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir)
require 'rubygems'
require 'middleman/base'
module Middleman
module Rack
autoload :Sprockets, "middleman/rack/sprockets"
autoload :MinifyJavascript, "middleman/rack/minify_javascript"
autoload :MinifyCSS, "middleman/rack/minify_css"
end
autoload :Base, "middleman/base"
autoload :Haml, "middleman/haml"
autoload :Helpers, "middleman/helpers"
end

View file

@ -12,6 +12,7 @@ module Middleman
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 :supported_formats, %w(erb)
@ -23,7 +24,6 @@ module Middleman
set :build_dir, "build"
set :http_prefix, nil
#use ::Rack::ConditionalGet if environment == :development
helpers Sinatra::ContentFor
set :features, []
@ -69,11 +69,8 @@ module Middleman
# Base case renderer (do nothing), Should be over-ridden
module StaticRender
def render_path(path, layout)
if template_exists?(path, :erb)
erb(path.to_sym, :layout => layout)
else
false
end
return false if !template_exists?(path, :erb)
erb(path.to_sym, :layout => layout)
end
end
include StaticRender
@ -96,11 +93,6 @@ module Middleman
@@layout = nil
end
# This will match all requests not overridden in the project's init.rb
not_found do
process_request
end
def self.enabled?(name)
name = (name.to_s << "?").to_sym
self.respond_to?(name) && self.send(name)
@ -110,6 +102,11 @@ module Middleman
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
@ -132,11 +129,6 @@ end
# Haml is required & includes helpers
require "middleman/haml"
require "middleman/sass"
require "middleman/helpers"
require "middleman/rack/static"
require "middleman/rack/sprockets"
require "middleman/rack/minify_javascript"
require "middleman/rack/minify_css"
class Middleman::Base
helpers Middleman::Helpers
@ -177,6 +169,7 @@ class Middleman::Base
end
end
use ::Rack::ConditionalGet if environment == :development
use Middleman::Rack::MinifyJavascript if minify_javascript?
use Middleman::Rack::MinifyCSS if minify_css?

View file

@ -1,29 +0,0 @@
module Sprockets
class SourceFile
def source_lines
@lines ||= begin
lines = []
comments = []
File.open(pathname.absolute_location, 'rb') do |file|
file.each do |line|
lines << line = SourceLine.new(self, line, file.lineno)
if line.begins_pdoc_comment? || comments.any?
comments << line
end
if line.ends_multiline_comment?
if line.ends_pdoc_comment?
comments.each { |l| l.comment! }
end
comments.clear
end
end
end
lines
end
end
end
end

View file

@ -1,9 +1,4 @@
begin
require 'sprockets'
require 'middleman/rack/sprockets+ruby19' # Sprockets ruby 1.9 duckpunch
rescue LoadError
puts "Sprockets not available. Install it with: gem install sprockets"
end
require 'sprockets'
class Middleman::Rack::Sprockets
def initialize(app, options={})
@ -33,3 +28,34 @@ class Middleman::Rack::Sprockets
end
Middleman::Base.supported_formats << "js"
# Sprockets ruby 1.9 duckpunch
module Sprockets
class SourceFile
def source_lines
@lines ||= begin
lines = []
comments = []
File.open(pathname.absolute_location, 'rb') do |file|
file.each do |line|
lines << line = SourceLine.new(self, line, file.lineno)
if line.begins_pdoc_comment? || comments.any?
comments << line
end
if line.ends_multiline_comment?
if line.ends_pdoc_comment?
comments.each { |l| l.comment! }
end
comments.clear
end
end
end
lines
end
end
end
end

View file

@ -1,18 +0,0 @@
class Middleman::Rack::Static
def initialize(app, options={})
@app = app
end
def call(env)
public_file_path = File.join(Middleman::Base.public, env["PATH_INFO"])
view_file_path = File.join(Middleman::Base.views, env["PATH_INFO"])
if File.exists?(public_file_path) && !File.directory?(public_file_path)
::Rack::File.new(Middleman::Base.public).call(env)
elsif File.exists?(view_file_path) && !File.directory?(view_file_path)
::Rack::File.new(Middleman::Base.views).call(env)
else
@app.call(env)
end
end
end