Sha256: ea6cdd24abb53abcb797ba89113327f478f571ff7cf992d60f508f492bcb0e81
Contents?: true
Size: 1.32 KB
Versions: 2
Compression:
Stored size: 1.32 KB
Contents
module Gretel class Crumbs class << self def layout(&block) # needs to be done here because Rails.application isn't set when this file is required self.class.send :include, Rails.application.routes.url_helpers instance_eval &block end def all @crumbs ||= {} end def crumb(name, &block) all[name] = block end def get_crumb(name, object = nil) crumb = all[name] raise ArgumentError, "Breadcrumb :#{name} not found." unless crumb @object = object # share the object so we can call it from link() and parent() @parent = nil crumb.call(object) Gretel::Crumb.new(@links, @parent) end def link(*args) options = args.extract_options! text = args[0] url = args[1] text = text.call(@object) if text.is_a?(Proc) url = url.call(@object) if url.is_a?(Proc) @links ||= [] @links << Gretel::Link.new(text, url, options) @links end def parent(name, object = nil) name = name.call(@object) if name.is_a?(Proc) object = object.call(@object) if object.is_a?(Proc) @parent = Gretel::Parent.new(name, object) end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
gretel-1.2.1 | lib/gretel/crumbs.rb |
gretel-1.2.0 | lib/gretel/crumbs.rb |