Class: ActionView::Renderer

Inherits:
Object show all
Defined in:
lib/active_scaffold/extensions/action_view_rendering.rb

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#render_as_embedded_view(context, options, &block) ⇒ Object



94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/active_scaffold/extensions/action_view_rendering.rb', line 94

def render_as_embedded_view(context, options, &block)
  require 'digest/md5'
  remote_controller = options[:active_scaffold]
  constraints = options[:constraints]
  conditions = options[:conditions]
  eid = Digest::MD5.hexdigest(context.controller.controller_name + remote_controller.to_s + constraints.to_s + conditions.to_s)
  options[:params] ||= {}
  options[:params].merge! :eid => eid, :embedded => true
  url_options = {:controller => remote_controller.to_s, :action => 'index'}.merge(options[:params])

  label = options[:label] || context.controller.class.active_scaffold_controller_by_controller_name(remote_controller.to_s).active_scaffold_config.list.label
  context.controller.session["as:#{eid}"] = {:constraints => constraints, :conditions => conditions, :list => {:label => options[:label]}}
  
  id = "as_#{eid}-content"
 
  if context.controller.respond_to?(:render_component_into_view)
    context.controller.send(:render_component_into_view, url_options)
  else
    if !context.controller.respond_to?(:uses_active_scaffold?) || context.controller.send(:uses_active_scaffold?) == false
      # have to add activescaffold view path cause parentcontroller is not activescaffold enabled
      ActiveScaffold.default_view_paths.each do |path|
        context.controller.append_view_path(ActionView::ActiveScaffoldResolver.new(path))
      end
    end
    url_options.delete(:embedded)
    options[:locals] ||= {}
    options[:locals].merge!({:url_options => url_options, :id=> id, :remote_controller => remote_controller})
    options[:partial] = 'embedded_controller'
    options.delete(:active_scaffold)
    options.delete(:params)
    render(context, options)
  end
end

#render_as_super_view(context, options, &block) ⇒ Object



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/active_scaffold/extensions/action_view_rendering.rb', line 74

def render_as_super_view(context, options, &block)
  last_view = @view_stack.last
  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[:is_template], options[:locals].keys)
    last_view[:templates].shift
  end
  options[:template] = last_view[:templates].shift
  @view_stack << last_view
  options.delete(:partial) if options[:partial] == :super
  result = if options.key?(:partial)
    render_partial_without_active_scaffold(last_view[:context], options)
  else
    render_template_without_active_scaffold(last_view[:context], options)
  end
  @view_stack.pop
  result
end

#render_as_view(context, options, &block) ⇒ Object



128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# File 'lib/active_scaffold/extensions/action_view_rendering.rb', line 128

def render_as_view(context, options, &block)
   if options.is_a?(Hash)
      current_view = {:view => options[:partial], :is_template => false} if options[:partial]
      current_view = {:view => options[:template], :is_template => !!options[:template]} if current_view.nil? && options[:template]
      if current_view.present?
        current_view[:locals] = options[:locals] if options[:locals]
        current_view[:context] = context
        @view_stack ||= []
        @view_stack << current_view
      end
    end
    result = if options.key?(:partial)
      render_partial_without_active_scaffold(context, options, &block)
    else
      render_template_without_active_scaffold(context, options, &block)
    end
    result
end

#render_partial_with_active_scaffold(context, options, &block) ⇒ Object

:nodoc:



59
60
61
62
63
64
65
# File 'lib/active_scaffold/extensions/action_view_rendering.rb', line 59

def render_partial_with_active_scaffold(context, options, &block) #:nodoc:
  if block_given?
    render(context, options, block)
  else
    render(context, options)
  end
end

#render_template_with_active_scaffold(context, options) ⇒ Object

:nodoc:



68
69
70
# File 'lib/active_scaffold/extensions/action_view_rendering.rb', line 68

def render_template_with_active_scaffold(context, options) #:nodoc:
  render(context, options)
end

#render_with_active_scaffold(context, options, &block) ⇒ Object

Adds two rendering options.

render :super

render :partial => :super, :locals =>=> ‘formheadline’

This syntax skips all template overrides and goes directly to the provided ActiveScaffold templates. Useful if you want to wrap an existing template. Just call super!

render :active_scaffold => #ActionView::Renderer.controllercontroller.to_s, options = {}+

Lets you embed an ActiveScaffold by referencing the controller where it’s configured.

You may specify options for the embedded scaffold. These constraints have three effects:

* the scaffold's only displays records matching the constraint
* all new records created will be assigned the constrained values
* constrained columns will be hidden (they're pretty boring at this point)

You may also specify options for the embedded scaffold. These only do 1/3 of what constraints do (they only limit search results). Any format accepted by ActiveRecord::Base.find is valid.

Defining options lets you completely customize the list title for the embedded scaffold.



48
49
50
51
52
53
54
55
56
# File 'lib/active_scaffold/extensions/action_view_rendering.rb', line 48

def render_with_active_scaffold(context, options, &block)
  if options && options[:partial] == :super
    render_as_super_view(context, options, &block)
  elsif options[:active_scaffold]
    render_as_embedded_view(context, options, &block)
  else
    render_as_view(context, options, &block)
  end
end