Sha256: 2d789153677bf50f2c96f224c8e14c90a8a22a6d45f4fb88edb7e20e2b754c81

Contents?: true

Size: 863 Bytes

Versions: 12

Compression:

Stored size: 863 Bytes

Contents

# frozen_string_literal: true

# This mechanism is used by 3rd party plugins.
# Normally you'd use partials from your own app
module Occams::ViewHooks
  # Array of declared hooks
  def self.hooks
    @hooks ||= {}
  end

  # Renders hook content
  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

  # Will declare a partial that will be rendered for this hook
  # Example:
  # Occams::ViewHooks.add(:navigation, 'shared/navigation')
  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

  # Removing previously declared hook
  def self.remove(name)
    hooks.delete(name)
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
occams-1.1.0 lib/occams/view_hooks.rb
occams-1.0.8 lib/occams/view_hooks.rb
occams-1.0.7.3 lib/occams/view_hooks.rb
occams-1.0.7.2 lib/occams/view_hooks.rb
occams-1.0.7.1 lib/occams/view_hooks.rb
occams-1.0.7 lib/occams/view_hooks.rb
occams-1.0.6.1 lib/occams/view_hooks.rb
occams-1.0.6 lib/occams/view_hooks.rb
occams-1.0.5 lib/occams/view_hooks.rb
occams-1.0.4 lib/occams/view_hooks.rb
occams-1.0.3 lib/occams/view_hooks.rb
occams-1.0.2 lib/occams/view_hooks.rb