Sha256: c8904cdddca8049285c01f398d43c7e33ab71f893e05e09339a491d04c9e01b9

Contents?: true

Size: 1.15 KB

Versions: 24

Compression:

Stored size: 1.15 KB

Contents

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)
      raise Nanoc::Int::Errors::UnknownFilter.new(filter_name) if klass.nil?

      # 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

24 entries across 24 versions & 1 rubygems

Version Path
nanoc-4.6.1 lib/nanoc/helpers/filtering.rb
nanoc-4.6.0 lib/nanoc/helpers/filtering.rb
nanoc-4.5.4 lib/nanoc/helpers/filtering.rb
nanoc-4.5.3 lib/nanoc/helpers/filtering.rb
nanoc-4.5.2 lib/nanoc/helpers/filtering.rb
nanoc-4.5.1 lib/nanoc/helpers/filtering.rb
nanoc-4.5.0 lib/nanoc/helpers/filtering.rb
nanoc-4.4.7 lib/nanoc/helpers/filtering.rb
nanoc-4.4.6 lib/nanoc/helpers/filtering.rb
nanoc-4.4.5 lib/nanoc/helpers/filtering.rb
nanoc-4.4.4 lib/nanoc/helpers/filtering.rb
nanoc-4.4.3 lib/nanoc/helpers/filtering.rb
nanoc-4.4.2 lib/nanoc/helpers/filtering.rb
nanoc-4.4.1 lib/nanoc/helpers/filtering.rb
nanoc-4.4.0 lib/nanoc/helpers/filtering.rb
nanoc-4.3.8 lib/nanoc/helpers/filtering.rb
nanoc-4.3.7 lib/nanoc/helpers/filtering.rb
nanoc-4.3.6 lib/nanoc/helpers/filtering.rb
nanoc-4.3.5 lib/nanoc/helpers/filtering.rb
nanoc-4.3.4 lib/nanoc/helpers/filtering.rb