Sha256: 74914193bb642c07d0ff2d41045a5c7c2a3c21af513a069697ea222ded483c18

Contents?: true

Size: 1.54 KB

Versions: 13

Compression:

Stored size: 1.54 KB

Contents

# encoding: utf-8

# Sorry for the interface violations, but it looks as if there are
# no interfaces in rails at all.
module Cells
  module Helpers
    module CaptureHelper
      # 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.parent_controller.view_context
        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. that SUCKS.
        global_view = controller.parent_controller.view_context
        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
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
cells-3.5.2 lib/cells/helpers/capture_helper.rb
cells-3.5.1 lib/cells/helpers/capture_helper.rb
cells-3.5.0 lib/cells/helpers/capture_helper.rb
cells-3.5.0.beta2 lib/cells/helpers/capture_helper.rb
cells-3.5.0.beta1 lib/cells/helpers/capture_helper.rb
cells-3.4.4 lib/cells/helpers/capture_helper.rb
cells-3.4.3 lib/cells/helpers/capture_helper.rb
cells-3.4.2 lib/cells/helpers/capture_helper.rb
cells-3.4.1 lib/cells/helpers/capture_helper.rb
cells-3.4.0 lib/cells/helpers/capture_helper.rb
cells-3.4.0.beta3 lib/cells/helpers/capture_helper.rb
cells-3.4.0.beta2 lib/cells/helpers/capture_helper.rb
cells-3.4.0.beta1 lib/cells/helpers/capture_helper.rb