Project

General

Profile

Patch #4878 » hook.patch

Patch for hook.rb - Thomas Löber, 2010-02-18 18:28

View differences:

hook.rb (Arbeitskopie)
# Calls a hook.
# Returns the listeners response.
def call_hook(hook, context={})
returning [] do |response|
hls = hook_listeners(hook)
if hls.any?
hls.each {|listener| response << listener.send(hook, context)}
end
end
hook_listeners(hook).map {|listener| listener.send(hook, context)}
end
end
......
#
def self.render_on(hook, options={})
define_method hook do |context|
context[:controller].send(:render_to_string, {:locals => context}.merge(options))
if !options.include?(:if) || evaluate_if_option(options[:if], context)
context[:controller].send(:render_to_string, {:locals => context}.merge(options))
end
end
end
private
def evaluate_if_option(if_option, context)
case if_option
when Symbol
send(if_option, context)
when Method, Proc
if_option.call(context)
end
end
end
# Helper module included in ApplicationHelper and ActionControllerso that
......
end
end
end
module ActionMailerMethods
def render_to_string(options={})
ActionView::Base.new(ActionController::Base.view_paths.dup, {}, self).render(options)
end
end
end
end
ApplicationHelper.send(:include, Redmine::Hook::Helper)
ActionController::Base.send(:include, Redmine::Hook::Helper)
ActionMailer::Base.send(:include, Redmine::Hook::ActionMailerMethods)
ActionView::Base.send(:include, Redmine::I18n)
    (1-1/1)