From 862a56a343a49da47987431f24633ff9c3cb6fc9 Mon Sep 17 00:00:00 2001 From: Thomas Reynolds Date: Wed, 13 Jun 2012 20:33:50 -0700 Subject: [PATCH] Attempt address #466 and avoid Bundler issues with RVM --- middleman-core/bin/middleman | 14 +++++++-- .../lib/middleman-core/extensions.rb | 30 ++++++++----------- 2 files changed, 25 insertions(+), 19 deletions(-) diff --git a/middleman-core/bin/middleman b/middleman-core/bin/middleman index b536f2bb..440bbbb8 100755 --- a/middleman-core/bin/middleman +++ b/middleman-core/bin/middleman @@ -22,6 +22,8 @@ if !ENV["MM_ROOT"] && found_path = locate_root ENV["MM_ROOT"] = found_path end +is_bundler_setup = false + # If we've found the root, try to setup Bundler if ENV["MM_ROOT"] @@ -33,12 +35,20 @@ if ENV["MM_ROOT"] ENV['BUNDLE_GEMFILE'] = git_gemfile.to_s end - require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE']) + if File.exists?(ENV['BUNDLE_GEMFILE']) + is_bundler_setup = true + require 'bundler/setup' + end end # Automatically discover extensions in RubyGems require "middleman-core/extensions" -::Middleman.load_extensions_in_path + +if is_bundler_setup + Bundler.require +else + ::Middleman.load_extensions_in_path +end require "middleman-core/cli" diff --git a/middleman-core/lib/middleman-core/extensions.rb b/middleman-core/lib/middleman-core/extensions.rb index 8478d2ea..37b0f59d 100644 --- a/middleman-core/lib/middleman-core/extensions.rb +++ b/middleman-core/lib/middleman-core/extensions.rb @@ -58,23 +58,19 @@ module Middleman # # @private def load_extensions_in_path - if defined?(Bundler) - Bundler.require - else - require "rubygems" - - begin - require "middleman-more" - rescue LoadError - end - - extensions = rubygems_latest_specs.select do |spec| - spec_has_file?(spec, EXTENSION_FILE) - end - - extensions.each do |spec| - require spec.name - end + require "rubygems" + + begin + require "middleman-more" + rescue LoadError + end + + extensions = rubygems_latest_specs.select do |spec| + spec_has_file?(spec, EXTENSION_FILE) + end + + extensions.each do |spec| + require spec.name end end