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

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

.hooksObject

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, options = {})
  out = ''
  (hooks[name.to_sym] || []).each do |path|
    out += template.render({ partial: path.first }.merge(options))
  end
  out.html_safe
end