Sha256: 259e18d9610edd708fe6ebc4cfb637aa5fd973c350d35af4281bdddaf9af5cc0

Contents?: true

Size: 1.33 KB

Versions: 1

Compression:

Stored size: 1.33 KB

Contents

# Sorry for the interface violations, but it looks as if there are 
# no interfaces in rails at all.
module CellsHelper

  # Executes #capture on the global ActionView and sets <tt>name</tt> as the 
  # instance variable name.
  #
  # Example:
  #
  #  <p>
  #  <% global_capture :greeting do
  #    <h1>Hi, Nick!</h1>
  #  <% end %>
  #
  # The captured markup can be accessed in your global action view or in your layout.
  #
  #  <%= @greeting %>
  def global_capture(name, &block)
    global_view = controller.instance_variable_get( "@template" ) 
    content     = capture &block
    global_view.send("instance_variable_set", "@#{name}", content)
  end
  
  
  # Executes #content_for on the global ActionView.
  #
  # Example:
  #
  #  <p>
  #  <% global_content_for :greetings do
  #    <h1>Hi, Michal!</h1>
  #  <% end %>
  #
  # As in global_capture, the markup can be accessed in your global action view or in your layout.
  #
  #  <%= yield :greetings %>
  def global_content_for(name, content = nil, &block)
    # OMG.
    global_view = controller.instance_variable_get( "@template" )
    ivar        = "@content_for_#{name}"
    content     = capture(&block) if block_given?
    old_content = global_view.send("instance_variable_get", ivar)
    
    
    global_view.send("instance_variable_set", ivar, "#{old_content}#{content}")
    
    nil
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
cells-2.3.0 lib/cells_helper.rb