Bring back extension block register syntax. Closes #1192
This commit is contained in:
parent
d3e9108f12
commit
37a8caf3fa
3 changed files with 29 additions and 6 deletions
|
@ -1,12 +1,11 @@
|
|||
require 'middleman-core/renderers/sass'
|
||||
require 'compass'
|
||||
|
||||
class Middleman::CoreExtensions::Compass < ::Middleman::Extension
|
||||
|
||||
def initialize(app, options_hash={}, &block)
|
||||
super
|
||||
|
||||
require 'compass'
|
||||
|
||||
# Hooks to manually update the compass config after we're
|
||||
# done with it
|
||||
app.define_hook :compass_config
|
||||
|
|
|
@ -88,7 +88,7 @@ module Middleman
|
|||
# @param [Symbol, Module] ext Which extension to activate
|
||||
# @return [void]
|
||||
def activate(ext, options={}, &block)
|
||||
if extension = ::Middleman::Extensions::registered[ext]
|
||||
if extension = ::Middleman::Extensions.load(ext)
|
||||
if extension.ancestors.include?(::Middleman::Extension)
|
||||
logger.debug "== Activating: #{ext}"
|
||||
|
||||
|
|
|
@ -17,11 +17,35 @@ module Middleman
|
|||
#
|
||||
# @param [Symbol] name The name of the extension
|
||||
# @param [Module] namespace The extension module
|
||||
def register(name, namespace)
|
||||
if !registered.has_key?(name.to_sym)
|
||||
registered[name.to_sym] = namespace
|
||||
# @yield Instead of passing a module in namespace, you can provide
|
||||
# a block which returns your extension module. This gives
|
||||
# you the ability to require other files only when the
|
||||
# extension is activated.
|
||||
def register(name, namespace=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)
|
||||
|
||||
registered[name.to_sym] = if block_given?
|
||||
block
|
||||
elsif namespace
|
||||
namespace
|
||||
end
|
||||
end
|
||||
|
||||
# Load an extension by name, evaluating block definition if necessary.
|
||||
def load(name)
|
||||
name = name.to_sym
|
||||
return nil unless registered.has_key?(name)
|
||||
|
||||
extension = registered[name]
|
||||
if extension.is_a?(Proc)
|
||||
extension = extension.call() || nil
|
||||
registered[name] = extension
|
||||
end
|
||||
|
||||
extension
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue