hook.patch
| hook.rb (Arbeitskopie) | ||
|---|---|---|
| 57 | 57 |
# Calls a hook. |
| 58 | 58 |
# Returns the listeners response. |
| 59 | 59 |
def call_hook(hook, context={})
|
| 60 |
returning [] do |response| |
|
| 61 |
hls = hook_listeners(hook) |
|
| 62 |
if hls.any? |
|
| 63 |
hls.each {|listener| response << listener.send(hook, context)}
|
|
| 64 |
end |
|
| 65 |
end |
|
| 60 |
hook_listeners(hook).map {|listener| listener.send(hook, context)}
|
|
| 66 | 61 |
end |
| 67 | 62 |
end |
| 68 | 63 | |
| ... | ... | |
| 110 | 105 |
# |
| 111 | 106 |
def self.render_on(hook, options={})
|
| 112 | 107 |
define_method hook do |context| |
| 113 |
context[:controller].send(:render_to_string, {:locals => context}.merge(options))
|
|
| 108 |
if !options.include?(:if) || evaluate_if_option(options[:if], context) |
|
| 109 |
context[:controller].send(:render_to_string, {:locals => context}.merge(options))
|
|
| 110 |
end |
|
| 114 | 111 |
end |
| 115 | 112 |
end |
| 113 | ||
| 114 |
private |
|
| 115 | ||
| 116 |
def evaluate_if_option(if_option, context) |
|
| 117 |
case if_option |
|
| 118 |
when Symbol |
|
| 119 |
send(if_option, context) |
|
| 120 |
when Method, Proc |
|
| 121 |
if_option.call(context) |
|
| 122 |
end |
|
| 123 |
end |
|
| 116 | 124 |
end |
| 117 | 125 | |
| 118 | 126 |
# Helper module included in ApplicationHelper and ActionControllerso that |
| ... | ... | |
| 145 | 153 |
end |
| 146 | 154 |
end |
| 147 | 155 |
end |
| 156 | ||
| 157 |
module ActionMailerMethods |
|
| 158 |
def render_to_string(options={})
|
|
| 159 |
ActionView::Base.new(ActionController::Base.view_paths.dup, {}, self).render(options)
|
|
| 160 |
end |
|
| 161 |
end |
|
| 148 | 162 |
end |
| 149 | 163 |
end |
| 150 | 164 | |
| 151 | 165 |
ApplicationHelper.send(:include, Redmine::Hook::Helper) |
| 152 | 166 |
ActionController::Base.send(:include, Redmine::Hook::Helper) |
| 167 |
ActionMailer::Base.send(:include, Redmine::Hook::ActionMailerMethods) |
|
| 168 |
ActionView::Base.send(:include, Redmine::I18n) |
|