From deb68c29a7124ca67fbe0988f27e8dfc50bef328 Mon Sep 17 00:00:00 2001 From: Thomas Reynolds Date: Mon, 29 Aug 2011 11:53:11 -0700 Subject: [PATCH] try to make extension loading generic --- lib/middleman.rb | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/lib/middleman.rb b/lib/middleman.rb index 4b00b5ea..2997afd8 100755 --- a/lib/middleman.rb +++ b/lib/middleman.rb @@ -159,13 +159,8 @@ module Middleman EXTENSION_FILE = "middleman_init.rb" def self.load_extensions_in_path - # If newer Rubygems - extensions = if Gem::Specification.respond_to? :latest_specs - ::Gem::Specification.latest_specs.select do |spec| - spec.contains_requirable_file?(EXTENSION_FILE) - end - else - ::Gem::GemPathSearcher.new.find_all(EXTENSION_FILE) + extensions = rubygems_latest_specs.select do |spec| + spec_has_file?(spec, EXTENSION_FILE) end extensions.each do |spec| @@ -174,6 +169,20 @@ module Middleman end end + def self.rubygems_latest_specs + # If newer Rubygems + if Gem::Specification.respond_to? :latest_specs + Gem::Specification.latest_specs + else + Gem.source_index.latest_specs + end + end + + def self.spec_has_file?(spec, path) + full_path = File.join(spec.full_gem_path, path) + File.exists?(full_path) + end + def self.server(&block) sandbox = Class.new(Sinatra::Base) sandbox.register Base