Module: ComfortableMexicanSofa::ViewHooks

Defined in:
lib/comfortable_mexican_sofa/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: ComfortableMexicanSofa::ViewHooks.add(:navigation, 'shared/navigation')


24
25
26
27
28
# File 'lib/comfortable_mexican_sofa/view_hooks.rb', line 24

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


8
9
10
# File 'lib/comfortable_mexican_sofa/view_hooks.rb', line 8

def self.hooks
  @hooks ||= {}
end

.remove(name) ⇒ Object

Removing previously declared hook


31
32
33
# File 'lib/comfortable_mexican_sofa/view_hooks.rb', line 31

def self.remove(name)
  hooks.delete(name)
end

.render(name, template, options = {}) ⇒ Object

Renders hook content


13
14
15
16
17
18
19
# File 'lib/comfortable_mexican_sofa/view_hooks.rb', line 13

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