Module: Middleman::Extensions

Defined in:
lib/middleman-core/extensions.rb

Class Method Summary collapse

Class Method Details

.load(name) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/middleman-core/extensions.rb', line 37

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

.register(name, namespace = nil) { ... } ⇒ Object

Register a new extension. Choose a name which will be used to activate the extension in config.rb, like this:

activate :my_extension

Provide your extension module either as the namespace parameter, or return it from the block:

Parameters:

  • name (Symbol)

    The name of the extension

  • namespace (Module) (defaults to: nil)

    The extension module

Yields:

  • 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.



24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/middleman-core/extensions.rb', line 24

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

.registeredObject



6
7
8
# File 'lib/middleman-core/extensions.rb', line 6

def registered
  @_registered ||= {}
end