Sha256: 05af19f229f60efa1cb0e1128cae7ff5a9dab914ae582cd4a74321a67ef1026c

Contents?: true

Size: 1.58 KB

Versions: 1

Compression:

Stored size: 1.58 KB

Contents

module Nanoc2

  # Nanoc2::BinaryFilter is responsible for filtering binary assets. It is the
  # (abstract) superclass for all binary filters. Subclasses should override
  # the +run+ method.
  class BinaryFilter < Plugin

    # Creates a new binary filter for the given asset and site.
    #
    # +asset_rep+:: A proxy for the asset representation (Nanoc2::AssetRep)
    #               that should be compiled by this filter.
    #
    # +asset+:: A proxy for the asset (Nanoc2::Asset) for which +asset_rep+ is
    #           the representation.
    #
    # +site+:: The site (Nanoc2::Site) this filter belongs to.
    #
    # +other_assigns+:: A hash containing other variables that should be made
    #                   available during filtering.
    def initialize(asset_rep, asset, site, other_assigns={})
      @asset_rep      = asset_rep
      @asset          = asset
      @pages          = site.pages.map   { |p| p.to_proxy }
      @assets         = site.assets.map  { |a| a.to_proxy }
      @layouts        = site.layouts.map { |l| l.to_proxy }
      @config         = site.config
      @site           = site
      @other_assigns  = other_assigns
    end

    # Runs the filter. This method returns a File instance pointing to a new
    # file, containing the filtered content.
    #
    # +file+:: A File instance representing the incoming file that should be
    #          filtered. This file should _not_ be modified.
    #
    # Subclasses must implement this method.
    def run(file)
      raise NotImplementedError.new("Nanoc2::BinaryFilter subclasses must implement #run")
    end

  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
nanoc2-2.2.3 lib/nanoc2/base/binary_filter.rb