class Gretel::Crumb

Attributes

context[R]

The current view context.

key[R]

Key of the breadcrumb.

Public Class Methods

new(context, key, *args) click to toggle source

Initializes a new crumb from the given key. It finds the breadcrumb created in Gretel::Crumbs.layout and renders the block using the arguments supplied in args.

# File lib/gretel/crumb.rb, line 7
def initialize(context, key, *args)
  if key.class.respond_to?(:model_name)
    # Enables calling `breadcrumb @product` instead of `breadcrumb :product, @product`
    args.unshift key
    key = key.class.model_name.to_s.underscore.to_sym
  end

  block = Gretel::Crumbs.crumbs[key]
  raise ArgumentError, "Breadcrumb :#{key} not found." unless block
  @key = key
  @context = context
  instance_exec(*args, &block)
end

Public Instance Methods

method_missing(method, *args, &block) click to toggle source

Proxy to view context.

# File lib/gretel/crumb.rb, line 66
def method_missing(method, *args, &block)
  context.send(method, *args, &block)
end
parent(*args) click to toggle source

Sets or gets the parent breadcrumb. If you supply a parent key and optional arguments, it will set the parent. If nothing is supplied, it will return the parent, if this has been set.

Example:

parent :category, category

Or short, which will infer the key from the model’s ‘model_name`:

parent category
# File lib/gretel/crumb.rb, line 52
def parent(*args)
  return @parent if args.empty?
  key = args.shift

  @parent = Gretel::Crumb.new(context, key, *args)
end