Module: ComfortableMexicanSofa::ViewHooks

Defined in:
lib/comfortable_mexican_sofa/view_hooks.rb

Class Method Summary collapse

Class Method Details

.add(name, partial_path) ⇒ Object

Will declare a partial that will be rendered for this hook Example: ComfortableMexicanSofa::ViewHooks.add(:navigation, ‘shared/navigation’)



20
21
22
23
# File 'lib/comfortable_mexican_sofa/view_hooks.rb', line 20

def self.add(name, partial_path)
  self.hooks[name.to_sym] ||= []
  self.hooks[name.to_sym] << partial_path
end

.hooksObject

Array of declared hooks



4
5
6
# File 'lib/comfortable_mexican_sofa/view_hooks.rb', line 4

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

.remove(name) ⇒ Object

Removing previously declared hook



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

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

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

Renders hook content



9
10
11
12
13
14
15
# File 'lib/comfortable_mexican_sofa/view_hooks.rb', line 9

def self.render(name, template, options = {})
  out = ''
  (self.hooks[name.to_sym] || []).each do |path|
    out += template.render({:partial => path}.merge(options))
  end
  return out.html_safe
end