From 41d5337f5bc9463ed19cd90ef2ab6097efcc53e1 Mon Sep 17 00:00:00 2001 From: Thomas Reynolds Date: Thu, 24 Nov 2011 14:06:04 -0800 Subject: [PATCH] allow extensions to pass version checks --- Rakefile | 2 -- lib/middleman/core_extensions/extensions.rb | 29 ++++++++++++++++++--- lib/middleman/version.rb | 1 + 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/Rakefile b/Rakefile index 52d41d40..e09bdd27 100644 --- a/Rakefile +++ b/Rakefile @@ -7,8 +7,6 @@ Cucumber::Rake::Task.new(:cucumber, 'Run features that should pass') do |t| t.cucumber_opts = "--color --tags ~@wip --strict --format #{ENV['CUCUMBER_FORMAT'] || 'pretty'}" end -#$LOAD_PATH.unshift 'lib' - require 'rake/testtask' require 'rake/clean' diff --git a/lib/middleman/core_extensions/extensions.rb b/lib/middleman/core_extensions/extensions.rb index cee35ec4..92c33e41 100644 --- a/lib/middleman/core_extensions/extensions.rb +++ b/lib/middleman/core_extensions/extensions.rb @@ -50,8 +50,27 @@ module Middleman::CoreExtensions::Extensions @_registered ||= {} end - def register(name, namespace=nil, &block) - registered[name.to_sym] = if block_given? + def register(name, namespace=nil, version=nil, &block) + # If we've already got a matching extension that passed the + # version check, bail out. + return if registered.has_key?(name.to_sym) && + !registered[name.to_sym].is_a?(String) + + if block_given? + version = namespace + end + + passed_version_check = true + if !version.nil? + requirement = ::Gem::Requirement.create(version) + if !requirement.satisfied_by?(Middleman::GEM_VERSION) + passed_version_check = false + end + end + + registered[name.to_sym] = if !passed_version_check + "== #{name} failed version check. Requested #{version}, got #{Middleman::VERSION}" + elsif block_given? block elsif namespace namespace @@ -64,7 +83,7 @@ module Middleman::CoreExtensions::Extensions extension = registered[name] if extension.is_a?(Proc) - extension = extension.call(Middleman::VERSION) || nil + extension = extension.call() || nil registered[name] = extension end @@ -102,8 +121,10 @@ module Middleman::CoreExtensions::Extensions if ext.nil? puts "== Unknown Extension: #{feature}" + elsif ext.is_a?(String) + puts ext else - puts "== Activating: #{feature}" if logging? + puts "== Activating: #{feature}" if logging? self.class.register(ext) end end diff --git a/lib/middleman/version.rb b/lib/middleman/version.rb index 48433d04..fc371818 100644 --- a/lib/middleman/version.rb +++ b/lib/middleman/version.rb @@ -1,3 +1,4 @@ module Middleman VERSION = "3.0.0.alpha.3" + GEM_VERSION = ::Gem::Version.create(VERSION) end