Class: Stasis::Helpers
Instance Method Summary collapse
-
#before_render ⇒ Object
This event triggers before each file renders through Stasis.
-
#helpers(&block) ⇒ Object
This method is bound to all controllers.
-
#initialize(stasis) ⇒ Helpers
constructor
A new instance of Helpers.
-
#reset ⇒ Object
This event resets all instance variables.
Methods inherited from Plugin
#_match_key?, _priority, #_within?, inherited, plugins, priority
Constructor Details
#initialize(stasis) ⇒ Helpers
Returns a new instance of Helpers.
8 9 10 11 |
# File 'lib/stasis/plugins/helpers.rb', line 8 def initialize(stasis) @stasis = stasis reset end |
Instance Method Details
#before_render ⇒ Object
This event triggers before each file renders through Stasis. For each helper ‘block`, evaluate the `block` in the scope of the `action` class.
15 16 17 18 19 20 21 |
# File 'lib/stasis/plugins/helpers.rb', line 15 def before_render @blocks.each do |(path, block)| if _within?(path) @stasis.action.class.class_eval(&block) end end end |
#helpers(&block) ⇒ Object
This method is bound to all controllers. Stores a block in the ‘@blocks` `Array`.
24 25 26 27 28 |
# File 'lib/stasis/plugins/helpers.rb', line 24 def helpers(&block) if block @blocks << [ @stasis.path, block ] end end |
#reset ⇒ Object
This event resets all instance variables.
31 32 33 |
# File 'lib/stasis/plugins/helpers.rb', line 31 def reset @blocks = [] end |