Class: 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

MAP

Constructor Summary

public initialize(a_assigns = {})

Creates a new filter with the given assigns.

a_assigns:A hash containing variables that should be made available during filtering.
[View source]


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

all, named

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

public identifier(identifier)

Sets the identifier for this filter.

[View source]


28
29
30
# File 'lib/nanoc3/base/filter.rb', line 28

def self.identifier(identifier)
  Nanoc3::Filter.register(self, identifier)
end

identifiers

public identifiers(*identifiers)

Sets the identifiers for this filter.

[View source]


23
24
25
# File 'lib/nanoc3/base/filter.rb', line 23

def self.identifiers(*identifiers)
  Nanoc3::Filter.register(self, *identifiers)
end

register

public register(class_or_name, *identifiers)

Registers the given class as a filter with the given identifier.

[View source]


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

public filename

Returns the filename associated with the item that is being filtered. The returned filename is in the format "item <identifier> (rep <name>)".

[View source]


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

public run(content, params = {})

Runs the filter. This method returns the filtered content.

content:The unprocessed content that should be filtered.

Subclasses must implement this method.

Meta Tags

Raises:

[NotImplementedError]
[View source]


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
Generated on Sunday, August 09 2009 at 01:43:07 PM by YARD 0.2.3.2 (ruby-1.8.7).