Module: RenderSuper::InstanceMethods

Defined in:
lib/render_super.rb

Instance Method Summary collapse

Instance Method Details

#render_with_super(*args, &block) ⇒ Object

Adds rendering option.

render :super

This renders the “super” template, i.e. the one hidden by the plugin



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/render_super.rb', line 42

def render_with_super(*args, &block)
  if args.first == :super
    last_view = view_stack.last || {:view => instance_variable_get(:@virtual_path).split('/').last}
    options = args[1] || {}
    options[:locals] ||= {}
    options[:locals].reverse_merge!(last_view[:locals] || {})
    if last_view[:templates].nil?
      last_view[:templates] = lookup_context.find_all_templates(last_view[:view], last_view[:partial], options[:locals].keys)
      last_view[:templates].shift
    end
    options[:template] = last_view[:templates].shift
    view_stack << last_view
    result = render_without_super options
    view_stack.pop
    result
  else
    options = args.first
    if options.is_a?(Hash)
      current_view = {:view => options[:partial], :partial => true} if options[:partial]
      current_view = {:view => options[:template], :partial => false} if current_view.nil? && options[:template]
      current_view[:locals] = options[:locals] if !current_view.nil? && options[:locals]
      view_stack << current_view if current_view.present?
    end
    result = render_without_super(*args, &block)
    view_stack.pop if current_view.present?
    result
  end
end

#view_stackObject



72
73
74
# File 'lib/render_super.rb', line 72

def view_stack
  @_view_stack ||= []
end