Module: RedmineExtensions::RenderingHelper

Included in:
ApplicationHelper
Defined in:
app/helpers/redmine_extensions/rendering_helper.rb

Instance Method Summary collapse

Instance Method Details

#query_outputs(presenter_or_query, options = {}) ⇒ Object



24
25
26
27
# File 'app/helpers/redmine_extensions/rendering_helper.rb', line 24

def query_outputs(presenter_or_query, options={})
  presenter = present(presenter_or_query, options) rescue RedmineExtensions::BasePresenter.new(presenter_or_query, self, options)
  RedmineExtensions::EasyQueryHelpers::Outputs.new(presenter, self)
end

#render_with_fallback(*attrs) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'app/helpers/redmine_extensions/rendering_helper.rb', line 4

def render_with_fallback(*attrs)
  raise 'Missing an options argument' unless attrs.last.is_a?(Hash)
  options = attrs.last
  raise 'Missing an fallback prefixes' unless options[:prefixes]
  partial = options[:partial] || attrs.first
  prefixes = options.delete(:prefixes)

  prefixes = prefixes.model if prefixes.is_a?(BasePresenter)
  prefixes = prefixes.hiearchy.map{|klass| klass.underscore.pluralize } if prefixes.is_a?(ActiveRecord::Base)

  prefixes.each do |prefix|
    if lookup_context.template_exists?(partial, prefix, true)
      partial.prepend("#{prefix}/")
      return render(*attrs)
    end
  end
  partial.prepend("#{prefixes.last}/")
  render(*attrs)
end