Class | Nanoc3::Filter |
In: |
lib/nanoc3/base/filter.rb
|
Parent: | Context |
Nanoc3::Filter is responsible for filtering items. It is the superclass for all textual filters.
A filter instance should only be used once. Filters should not be reused since they store state.
When creating a filter with a hash containing assigned variables, those variables will be made available in the `@assigns` instance variable and the {assigns} method. The assigns itself will also be available as instance variables and instance methods.
@example Accessing assigns in different ways
filter = SomeFilter.new({ :foo => 'bar' }) filter.instance_eval { @assigns[:foo] } # => 'bar' filter.instance_eval { assigns[:foo] } # => 'bar' filter.instance_eval { @foo } # => 'bar' filter.instance_eval { foo } # => 'bar'
@abstract Subclass and override {run} to implement a custom filter.
TMP_BINARY_ITEMS_DIR | = | 'tmp/binary_items' | The path to the directory where temporary binary items are stored |
assigns | [R] |
A hash containing variables that will be made available during filtering.
@return [Hash] |
@return [Boolean] True if this filter can be applied to binary item
representations, false otherwise
Sets the new type for the filter. The type can be `:binary` (default) or `:text`. The given argument can either be a symbol indicating both “from” and “to” types, or a hash where the only key is the “from” type and the only value is the “to” type.
@example Specifying a text-to-text filter
type :text
@example Specifying a text-to-binary filter
type :text => :binary
@param [Symbol, Hash] arg The new type of this filter
@return [void]
Runs the filter on the given content or filename.
@abstract
@param [String] content_or_filename The unprocessed content that should
be filtered (if the item is a textual item) or the path to the file that should be filtered (if the item is a binary item)
@param [Hash] params A hash containing parameters. Filter subclasses can
use these parameters to allow modifying the filter's behaviour.
@return [String, void] If the filter output binary content, the return
value is undefined; if the filter outputs textual content, the return value will be the filtered content.