Class: NanocHtmlPipeline::Filter

Inherits:
Nanoc::Filter
  • Object
show all
Defined in:
lib/nanoc-html-pipeline/filter.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.filter_key(s) ⇒ Object



11
12
13
# File 'lib/nanoc-html-pipeline/filter.rb', line 11

def self.filter_key(s)
  s.to_s.downcase.to_sym
end

.is_filter(f) ⇒ Object



15
16
17
18
19
# File 'lib/nanoc-html-pipeline/filter.rb', line 15

def self.is_filter(f)
  f < HTML::Pipeline::Filter
rescue LoadError, ArgumentError
  false
end

Instance Method Details

#run(content, params = {}) ⇒ String

Returns The filtered content.

Parameters:

  • content (String)

    The content to filter

Returns:

  • (String)

    The filtered content



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/nanoc-html-pipeline/filter.rb', line 27

def run(content, params={})
  # Get options
  options = {:pipeline => []}.merge(params)

  filters = options.delete(:pipeline).map do |f|
    if self.class.is_filter(f)
      f
    else
      key = self.class.filter_key(f)
      filter = HTML::Pipeline.constants.find { |c| c.downcase == key }
      # possibly a custom filter
      if filter.nil?
        Nanoc.const_get(f)
      else
        HTML::Pipeline.const_get(filter)
      end
    end
  end

  HTML::Pipeline.new(filters, options).to_html(content)
end