Class: Crummy::CustomRenderer

Inherits:
Object
  • Object
show all
Includes:
ActionView::Helpers::UrlHelper
Defined in:
lib/engine_room/crummy/custom_renderer.rb

Instance Method Summary collapse

Instance Method Details

#render_crumbs(crumbs, options = {}) ⇒ Object

Render the list of crumbs as either html or xml

Takes 3 options: The output format. Can either be xml or html. Default :html

:format => (:html|:xml)

The seperator text. It does not assume you want spaces on either side so you must specify. Default » for :html and crumb for xml

:seperator => string

Render links in the output. Default true

:link => boolean        

Examples:
render_crumbs                     #=> <a href="/">Home</a> &raquo; <a href="/businesses">Businesses</a>
render_crumbs :seperator => ' | ' #=> <a href="/">Home</a> | <a href="/businesses">Businesses</a>
render_crumbs :format => :xml     #=> <crumb href="/">Home</crumb><crumb href="/businesses">Businesses</crumb>

The only argument is for the seperator text. It does not assume you want spaces on either side so you must specify. Defaults to &raquo;

render_crumbs(" . ")  #=> <a href="/">Home</a> . <a href="/businesses">Businesses</a>


26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/engine_room/crummy/custom_renderer.rb', line 26

def render_crumbs(crumbs, options = {})
  options[:format] = :html if options[:format] == nil
  if options[:seperator] == nil
    options[:seperator] = " &raquo; " if options[:format] == :html 
    options[:seperator] = "crumb" if options[:format] == :xml 
  end
  options[:links] = true if options[:links] == nil
  case options[:format]
  when :html
    crumb_string = crumbs.collect do |crumb|
      crumb_to_html crumb, crumbs.last==crumb ? false : options[:links]
      #crumb_to_html crumb, options[:links]
    end * options[:seperator]
    crumb_string = crumb_string.html_safe if crumb_string.respond_to?(:html_safe)
    crumb_string
  when :xml
    crumbs.collect do |crumb|
      crumb_to_xml crumb, options[:links], options[:seperator]
    end * ''
  else
    raise ArgumentError, "Unknown breadcrumb output format"
  end
end