Module: ComfortableMexicanSofa::ViewHooks

Defined in:
lib/comfortable_mexican_sofa/view_hooks.rb

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’)



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

def self.add(name, partial_path, position = 0)
  self.hooks[name.to_sym] ||= []
  self.hooks[name.to_sym] << [partial_path, position]
  self.hooks[name.to_sym].sort_by! { |hook| hook.last }
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



28
29
30
# File 'lib/comfortable_mexican_sofa/view_hooks.rb', line 28

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.first}.merge(options))
  end
  return out.html_safe
end