Merge pull request #268 from pusewicz/fix-cli-bundler

Fix middleman init MY_PROJECT --bundler
This commit is contained in:
Thomas Reynolds 2012-02-11 09:42:09 -08:00
commit 8094af43d4

View file

@ -18,76 +18,78 @@ end
# Simple callback library # Simple callback library
require "middleman-core/vendor/hooks-0.2.0/lib/hooks" require "middleman-core/vendor/hooks-0.2.0/lib/hooks"
require "middleman-core/version"
# Top-level Middleman object # Top-level Middleman object
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)
JRUBY = !!(RbConfig::CONFIG["RUBY_INSTALL_NAME"] =~ /^jruby/i) unless const_defined?(:JRUBY) JRUBY = !!(RbConfig::CONFIG["RUBY_INSTALL_NAME"] =~ /^jruby/i) unless const_defined?(:JRUBY)
DARWIN = RbConfig::CONFIG['target_os'] =~ /darwin/i unless const_defined?(:DARWIN) DARWIN = RbConfig::CONFIG['target_os'] =~ /darwin/i unless const_defined?(:DARWIN)
LINUX = RbConfig::CONFIG['target_os'] =~ /linux/i unless const_defined?(:LINUX) LINUX = RbConfig::CONFIG['target_os'] =~ /linux/i unless const_defined?(:LINUX)
# Auto-load modules on-demand # Auto-load modules on-demand
autoload :Base, "middleman-core/base" autoload :Base, "middleman-core/base"
autoload :Cache, "middleman-core/cache" autoload :Cache, "middleman-core/cache"
autoload :Templates, "middleman-core/templates" autoload :Templates, "middleman-core/templates"
autoload :Watcher, "middleman-core/watcher" autoload :Watcher, "middleman-core/watcher"
module Cli module Cli
autoload :Base, "middleman-core/cli" autoload :Base, "middleman-core/cli"
autoload :Build, "middleman-core/cli/build" autoload :Build, "middleman-core/cli/build"
autoload :Init, "middleman-core/cli/init" autoload :Init, "middleman-core/cli/init"
autoload :Server, "middleman-core/cli/server" autoload :Server, "middleman-core/cli/server"
end end
# Custom Renderers # Custom Renderers
module Renderers module Renderers
autoload :ERb, "middleman-core/renderers/erb" autoload :ERb, "middleman-core/renderers/erb"
end end
module Sitemap module Sitemap
autoload :Store, "middleman-core/sitemap/store" autoload :Store, "middleman-core/sitemap/store"
autoload :Page, "middleman-core/sitemap/page" autoload :Page, "middleman-core/sitemap/page"
autoload :Template, "middleman-core/sitemap/template" autoload :Template, "middleman-core/sitemap/template"
end end
module CoreExtensions module CoreExtensions
# File Change Notifier # File Change Notifier
autoload :FileWatcher, "middleman-core/core_extensions/file_watcher" autoload :FileWatcher, "middleman-core/core_extensions/file_watcher"
# In-memory Sitemap # In-memory Sitemap
autoload :Sitemap, "middleman-core/core_extensions/sitemap" autoload :Sitemap, "middleman-core/core_extensions/sitemap"
# Add Builder callbacks # Add Builder callbacks
autoload :Builder, "middleman-core/core_extensions/builder" autoload :Builder, "middleman-core/core_extensions/builder"
# Custom Feature API # Custom Feature API
autoload :Extensions, "middleman-core/core_extensions/extensions" autoload :Extensions, "middleman-core/core_extensions/extensions"
# Asset Path Pipeline # Asset Path Pipeline
autoload :Assets, "middleman-core/core_extensions/assets" autoload :Assets, "middleman-core/core_extensions/assets"
# Data looks at the data/ folder for YAML files and makes them available # Data looks at the data/ folder for YAML files and makes them available
# to dynamic requests. # to dynamic requests.
autoload :Data, "middleman-core/core_extensions/data" autoload :Data, "middleman-core/core_extensions/data"
# Parse YAML from templates # Parse YAML from templates
autoload :FrontMatter, "middleman-core/core_extensions/front_matter" autoload :FrontMatter, "middleman-core/core_extensions/front_matter"
# External helpers looks in the helpers/ folder for helper modules # External helpers looks in the helpers/ folder for helper modules
autoload :ExternalHelpers, "middleman-core/core_extensions/external_helpers" autoload :ExternalHelpers, "middleman-core/core_extensions/external_helpers"
# DefaultHelpers are the built-in dynamic template helpers. # DefaultHelpers are the built-in dynamic template helpers.
autoload :DefaultHelpers, "middleman-core/core_extensions/default_helpers" autoload :DefaultHelpers, "middleman-core/core_extensions/default_helpers"
# Extended version of Padrino's rendering # Extended version of Padrino's rendering
autoload :Rendering, "middleman-core/core_extensions/rendering" autoload :Rendering, "middleman-core/core_extensions/rendering"
# Pass custom options to views # Pass custom options to views
autoload :Routing, "middleman-core/core_extensions/routing" autoload :Routing, "middleman-core/core_extensions/routing"
# Catch and show exceptions at the Rack level # Catch and show exceptions at the Rack level
autoload :ShowExceptions, "middleman-core/core_extensions/show_exceptions" autoload :ShowExceptions, "middleman-core/core_extensions/show_exceptions"
end end
module Extensions module Extensions
# Provide Apache-style index.html files for directories # Provide Apache-style index.html files for directories
autoload :DirectoryIndexes, "middleman-core/extensions/directory_indexes" autoload :DirectoryIndexes, "middleman-core/extensions/directory_indexes"
@ -95,18 +97,18 @@ module Middleman
# Lorem provides a handful of helpful prototyping methods to generate # Lorem provides a handful of helpful prototyping methods to generate
# words, paragraphs, fake images, names and email addresses. # words, paragraphs, fake images, names and email addresses.
autoload :Lorem, "middleman-core/extensions/lorem" autoload :Lorem, "middleman-core/extensions/lorem"
# AutomaticImageSizes inspects the images used in your dynamic templates # AutomaticImageSizes inspects the images used in your dynamic templates
# and automatically adds width and height attributes to their HTML # and automatically adds width and height attributes to their HTML
# elements. # elements.
autoload :AutomaticImageSizes, "middleman-core/extensions/automatic_image_sizes" autoload :AutomaticImageSizes, "middleman-core/extensions/automatic_image_sizes"
# AssetHost allows you to setup multiple domains to host your static # AssetHost allows you to setup multiple domains to host your static
# assets. Calls to asset paths in dynamic templates will then rotate # assets. Calls to asset paths in dynamic templates will then rotate
# through each of the asset servers to better spread the load. # through each of the asset servers to better spread the load.
autoload :AssetHost, "middleman-core/extensions/asset_host" autoload :AssetHost, "middleman-core/extensions/asset_host"
end end
module Extensions module Extensions
class << self class << self
def registered def registered
@ -114,9 +116,9 @@ module Middleman
end end
def register(name, namespace=nil, version=nil, &block) def register(name, namespace=nil, version=nil, &block)
# If we've already got a matching extension that passed the # If we've already got a matching extension that passed the
# version check, bail out. # version check, bail out.
return if registered.has_key?(name.to_sym) && return if registered.has_key?(name.to_sym) &&
!registered[name.to_sym].is_a?(String) !registered[name.to_sym].is_a?(String)
if block_given? if block_given?
@ -154,12 +156,12 @@ module Middleman
end end
end end
end end
# Where to look in gems for extensions to auto-register # Where to look in gems for extensions to auto-register
EXTENSION_FILE = File.join("lib", "middleman_extension.rb") unless const_defined?(:EXTENSION_FILE) EXTENSION_FILE = File.join("lib", "middleman_extension.rb") unless const_defined?(:EXTENSION_FILE)
class << self class << self
# Recursively convert a normal Hash into a HashWithIndifferentAccess # Recursively convert a normal Hash into a HashWithIndifferentAccess
# #
# @private # @private
@ -181,7 +183,7 @@ module Middleman
data data
end end
end end
# Automatically load extensions from available RubyGems # Automatically load extensions from available RubyGems
# which contain the EXTENSION_FILE # which contain the EXTENSION_FILE
# #
@ -190,12 +192,12 @@ module Middleman
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
end end
# Backwards compatible means of finding all the latest gemspecs # Backwards compatible means of finding all the latest gemspecs
# available on the system # available on the system
# #
@ -209,7 +211,7 @@ module Middleman
::Gem.source_index.latest_specs ::Gem.source_index.latest_specs
end end
end end
# Where a given Gem::Specification has a specific file. Used # Where a given Gem::Specification has a specific file. Used
# to discover extensions and Sprockets-supporting gems. # to discover extensions and Sprockets-supporting gems.
# #
@ -221,9 +223,9 @@ module Middleman
full_path = File.join(spec.full_gem_path, path) full_path = File.join(spec.full_gem_path, path)
File.exists?(full_path) File.exists?(full_path)
end end
# Create a new Class which is based on Middleman::Base # Create a new Class which is based on Middleman::Base
# Used to create a safe sandbox into which extensions and # Used to create a safe sandbox into which extensions and
# configuration can be included later without impacting # configuration can be included later without impacting
# other classes and instances. # other classes and instances.
# #
@ -231,34 +233,34 @@ module Middleman
def server(&block) def server(&block)
Class.new(Middleman::Base) Class.new(Middleman::Base)
end end
# Creates a new Rack::Server # Creates a new Rack::Server
# #
# @param [Hash] options to pass to Rack::Server.new # @param [Hash] options to pass to Rack::Server.new
# @return [Rack::Server] # @return [Rack::Server]
def start_server(options={}) def start_server(options={})
require "webrick" require "webrick"
opts = { opts = {
:Port => options[:port] || 4567, :Port => options[:port] || 4567,
:Host => options[:host] || "0.0.0.0", :Host => options[:host] || "0.0.0.0",
:AccessLog => [] :AccessLog => []
} }
opts[:Logger] = WEBrick::Log::new("/dev/null", 7) if !options[:logging] opts[:Logger] = WEBrick::Log::new("/dev/null", 7) if !options[:logging]
app_class = options[:app] ||= ::Middleman.server.inst app_class = options[:app] ||= ::Middleman.server.inst
opts[:app] = app_class opts[:app] = app_class
# Disable for Beta 1. See if people notice. # Disable for Beta 1. See if people notice.
# require "thin" # require "thin"
# ::Thin::Logging.silent = !options[:logging] # ::Thin::Logging.silent = !options[:logging]
# opts[:server] = 'thin' # opts[:server] = 'thin'
opts[:server] = 'webrick' opts[:server] = 'webrick'
server = ::Rack::Server.new(opts) server = ::Rack::Server.new(opts)
server.start server.start
server server
end end
end end
end end