Sha256: 1fe0c09b7dd05de3724c09618a30b28c55d12a0fcb6b6689fd85329e1c6c1ac1

Contents?: true

Size: 897 Bytes

Versions: 17

Compression:

Stored size: 897 Bytes

Contents

# frozen_string_literal: true

# This mechanism is used by 3rd party plugins.
# Normally you'd use partials from your own app
module ComfortableMexicanSofa::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:
  # ComfortableMexicanSofa::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

17 entries across 17 versions & 6 rubygems

Version Path
comfortable_mexican_sofa-2.0.19 lib/comfortable_mexican_sofa/view_hooks.rb
PixelForce_ETS-0.0.2 lib/comfortable_mexican_sofa/view_hooks.rb
PixelForce_ETS-0.0.1 lib/comfortable_mexican_sofa/view_hooks.rb
kcyEtsTest2-0.0.4 lib/comfortable_mexican_sofa/view_hooks.rb
kcyEtsTest2-0.0.3 lib/comfortable_mexican_sofa/view_hooks.rb
kcyEtsTest2-0.0.2 lib/comfortable_mexican_sofa/view_hooks.rb
kcyEtsTest2-0.0.1 lib/comfortable_mexican_sofa/view_hooks.rb
kcyEtsTest-0.0.1 lib/comfortable_mexican_sofa/view_hooks.rb
kcyEtsTest-2.2.19 lib/comfortable_mexican_sofa/view_hooks.rb
ComfortableMexicanSofa-2.0.18 lib/comfortable_mexican_sofa/view_hooks.rb
kcy1-1.0 lib/comfortable_mexican_sofa/view_hooks.rb
comfortable_mexican_sofa-2.0.18 lib/comfortable_mexican_sofa/view_hooks.rb
comfortable_mexican_sofa-2.0.17 lib/comfortable_mexican_sofa/view_hooks.rb
comfortable_mexican_sofa-2.0.16 lib/comfortable_mexican_sofa/view_hooks.rb
comfortable_mexican_sofa-2.0.15 lib/comfortable_mexican_sofa/view_hooks.rb
comfortable_mexican_sofa-2.0.14 lib/comfortable_mexican_sofa/view_hooks.rb
comfortable_mexican_sofa-2.0.13 lib/comfortable_mexican_sofa/view_hooks.rb