Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Adds breadcrumbs to twitter-bootstrap-rails #136

Merged
merged 3 commits into from

2 participants

@ji
ji commented

Usage.

Add this to Your application_layout.html.erb:

<%= render_breadcrumbs %>
<%= yield %>

Add this to Your controller (i.e. ProductsController):

add_breadcrumb "New Product", "/products/new", only: [:new, :create]

That's it.

@ji
ji commented

Sorry, forgot to push that one before i made the pull request.

@seyhunak seyhunak merged commit cdeb008 into seyhunak:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
5 app/helpers/twitter_breadcrumbs_helper.rb
@@ -0,0 +1,5 @@
+module TwitterBreadcrumbsHelper
+ def render_breadcrumbs(divider = '/')
+ render partial: 'twitter-bootstrap/breadcrumbs', locals: {divider: divider}
+ end
+end
View
14 app/views/twitter-bootstrap/_breadcrumbs.html.erb
@@ -0,0 +1,14 @@
+<ul class="breadcrumb">
+ <% separator = divider %>
+ <% if @breadcrumbs %>
+ <% @breadcrumbs[0..-2].each do |crumb| %>
+ <li>
+ <a href="<%= crumb[:url] %>"><%= crumb[:name] %></a>
+ <span class="divider"><%= separator %></span>
+ </li>
+ <% end %>
+ <li class="active">
+ <a href="<%= @breadcrumbs.last[:url] %>"><%= @breadcrumbs.last[:name] %></a>
+ </li>
+ <% end %>
+</ul>
View
12 lib/twitter/bootstrap/rails/engine.rb
@@ -1,16 +1,22 @@
require 'rails'
+require File.dirname(__FILE__) + '/twitter-bootstrap-breadcrumbs.rb'
module Twitter
module Bootstrap
module Rails
class Engine < ::Rails::Engine
-
+
initializer 'twitter-bootstrap-rails.setup',
:after => 'less-rails.after.load_config_initializers',
:group => :all do |app|
- app.config.less.paths << File.join(config.root, 'vendor', 'toolkit')
- end
+ app.config.less.paths << File.join(config.root, 'vendor', 'toolkit')
+ end
+ initializer 'twitter-bootstrap-rails.setup_helpers' do |app|
+ app.config.to_prepare do
+ ActionController::Base.send(:include, BreadCrumbs)
+ end
+ end
end
end
end
View
25 lib/twitter/bootstrap/rails/twitter-bootstrap-breadcrumbs.rb
@@ -0,0 +1,25 @@
+module Twitter
+ module Bootstrap
+ module BreadCrumbs
+ def self.included(base)
+ base.extend(ClassMethods)
+ end
+
+ module ClassMethods
+ def add_breadcrumb name, url, options={}
+ before_filter options do |controller|
+ controller.send :add_breadcrumb, name, url
+ end
+ end
+ end
+
+ protected
+
+ def add_breadcrumb name, url = ''
+ @breadcrumbs ||= []
+ url = eval(url) if url =~ /_path|_url|@/
+ @breadcrumbs << {name: name, url: url}
+ end
+ end
+ end
+end
Something went wrong with that request. Please try again.