module BreadcrumbsHelper
def breadcrumbs(breadcrumbs={})
html_safe <<-HTML
#{render_breadcrumbs(breadcrumbs)}
HTML
end
def render_breadcrumbs(breadcrumbs)
html = ""
breadcrumbs.each_with_index do |(name, value), index|
active = (index + 1) == breadcrumbs.length
html << render_breadcrumb(active, name, value)
end
html
end
def render_breadcrumb(active, name, value=nil)
if value.nil?
render_selected_breadcrumb(active, name)
elsif value.is_a?(Array)
if value.length <= 1
render_breadcrumb_option(name, active)
else
render_dropdown_breadcrumb(active, name, value)
end
else
render_simple_breadcrumb(active, name, value)
end
end
def render_dropdown_breadcrumb(active, model, options)
<<-HTML
#{model.name}
HTML
end
def render_breadcrumb_option(model, active=false)
"#{model.name}"
end
def render_simple_breadcrumb(active, name, url)
"#{name}"
end
def render_selected_breadcrumb(active, name)
"#{name}"
end
end