Module: Occams::ViewHooks
- Defined in:
- lib/occams/view_hooks.rb
Overview
This mechanism is used by 3rd party plugins. Normally you’d use partials from your own app
Class Method Summary collapse
-
.add(name, partial_path, position = 0) ⇒ Object
Will declare a partial that will be rendered for this hook Example: Occams::ViewHooks.add(:navigation, ‘shared/navigation’).
-
.hooks ⇒ Object
Array of declared hooks.
-
.remove(name) ⇒ Object
Removing previously declared hook.
-
.render(name, template, options = {}) ⇒ Object
Renders hook content.
Class Method Details
.add(name, partial_path, position = 0) ⇒ Object
Will declare a partial that will be rendered for this hook Example: Occams::ViewHooks.add(:navigation, ‘shared/navigation’)
23 24 25 26 27 |
# File 'lib/occams/view_hooks.rb', line 23 def self.add(name, partial_path, position = 0) hooks[name.to_sym] ||= [] hooks[name.to_sym] << [partial_path, position] hooks[name.to_sym].sort_by!(&:last) end |
.hooks ⇒ Object
Array of declared hooks
7 8 9 |
# File 'lib/occams/view_hooks.rb', line 7 def self.hooks @hooks ||= {} end |
.remove(name) ⇒ Object
Removing previously declared hook
30 31 32 |
# File 'lib/occams/view_hooks.rb', line 30 def self.remove(name) hooks.delete(name) end |
.render(name, template, options = {}) ⇒ Object
Renders hook content
12 13 14 15 16 17 18 |
# File 'lib/occams/view_hooks.rb', line 12 def self.render(name, template, = {}) out = '' (hooks[name.to_sym] || []).each do |path| out += template.render({ partial: path.first }.merge()) end out.html_safe end |