diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2014-10-18 08:09:31 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2014-10-18 08:09:31 +0000 |
commit | ff9be52e45ed67b3d57ccbfee62f7c230738109c (patch) | |
tree | daa72e5697aa2f69f3f45c3875b2a99164c17f0b /lib/redmine/hook.rb | |
parent | 2ab1a9dccd3443f33933fb68824278e623d4e843 (diff) | |
download | redmine-ff9be52e45ed67b3d57ccbfee62f7c230738109c.tar.gz redmine-ff9be52e45ed67b3d57ccbfee62f7c230738109c.zip |
Ability to render multiple partials with view hook (#17763).
git-svn-id: http://svn.redmine.org/redmine/trunk@13449 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'lib/redmine/hook.rb')
-rw-r--r-- | lib/redmine/hook.rb | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/lib/redmine/hook.rb b/lib/redmine/hook.rb index 715cbaf80..a20248154 100644 --- a/lib/redmine/hook.rb +++ b/lib/redmine/hook.rb @@ -99,20 +99,29 @@ module Redmine {:only_path => true } end - # Helper method to directly render a partial using the context: + # Helper method to directly render using the context, + # render_options must be valid #render options. # # class MyHook < Redmine::Hook::ViewListener # render_on :view_issues_show_details_bottom, :partial => "show_more_data" # end # - def self.render_on(hook, options={}) + # class MultipleHook < Redmine::Hook::ViewListener + # render_on :view_issues_show_details_bottom, + # {:partial => "show_more_data"}, + # {:partial => "show_even_more_data"} + # end + # + def self.render_on(hook, *render_options) define_method hook do |context| - 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}" + render_options.map do |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 end |