Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save equivalent/9972557 to your computer and use it in GitHub Desktop.
Save equivalent/9972557 to your computer and use it in GitHub Desktop.
breadcrumbs_on_rails for Bootstrap 3 override
# The BootstrapBreadcrumbsBuilder is a Bootstrap compatible breadcrumb builder.
# It provides basic functionalities to render a breadcrumb navigation according to Bootstrap's conventions.
#
# Originally from https://gist.github.com/riyad/1933884/ modified for Bootstrap 3 and "Go to hell with separator, use Css Dumbass"
# policy
#
# You can use it with the :builder option on render_breadcrumbs:
# <%= render_breadcrumbs :builder => ::BootstrapBreadcrumbsBuilder" %>
#
#
class BootstrapBreadcrumbsBuilder < BreadcrumbsOnRails::Breadcrumbs::Builder
NoBreadcrumbsPassed = Class.new(StandardError)
def render
regular_elements = @elements.dup
active_element = regular_elements.pop || raise(NoBreadcrumbsPassed)
@context.content_tag(:ol, class: 'breadcrumb') do
regular_elements.collect do |element|
render_regular_element(element)
end.join.html_safe + render_active_element(active_element).html_safe
end
end
def render_regular_element(element)
@context.content_tag :li do
@context.link_to(compute_name(element), compute_path(element), element.options)
end
end
def render_active_element(element)
@context.content_tag :li, class: 'active' do
compute_name(element)
end
end
end
@equivalent
Copy link
Author

use for Breadcrumbs on Rails gem https://github.com/weppos/breadcrumbs_on_rails & Bootstrap 3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment