Skip to content

Instantly share code, notes, and snippets.

@steveclarke
Last active May 27, 2021 23:30
Show Gist options
  • Select an option

  • Save steveclarke/ef39f3f0fa8f28ca01e28111a3a64880 to your computer and use it in GitHub Desktop.

Select an option

Save steveclarke/ef39f3f0fa8f28ca01e28111a3a64880 to your computer and use it in GitHub Desktop.

Revisions

  1. steveclarke renamed this gist May 27, 2021. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. steveclarke created this gist May 27, 2021.
    41 changes: 41 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,41 @@
    Custom Builder for [Breadcrumbs on Rails](https://github.com/weppos/breadcrumbs_on_rails) with Bootstrap 5:

    ```ruby
    # app/lib/bootstrap_five_breadcrumbs.rb
    class BootstrapFiveBreadcrumbs < BreadcrumbsOnRails::Breadcrumbs::SimpleBuilder
    def render
    return '' if @elements.size == 0

    @options[:outer_tag] ||= :ol
    @options[:tag] ||= :li
    @options[:separator] ||= ""

    @context.content_tag(@options[:outer_tag], class: 'breadcrumb') do
    @elements.collect do |element|
    render_element(element)
    end.join(@options[:separator]).html_safe
    end
    end

    def render_element(element)
    if element.path == nil
    content = compute_name(element)
    else
    content = @context.link_to_unless_current(compute_name(element), compute_path(element), element.options)
    end

    if @elements.last == element
    @context.content_tag(@options[:tag], content, class: "breadcrumb-item active", "aria-current": "page")
    else
    @context.content_tag(@options[:tag], content, class: "breadcrumb-item")
    end
    end
    end
    ```

    ```erb
    # _breadcrumbs.html.erb
    <nav aria-label="breadcrumb">
    <%= render_breadcrumbs builder: ::BootstrapFiveBreadcrumbs %>
    </nav>
    ```