Module: ActionView::Helpers::CaptureHelper

Defined in:
lib/interlock/action_view.rb

Instance Method Summary collapse

Instance Method Details

#content_for(name, content = nil, &block) ⇒ Object

Override content_for so we can cache the instance variables it sets along with the fragment.



83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/interlock/action_view.rb', line 83

def content_for(name, content = nil, &block)
  ivar = "@content_for_#{name}"
  existing_content = instance_variable_get(ivar).to_s
  this_content = (block_given? ? capture(&block) : content)
  
  # If we are in a view_cache block, cache what we added to this instance variable
  if @cached_content_for
    @cached_content_for[name] = "#{@cached_content_for[name]}#{this_content}"
  end
  
  instance_variable_set(ivar, existing_content + this_content)
end