Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save zambon/9521174 to your computer and use it in GitHub Desktop.
Save zambon/9521174 to your computer and use it in GitHub Desktop.
#
# The BootstrapBreadcrumbsBuilder is a Bootstrap compatible breadcrumb builder.
# It provides basic functionalities to render a breadcrumb navigation according
# to Bootstrap's conventions.
#
# 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
@context.content_tag(:ol, class: "breadcrumb") do
@elements.collect { |e| render_element(e) }.join("\n").html_safe
end
end
private
def render_element(e)
name, path = compute_name(e), compute_path(e)
current = @context.current_page? path
@context.content_tag(:li, class: ("active" if current)) do
@context.link_to_unless_current(name, path, e.options)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment