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)
17 17

  
18 18
module Redmine
19 19
  module Hook
20
    include ActionController::UrlWriter
21

  
20 22
    @@listener_classes = []
21 23
    @@listeners = nil
22 24
    @@hook_listeners = {}
......
55 57
      # Calls a hook.
56 58
      # Returns the listeners response.
57 59
      def call_hook(hook, context={})
58
        response = ''
59
        hook_listeners(hook).each do |listener|
60
          response << listener.send(hook, context).to_s
60
        returning [] do |response|
61
          hls = hook_listeners(hook)
62
          if hls.any?
63
            request = context[:request]
64
            if request
65
              default_url_options[:host] ||= request.env["SERVER_NAME"]
66
              default_url_options[:port] ||= request.env["SERVER_PORT"]
67
            end
68
            hls.each {|listener| response << listener.send(hook, context)}
69
          end
61 70
        end
62
        response
63 71
      end
64 72
    end
65 73

  
......
91 99
      include ActionView::Helpers::TextHelper
92 100
      include ActionController::UrlWriter
93 101
      include ApplicationHelper
102

  
103
      def self.render_on(hook, options={})
104
        define_method hook do |context|
105
          context[:controller].send(:render_to_string, {:locals => context}.merge(options))
106
        end
107
      end
94 108
    end
95 109

  
96 110
    # Helper module included in ApplicationHelper so that hooks can be called
......
99 113
    #   <%= call_hook(:another_hook, :foo => 'bar' %>
100 114
    # 
101 115
    # Current project is automatically added to the call context.
102
    module Helper
116
    module ApplicationHelperMethods
103 117
      def call_hook(hook, context={})
104
        Redmine::Hook.call_hook(hook, {:project => @project}.merge(context))
118
        ctx = {:controller => controller, :project => @project, :request => request}
119
        Redmine::Hook.call_hook(hook, ctx.merge(context)).join
105 120
      end
106 121
    end
122

  
123
    module ActionControllerMethods
124
      def call_hook(hook, context={})
125
        ctx = {:controller => self, :project => @project, :request => request}
126
        Redmine::Hook.call_hook(hook, ctx.merge(context))
127
      end
128
    end
107 129
  end
108 130
end
109 131

  
110
ApplicationHelper.send(:include, Redmine::Hook::Helper)
111
ActionController::Base.send(:include, Redmine::Hook::Helper)
132
ApplicationHelper.send(:include, Redmine::Hook::ApplicationHelperMethods)
133
ActionController::Base.send(:include, Redmine::Hook::ActionControllerMethods)
(1-1/3)