Module: Redmine::Hook::Helper

Included in:
ApplicationController, ApplicationHelper
Defined in:
lib/redmine/hook.rb

Overview

Helper module included in ApplicationHelper and ActionController so that hooks can be called in views like this:

<%= call_hook(:some_hook) %>
<%= call_hook(:another_hook, :foo => 'bar') %>

Or in controllers like:

call_hook(:some_hook)
call_hook(:another_hook, :foo => 'bar')

Hooks added to views will be concatenated into a string. Hooks added to controllers will return an array of results.

Several objects are automatically added to the call context:

  • project => current project

  • request => Request instance

  • controller => current Controller instance

  • hook_caller => object that called the hook

Instance Method Summary collapse

Instance Method Details

#call_hook(hook, context = {}) ⇒ Object



93
94
95
96
97
98
99
100
101
102
103
# File 'lib/redmine/hook.rb', line 93

def call_hook(hook, context={})
  if is_a?(ActionController::Base)
    default_context = {:controller => self, :project => @project, :request => request, :hook_caller => self}
    Redmine::Hook.call_hook(hook, default_context.merge(context))
  else
    default_context = {:project => @project, :hook_caller => self}
    default_context[:controller] = controller if respond_to?(:controller)
    default_context[:request] = request if respond_to?(:request)
    Redmine::Hook.call_hook(hook, default_context.merge(context)).join(' ').html_safe
  end
end