Skip to content

Instantly share code, notes, and snippets.

@kugaevsky
Created February 7, 2017 19:26
Show Gist options
  • Save kugaevsky/f5187a8f86c66207c47b32cb9ad9d85c to your computer and use it in GitHub Desktop.
Save kugaevsky/f5187a8f86c66207c47b32cb9ad9d85c to your computer and use it in GitHub Desktop.
Breadcrumbs on Rails Builder for Semantic UI
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'
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 element.options.delete(:last)
@context.content_tag(:div, content, class: 'active section')
else
ERB::Util.h(content)
end
end
def separator
@context.content_tag :div, '/', class: 'divider'
end
end
@kugaevsky
Copy link
Author

How to use

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

# config/application.rb
config.autoload_paths << "#{Rails.root}/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