summaryrefslogtreecommitdiff
path: root/lib/bootstrap_breadcrumbs_builder.rb
diff options
context:
space:
mode:
authorStefan Wintermeyer <stefan.wintermeyer@amooma.de>2013-01-21 20:18:16 +0100
committerStefan Wintermeyer <stefan.wintermeyer@amooma.de>2013-01-22 00:02:50 +0100
commit18ed88c7e3c789366f6e5443dc4ee0bc981a4b88 (patch)
tree847f179022a2c69c1b641fcb2aa474f168877649 /lib/bootstrap_breadcrumbs_builder.rb
parent495bbfdf78206c8adaec057e83900dda6754092c (diff)
Started the migration to Twitter Bootstrap.
Diffstat (limited to 'lib/bootstrap_breadcrumbs_builder.rb')
-rw-r--r--lib/bootstrap_breadcrumbs_builder.rb32
1 files changed, 32 insertions, 0 deletions
diff --git a/lib/bootstrap_breadcrumbs_builder.rb b/lib/bootstrap_breadcrumbs_builder.rb
new file mode 100644
index 0000000..1d6326b
--- /dev/null
+++ b/lib/bootstrap_breadcrumbs_builder.rb
@@ -0,0 +1,32 @@
+# The BootstrapBreadcrumbsBuilder is a Bootstrap compatible breadcrumb builder.
+# It provides basic functionalities to render a breadcrumb navigation according to Bootstrap's conventions.
+#
+# BootstrapBreadcrumbsBuilder accepts a limited set of options:
+# * separator: what should be displayed as a separator between elements
+#
+# You can use it with the :builder option on render_breadcrumbs:
+# <%= render_breadcrumbs :builder => ::BootstrapBreadcrumbsBuilder, :separator => "&raquo;" %>
+#
+# Note: You may need to adjust the autoload_paths in your config/application.rb file for rails to load this class:
+# config.autoload_paths += Dir["#{config.root}/lib/"]
+#
+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)
+ current = @context.current_page?(compute_path(element))
+
+ @context.content_tag(:li, :class => ('active' if current)) do
+ link_or_text = @context.link_to_unless_current(compute_name(element), compute_path(element), element.options)
+ divider = @context.content_tag(:span, (@options[:separator] || '/').html_safe, :class => 'divider') unless current
+
+ link_or_text + (divider || '')
+ end
+ end
+end \ No newline at end of file