Skip to content

Commit

Permalink
A slightly more elegant xml implementation. Now with options
Browse files Browse the repository at this point in the history
  • Loading branch information
Kasper Weibel Nielsen-Refs committed Sep 9, 2008
1 parent eca946b commit 32cc72c
Showing 1 changed file with 22 additions and 13 deletions.
35 changes: 22 additions & 13 deletions lib/crummy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,27 +72,36 @@ def add_crumb(name, url=nil)
#
# render_crumbs(" . ") #=> <a href="/">Home</a> . <a href="/businesses">Businesses</a>
#
def render_crumbs(seperator=" &raquo; ", links = true)
crumbs.collect do |crumb|
crumb_to_html crumb, links
end * seperator
def render_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
crumbs.collect do |crumb|
crumb_to_html crumb, options[:links]
end * options[:seperator]
when :xml
crumbs.collect do |crumb|
crumb_to_xml crumb, options[:links], options[:seperator]
end * ''
else
raise "Unknown breadcrumb output format"
end
end

def crumb_to_html(crumb, links)
name, url = crumb
url && links ? link_to(name, url) : name
end

def render_crumbs_to_xml(seperator=" &raquo; ", links = true)
crumbs.collect do |crumb|
crumb_to_xml crumb, links
end * ''
end

def crumb_to_xml(crumb, links)
def crumb_to_xml(crumb, links, seperator)
name, url = crumb
url && links ? "<crumb href=\"#{url}\">#{name}</crumb>" : "<crumb>#{name}</crumb>"
url && links ? "<#{seperator} href=\"#{url}\">#{name}</#{seperator}>" : "<#{seperator}>#{name}</#{seperator}>"
end

end
end
end

0 comments on commit 32cc72c

Please sign in to comment.