Class: Stasis::Ignore

Inherits:
Plugin
  • Object
show all
Defined in:
lib/stasis/plugins/ignore.rb

Instance Method Summary collapse

Methods inherited from Plugin

#_match_key?, _priority, #_within?, inherited, plugins, priority

Constructor Details

#initialize(stasis) ⇒ Ignore

Returns a new instance of Ignore.



8
9
10
11
# File 'lib/stasis/plugins/ignore.rb', line 8

def initialize(stasis)
  @stasis = stasis
  reset
end

Instance Method Details

#before_renderObject

This event triggers before each file renders. Rejects any ‘paths` that are included in the `@ignore` `Array`.



15
16
17
18
19
20
21
22
# File 'lib/stasis/plugins/ignore.rb', line 15

def before_render
  matches = _match_key?(@ignore, @stasis.path)
  matches.each do |group|
    group.each do |path|
      @stasis.path = nil if _within?(path)
    end
  end
end

#ignore(*array) ⇒ Object

This method is bound to all controllers. Adds an ‘Array` of paths to the `@ignore` `Array`.



26
27
28
29
30
31
32
33
34
# File 'lib/stasis/plugins/ignore.rb', line 26

def ignore(*array)
  array.each do |path|
    path = @stasis.controller._resolve(path)
    if path
      @ignore[path] ||= []
      @ignore[path] << @stasis.path
    end
  end
end

#resetObject

This event resets all instance variables.



37
38
39
# File 'lib/stasis/plugins/ignore.rb', line 37

def reset
  @ignore = {}
end