Mercurial > hg > soundsoftware-site
diff lib/redmine/hook.rb @ 1115:433d4f72a19b redmine-2.2
Update to Redmine SVN revision 11137 on 2.2-stable branch
author | Chris Cannam |
---|---|
date | Mon, 07 Jan 2013 12:01:42 +0000 |
parents | cbb26bc654de |
children | 622f24f53b42 |
line wrap: on
line diff
--- a/lib/redmine/hook.rb Wed Jun 27 14:54:18 2012 +0100 +++ b/lib/redmine/hook.rb Mon Jan 07 12:01:42 2013 +0000 @@ -1,5 +1,5 @@ # Redmine - project management software -# Copyright (C) 2006-2011 Jean-Philippe Lang +# Copyright (C) 2006-2012 Jean-Philippe Lang # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License @@ -17,8 +17,6 @@ module Redmine module Hook - include ActionController::UrlWriter - @@listener_classes = [] @@listeners = nil @@hook_listeners = {} @@ -88,12 +86,11 @@ include ActionView::Helpers::FormTagHelper include ActionView::Helpers::FormOptionsHelper include ActionView::Helpers::JavaScriptHelper - include ActionView::Helpers::PrototypeHelper include ActionView::Helpers::NumberHelper include ActionView::Helpers::UrlHelper include ActionView::Helpers::AssetTagHelper include ActionView::Helpers::TextHelper - include ActionController::UrlWriter + include Rails.application.routes.url_helpers include ApplicationHelper # Default to creating links using only the path. Subclasses can @@ -110,9 +107,23 @@ # def self.render_on(hook, options={}) define_method hook do |context| - context[:controller].send(:render_to_string, {:locals => context}.merge(options)) + if context[:hook_caller].respond_to?(:render) + context[:hook_caller].send(:render, {:locals => context}.merge(options)) + elsif context[:controller].is_a?(ActionController::Base) + context[:controller].send(:render_to_string, {:locals => context}.merge(options)) + else + raise "Cannot render #{self.name} hook from #{context[:hook_caller].class.name}" + end end end + + def controller + nil + end + + def config + ActionController::Base.config + end end # Helper module included in ApplicationHelper and ActionController so that @@ -133,15 +144,18 @@ # * project => current project # * request => Request instance # * controller => current Controller instance + # * hook_caller => object that called the hook # module Helper def call_hook(hook, context={}) if is_a?(ActionController::Base) - default_context = {:controller => self, :project => @project, :request => request} + default_context = {:controller => self, :project => @project, :request => request, :hook_caller => self} Redmine::Hook.call_hook(hook, default_context.merge(context)) else - default_context = {:controller => controller, :project => @project, :request => request} - Redmine::Hook.call_hook(hook, default_context.merge(context)).join(' ') + 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 end