@@ -1,16 +1,16 | |||
|
1 | 1 | # Redmine - project management software |
|
2 |
# Copyright (C) 2006-20 |
|
|
2 | # Copyright (C) 2006-2011 Jean-Philippe Lang | |
|
3 | 3 | # |
|
4 | 4 | # This program is free software; you can redistribute it and/or |
|
5 | 5 | # modify it under the terms of the GNU General Public License |
|
6 | 6 | # as published by the Free Software Foundation; either version 2 |
|
7 | 7 | # of the License, or (at your option) any later version. |
|
8 |
# |
|
|
8 | # | |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 |
# |
|
|
13 | # | |
|
14 | 14 | # You should have received a copy of the GNU General Public License |
|
15 | 15 | # along with this program; if not, write to the Free Software |
|
16 | 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
@@ -22,7 +22,7 module Redmine | |||
|
22 | 22 | @@listener_classes = [] |
|
23 | 23 | @@listeners = nil |
|
24 | 24 | @@hook_listeners = {} |
|
25 | ||
|
25 | ||
|
26 | 26 | class << self |
|
27 | 27 | # Adds a listener class. |
|
28 | 28 | # Automatically called when a class inherits from Redmine::Hook::Listener. |
@@ -31,29 +31,29 module Redmine | |||
|
31 | 31 | @@listener_classes << klass |
|
32 | 32 | clear_listeners_instances |
|
33 | 33 | end |
|
34 | ||
|
34 | ||
|
35 | 35 | # Returns all the listerners instances. |
|
36 | 36 | def listeners |
|
37 | 37 | @@listeners ||= @@listener_classes.collect {|listener| listener.instance} |
|
38 | 38 | end |
|
39 | ||
|
39 | ||
|
40 | 40 | # Returns the listeners instances for the given hook. |
|
41 | 41 | def hook_listeners(hook) |
|
42 | 42 | @@hook_listeners[hook] ||= listeners.select {|listener| listener.respond_to?(hook)} |
|
43 | 43 | end |
|
44 | ||
|
44 | ||
|
45 | 45 | # Clears all the listeners. |
|
46 | 46 | def clear_listeners |
|
47 | 47 | @@listener_classes = [] |
|
48 | 48 | clear_listeners_instances |
|
49 | 49 | end |
|
50 | ||
|
50 | ||
|
51 | 51 | # Clears all the listeners instances. |
|
52 | 52 | def clear_listeners_instances |
|
53 | 53 | @@listeners = nil |
|
54 | 54 | @@hook_listeners = {} |
|
55 | 55 | end |
|
56 | ||
|
56 | ||
|
57 | 57 | # Calls a hook. |
|
58 | 58 | # Returns the listeners response. |
|
59 | 59 | def call_hook(hook, context={}) |
@@ -101,11 +101,11 module Redmine | |||
|
101 | 101 | def self.default_url_options |
|
102 | 102 | {:only_path => true } |
|
103 | 103 | end |
|
104 | ||
|
104 | ||
|
105 | 105 | # Helper method to directly render a partial using the context: |
|
106 |
# |
|
|
106 | # | |
|
107 | 107 | # class MyHook < Redmine::Hook::ViewListener |
|
108 |
# render_on :view_issues_show_details_bottom, :partial => "show_more_data" |
|
|
108 | # render_on :view_issues_show_details_bottom, :partial => "show_more_data" | |
|
109 | 109 | # end |
|
110 | 110 | # |
|
111 | 111 | def self.render_on(hook, options={}) |
@@ -117,23 +117,23 module Redmine | |||
|
117 | 117 | |
|
118 | 118 | # Helper module included in ApplicationHelper and ActionControllerso that |
|
119 | 119 | # hooks can be called in views like this: |
|
120 |
# |
|
|
120 | # | |
|
121 | 121 | # <%= call_hook(:some_hook) %> |
|
122 | 122 | # <%= call_hook(:another_hook, :foo => 'bar' %> |
|
123 |
# |
|
|
123 | # | |
|
124 | 124 | # Or in controllers like: |
|
125 | 125 | # call_hook(:some_hook) |
|
126 | 126 | # call_hook(:another_hook, :foo => 'bar' |
|
127 |
# |
|
|
127 | # | |
|
128 | 128 | # Hooks added to views will be concatenated into a string. Hooks added to |
|
129 | 129 | # controllers will return an array of results. |
|
130 | 130 | # |
|
131 | 131 | # Several objects are automatically added to the call context: |
|
132 |
# |
|
|
132 | # | |
|
133 | 133 | # * project => current project |
|
134 | 134 | # * request => Request instance |
|
135 | 135 | # * controller => current Controller instance |
|
136 |
# |
|
|
136 | # | |
|
137 | 137 | module Helper |
|
138 | 138 | def call_hook(hook, context={}) |
|
139 | 139 | if is_a?(ActionController::Base) |
@@ -142,7 +142,7 module Redmine | |||
|
142 | 142 | else |
|
143 | 143 | default_context = {:controller => controller, :project => @project, :request => request} |
|
144 | 144 | Redmine::Hook.call_hook(hook, default_context.merge(context)).join(' ') |
|
145 |
end |
|
|
145 | end | |
|
146 | 146 | end |
|
147 | 147 | end |
|
148 | 148 | end |
General Comments 0
You need to be logged in to leave comments.
Login now