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.
# You can use it with the :builder option on render_breadcrumbs:
# <%= render_breadcrumbs :builder => ::BootstrapBreadcrumbsBuilder %>
#
# Note: You may need to adjust the autoload_paths in your config/application.rb file for rails to load this class:
# config.autoload_paths += Dir["#{config.root}/lib/"]
#
class BootstrapBreadcrumbsBuilder < BreadcrumbsOnRails::Breadcrumbs::Builder
def render
return '' if @elements.empty?
@context.content_tag :ol, class: 'breadcrumb' do
@elements.collect do |element|
render_element element
end.join("\n").html_safe
end
end
def render_element element
current = @context.current_page? compute_path(element)
@context.content_tag :li, class: ('active' if current) do
@context.link_to_unless_current compute_name(element), compute_path(element), element.options
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment