Module: Nanoc3::Helpers::Filtering
- Includes:
- Capturing
- Defined in:
- lib/nanoc3/helpers/filtering.rb
Overview
Provides functionality for filtering parts of an item or a layout.
Instance Method Summary collapse
-
#filter(filter_name, arguments = {}, &block) ⇒ void
Filters the content in the given block and outputs it.
Methods included from Capturing
Instance Method Details
#filter(filter_name, arguments = {}, &block) ⇒ void
This method returns an undefined value.
Filters the content in the given block and outputs it. This function does not return anything; instead, the filtered contents is directly appended to the output buffer (‘_erbout`).
This function has been tested with ERB and Haml. Other filters may not work correctly.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/nanoc3/helpers/filtering.rb', line 31 def filter(filter_name, arguments={}, &block) # Capture block data = capture(&block) # Find filter klass = Nanoc3::Filter.named(filter_name) raise Nanoc3::Errors::UnknownFilter.new(filter_name) if klass.nil? filter = klass.new(@item_rep.assigns) # Filter captured data filtered_data = filter.run(data, arguments) # Append filtered data to buffer buffer = eval('_erbout', block.binding) buffer << filtered_data end |