Class: Stasis::Plugin

Inherits:
Object
  • Object
show all
Defined in:
lib/stasis/plugin.rb

Direct Known Subclasses

Before, Helpers, Ignore, Instead, Layout, Priority, Render

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Class Attribute Details

._methodsObject

‘Hash` – Keys are the “bind as” method names and values are the actual method names on the `Plugin` instance.



16
17
18
# File 'lib/stasis/plugin.rb', line 16

def _methods
  @_methods
end

Class Method Details

._priorityObject

‘Fixnum` – The execution priority for this plugin (defaults to 0).



19
# File 'lib/stasis/plugin.rb', line 19

def _priority; @priority || 0; end

.inherited(subclass) ⇒ Object



5
6
7
8
# File 'lib/stasis/plugin.rb', line 5

def inherited(subclass)
  @plugins ||= []
  @plugins << subclass
end

.pluginsObject



10
11
12
# File 'lib/stasis/plugin.rb', line 10

def plugins
  (@plugins || []).dup
end

.priority(number) ⇒ Object

Class method to set priority on the ‘Plugin`.



56
57
58
# File 'lib/stasis/plugin.rb', line 56

def priority(number)
  @priority = number
end

Instance Method Details

#_match_key?(hash, match_key) ⇒ Boolean

Helper method provided for built-in Stasis plugins. Returns an ‘Array` of values of a `Hash` whose keys are `nil`, a literal match, or a pattern match.

Returns:

  • (Boolean)


74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/stasis/plugin.rb', line 74

def _match_key?(hash, match_key)
  hash.inject([]) do |array, (key, value)|
    if key.nil?
      array << value
    elsif key.is_a?(::String) && key == match_key
      array << value
    elsif key.is_a?(::Regexp) && key =~ match_key
      array << value
    end
    array
  end
end

#_within?(within_path, path = @stasis.path) ⇒ Boolean

Helper method provided for built-in Stasis plugins. Returns a boolean value denoting whether or not a path is within another path.

Returns:

  • (Boolean)


63
64
65
66
67
68
69
70
# File 'lib/stasis/plugin.rb', line 63

def _within?(within_path, path=@stasis.path)
  if within_path && path
    dir = File.dirname(within_path)
    path[0..dir.length-1] == dir
  else
    true
  end
end