Require Bundler (a Gemfile) for all set up Middleman projects. We still do extension auto-discovery for "init". Gemfile may now be in any parent directory of 'config.rb', in case the Middleman project is in a subdirectory of a larger project.

This commit is contained in:
Ben Hollis 2014-03-03 23:08:32 -08:00
parent 9e9bed0043
commit 220d1e8948
3 changed files with 29 additions and 28 deletions

View file

@ -1,6 +1,9 @@
master master
=== ===
* Remove 'upgrade' and 'install' CLI commands.
* Gemfile may be in a parent directory of your Middleman project root (where 'config.rb' is).
* All dependencies for your Middleman project must be expressed in `Gemfile` - Bundler is no longer optional.
* Asciidoc information now available with the `asciidoc` local, which is a normal hash. * Asciidoc information now available with the `asciidoc` local, which is a normal hash.
* Remove `page` template local. Use `current_resource` instead. * Remove `page` template local. Use `current_resource` instead.
* Dropped support for providing a block to `page` & `proxy`. * Dropped support for providing a block to `page` & `proxy`.

View file

@ -88,7 +88,6 @@ end
# Include the core CLI items # Include the core CLI items
require 'middleman-cli/init' require 'middleman-cli/init'
require 'middleman-cli/bundler'
require 'middleman-cli/extension' require 'middleman-cli/extension'
require 'middleman-cli/server' require 'middleman-cli/server'
require 'middleman-cli/build' require 'middleman-cli/build'

View file

@ -8,35 +8,16 @@ module Middleman
@_is_setup ||= begin @_is_setup ||= begin
# Only look for config.rb if MM_ROOT isn't set # Only look for config.rb if MM_ROOT isn't set
if !ENV['MM_ROOT'] && found_path = locate_root if !ENV['MM_ROOT'] && (found_path = findup('config.rb'))
ENV['MM_ROOT'] = found_path ENV['MM_ROOT'] = found_path
end end
is_bundler_setup = false
# If we've found the root, try to setup Bundler # If we've found the root, try to setup Bundler
if ENV['MM_ROOT'] if ENV['MM_ROOT']
setup_bundler
root_gemfile = File.expand_path('Gemfile', ENV['MM_ROOT']) else
ENV['BUNDLE_GEMFILE'] ||= root_gemfile
if !File.exists?(ENV['BUNDLE_GEMFILE'])
git_gemfile = Pathname.new(__FILE__).expand_path.parent.parent.parent + 'Gemfile'
ENV['BUNDLE_GEMFILE'] = git_gemfile.to_s
end
if File.exists?(ENV['BUNDLE_GEMFILE'])
is_bundler_setup = true
require 'bundler/setup'
end
end
# Automatically discover extensions in RubyGems # Automatically discover extensions in RubyGems
require 'middleman-core/extensions' require 'middleman-core/extensions'
if is_bundler_setup
Bundler.require
else
::Middleman.load_extensions_in_path ::Middleman.load_extensions_in_path
end end
@ -44,11 +25,29 @@ module Middleman
end end
end end
# Recursive method to find config.rb private
def locate_root(cwd = Pathname.new(Dir.pwd))
return cwd.to_s if (cwd + 'config.rb').exist? # Set BUNDLE_GEMFILE and run Bundler setup. Raises an exception if there is no Gemfile
def setup_bundler
ENV['BUNDLE_GEMFILE'] ||= findup('Gemfile', ENV['MM_ROOT'])
if !File.exists?(ENV['BUNDLE_GEMFILE'])
ENV['BUNDLE_GEMFILE'] = File.expand_path('../../../../Gemfile', __FILE__)
end
if File.exists?(ENV['BUNDLE_GEMFILE'])
require 'bundler/setup'
Bundler.require
else
raise "Couldn't find your Gemfile. Middleman projects require a Gemfile for specifying dependencies."
end
end
# Recursive method to find a file in parent directories
def findup(filename, cwd = Pathname.new(Dir.pwd))
return cwd.to_s if (cwd + filename).exist?
return false if cwd.root? return false if cwd.root?
locate_root(cwd.parent) findup(cwd.parent)
end end
end end