Sha256: 1a8393348ac7debbe15c1d1aa94edb45ae40e49b1a212b8c0ddf54dd7c9d410f

Contents?: true

Size: 1.11 KB

Versions: 15

Compression:

Stored size: 1.11 KB

Contents

# frozen_string_literal: true

module Nanoc::Helpers
  # @see http://nanoc.ws/doc/reference/helpers/#filtering
  module Filtering
    require 'nanoc/helpers/capturing'
    include Nanoc::Helpers::Capturing

    # @param [Symbol] filter_name
    # @param [Hash] arguments
    #
    # @return [void]
    def filter(filter_name, arguments = {}, &block)
      # Capture block
      data = capture(&block)

      # Find filter
      klass = Nanoc::Filter.named!(filter_name)

      # Create filter
      assigns = {
        item: @item,
        rep: @rep,
        item_rep: @item_rep,
        items: @items,
        layouts: @layouts,
        config: @config,
        content: @content,
      }
      filter = klass.new(assigns)

      # Filter captured data
      Nanoc::Int::NotificationCenter.post(:filtering_started, @item_rep._unwrap, filter_name)
      filtered_data = filter.setup_and_run(data, arguments)
      Nanoc::Int::NotificationCenter.post(:filtering_ended, @item_rep._unwrap, filter_name)

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

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
nanoc-4.11.0 lib/nanoc/helpers/filtering.rb
nanoc-4.10.4 lib/nanoc/helpers/filtering.rb
nanoc-4.10.3 lib/nanoc/helpers/filtering.rb
nanoc-4.10.2 lib/nanoc/helpers/filtering.rb
nanoc-4.10.1 lib/nanoc/helpers/filtering.rb
nanoc-4.10.0 lib/nanoc/helpers/filtering.rb
nanoc-4.9.9 lib/nanoc/helpers/filtering.rb
nanoc-4.9.8 lib/nanoc/helpers/filtering.rb
nanoc-4.9.7 lib/nanoc/helpers/filtering.rb
nanoc-4.9.6 lib/nanoc/helpers/filtering.rb
nanoc-4.9.5 lib/nanoc/helpers/filtering.rb
nanoc-4.9.4 lib/nanoc/helpers/filtering.rb
nanoc-4.9.3 lib/nanoc/helpers/filtering.rb
nanoc-4.9.2 lib/nanoc/helpers/filtering.rb
nanoc-4.9.1 lib/nanoc/helpers/filtering.rb