Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save leouofa/875ad4535812f7cc28cbb387c5def27d to your computer and use it in GitHub Desktop.
Save leouofa/875ad4535812f7cc28cbb387c5def27d to your computer and use it in GitHub Desktop.
Breadcrumbs on Rails Builder for Semantic UI & Fomantic UI (Updated for Rails 6)
class SemanticBreadcrumbsBuilder < BreadcrumbsOnRails::Breadcrumbs::Builder
def render
@elements[-1].options[:last] = true
@elements.collect do |element|
render_element(element)
end.join(@options[:separator] || separator)
end
def render_element(element)
element.options[:class] ||= 'section'
content = if element.path.nil?
compute_name(element)
else
@context.link_to_unless_current(compute_name(element), compute_path(element), element.options)
end
if element.options.delete(:last)
@context.tag.div(content, class: 'active section')
else
ERB::Util.h(content)
end
end
def separator
@context.tag.div('/', class: 'divider')
end
end
@leouofa
Copy link
Author

leouofa commented Jul 28, 2020

How to use with Rails 6

Put file to lib/builders/semantic_breadcrumbs_builder.rb and edit your app files

# config/application.rb
config.autoload_paths << Rails.root.join('lib/builders')
// app/views/layouts/application.html.slim
.ui.breadcrumb = render_breadcrumbs builder: SemanticBreadcrumbsBuilder

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