Module: Nanoc2::Helpers::Filtering

Defined in:
lib/nanoc2/helpers/filtering.rb

Overview

Nanoc2::Helpers::Filtering provides a filter method, which allows parts of a page to be filtered.

For example, the following piece of code only runs the “rubypants” filter on the second paragraph:

<p>Lorem ipsum dolor sit amet...</p>
<% filter :rubypants do %>
  <p>Consectetur adipisicing elit...</p>
<% end %>

This helper likely only works with ERB (and perhaps Erubis).

To activate this helper, include it, like this:

include Nanoc2::Helpers::Filtering

Instance Method Summary collapse

Instance Method Details

#filter(filter_name, &block) ⇒ Object

Filters the content in the given block and outputs it.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/nanoc2/helpers/filtering.rb', line 22

def filter(filter_name, &block)
  # Capture block
  data = capture(&block)

  # Find filter
  filter = Nanoc2::Filter.named(filter_name).new(@_obj_rep)

  # Filter captured data
  filtered_data = filter.run(data)

  # Append filtered data to buffer
  buffer = eval('_erbout', block.binding)
  buffer << filtered_data
end