Class: Nanoc3::Filter
- Nanoc3::Plugin
- Nanoc3::Filter
Nanoc3::Filter is responsible for filtering items. It is the (abstract) superclass for all textual filters. Subclasses should override the run method.
Attributes
Instance Attributes
| assigns | [R] | public |
A hash containing variables that will be made available during filtering. |
|---|
Constants Inherited from Nanoc3::Plugin
Constructor Summary
Creates a new filter with the given assigns.
| a_assigns: | A hash containing variables that should be made available during filtering. |
18 19 20 |
# File 'lib/nanoc3/base/filter.rb', line 18 def initialize(a_assigns={}) @assigns = a_assigns end |
Public Visibility
Public Class Method Summary
| identifier(identifier) |
Sets the identifier for this filter. |
|---|---|
| identifiers(*identifiers) |
Sets the identifiers for this filter. |
| register(class_or_name, *identifiers) |
Registers the given class as a filter with the given identifier. |
Public Class Methods Inherited from Nanoc3::Plugin
Public Instance Method Summary
| #filename |
Returns the filename associated with the item that is being filtered. |
|---|---|
| #run(content, params = {}) |
Runs the filter. |
Public Class Method Details
identifier
Sets the identifier for this filter.
28 29 30 |
# File 'lib/nanoc3/base/filter.rb', line 28 def self.identifier(identifier) Nanoc3::Filter.register(self, identifier) end |
identifiers
Sets the identifiers for this filter.
23 24 25 |
# File 'lib/nanoc3/base/filter.rb', line 23 def self.identifiers(*identifiers) Nanoc3::Filter.register(self, *identifiers) end |
register
Registers the given class as a filter with the given identifier.
33 34 35 |
# File 'lib/nanoc3/base/filter.rb', line 33 def self.register(class_or_name, *identifiers) Nanoc3::Plugin.register(Nanoc3::Filter, class_or_name, *identifiers) end |
Public Instance Method Details
filename
Returns the filename associated with the item that is being filtered. The returned filename is in the format "item <identifier> (rep <name>)".
48 49 50 51 52 53 54 55 56 |
# File 'lib/nanoc3/base/filter.rb', line 48 def filename if assigns[:layout] "layout #{assigns[:layout].identifier}" elsif assigns[:item] "item #{assigns[:item].identifier} (rep #{assigns[:item_rep].name})" else '?' end end |
run
Runs the filter. This method returns the filtered content.
| content: | The unprocessed content that should be filtered. |
Subclasses must implement this method.
42 43 44 |
# File 'lib/nanoc3/base/filter.rb', line 42 def run(content, params={}) raise NotImplementedError.new("Nanoc3::Filter subclasses must implement #run") end |