From 25ce57017bd3face66d8ba7653f2e0fa7111e0c3 Mon Sep 17 00:00:00 2001 From: tdreyno Date: Tue, 2 Mar 2010 22:00:46 -0800 Subject: [PATCH] autoload --- lib/middleman.rb | 15 +++++++++- lib/middleman/base.rb | 27 +++++++---------- lib/middleman/rack/sprockets+ruby19.rb | 29 ------------------- lib/middleman/rack/sprockets.rb | 40 +++++++++++++++++++++----- lib/middleman/rack/static.rb | 18 ------------ 5 files changed, 57 insertions(+), 72 deletions(-) delete mode 100755 lib/middleman/rack/sprockets+ruby19.rb delete mode 100644 lib/middleman/rack/static.rb diff --git a/lib/middleman.rb b/lib/middleman.rb index f731059d..490798fa 100755 --- a/lib/middleman.rb +++ b/lib/middleman.rb @@ -2,4 +2,17 @@ libdir = File.dirname(__FILE__) $LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir) require 'rubygems' -require 'middleman/base' \ No newline at end of file + +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 \ No newline at end of file diff --git a/lib/middleman/base.rb b/lib/middleman/base.rb index e10d7bf5..7ffb7789 100644 --- a/lib/middleman/base.rb +++ b/lib/middleman/base.rb @@ -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 @@ -95,11 +92,6 @@ module Middleman ensure @@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 @@ -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 @@ -176,7 +168,8 @@ class Middleman::Base require "middleman/#{feature_path}" end end - + + use ::Rack::ConditionalGet if environment == :development use Middleman::Rack::MinifyJavascript if minify_javascript? use Middleman::Rack::MinifyCSS if minify_css? diff --git a/lib/middleman/rack/sprockets+ruby19.rb b/lib/middleman/rack/sprockets+ruby19.rb deleted file mode 100755 index 59894983..00000000 --- a/lib/middleman/rack/sprockets+ruby19.rb +++ /dev/null @@ -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 \ No newline at end of file diff --git a/lib/middleman/rack/sprockets.rb b/lib/middleman/rack/sprockets.rb index 6797ce21..add50482 100644 --- a/lib/middleman/rack/sprockets.rb +++ b/lib/middleman/rack/sprockets.rb @@ -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={}) @@ -32,4 +27,35 @@ class Middleman::Rack::Sprockets end end -Middleman::Base.supported_formats << "js" \ No newline at end of file +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 \ No newline at end of file diff --git a/lib/middleman/rack/static.rb b/lib/middleman/rack/static.rb deleted file mode 100644 index 96a0ff1b..00000000 --- a/lib/middleman/rack/static.rb +++ /dev/null @@ -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 \ No newline at end of file