-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
58 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# frozen_string_literal: true | ||
|
||
module BreadCrumbs | ||
def self.included(base) | ||
base.extend(ClassMethods) | ||
end | ||
|
||
module ClassMethods | ||
def add_breadcrumb(name, url, options = {}) | ||
class_name = self.name | ||
before_action options do |controller| | ||
name = controller.send :translate_breadcrumb, name, class_name if name.is_a?(Symbol) | ||
controller.send :add_breadcrumb, name, url | ||
end | ||
end | ||
end | ||
|
||
protected | ||
def add_breadcrumb(name, url = '', options = {}) | ||
@breadcrumbs ||= [] | ||
name = translate_breadcrumb(name, self.class.name) if name.is_a?(Symbol) | ||
url = eval(url.to_s) if url =~ /_path|_url|@/ # rubocop:disable Performance/RegexpMatch | ||
@breadcrumbs << { name: name, url: url, options: options } | ||
end | ||
|
||
def translate_breadcrumb(name, class_name) | ||
scope = [:breadcrumbs] | ||
namespace = class_name.underscore.split('/') | ||
namespace.last.sub!('_controller', '') | ||
scope += namespace | ||
|
||
I18n.t name, scope: scope | ||
end | ||
|
||
def render_breadcrumbs(divider = '/') | ||
s = render partial: 'twitter-bootstrap/breadcrumbs', locals: { divider: divider } | ||
s.first | ||
end | ||
end |