simplest thing that could work implementation of Middleman::Extension
This commit is contained in:
parent
cd539f4e91
commit
420b4c6087
|
@ -78,6 +78,7 @@ module Middleman
|
|||
@extensions ||= []
|
||||
@extensions += [extension]
|
||||
|
||||
if extension.instance_of? Module
|
||||
extend extension
|
||||
if extension.respond_to?(:registered)
|
||||
if extension.method(:registered).arity === 1
|
||||
|
@ -86,6 +87,9 @@ module Middleman
|
|||
extension.registered(self, options, &block)
|
||||
end
|
||||
end
|
||||
elsif extension.instance_of?(Class) && extension.ancestors.include?(::Middleman::Extension)
|
||||
extension.new(self, options, &block)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -100,4 +100,40 @@ module Middleman
|
|||
File.exists?(full_path)
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue