Sha256: 26fb4d0528a5a59bb7e72269b1e8b9c4bdbc5fb9aa431e58bd2ee29b15f7fd9b

Contents?: true

Size: 724 Bytes

Versions: 2

Compression:

Stored size: 724 Bytes

Contents

module LucyCms::ViewHooks
  
  # Array of declared hooks
  def self.hooks
    @@hooks ||= { }
  end
  
  # Renders hook content
  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
  
  # Will declare a partial that will be rendered for this hook
  # Example:
  # ComfortableMexicanSofa::ViewHooks.add(:navigation, 'shared/navigation')
  def self.add(name, partial_path)
    self.hooks[name.to_sym] ||= []
    self.hooks[name.to_sym] << partial_path
  end
  
  # Removing previously declared hook
  def self.remove(name)
    self.hooks.delete(name)
  end
  
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
lucy_cms-0.0.5 lib/LucyCMS/view_hooks.rb
lucy_cms-0.0.4 lib/LucyCMS/view_hooks.rb