module ComfortableMexicanSofa::ViewHooks

This mechanism is used by 3rd party plugins. Normally you'd use partials from your own app

Public Class Methods

add(name, partial_path, position = 0) click to toggle source

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

# 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
hooks() click to toggle source

Array of declared hooks

# File lib/comfortable_mexican_sofa/view_hooks.rb, line 8
def self.hooks
  @hooks ||= {}
end
remove(name) click to toggle source

Removing previously declared hook

# File lib/comfortable_mexican_sofa/view_hooks.rb, line 31
def self.remove(name)
  hooks.delete(name)
end
render(name, template, options = {}) click to toggle source

Renders hook content

# 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