Class: ActionView::Renderer
- Defined in:
- lib/active_scaffold/extensions/action_view_rendering.rb
Overview
:nodoc:
Instance Method Summary collapse
- #render_as_embedded_view(context, options, &block) ⇒ Object
- #render_as_super_view(context, options, &block) ⇒ Object
- #render_as_view(context, options, &block) ⇒ Object
-
#render_partial_with_active_scaffold(context, options, &block) ⇒ Object
:nodoc:.
-
#render_template_with_active_scaffold(context, options) ⇒ Object
:nodoc:.
-
#render_with_active_scaffold(context, options, &block) ⇒ Object
Adds two rendering options.
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 (context, , &block) require 'digest/md5' remote_controller = [:active_scaffold] constraints = [:constraints] conditions = [:conditions] eid = Digest::MD5.hexdigest(context.controller.controller_name + remote_controller.to_s + constraints.to_s + conditions.to_s) [:params] ||= {} [:params].merge! :eid => eid, :embedded => true = {:controller => remote_controller.to_s, :action => 'index'}.merge([:params]) label = [: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 => [:label]}} id = "as_#{eid}-content" if context.controller.respond_to?(:render_component_into_view) context.controller.send(:render_component_into_view, ) 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 .delete(:embedded) [:locals] ||= {} [:locals].merge!({:url_options => , :id=> id, :remote_controller => remote_controller}) [:partial] = 'embedded_controller' .delete(:active_scaffold) .delete(:params) render(context, ) 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, , &block) last_view = @view_stack.last [:locals] ||= {} [: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], [:locals].keys) last_view[:templates].shift end [:template] = last_view[:templates].shift @view_stack << last_view .delete(:partial) if [:partial] == :super result = if .key?(:partial) render_partial_without_active_scaffold(last_view[:context], ) else render_template_without_active_scaffold(last_view[:context], ) 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, , &block) if .is_a?(Hash) current_view = {:view => [:partial], :is_template => false} if [:partial] current_view = {:view => [:template], :is_template => !![:template]} if current_view.nil? && [:template] if current_view.present? current_view[:locals] = [:locals] if [:locals] current_view[:context] = context @view_stack ||= [] @view_stack << current_view end end result = if .key?(:partial) render_partial_without_active_scaffold(context, , &block) else render_template_without_active_scaffold(context, , &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, , &block) #:nodoc: if block_given? render(context, , block) else render(context, ) 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, ) #:nodoc: render(context, ) 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, , &block) if && [:partial] == :super render_as_super_view(context, , &block) elsif [:active_scaffold] (context, , &block) else render_as_view(context, , &block) end end |