Module: Docter::Filter

Defined in:
lib/docter/page.rb

Overview

Filters are used to process HTML before rendering, e.g to apply syntax highlighting, URL rewriting. To add a new filter:

filter_for(:upcase) { |html| html.upcase }

Class Method Summary collapse

Class Method Details

.filter_for(name, &block) ⇒ Object

:call-seq:

filter_for(name) { |html| ... }

Defines a filter for name using a block that will transform the HTML.



257
258
259
260
# File 'lib/docter/page.rb', line 257

def filter_for(name, &block)
  @filters[name.to_sym] = block
  self
end

.listObject

:call-seq:

list => names

Return the names of all defined filters.



249
250
251
# File 'lib/docter/page.rb', line 249

def list
  @filters.keys
end

.process(html, *using) ⇒ Object

:call-seq:

process(html) => html
process(html, *name) => html

Process the HTML using the available filters and returns the resulting HTML. The second form uses only the selected filters.



268
269
270
271
272
# File 'lib/docter/page.rb', line 268

def process(html, *using)
  using = using.flatten.compact
  (using.empty? ? @filters.values : @filters.values_at(*using)).
    inject(html) { |html, filter| filter.call(html) }
end