Class: Stasis::Priority
Instance Method Summary collapse
-
#before_all ⇒ Object
This event triggers before all files render through Stasis.
-
#initialize(stasis) ⇒ Priority
constructor
A new instance of Priority.
-
#priority(hash) ⇒ Object
This method is bound to all controllers.
-
#reset ⇒ Object
This event resets all instance variables.
Methods inherited from Plugin
#_match_key?, _priority, #_within?, inherited, plugins, priority
Constructor Details
#initialize(stasis) ⇒ Priority
10 11 12 13 |
# File 'lib/stasis/plugins/priority.rb', line 10 def initialize(stasis) @stasis = stasis reset end |
Instance Method Details
#before_all ⇒ Object
This event triggers before all files render through Stasis. Collect matching paths and sort those paths by priority.
17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/stasis/plugins/priority.rb', line 17 def before_all @stasis.paths.collect! do |path| priority = 0 matches = _match_key?(@priorities, path) matches.each do |(within, value, force)| priority = value if _within?(within, path) || force end [ path, priority ] end @stasis.paths.sort! { |a, b| b[1] <=> a[1] } @stasis.paths.collect! { |(path, priority)| path } end |
#priority(hash) ⇒ Object
This method is bound to all controllers. Stores a priority integer in the ‘@@priorities` Hash, where the key is a path and the value is the priority.
32 33 34 35 36 37 38 39 40 |
# File 'lib/stasis/plugins/priority.rb', line 32 def priority(hash) hash = hash.inject({}) do |hash, (key, value)| force = key[0..0] == '/' if key.is_a?(::String) key = @stasis.controller._resolve(key) hash[key] = [ @stasis.path, value, force ] if key hash end @priorities.merge!(hash) end |
#reset ⇒ Object
This event resets all instance variables.
43 44 45 |
# File 'lib/stasis/plugins/priority.rb', line 43 def reset @priorities = {} end |