Module Nanoc3::Helpers::Capturing
In: lib/nanoc3/helpers/capturing.rb

Provides functionality for “capturing” content in one place and reusing this content elsewhere.

For example, suppose you want the sidebar of your site to contain a short summary of the item. You could put the summary in the meta file, but that’s not possible when the summary contains eRuby. You could also put the sidebar inside the actual item, but that’s not very pretty. Instead, you write the summary on the item itself, but capture it, and print it in the sidebar layout.

@example Capturing content into a `content_for_summary` attribute

  <% content_for :summary do %>
    <p>On this item, nanoc is introduced, blah blah.</p>
  <% end %>

@example Showing captured content in a sidebar

  <div id="sidebar">
    <h3>Summary</h3>
    <%= @item[:content_for_summary] || '(no summary)' %>
  </div>

Methods

Public Instance methods

Evaluates the given block and returns the result. The contents of the block is not outputted.

This function has been tested with ERB and Haml. Other filters may not work correctly.

@return [String] The captured result

Captures the content inside the block and stores it in an item attribute named `content_for_` followed by the given name. The content of the block itself will not be outputted.

@param [Symbol, String] The base name of the attribute into which the content should be stored

@return [void]

[Validate]