Class: Content::Pipeline

Inherits:
Object
  • Object
show all
Defined in:
lib/content/pipeline.rb,
lib/content/pipeline/filters.rb,
lib/content/pipeline/version.rb

Defined Under Namespace

Modules: Filters, Jekyll Classes: Filter

Constant Summary collapse

VERSION =
"1.2.0"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filters = nil, opts = nil) ⇒ Pipeline





14
15
16
17
18
19
20
21
22
23
24
# File 'lib/content/pipeline.rb', line 14

def initialize(filters = nil, opts = nil)
  if filters.is_a?(Hash) && opts.nil?
    opts = filters
    filters =  nil
  end


  opts = {} if opts.nil?
  filters = Filters::DEFAULT_FILTERS if filters.nil?
  @opts, @filters = opts.freeze, [ filters ].flatten.freeze
end

Instance Attribute Details

#filtersObject (readonly)

Returns the value of attribute filters.



7
8
9
# File 'lib/content/pipeline.rb', line 7

def filters
  @filters
end

#optsObject (readonly)

Returns the value of attribute opts.



7
8
9
# File 'lib/content/pipeline.rb', line 7

def opts
  @opts
end

Instance Method Details

#filter(out, opts = {}) ⇒ Object





31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/content/pipeline.rb', line 31

def filter(out, opts = {})
  return out if out.nil? || out.empty? || @filters.empty?

  opts = @opts.deep_merge(opts)
  @filters.each_with_index do |f, i|
    fopts = opts.values_at(*to_opt(f)).delete_if(&:nil?). \
      reduce({}, :merge)

    out = f.new(out, fopts).run(@filters[i + 1])
  end

out
end