Module: TemplateStreaming::Autoflushing::View

Defined in:
lib/template_streaming/autoflushing.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



16
17
18
# File 'lib/template_streaming/autoflushing.rb', line 16

def self.included(base)
  base.alias_method_chain :render, :template_streaming_autoflushing
end

Instance Method Details

#capture(*args, &block) ⇒ Object



26
27
28
29
30
31
32
33
34
35
# File 'lib/template_streaming/autoflushing.rb', line 26

def capture(*args, &block)
  if block == @_proc_for_layout
    # Rendering the content of a streamed layout - inject autoflushing.
    with_autoflushing do
      super
    end
  else
    super
  end
end

#render_with_template_streaming_autoflushing(*args, &block) ⇒ Object



20
21
22
23
24
# File 'lib/template_streaming/autoflushing.rb', line 20

def render_with_template_streaming_autoflushing(*args, &block)
  with_autoflushing do
    render_without_template_streaming_autoflushing(*args, &block)
  end
end

#with_autoflushingObject



37
38
39
40
41
42
43
44
45
46
# File 'lib/template_streaming/autoflushing.rb', line 37

def with_autoflushing
  controller.flush if TemplateStreaming.autoflush
  fragment = yield
  if TemplateStreaming.autoflush
    controller.push(fragment)
    ''
  else
    fragment
  end
end