Tweak callback delegation
This commit is contained in:
parent
69e66b04df
commit
ee0f9f00f5
3 changed files with 16 additions and 16 deletions
|
@ -261,6 +261,12 @@ module Middleman
|
|||
# Eval config.
|
||||
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
|
||||
execute_callbacks(:after_configuration_eval)
|
||||
|
||||
|
@ -292,12 +298,6 @@ module Middleman
|
|||
logger.debug "== Reading: #{config[:environment]} config"
|
||||
config_context.instance_eval File.read(env_config), env_config, 1
|
||||
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
|
||||
|
||||
# Clean up missing Tilt exts
|
||||
|
|
|
@ -9,6 +9,7 @@ module Middleman
|
|||
Contract Any
|
||||
def initialize
|
||||
@callbacks = ::Hamster.hash
|
||||
@subscribers = ::Hamster.vector
|
||||
end
|
||||
|
||||
Contract RespondTo[:define_singleton_method], ArrayOf[Symbol] => Any
|
||||
|
@ -28,6 +29,7 @@ module Middleman
|
|||
end
|
||||
|
||||
install_target.define_singleton_method(:callbacks_for, &method(:callbacks_for))
|
||||
install_target.define_singleton_method(:subscribe_to_callbacks, &method(:subscribe))
|
||||
end
|
||||
|
||||
Contract Or[Symbol, ArrayOf[Symbol]], Proc => Any
|
||||
|
@ -39,9 +41,15 @@ module Middleman
|
|||
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
|
||||
def execute(keys, args=[], scope=self)
|
||||
callbacks_for(keys).each { |b| scope.instance_exec(*args, &b) }
|
||||
@subscribers.each { |b| scope.instance_exec(keys, *args, &b) }
|
||||
end
|
||||
|
||||
Contract Or[Symbol, ArrayOf[Symbol]] => ::Hamster::Vector
|
||||
|
|
|
@ -15,19 +15,11 @@ module Middleman
|
|||
@app = app
|
||||
@template_context_class = template_context_class
|
||||
|
||||
sub_callbacks = [:before_build, :after_build, :configure, :after_configuration, :ready]
|
||||
|
||||
@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.
|
||||
self_context = self
|
||||
|
||||
sub_callbacks.each do |key|
|
||||
app.send(key) do |*args|
|
||||
self_context.execute_callbacks(key, args)
|
||||
end
|
||||
end
|
||||
app.subscribe_to_callbacks(&method(:execute_callbacks))
|
||||
end
|
||||
|
||||
def helpers(*helper_modules, &block)
|
||||
|
|
Loading…
Reference in a new issue