Project

General

Profile

Feature #17763 » multiple_render.patch

Jean-Philippe Lang, 2014-10-13 21:03

View differences:

lib/redmine/hook.rb (working copy)
99 99
        {:only_path => true }
100 100
      end
101 101

  
102
      # Helper method to directly render a partial using the context:
102
      # Helper method to directly render using the context,
103
      # render_options must be valid #render options.
103 104
      #
104 105
      #   class MyHook < Redmine::Hook::ViewListener
105 106
      #     render_on :view_issues_show_details_bottom, :partial => "show_more_data"
106 107
      #   end
107 108
      #
108
      def self.render_on(hook, options={})
109
      #   class MultipleHook < Redmine::Hook::ViewListener
110
      #     render_on :view_issues_show_details_bottom,
111
      #       {:partial => "show_more_data"},
112
      #       {:partial => "show_even_more_data"}
113
      #   end
114
      #
115
      def self.render_on(hook, *render_options)
109 116
        define_method hook do |context|
110
          if context[:hook_caller].respond_to?(:render)
111
            context[:hook_caller].send(:render, {:locals => context}.merge(options))
112
          elsif context[:controller].is_a?(ActionController::Base)
113
            context[:controller].send(:render_to_string, {:locals => context}.merge(options))
114
          else
115
            raise "Cannot render #{self.name} hook from #{context[:hook_caller].class.name}"
117
          render_options.map do |options|
118
            if context[:hook_caller].respond_to?(:render)
119
              context[:hook_caller].send(:render, {:locals => context}.merge(options))
120
            elsif context[:controller].is_a?(ActionController::Base)
121
              context[:controller].send(:render_to_string, {:locals => context}.merge(options))
122
            else
123
              raise "Cannot render #{self.name} hook from #{context[:hook_caller].class.name}"
124
            end
116 125
          end
117 126
        end
118 127
      end
(2-2/2)