autoload
This commit is contained in:
parent
65925fc0e5
commit
25ce57017b
|
@ -2,4 +2,17 @@ libdir = File.dirname(__FILE__)
|
||||||
$LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir)
|
$LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir)
|
||||||
|
|
||||||
require 'rubygems'
|
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
|
|
@ -12,6 +12,7 @@ module Middleman
|
||||||
set :app_file, __FILE__
|
set :app_file, __FILE__
|
||||||
set :root, ENV["MM_DIR"] || Dir.pwd
|
set :root, ENV["MM_DIR"] || Dir.pwd
|
||||||
set :reload, false
|
set :reload, false
|
||||||
|
set :sessions, false
|
||||||
set :logging, false
|
set :logging, false
|
||||||
set :environment, ENV['MM_ENV'] || :development
|
set :environment, ENV['MM_ENV'] || :development
|
||||||
set :supported_formats, %w(erb)
|
set :supported_formats, %w(erb)
|
||||||
|
@ -23,7 +24,6 @@ module Middleman
|
||||||
set :build_dir, "build"
|
set :build_dir, "build"
|
||||||
set :http_prefix, nil
|
set :http_prefix, nil
|
||||||
|
|
||||||
#use ::Rack::ConditionalGet if environment == :development
|
|
||||||
helpers Sinatra::ContentFor
|
helpers Sinatra::ContentFor
|
||||||
|
|
||||||
set :features, []
|
set :features, []
|
||||||
|
@ -69,11 +69,8 @@ module Middleman
|
||||||
# Base case renderer (do nothing), Should be over-ridden
|
# Base case renderer (do nothing), Should be over-ridden
|
||||||
module StaticRender
|
module StaticRender
|
||||||
def render_path(path, layout)
|
def render_path(path, layout)
|
||||||
if template_exists?(path, :erb)
|
return false if !template_exists?(path, :erb)
|
||||||
erb(path.to_sym, :layout => layout)
|
erb(path.to_sym, :layout => layout)
|
||||||
else
|
|
||||||
false
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
include StaticRender
|
include StaticRender
|
||||||
|
@ -96,11 +93,6 @@ module Middleman
|
||||||
@@layout = nil
|
@@layout = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
# This will match all requests not overridden in the project's init.rb
|
|
||||||
not_found do
|
|
||||||
process_request
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.enabled?(name)
|
def self.enabled?(name)
|
||||||
name = (name.to_s << "?").to_sym
|
name = (name.to_s << "?").to_sym
|
||||||
self.respond_to?(name) && self.send(name)
|
self.respond_to?(name) && self.send(name)
|
||||||
|
@ -110,6 +102,11 @@ module Middleman
|
||||||
self.class.enabled?(name)
|
self.class.enabled?(name)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# This will match all requests not overridden in the project's init.rb
|
||||||
|
not_found do
|
||||||
|
process_request
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
def process_request(layout = :layout)
|
def process_request(layout = :layout)
|
||||||
# Normalize the path and add index if we're looking at a directory
|
# Normalize the path and add index if we're looking at a directory
|
||||||
|
@ -132,11 +129,6 @@ end
|
||||||
# Haml is required & includes helpers
|
# Haml is required & includes helpers
|
||||||
require "middleman/haml"
|
require "middleman/haml"
|
||||||
require "middleman/sass"
|
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
|
class Middleman::Base
|
||||||
helpers Middleman::Helpers
|
helpers Middleman::Helpers
|
||||||
|
@ -177,6 +169,7 @@ class Middleman::Base
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
use ::Rack::ConditionalGet if environment == :development
|
||||||
use Middleman::Rack::MinifyJavascript if minify_javascript?
|
use Middleman::Rack::MinifyJavascript if minify_javascript?
|
||||||
use Middleman::Rack::MinifyCSS if minify_css?
|
use Middleman::Rack::MinifyCSS if minify_css?
|
||||||
|
|
||||||
|
|
|
@ -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
|
|
|
@ -1,9 +1,4 @@
|
||||||
begin
|
require 'sprockets'
|
||||||
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
|
|
||||||
|
|
||||||
class Middleman::Rack::Sprockets
|
class Middleman::Rack::Sprockets
|
||||||
def initialize(app, options={})
|
def initialize(app, options={})
|
||||||
|
@ -33,3 +28,34 @@ class Middleman::Rack::Sprockets
|
||||||
end
|
end
|
||||||
|
|
||||||
Middleman::Base.supported_formats << "js"
|
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
|
|
@ -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
|
|
Loading…
Reference in a new issue