Sha256: 0a7274d4d3a65ed0cbb487c21cca694d091234f34e37cd5f08dc5cfb7721ad18

Contents?: true

Size: 1.53 KB

Versions: 11

Compression:

Stored size: 1.53 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.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
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
cells-3.3.10 lib/cells/helpers/capture_helper.rb
cells-3.3.9 lib/cells/helpers/capture_helper.rb
cells-3.3.8 lib/cells/helpers/capture_helper.rb
cells-3.3.7 lib/cells/helpers/capture_helper.rb
cells-3.3.6 lib/cells/helpers/capture_helper.rb
cells-3.3.5 lib/cells/helpers/capture_helper.rb
cells-3.3.4 lib/cells/helpers/capture_helper.rb
cells-3.3.3 lib/cells/helpers/capture_helper.rb
cells-3.3.2 lib/cells/helpers/capture_helper.rb
cells-3.3.1 lib/cells/helpers/capture_helper.rb
cells-3.3.0 lib/cells/helpers/capture_helper.rb