Module: TemplateStreaming::View

Defined in:
lib/template_streaming.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



198
199
200
201
# File 'lib/template_streaming.rb', line 198

def self.included(base)
  base.alias_method_chain :_render_with_layout, :template_streaming
  base.alias_method_chain :flash, :template_streaming
end

Instance Method Details

#_render_with_layout_with_template_streaming(options, local_assigns, &block) ⇒ Object



203
204
205
206
207
# File 'lib/template_streaming.rb', line 203

def _render_with_layout_with_template_streaming(options, local_assigns, &block)
  with_prelayout prelayout_for(options), local_assigns do
    _render_with_layout_without_template_streaming(options, local_assigns, &block)
  end
end

#flash_with_template_streamingObject

:nodoc:



243
244
245
246
# File 'lib/template_streaming.rb', line 243

def flash_with_template_streaming # :nodoc:
  # Override ActionView::Base#flash to prevent a double-sweep.
  controller.instance_eval { @template_streaming_flash || flash }
end

#prelayout_for(options) ⇒ Object



230
231
232
233
234
235
236
237
238
239
240
241
# File 'lib/template_streaming.rb', line 230

def prelayout_for(options)
  layout = options[:layout] or
    return nil
  # Views can call #render with :layout to render a layout
  # *partial* which we don't want to interfere with. Only the
  # interlal toplevel #render calls :layout with an
  # ActionView::Template
  layout.is_a?(ActionView::Template) or
    return nil
  view_paths.find_template('pre' + layout.path_without_format_and_extension, layout.format)
rescue ActionView::MissingTemplate
end

#with_prelayout(prelayout, locals, &block) ⇒ Object



209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
# File 'lib/template_streaming.rb', line 209

def with_prelayout(prelayout, locals, &block)
  if prelayout
    begin
      @_proc_for_layout = lambda do
        # nil out @_proc_for_layout else rendering with the layout will call it again.
        @_proc_for_layout, original_proc_for_layout = nil, @_proc_for_layout
        begin
          block.call
        ensure
          @_proc_for_layout = original_proc_for_layout
        end
      end
      render(:file => prelayout, :locals => locals)
    ensure
      @_proc_for_layout = nil
    end
  else
    yield
  end
end