Project

General

Profile

Feature #2542 » hook.rb.diff

Patch for hook.rb - Thomas Löber, 2009-02-02 10:00

View differences:

lib/redmine/hook.rb (Arbeitskopie)
module Redmine
module Hook
include ActionController::UrlWriter
@@listener_classes = []
@@listeners = nil
@@hook_listeners = {}
......
# Calls a hook.
# Returns the listeners response.
def call_hook(hook, context={})
response = ''
hook_listeners(hook).each do |listener|
response << listener.send(hook, context).to_s
returning [] do |response|
hls = hook_listeners(hook)
if hls.any?
request = context[:request]
if request
default_url_options[:host] ||= request.env["SERVER_NAME"]
default_url_options[:port] ||= request.env["SERVER_PORT"]
end
hls.each {|listener| response << listener.send(hook, context)}
end
end
response
end
end
......
include ActionView::Helpers::TextHelper
include ActionController::UrlWriter
include ApplicationHelper
def self.render_on(hook, options={})
define_method hook do |context|
context[:controller].send(:render_to_string, {:locals => context}.merge(options))
end
end
end
# Helper module included in ApplicationHelper so that hooks can be called
......
# <%= call_hook(:another_hook, :foo => 'bar' %>
#
# Current project is automatically added to the call context.
module Helper
module ApplicationHelperMethods
def call_hook(hook, context={})
Redmine::Hook.call_hook(hook, {:project => @project}.merge(context))
ctx = {:controller => controller, :project => @project, :request => request}
Redmine::Hook.call_hook(hook, ctx.merge(context)).join
end
end
module ActionControllerMethods
def call_hook(hook, context={})
ctx = {:controller => self, :project => @project, :request => request}
Redmine::Hook.call_hook(hook, ctx.merge(context))
end
end
end
end
ApplicationHelper.send(:include, Redmine::Hook::Helper)
ActionController::Base.send(:include, Redmine::Hook::Helper)
ApplicationHelper.send(:include, Redmine::Hook::ApplicationHelperMethods)
ActionController::Base.send(:include, Redmine::Hook::ActionControllerMethods)
(1-1/3)