Sha256: 1e1f4c78acfa421e06028c5e5e4af8a0848420c6d7837c93f157e968f3f63f94

Contents?: true

Size: 1.11 KB

Versions: 41

Compression:

Stored size: 1.11 KB

Contents

# frozen_string_literal: true

module Nanoc::Helpers
  # @see https://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::Core::NotificationCenter.post(:filtering_started, @item_rep._unwrap, filter_name)
      filtered_data = filter.setup_and_run(data, arguments)
      Nanoc::Core::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

41 entries across 41 versions & 1 rubygems

Version Path
nanoc-4.11.23 lib/nanoc/helpers/filtering.rb
nanoc-4.11.22 lib/nanoc/helpers/filtering.rb
nanoc-4.11.21 lib/nanoc/helpers/filtering.rb
nanoc-4.11.20 lib/nanoc/helpers/filtering.rb
nanoc-4.11.19 lib/nanoc/helpers/filtering.rb
nanoc-4.11.18 lib/nanoc/helpers/filtering.rb
nanoc-4.11.17 lib/nanoc/helpers/filtering.rb
nanoc-4.11.16 lib/nanoc/helpers/filtering.rb
nanoc-4.11.15 lib/nanoc/helpers/filtering.rb
nanoc-4.11.14 lib/nanoc/helpers/filtering.rb
nanoc-4.11.13 lib/nanoc/helpers/filtering.rb
nanoc-4.11.12 lib/nanoc/helpers/filtering.rb
nanoc-4.11.11 lib/nanoc/helpers/filtering.rb
nanoc-4.11.10 lib/nanoc/helpers/filtering.rb
nanoc-4.11.9 lib/nanoc/helpers/filtering.rb
nanoc-4.11.8 lib/nanoc/helpers/filtering.rb
nanoc-4.11.7 lib/nanoc/helpers/filtering.rb
nanoc-4.11.6 lib/nanoc/helpers/filtering.rb
nanoc-4.11.5 lib/nanoc/helpers/filtering.rb
nanoc-4.11.4 lib/nanoc/helpers/filtering.rb