Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save miharekar/6765127 to your computer and use it in GitHub Desktop.
Save miharekar/6765127 to your computer and use it in GitHub Desktop.
Bootstrap 3 compatible breadcrumbs builder for breadcrumbs_on_rails gem.
# See SimpleBuilder in https://github.com/weppos/breadcrumbs_on_rails/blob/master/lib/breadcrumbs_on_rails/breadcrumbs.rb
class BootstrapBreadcrumbsBuilder < BreadcrumbsOnRails::Breadcrumbs::Builder
def render
@context.content_tag(:ul, class: 'breadcrumb') do
@elements.collect do |element|
render_element(element)
end.join.html_safe
end
end
def render_element(element)
current = @context.current_page?(compute_path(element))
@context.content_tag(:li, class: ('active' if current)) do
link_or_text = @context.link_to_unless_current(compute_name(element), compute_path(element), element.options)
divider = @context.content_tag(:span, (@options[:separator] || '/').html_safe, class: 'divider') unless current
link_or_text + (divider || '')
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment