aboutsummaryrefslogtreecommitdiffstats
path: root/lib/bootstrap_breadcrumbs_builder.rb
diff options
context:
space:
mode:
authorLuc Donnet2014-08-19 13:55:32 +0200
committerLuc Donnet2014-08-19 13:55:32 +0200
commit31e20231366bd2716d762720b83e883f46d60ba8 (patch)
tree48296a04ed9578023c52bb116f8e9e59562d1d2f /lib/bootstrap_breadcrumbs_builder.rb
parent6bc916c070f8c11b979ff6a7a1e1d6721475b47e (diff)
downloadchouette-core-31e20231366bd2716d762720b83e883f46d60ba8.tar.bz2
Initialize breadcrumbs for time table, need to be deployed everywhere
Diffstat (limited to 'lib/bootstrap_breadcrumbs_builder.rb')
-rw-r--r--lib/bootstrap_breadcrumbs_builder.rb31
1 files changed, 31 insertions, 0 deletions
diff --git a/lib/bootstrap_breadcrumbs_builder.rb b/lib/bootstrap_breadcrumbs_builder.rb
new file mode 100644
index 000000000..daa154bdf
--- /dev/null
+++ b/lib/bootstrap_breadcrumbs_builder.rb
@@ -0,0 +1,31 @@
+# bootstrap builder for breadcrumbs_on_rails gem
+class BootstrapBreadcrumbsBuilder < BreadcrumbsOnRails::Breadcrumbs::Builder
+ def render
+ @context.content_tag(:ul, class: 'breadcrumb') do
+ @elements.collect do |element|
+ render_element(element)
+ end.join.html_safe
+ end
+ end
+
+ def render_element(element)
+ active = element.path.nil? || @context.current_page?(compute_path(element))
+ # Bootstrap use '/' divider by default but you can customize it:
+ # divider = @context.content_tag(:span, '/'.html_safe, class: 'divider') unless active
+
+ @context.content_tag(:li, :class => ('active' if active)) do
+ content = if element.path.nil?
+ compute_name(element)
+ else
+ @context.link_to_unless_current(compute_name(element), compute_path(element), element.options)
+ end
+
+ # content + (divider || '')
+ content
+ end
+ end
+end
+
+
+# Usage:
+# = render_breadcrumbs(builder: BootstrapBreadcrumbsBuilder) \ No newline at end of file