Class: Crummy::CustomRenderer
- Inherits:
-
Object
- Object
- Crummy::CustomRenderer
- Includes:
- ActionView::Helpers::UrlHelper
- Defined in:
- lib/engine_room/crummy/custom_renderer.rb
Instance Method Summary collapse
-
#render_crumbs(crumbs, options = {}) ⇒ Object
Render the list of crumbs as either html or xml.
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> » <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 »
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, = {}) [:format] = :html if [:format] == nil if [:seperator] == nil [:seperator] = " » " if [:format] == :html [:seperator] = "crumb" if [:format] == :xml end [:links] = true if [:links] == nil case [:format] when :html crumb_string = crumbs.collect do |crumb| crumb_to_html crumb, crumbs.last==crumb ? false : [:links] #crumb_to_html crumb, options[:links] end * [: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, [:links], [:seperator] end * '' else raise ArgumentError, "Unknown breadcrumb output format" end end |