active_breadcrumbs 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.bnsignore +18 -0
- data/.gitignore +30 -0
- data/Gemfile +4 -0
- data/History.txt +89 -0
- data/README.md +148 -0
- data/Rakefile +25 -0
- data/active_breadcrumbs.gemspec +48 -0
- data/lib/active_breadcrumbs/breadcrumbs.rb +133 -0
- data/lib/active_breadcrumbs/breadcrumbs_tester.rb +3 -0
- data/lib/active_breadcrumbs.rb +63 -0
- data/spec/active_breadcrumbs_spec.rb +96 -0
- data/spec/spec_helper.rb +15 -0
- data/test/test_active_breadcrumbs.rb +0 -0
- data/version.txt +1 -0
- metadata +151 -0
data/.bnsignore
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# The list of files that should be ignored by Mr Bones.
|
2
|
+
# Lines that start with '#' are comments.
|
3
|
+
#
|
4
|
+
# A .gitignore file can be used instead by setting it as the ignore
|
5
|
+
# file in your Rakefile:
|
6
|
+
#
|
7
|
+
# Bones {
|
8
|
+
# ignore_file '.gitignore'
|
9
|
+
# }
|
10
|
+
#
|
11
|
+
# For a project with a C extension, the following would be a good set of
|
12
|
+
# exclude patterns (uncomment them if you want to use them):
|
13
|
+
# *.[oa]
|
14
|
+
# *~
|
15
|
+
announcement.txt
|
16
|
+
coverage
|
17
|
+
doc
|
18
|
+
pkg
|
data/.gitignore
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
.bundle
|
2
|
+
Gemfile.lock
|
3
|
+
.DS_Store
|
4
|
+
.project
|
5
|
+
*.log
|
6
|
+
log/*
|
7
|
+
config/database.yml
|
8
|
+
*.db
|
9
|
+
db/*.sqlite3
|
10
|
+
public/system/*
|
11
|
+
*.swp
|
12
|
+
*~
|
13
|
+
tmp/**/*
|
14
|
+
dump
|
15
|
+
tmp/*
|
16
|
+
pkg/*
|
17
|
+
coverage/*
|
18
|
+
spec/coverage/*
|
19
|
+
rails_best_practices_output.html
|
20
|
+
schema.rb
|
21
|
+
solr/data
|
22
|
+
spec/models/coverage
|
23
|
+
spec/controllers/coverage
|
24
|
+
spec/views/coverage
|
25
|
+
.redcar
|
26
|
+
*redcar*
|
27
|
+
vendor/cache
|
28
|
+
vendor/ruby
|
29
|
+
public/data/*.xml
|
30
|
+
solr/pids
|
data/Gemfile
ADDED
data/History.txt
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
== 0.6.0 / 2012-08-06
|
2
|
+
|
3
|
+
* 1 A develop-centric release that includes RSpec tests and support for
|
4
|
+
bundler.
|
5
|
+
|
6
|
+
== 0.5.0 / 2012-03-09
|
7
|
+
|
8
|
+
* 1 The breadcrumbs string that is returned is now html_safe for maximum
|
9
|
+
convenience.
|
10
|
+
|
11
|
+
* 2 Inidividual breadcrumb titles are gracefully truncated to 30
|
12
|
+
characters by default. This limit can be overridden for all
|
13
|
+
breadcrumbs if necessary.
|
14
|
+
|
15
|
+
== 0.4.0 / 2012-02-14
|
16
|
+
|
17
|
+
Some minor enhancements to ensure that the gem functions out-of-the-box with
|
18
|
+
support for graphic separators between the breadcrumbs.
|
19
|
+
|
20
|
+
* 1 Added a "separator" option to the breadcrumbs method.
|
21
|
+
|
22
|
+
breadcrumbs(['Home', root_path, 'Admin', admin_path],
|
23
|
+
:direction => 'left', :separator => '<')
|
24
|
+
|
25
|
+
* 2 Values for the "direction" option can now be symbols.
|
26
|
+
|
27
|
+
breadcrumbs(['Home', root_path, 'Admin', admin_path],
|
28
|
+
:direction => :left)
|
29
|
+
|
30
|
+
== 0.3.0 / 2012-02-07
|
31
|
+
|
32
|
+
The plugin was converted into a gem, verified on Ruby 1.8.7, and updated for
|
33
|
+
Ruby 1.9.x and Rails 3.x.
|
34
|
+
|
35
|
+
* 1 The name of the gem was changed to "active_breadcrumbs" because the
|
36
|
+
name "breadcrumbs" was already taken at Rubygems.org.
|
37
|
+
|
38
|
+
* 2 Added Ruby magic so the breadcrumbs method becomes available in both the
|
39
|
+
ActionView and ActionController Rails modules. The benefit is that
|
40
|
+
the breadcrumbs method can be used in views or controllers without the
|
41
|
+
user having to use any code inclusion mechanism ('requires', etc.).
|
42
|
+
|
43
|
+
* 3 Added better documentation.
|
44
|
+
|
45
|
+
* 4 Put the gem repository on gitHub for public consumption.
|
46
|
+
|
47
|
+
== 0.2.0 / 2009-12-21
|
48
|
+
|
49
|
+
The major change was that the breadcrumbs functionality was organized as a
|
50
|
+
plugin.
|
51
|
+
|
52
|
+
* 1 The format of a breadcrumbs trail changed in this version. A typical
|
53
|
+
example:
|
54
|
+
|
55
|
+
@cookie_trail = breadcrumbs([ 'Home', root_url,
|
56
|
+
'Admin', admin_url,
|
57
|
+
'Presentations', admin_presentations_url],
|
58
|
+
:direction => 'left')
|
59
|
+
|
60
|
+
It would have been nice to use an ordered Hash (key entry order is
|
61
|
+
preserved in Ruby 1.9.x) for the individual breadcrumbs, but a lot of
|
62
|
+
people are still using Rails 3.x with Ruby 1.8.7, which does not have
|
63
|
+
ordered hashes. It's still a simpler format than previously.
|
64
|
+
|
65
|
+
* 2 Easily used in views or controllers.
|
66
|
+
|
67
|
+
* 3 Accompanied by another blog entry (also now slightly outdated)..
|
68
|
+
|
69
|
+
Creating a Breadcrumb Trail in Rails, Part 2
|
70
|
+
http://www.keenertech.com/articles/2009/12/21/creating-a-breadcrumb-trail-in-rails-part-2
|
71
|
+
|
72
|
+
|
73
|
+
== 0.1.0 / 2008-06-18
|
74
|
+
|
75
|
+
* 1 Supported the creation of a very simple breadcrumbs trail. Perfect for a
|
76
|
+
structure-based breadcrumbs trail.
|
77
|
+
|
78
|
+
* 2 Breadcrumbs trails can be specified using the following format:
|
79
|
+
|
80
|
+
<%= show_breadcrumbs( [ 'Home', ['main'],
|
81
|
+
'Tools', ['tools'],
|
82
|
+
'Antimatter', ['tools', 'antimatter']],
|
83
|
+
:direction => 'left') %>
|
84
|
+
|
85
|
+
* 3 Accompanied by a blog entry (now slightly outdated):
|
86
|
+
|
87
|
+
Creating a Breadcrumb Trail in Rails, Part 1
|
88
|
+
http://www.keenertech.com/articles/2008/06/18/creating_a_breadcrumbs_trail1
|
89
|
+
|
data/README.md
ADDED
@@ -0,0 +1,148 @@
|
|
1
|
+
active_breadcrumbs
|
2
|
+
==================
|
3
|
+
|
4
|
+
This gem makes it easy to generate breadcrumb trails in a Rails application.
|
5
|
+
The emphasis is on "structural" breadcrumbs, where a breadcrumb trail reflects
|
6
|
+
the logical structure of a web site (as opposed to a "dynamic" trail, which
|
7
|
+
reflects where the user has been - for which I humbbly suggest the user take
|
8
|
+
advantage of the browser's Back button).
|
9
|
+
|
10
|
+
To generate a breadcrumb trail:
|
11
|
+
|
12
|
+
@trail = breadcrumbs(['Home', root_path, 'Admin', admin_path],
|
13
|
+
:direction => 'right', :separator => '<')
|
14
|
+
|
15
|
+
The first argument is an array in which alternate elements represent the
|
16
|
+
link text of a breadcrumb followed by the URL/path. Options include:
|
17
|
+
|
18
|
+
:direction - Legal values of :left and :right, where :right means that the
|
19
|
+
trails runs to the right, or vice versa for :left. Defaults
|
20
|
+
to :right.
|
21
|
+
|
22
|
+
:separator - The separator to use between breadcrumbs. By default, the
|
23
|
+
separator will be ">" or "<" depending on the direction,
|
24
|
+
but thedefaults can be overridden by this option.
|
25
|
+
|
26
|
+
The breadcrumbs method can be used in both views and controllers. Simply
|
27
|
+
include the active_breadcrumbs gem in your Gemfile, and the breadcrumbs
|
28
|
+
method will be available for both Rails views and controllers.
|
29
|
+
|
30
|
+
Despite its availability in controllers, the breadcrumbs method is most often
|
31
|
+
use in views. Typically, a view will have a snippet of code that stores the
|
32
|
+
breadcrumbs in a variable, such as @trail, which will be referenced in a
|
33
|
+
layout so that the breadcrumbs trail gets displayed.
|
34
|
+
|
35
|
+
The separator can be defined individually for each breadcrumb trail, but this
|
36
|
+
is tedious. The following code overrides the separator in an initializers
|
37
|
+
file (which will be placed in the config/initializers directory of your Rails
|
38
|
+
web site):
|
39
|
+
|
40
|
+
module ActionView
|
41
|
+
|
42
|
+
class Base
|
43
|
+
|
44
|
+
# Overrides the version of this method that is provided by the
|
45
|
+
# active_breadcrumbs gem.
|
46
|
+
|
47
|
+
def breadcrumb_separator_right
|
48
|
+
image_tag('triangle_right.gif')
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
Individual breadcrumb titles are gracefully truncated to 30 characters by
|
56
|
+
default. As with breadcrumb separators, this can be overridden for all
|
57
|
+
breadcrumbs if needed.
|
58
|
+
|
59
|
+
module ActionView
|
60
|
+
|
61
|
+
class Base
|
62
|
+
|
63
|
+
def breadcrumb_size_limit
|
64
|
+
WHATEVER_YOUR_SIZE_LIMIT_IS
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
|
71
|
+
Initial Genesis
|
72
|
+
===============
|
73
|
+
|
74
|
+
This gem has evolved over time. First, it was an application helper, then a
|
75
|
+
library method and eventually a plugin. Now it's a gem, which should hopefully
|
76
|
+
be it's final form. Consequently, a version of this code has been in use for
|
77
|
+
the KeenerTech.com blog site and several other small web sites for the last
|
78
|
+
few years.
|
79
|
+
|
80
|
+
It's genesis was in a couple of blog entries that were written a few years ago
|
81
|
+
by David Keener. Note that the original articles are slightly out-of-date now
|
82
|
+
that Rails 3.0 has come out.
|
83
|
+
|
84
|
+
Creating a Breadcrumb Trail in Rails, Part 1
|
85
|
+
http://www.keenertech.com/articles/2008/06/18/creating_a_breadcrumbs_trail1
|
86
|
+
|
87
|
+
Creating a Breadcrumb Trail in Rails, Part 2
|
88
|
+
http://www.keenertech.com/articles/2009/12/21/creating-a-breadcrumb-trail-in-rails-part-2
|
89
|
+
|
90
|
+
Features
|
91
|
+
--------
|
92
|
+
|
93
|
+
* A simple utility for creating breadcrumb trails as a navigational aid for
|
94
|
+
web sites.
|
95
|
+
|
96
|
+
* Functionality is available in both Rails views and controllers.
|
97
|
+
|
98
|
+
* Easily create breadcrumb trails that run from left-to-right or vice versa.
|
99
|
+
|
100
|
+
* Easily override separator definitions to create customized breadcrumb
|
101
|
+
trails, i.e. - breadcrumb trails with a graphic image as a separator.
|
102
|
+
|
103
|
+
Examples
|
104
|
+
--------
|
105
|
+
|
106
|
+
@trail = breadcrumbs(['Home', root_path, 'Admin', admin_path],
|
107
|
+
:direction => 'right', :separator => '<')
|
108
|
+
|
109
|
+
Requirements
|
110
|
+
------------
|
111
|
+
|
112
|
+
* Requires Rails 3.x.
|
113
|
+
|
114
|
+
Install
|
115
|
+
-------
|
116
|
+
|
117
|
+
* gem install active_breadcrumbs
|
118
|
+
|
119
|
+
Author
|
120
|
+
------
|
121
|
+
|
122
|
+
Original Author: David Keener
|
123
|
+
|
124
|
+
License
|
125
|
+
-------
|
126
|
+
|
127
|
+
The MIT License
|
128
|
+
|
129
|
+
Copyright (c) 2012 David Keener
|
130
|
+
|
131
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
132
|
+
a copy of this software and associated documentation files (the
|
133
|
+
'Software'), to deal in the Software without restriction, including
|
134
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
135
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
136
|
+
permit persons to whom the Software is furnished to do so, subject to
|
137
|
+
the following conditions:
|
138
|
+
|
139
|
+
The above copyright notice and this permission notice shall be
|
140
|
+
included in all copies or substantial portions of the Software.
|
141
|
+
|
142
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
143
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
144
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
145
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
146
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
147
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
148
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
begin
|
2
|
+
require 'bones'
|
3
|
+
rescue LoadError
|
4
|
+
abort '### Please install the "bones" gem ###'
|
5
|
+
end
|
6
|
+
|
7
|
+
task :default => 'test:run'
|
8
|
+
task 'gem:release' => 'test:run'
|
9
|
+
|
10
|
+
Bones {
|
11
|
+
name 'active_breadcrumbs'
|
12
|
+
authors 'David Keener'
|
13
|
+
email 'dkeener@keenertech.com'
|
14
|
+
url 'http://www.keenertech.com'
|
15
|
+
|
16
|
+
# Rails isn't needed for functionality, but the gem adds its
|
17
|
+
# modules to various Rails modules
|
18
|
+
|
19
|
+
depend_on 'rails', '~>3.0'
|
20
|
+
depend_on 'bones', '~>3.8.0', :development => true
|
21
|
+
depend_on 'bones-rspec', '~>2.0.1', :development => true
|
22
|
+
depend_on 'rake', '0.8.7', :development => true
|
23
|
+
depend_on 'rspec', '~> 2.7.0', :development => true
|
24
|
+
}
|
25
|
+
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = "active_breadcrumbs"
|
5
|
+
s.version = "0.6.0"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["David Keener"]
|
9
|
+
s.date = "2012-08-06"
|
10
|
+
s.description = "This gem makes it easy to generate breadcrumb trails in a Rails application.\nThe emphasis is on \"structural\" breadcrumbs, where a breadcrumb trail reflects\nthe logical structure of a web site (as opposed to a \"dynamic\" trail, which\nreflects where the user has been - for which I humbbly suggest the user take\nadvantage of the browser's Back button)."
|
11
|
+
s.email = "dkeener@keenertech.com"
|
12
|
+
s.extra_rdoc_files = ["History.txt"]
|
13
|
+
s.files = [".bnsignore", ".gitignore", "Gemfile", "History.txt", "README.md", "Rakefile", "active_breadcrumbs.gemspec", "lib/active_breadcrumbs.rb", "lib/active_breadcrumbs/breadcrumbs.rb", "lib/active_breadcrumbs/breadcrumbs_tester.rb", "spec/active_breadcrumbs_spec.rb", "spec/spec_helper.rb", "test/test_active_breadcrumbs.rb", "version.txt"]
|
14
|
+
s.homepage = "http://www.keenertech.com"
|
15
|
+
s.rdoc_options = ["--main", "README.md"]
|
16
|
+
s.require_paths = ["lib"]
|
17
|
+
s.rubyforge_project = "active_breadcrumbs"
|
18
|
+
s.rubygems_version = "1.8.16"
|
19
|
+
s.summary = "This gem makes it easy to generate breadcrumb trails in a Rails application."
|
20
|
+
s.test_files = ["test/test_active_breadcrumbs.rb"]
|
21
|
+
|
22
|
+
if s.respond_to? :specification_version then
|
23
|
+
s.specification_version = 3
|
24
|
+
|
25
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
26
|
+
s.add_runtime_dependency(%q<rails>, ["~> 3.0"])
|
27
|
+
s.add_development_dependency(%q<bones>, ["~> 3.8.0"])
|
28
|
+
s.add_development_dependency(%q<bones-rspec>, ["~> 2.0.1"])
|
29
|
+
s.add_development_dependency(%q<rake>, ["= 0.8.7"])
|
30
|
+
s.add_development_dependency(%q<rspec>, ["~> 2.7.0"])
|
31
|
+
s.add_development_dependency(%q<bones>, [">= 3.8.0"])
|
32
|
+
else
|
33
|
+
s.add_dependency(%q<rails>, ["~> 3.0"])
|
34
|
+
s.add_dependency(%q<bones>, ["~> 3.8.0"])
|
35
|
+
s.add_dependency(%q<bones-rspec>, ["~> 2.0.1"])
|
36
|
+
s.add_dependency(%q<rake>, ["= 0.8.7"])
|
37
|
+
s.add_dependency(%q<rspec>, ["~> 2.7.0"])
|
38
|
+
s.add_dependency(%q<bones>, [">= 3.8.0"])
|
39
|
+
end
|
40
|
+
else
|
41
|
+
s.add_dependency(%q<rails>, ["~> 3.0"])
|
42
|
+
s.add_dependency(%q<bones>, ["~> 3.8.0"])
|
43
|
+
s.add_dependency(%q<bones-rspec>, ["~> 2.0.1"])
|
44
|
+
s.add_dependency(%q<rake>, ["= 0.8.7"])
|
45
|
+
s.add_dependency(%q<rspec>, ["~> 2.7.0"])
|
46
|
+
s.add_dependency(%q<bones>, [">= 3.8.0"])
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,133 @@
|
|
1
|
+
module ActiveBreadcrumbs
|
2
|
+
|
3
|
+
module Breadcrumbs
|
4
|
+
require 'CGI'
|
5
|
+
|
6
|
+
BREADCRUMB_SIZE_LIMIT = 30
|
7
|
+
|
8
|
+
def self.included(klass)
|
9
|
+
klass.send(:extend, ClassMethods)
|
10
|
+
klass.send(:include, InstanceMethods)
|
11
|
+
end
|
12
|
+
|
13
|
+
module ClassMethods
|
14
|
+
|
15
|
+
end # ClassMethods
|
16
|
+
|
17
|
+
module InstanceMethods
|
18
|
+
|
19
|
+
# Returns a string containing the HTML necessary to display a breadcrumb
|
20
|
+
# trail. The first arg contains an array of elements, where the first
|
21
|
+
# element is the name of a breadcrumb, the second is the associated path,
|
22
|
+
# and so on in alternating fashion. The final arg is a hash containing
|
23
|
+
# options, where the only option currently defined is "direction". This
|
24
|
+
# can have values of either "left" or "right", and governs which way the
|
25
|
+
# breadcrumbs will be oriented. The default is "right".
|
26
|
+
#
|
27
|
+
# An example of the method's usage in a view is:
|
28
|
+
#
|
29
|
+
# <%= breadcrumbs(
|
30
|
+
# ['Home', 'home_url',
|
31
|
+
# 'Tools', 'tools_url',
|
32
|
+
# 'Antimatter', 'antimatter_url'],
|
33
|
+
# :direction => 'left',
|
34
|
+
# :separator => ">") %>
|
35
|
+
|
36
|
+
def breadcrumbs(crumbs, opts = nil)
|
37
|
+
direction = 'right' # Default direction
|
38
|
+
separator = breadcrumb_separator_right # Default separator
|
39
|
+
if opts != nil
|
40
|
+
dir = opts[:direction].to_s
|
41
|
+
if dir == 'left'
|
42
|
+
direction = dir
|
43
|
+
separator = breadcrumb_separator_left
|
44
|
+
end
|
45
|
+
separator = opts[:separator] if opts[:separator]
|
46
|
+
end
|
47
|
+
|
48
|
+
str = ""
|
49
|
+
if crumbs.size > 0
|
50
|
+
str += '<div id="breadcrumbs">'
|
51
|
+
if direction == 'right'
|
52
|
+
i = 0
|
53
|
+
while i < crumbs.size
|
54
|
+
url = crumbs[i + 1]
|
55
|
+
str += " #{separator} " if i > 0
|
56
|
+
str += build_crumb(crumbs[i], url)
|
57
|
+
i += 2
|
58
|
+
end
|
59
|
+
else # Direction equals left
|
60
|
+
i = crumbs.size - 2
|
61
|
+
while i >= 0
|
62
|
+
url = crumbs[i + 1]
|
63
|
+
str += " #{separator} " if i < (crumbs.size - 2)
|
64
|
+
str += build_crumb(crumbs[i], url)
|
65
|
+
i -= 2
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
str += '</div>'
|
70
|
+
end
|
71
|
+
|
72
|
+
defined?(ActionController::Base) ? str.html_safe : str
|
73
|
+
end
|
74
|
+
|
75
|
+
# Returns TRUE if the provided value is an external URL and FALSE if it
|
76
|
+
# represents the name of a controller. External URL's can be easily
|
77
|
+
# distinguished because they begin with "http".
|
78
|
+
|
79
|
+
def is_external_breadcrumb?(val)
|
80
|
+
val.to_s.start_with?('http')
|
81
|
+
end
|
82
|
+
|
83
|
+
# Returns a string containing the HTML for one breadcrumb link within a
|
84
|
+
# breadcrumb trail. The first argument is the title of the link, while the
|
85
|
+
# second is the destination URL for the link.
|
86
|
+
|
87
|
+
def build_crumb(title, url)
|
88
|
+
str = ""
|
89
|
+
xtitle = CGI::escapeHTML(truncate(title, breadcrumb_size_limit))
|
90
|
+
if is_external_breadcrumb?(url)
|
91
|
+
str += "<a href=\"#{url}\" class=\"bt_external\">#{xtitle}</a>"
|
92
|
+
else
|
93
|
+
str += "<a href='#{url}'>#{xtitle}</a>"
|
94
|
+
end
|
95
|
+
str
|
96
|
+
end
|
97
|
+
|
98
|
+
# Defines the separator used between breadcrumb elements when the
|
99
|
+
# breadcrumbs are traversed from right to left, i.e. - the separator
|
100
|
+
# points to the left.
|
101
|
+
|
102
|
+
def breadcrumb_separator_left
|
103
|
+
"<"
|
104
|
+
end
|
105
|
+
|
106
|
+
# Defines the separator used between breadcrumb elements when the
|
107
|
+
# breadcrumbs are traversed from left to right, i.e. - the separator
|
108
|
+
# points to the right. This is the direction in which most breadcrumb
|
109
|
+
# trails are oriented.
|
110
|
+
|
111
|
+
def breadcrumb_separator_right
|
112
|
+
">"
|
113
|
+
end
|
114
|
+
|
115
|
+
# Returns the maximum allowed size of an individual breadcrumb item,
|
116
|
+
# which is defined by the BREADCRUMB_SIZE_LIMIT constant. This method
|
117
|
+
# can be overridden to increase the size limit for all breadcrumbs.
|
118
|
+
|
119
|
+
def breadcrumb_size_limit
|
120
|
+
BREADCRUMB_SIZE_LIMIT
|
121
|
+
end
|
122
|
+
|
123
|
+
def truncate(str, size)
|
124
|
+
return str if size >= str.size
|
125
|
+
return str[0, size] if str.size <= 3
|
126
|
+
str[0, size -3] + '...'
|
127
|
+
end
|
128
|
+
|
129
|
+
end # InstanceMethods
|
130
|
+
|
131
|
+
end # Module
|
132
|
+
|
133
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
module ActiveBreadcrumbs
|
2
|
+
|
3
|
+
# :stopdoc:
|
4
|
+
LIBPATH = ::File.expand_path('..', __FILE__) + ::File::SEPARATOR
|
5
|
+
PATH = ::File.dirname(LIBPATH) + ::File::SEPARATOR
|
6
|
+
VERSION = ::File.read(PATH + 'version.txt').strip
|
7
|
+
# :startdoc:
|
8
|
+
|
9
|
+
# Returns the library path for the module. If any arguments are given,
|
10
|
+
# they will be joined to the end of the libray path using
|
11
|
+
# <tt>File.join</tt>.
|
12
|
+
#
|
13
|
+
def self.libpath( *args )
|
14
|
+
rv = args.empty? ? LIBPATH : ::File.join(LIBPATH, args.flatten)
|
15
|
+
if block_given?
|
16
|
+
begin
|
17
|
+
$LOAD_PATH.unshift LIBPATH
|
18
|
+
rv = yield
|
19
|
+
ensure
|
20
|
+
$LOAD_PATH.shift
|
21
|
+
end
|
22
|
+
end
|
23
|
+
return rv
|
24
|
+
end
|
25
|
+
|
26
|
+
# Returns the lpath for the module. If any arguments are given,
|
27
|
+
# they will be joined to the end of the path using
|
28
|
+
# <tt>File.join</tt>.
|
29
|
+
#
|
30
|
+
def self.path( *args )
|
31
|
+
rv = args.empty? ? PATH : ::File.join(PATH, args.flatten)
|
32
|
+
if block_given?
|
33
|
+
begin
|
34
|
+
$LOAD_PATH.unshift PATH
|
35
|
+
rv = yield
|
36
|
+
ensure
|
37
|
+
$LOAD_PATH.shift
|
38
|
+
end
|
39
|
+
end
|
40
|
+
return rv
|
41
|
+
end
|
42
|
+
|
43
|
+
# Utility method used to require all files ending in .rb that lie in the
|
44
|
+
# directory below this file that has the same name as the filename passed
|
45
|
+
# in. Optionally, a specific _directory_ name can be passed in such that
|
46
|
+
# the _filename_ does not have to be equivalent to the directory.
|
47
|
+
#
|
48
|
+
def self.require_all_libs_relative_to( fname, dir = nil )
|
49
|
+
dir ||= ::File.basename(fname, '.*')
|
50
|
+
search_me = ::File.expand_path(
|
51
|
+
::File.join(::File.dirname(fname), dir, '**', '*.rb'))
|
52
|
+
|
53
|
+
Dir.glob(search_me).sort.each {|rb| require rb}
|
54
|
+
end
|
55
|
+
|
56
|
+
end # module ActiveBreadcrumbs
|
57
|
+
|
58
|
+
ActiveBreadcrumbs.require_all_libs_relative_to(__FILE__)
|
59
|
+
|
60
|
+
if defined?(ActionController::Base)
|
61
|
+
ActionController::Base.send :include, ActiveBreadcrumbs::Breadcrumbs
|
62
|
+
ActionView::Base.send :include, ActiveBreadcrumbs::Breadcrumbs
|
63
|
+
end
|
@@ -0,0 +1,96 @@
|
|
1
|
+
|
2
|
+
require File.join(File.dirname(__FILE__), %w[spec_helper])
|
3
|
+
|
4
|
+
describe ActiveBreadcrumbs do
|
5
|
+
|
6
|
+
before(:each) do
|
7
|
+
@obj = BreadcrumbsTester.new
|
8
|
+
end
|
9
|
+
|
10
|
+
describe ": Utilities - " do
|
11
|
+
|
12
|
+
it "is_external_breadcrumb? can identify non-local URLs" do
|
13
|
+
@obj.is_external_breadcrumb?('http://www.external.com').should be == true
|
14
|
+
end
|
15
|
+
|
16
|
+
it "is_external_breadcrumb? can identify local URLs" do
|
17
|
+
@obj.is_external_breadcrumb?('internal').should be == false
|
18
|
+
end
|
19
|
+
|
20
|
+
it "breadcrumb_separator_left provides the left separator" do
|
21
|
+
@obj.breadcrumb_separator_left.should be == '<'
|
22
|
+
end
|
23
|
+
|
24
|
+
it "breadcrumb_separator_right provides the rigth separator" do
|
25
|
+
@obj.breadcrumb_separator_right.should be == '>'
|
26
|
+
end
|
27
|
+
|
28
|
+
it "breadcrumb_size_limit provides the currently defined breadcrumb size limit" do
|
29
|
+
@obj.breadcrumb_size_limit.should be == ActiveBreadcrumbs::Breadcrumbs::BREADCRUMB_SIZE_LIMIT
|
30
|
+
end
|
31
|
+
|
32
|
+
it "truncate does not change a string that is smaller than the limit" do
|
33
|
+
@obj.truncate('Zebra', 30).should be == 'Zebra'
|
34
|
+
end
|
35
|
+
|
36
|
+
it "truncate does not change a string that is >= the ellipsis size" do
|
37
|
+
@obj.truncate('Jed', 3).should be == 'Jed'
|
38
|
+
end
|
39
|
+
|
40
|
+
it "truncate does not change a string that is >= the ellipsis size" do
|
41
|
+
@obj.truncate('Supercalifragilisticexpialidocious', 20).should be == 'Supercalifragilis...'
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
describe ": Building Crumbs - " do
|
47
|
+
|
48
|
+
before(:each) do
|
49
|
+
@crumbs = ['Home', 'home_url',
|
50
|
+
'Tools', 'tools_url',
|
51
|
+
'Antimatter', 'antimatter_url']
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should build crumb to a fully specified URL" do
|
55
|
+
crumb = @obj.build_crumb('Test', 'http://www.external.com')
|
56
|
+
crumb.should match 'Test'
|
57
|
+
crumb.should match 'http://www.external.com'
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should build crumb to a relative URL" do
|
61
|
+
crumb = @obj.build_crumb('Test', '/books/123')
|
62
|
+
crumb.should match 'Test'
|
63
|
+
crumb.should match '/books/123'
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should build breadcrumbs from an array" do
|
67
|
+
bc = @obj.breadcrumbs(@crumbs)
|
68
|
+
bc.should match 'Home'
|
69
|
+
bc.should match 'Tools'
|
70
|
+
bc.should match 'Antimatter'
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should build breadcrumbs with a default separator pointing right" do
|
74
|
+
bc = @obj.breadcrumbs(@crumbs)
|
75
|
+
bc.should match '>'
|
76
|
+
end
|
77
|
+
|
78
|
+
it "should build breadcrumbs with a default separator pointing left (and direction as a string)" do
|
79
|
+
bc = @obj.breadcrumbs(@crumbs, :direction => 'left')
|
80
|
+
bc.should match '<'
|
81
|
+
end
|
82
|
+
|
83
|
+
it "should build breadcrumbs with a default separator pointing left (and direction as a symbol)" do
|
84
|
+
bc = @obj.breadcrumbs(@crumbs, :direction => :left)
|
85
|
+
bc.should match '<'
|
86
|
+
end
|
87
|
+
|
88
|
+
it "should build breadcrumbs with a custom separator" do
|
89
|
+
bc = @obj.breadcrumbs(@crumbs, :separator => '|')
|
90
|
+
bc.should match '|'
|
91
|
+
end
|
92
|
+
|
93
|
+
end
|
94
|
+
|
95
|
+
end
|
96
|
+
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
|
2
|
+
require File.expand_path(
|
3
|
+
File.join(File.dirname(__FILE__), %w[.. lib active_breadcrumbs]))
|
4
|
+
|
5
|
+
RSpec.configure do |config|
|
6
|
+
# == Mock Framework
|
7
|
+
#
|
8
|
+
# RSpec uses it's own mocking framework by default. If you prefer to
|
9
|
+
# use mocha, flexmock or RR, uncomment the appropriate line:
|
10
|
+
#
|
11
|
+
# config.mock_with :mocha
|
12
|
+
# config.mock_with :flexmock
|
13
|
+
# config.mock_with :rr
|
14
|
+
end
|
15
|
+
|
File without changes
|
data/version.txt
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.6.0
|
metadata
ADDED
@@ -0,0 +1,151 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: active_breadcrumbs
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.6.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- David Keener
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-08-07 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rails
|
16
|
+
requirement: &11114712 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '3.0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *11114712
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: bones
|
27
|
+
requirement: &11114268 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ~>
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 3.8.0
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *11114268
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: bones-rspec
|
38
|
+
requirement: &11113800 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ~>
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 2.0.1
|
44
|
+
type: :development
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *11113800
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: rake
|
49
|
+
requirement: &11113368 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - =
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.8.7
|
55
|
+
type: :development
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *11113368
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: rspec
|
60
|
+
requirement: &11112852 !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ~>
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: 2.7.0
|
66
|
+
type: :development
|
67
|
+
prerelease: false
|
68
|
+
version_requirements: *11112852
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: bones
|
71
|
+
requirement: &11112456 !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ! '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: 3.8.0
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: *11112456
|
80
|
+
description: ! 'This gem makes it easy to generate breadcrumb trails in a Rails application.
|
81
|
+
|
82
|
+
The emphasis is on "structural" breadcrumbs, where a breadcrumb trail reflects
|
83
|
+
|
84
|
+
the logical structure of a web site (as opposed to a "dynamic" trail, which
|
85
|
+
|
86
|
+
reflects where the user has been - for which I humbbly suggest the user take
|
87
|
+
|
88
|
+
advantage of the browser''s Back button).'
|
89
|
+
email: dkeener@keenertech.com
|
90
|
+
executables: []
|
91
|
+
extensions: []
|
92
|
+
extra_rdoc_files:
|
93
|
+
- !binary |-
|
94
|
+
SGlzdG9yeS50eHQ=
|
95
|
+
files:
|
96
|
+
- !binary |-
|
97
|
+
LmJuc2lnbm9yZQ==
|
98
|
+
- !binary |-
|
99
|
+
LmdpdGlnbm9yZQ==
|
100
|
+
- !binary |-
|
101
|
+
R2VtZmlsZQ==
|
102
|
+
- !binary |-
|
103
|
+
SGlzdG9yeS50eHQ=
|
104
|
+
- !binary |-
|
105
|
+
UkVBRE1FLm1k
|
106
|
+
- !binary |-
|
107
|
+
UmFrZWZpbGU=
|
108
|
+
- !binary |-
|
109
|
+
YWN0aXZlX2JyZWFkY3J1bWJzLmdlbXNwZWM=
|
110
|
+
- !binary |-
|
111
|
+
bGliL2FjdGl2ZV9icmVhZGNydW1icy5yYg==
|
112
|
+
- !binary |-
|
113
|
+
bGliL2FjdGl2ZV9icmVhZGNydW1icy9icmVhZGNydW1icy5yYg==
|
114
|
+
- !binary |-
|
115
|
+
bGliL2FjdGl2ZV9icmVhZGNydW1icy9icmVhZGNydW1ic190ZXN0ZXIucmI=
|
116
|
+
- !binary |-
|
117
|
+
c3BlYy9hY3RpdmVfYnJlYWRjcnVtYnNfc3BlYy5yYg==
|
118
|
+
- !binary |-
|
119
|
+
c3BlYy9zcGVjX2hlbHBlci5yYg==
|
120
|
+
- !binary |-
|
121
|
+
dGVzdC90ZXN0X2FjdGl2ZV9icmVhZGNydW1icy5yYg==
|
122
|
+
- !binary |-
|
123
|
+
dmVyc2lvbi50eHQ=
|
124
|
+
homepage: http://www.keenertech.com
|
125
|
+
licenses: []
|
126
|
+
post_install_message:
|
127
|
+
rdoc_options:
|
128
|
+
- --main
|
129
|
+
- README.md
|
130
|
+
require_paths:
|
131
|
+
- lib
|
132
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
133
|
+
none: false
|
134
|
+
requirements:
|
135
|
+
- - ! '>='
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
version: '0'
|
138
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
139
|
+
none: false
|
140
|
+
requirements:
|
141
|
+
- - ! '>='
|
142
|
+
- !ruby/object:Gem::Version
|
143
|
+
version: '0'
|
144
|
+
requirements: []
|
145
|
+
rubyforge_project: active_breadcrumbs
|
146
|
+
rubygems_version: 1.8.16
|
147
|
+
signing_key:
|
148
|
+
specification_version: 3
|
149
|
+
summary: This gem makes it easy to generate breadcrumb trails in a Rails application.
|
150
|
+
test_files:
|
151
|
+
- test/test_active_breadcrumbs.rb
|