Sha256: 5a3fd1715f4fd4168d7c2eca66ac8259bc430711d9c31ce0a9d477b2d7c9311d

Contents?: true

Size: 724 Bytes

Versions: 3

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

3 entries across 3 versions & 1 rubygems

Version Path
lucy_cms-0.0.3 lib/LucyCMS/view_hooks.rb
lucy_cms-0.0.2 lib/LucyCMS/view_hooks.rb
lucy_cms-0.0.1 lib/LucyCMS/view_hooks.rb