bootstrap_breadcrumbs_builder.rb 927 B

12345678910111213141516171819202122232425262728293031323334
  1. class BootstrapBreadcrumbsBuilder < BreadcrumbsOnRails::Breadcrumbs::Builder
  2. def render
  3. if @elements.size > 0
  4. set_context
  5. else
  6. set_element
  7. end
  8. end
  9. def set_context
  10. @context.content_tag(:ol, class: 'breadcrumb') do
  11. @elements.collect do |element|
  12. render_element(element)
  13. end.join.html_safe
  14. end
  15. end
  16. def set_element
  17. @elements.collect do |element|
  18. render_element(element)
  19. end.join(@options[:separator] || ' &raquo;')
  20. end
  21. def render_element(element)
  22. current = @context.current_page?(compute_path(element))
  23. @context.content_tag(:li, class: "breadcrumb-item #{'active' if current}") do
  24. link_or_text = @context.link_to_unless_current(compute_name(element),
  25. compute_path(element),
  26. element.options)
  27. link_or_text
  28. end
  29. end
  30. end