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.



242
243
244
245
# File 'lib/docter/page.rb', line 242

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

.listObject

:call-seq:

list => names

Return the names of all defined filters.



234
235
236
# File 'lib/docter/page.rb', line 234

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.



253
254
255
256
257
# File 'lib/docter/page.rb', line 253

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