Tweak callback delegation
This commit is contained in:
parent
69e66b04df
commit
ee0f9f00f5
|
@ -261,6 +261,12 @@ module Middleman
|
||||||
# Eval config.
|
# Eval config.
|
||||||
evaluate_configuration!
|
evaluate_configuration!
|
||||||
|
|
||||||
|
# Run any `configure` blocks for the current environment.
|
||||||
|
execute_callbacks([:configure, config[:environment]])
|
||||||
|
|
||||||
|
# Run any `configure` blocks for the current mode.
|
||||||
|
execute_callbacks([:configure, config[:mode]])
|
||||||
|
|
||||||
# Post parsing, pre-extension callback
|
# Post parsing, pre-extension callback
|
||||||
execute_callbacks(:after_configuration_eval)
|
execute_callbacks(:after_configuration_eval)
|
||||||
|
|
||||||
|
@ -292,12 +298,6 @@ module Middleman
|
||||||
logger.debug "== Reading: #{config[:environment]} config"
|
logger.debug "== Reading: #{config[:environment]} config"
|
||||||
config_context.instance_eval File.read(env_config), env_config, 1
|
config_context.instance_eval File.read(env_config), env_config, 1
|
||||||
end
|
end
|
||||||
|
|
||||||
# Run any `configure` blocks for the current environment.
|
|
||||||
execute_callbacks([:configure, config[:environment]])
|
|
||||||
|
|
||||||
# Run any `configure` blocks for the current mode.
|
|
||||||
execute_callbacks([:configure, config[:mode]])
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Clean up missing Tilt exts
|
# Clean up missing Tilt exts
|
||||||
|
|
|
@ -9,6 +9,7 @@ module Middleman
|
||||||
Contract Any
|
Contract Any
|
||||||
def initialize
|
def initialize
|
||||||
@callbacks = ::Hamster.hash
|
@callbacks = ::Hamster.hash
|
||||||
|
@subscribers = ::Hamster.vector
|
||||||
end
|
end
|
||||||
|
|
||||||
Contract RespondTo[:define_singleton_method], ArrayOf[Symbol] => Any
|
Contract RespondTo[:define_singleton_method], ArrayOf[Symbol] => Any
|
||||||
|
@ -28,6 +29,7 @@ module Middleman
|
||||||
end
|
end
|
||||||
|
|
||||||
install_target.define_singleton_method(:callbacks_for, &method(:callbacks_for))
|
install_target.define_singleton_method(:callbacks_for, &method(:callbacks_for))
|
||||||
|
install_target.define_singleton_method(:subscribe_to_callbacks, &method(:subscribe))
|
||||||
end
|
end
|
||||||
|
|
||||||
Contract Or[Symbol, ArrayOf[Symbol]], Proc => Any
|
Contract Or[Symbol, ArrayOf[Symbol]], Proc => Any
|
||||||
|
@ -39,9 +41,15 @@ module Middleman
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Contract Proc => Any
|
||||||
|
def subscribe(&block)
|
||||||
|
@subscribers = @subscribers.push(block)
|
||||||
|
end
|
||||||
|
|
||||||
Contract Or[Symbol, ArrayOf[Symbol]], Maybe[ArrayOf[Any]], Maybe[RespondTo[:instance_exec]] => Any
|
Contract Or[Symbol, ArrayOf[Symbol]], Maybe[ArrayOf[Any]], Maybe[RespondTo[:instance_exec]] => Any
|
||||||
def execute(keys, args=[], scope=self)
|
def execute(keys, args=[], scope=self)
|
||||||
callbacks_for(keys).each { |b| scope.instance_exec(*args, &b) }
|
callbacks_for(keys).each { |b| scope.instance_exec(*args, &b) }
|
||||||
|
@subscribers.each { |b| scope.instance_exec(keys, *args, &b) }
|
||||||
end
|
end
|
||||||
|
|
||||||
Contract Or[Symbol, ArrayOf[Symbol]] => ::Hamster::Vector
|
Contract Or[Symbol, ArrayOf[Symbol]] => ::Hamster::Vector
|
||||||
|
|
|
@ -15,19 +15,11 @@ module Middleman
|
||||||
@app = app
|
@app = app
|
||||||
@template_context_class = template_context_class
|
@template_context_class = template_context_class
|
||||||
|
|
||||||
sub_callbacks = [:before_build, :after_build, :configure, :after_configuration, :ready]
|
|
||||||
|
|
||||||
@callbacks = ::Middleman::CallbackManager.new
|
@callbacks = ::Middleman::CallbackManager.new
|
||||||
@callbacks.install_methods!(self, sub_callbacks)
|
@callbacks.install_methods!(self, [:before_build, :after_build, :configure, :after_configuration, :ready])
|
||||||
|
|
||||||
# Trigger internal callbacks when app level are executed.
|
# Trigger internal callbacks when app level are executed.
|
||||||
self_context = self
|
app.subscribe_to_callbacks(&method(:execute_callbacks))
|
||||||
|
|
||||||
sub_callbacks.each do |key|
|
|
||||||
app.send(key) do |*args|
|
|
||||||
self_context.execute_callbacks(key, args)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def helpers(*helper_modules, &block)
|
def helpers(*helper_modules, &block)
|
||||||
|
|
Loading…
Reference in a new issue