Module: RenderSuper::InstanceMethods

Defined in:
lib/render_super_visagio.rb

Instance Method Summary collapse

Instance Method Details

#render(*args, &block) ⇒ Object

Adds rendering option.

render :super

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



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/render_super_visagio.rb', line 34

def render(*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 = 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 = super
    view_stack.pop if current_view.present?
    result
  end
end

#view_stackObject



64
65
66
# File 'lib/render_super_visagio.rb', line 64

def view_stack
  @_view_stack ||= []
end