simplest thing that could work implementation of Middleman::Extension
This commit is contained in:
parent
cd539f4e91
commit
420b4c6087
|
@ -78,13 +78,17 @@ module Middleman
|
||||||
@extensions ||= []
|
@extensions ||= []
|
||||||
@extensions += [extension]
|
@extensions += [extension]
|
||||||
|
|
||||||
extend extension
|
if extension.instance_of? Module
|
||||||
if extension.respond_to?(:registered)
|
extend extension
|
||||||
if extension.method(:registered).arity === 1
|
if extension.respond_to?(:registered)
|
||||||
extension.registered(self, &block)
|
if extension.method(:registered).arity === 1
|
||||||
else
|
extension.registered(self, &block)
|
||||||
extension.registered(self, options, &block)
|
else
|
||||||
|
extension.registered(self, options, &block)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
elsif extension.instance_of?(Class) && extension.ancestors.include?(::Middleman::Extension)
|
||||||
|
extension.new(self, options, &block)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -100,4 +100,40 @@ module Middleman
|
||||||
File.exists?(full_path)
|
File.exists?(full_path)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
class Extension
|
||||||
|
class << self
|
||||||
|
def config
|
||||||
|
@_config ||= ::Middleman::Configuration::ConfigurationManager.new
|
||||||
|
end
|
||||||
|
|
||||||
|
def option(key, default=nil, description=nil)
|
||||||
|
config.define_setting(key, default, description)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
attr_accessor :app, :options
|
||||||
|
|
||||||
|
def initialize(klass, options_hash={}, &block)
|
||||||
|
@options = ::Middleman::Configuration::ConfigurationManager.new
|
||||||
|
@options.load_settings(self.class.config.all_settings)
|
||||||
|
|
||||||
|
options_hash.each do |k, v|
|
||||||
|
@options[k] = v
|
||||||
|
end
|
||||||
|
|
||||||
|
block.call(@options) if block_given?
|
||||||
|
|
||||||
|
ext = self
|
||||||
|
klass.after_configuration do
|
||||||
|
ext.app = self
|
||||||
|
ext.after_configuration
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def after_configuration
|
||||||
|
|
||||||
|
nil
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue