easycrumbs 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +36 -0
- data/VERSION +1 -1
- data/easycrumbs.gemspec +4 -2
- data/test/test_custom_collection.rb +41 -0
- metadata +6 -4
data/README.rdoc
CHANGED
@@ -187,5 +187,41 @@ By default last element will always be render as hyperlink. If you would like to
|
|
187
187
|
breadcrumbs :last_link => true
|
188
188
|
<a href="/actors"/>Actors</a> > <a href="/actors/1/edit">Edit Leonardo Di Caprio</a>
|
189
189
|
|
190
|
+
== Custom collection
|
191
|
+
If you do not like idea that breadcrumbs are recognized using routes.rb file then you can write your own breadcrumbs generator.
|
192
|
+
Create new class inherited from EasyCrumbs::Collection or just monkey patch initialize method from EasyCrumbs::Collection
|
193
|
+
|
194
|
+
Look at example for acts_as_tree gem
|
195
|
+
|
196
|
+
class EasyCrumbs::Collection
|
197
|
+
def initialize(request, options = {})
|
198
|
+
object = options[:object]
|
199
|
+
collection = []
|
200
|
+
path = {:action => 'show', :controller => 'people'}
|
201
|
+
|
202
|
+
while(!object.nil?)
|
203
|
+
collection << Breadcrumb.new(object, options.merge(:path => path.merge(:id => object.id)))
|
204
|
+
object = object.parent
|
205
|
+
end
|
206
|
+
@breadcrumbs = collection.reverse
|
207
|
+
end
|
208
|
+
end
|
209
|
+
|
210
|
+
* you will get request object and options hash from view helper(look at lib/easycrumbs/view_helpers.rb for more details)
|
211
|
+
* you have to set @breadcrumbs as collection of EasyCrumbs::Breadcrumb objects
|
212
|
+
* remember to pass options hash to every EasyCrumbs::Breadcrumb object
|
213
|
+
* path have to be a hash and has to be recognized by rails routing system
|
214
|
+
|
215
|
+
For objects:
|
216
|
+
grandfather = Person.create, :breadcrumb => "Grandfather"
|
217
|
+
father = Person.create :parent => grandfather, :breadcrumb => "Father"
|
218
|
+
son = Person.create :parent => father, :breadcrumb => "Son"
|
219
|
+
The code:
|
220
|
+
breadcrumbs, :last_link => false
|
221
|
+
will generate this:
|
222
|
+
<a href="/people/1">Grandfather</a> > <a href="/people/2">Father</a> > Son
|
223
|
+
|
224
|
+
Look at code at tests for more details
|
225
|
+
|
190
226
|
== Copyright
|
191
227
|
Copyright (c) 2010 Stanisław Kolarzowski. See LICENSE for details.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.1.0
|
data/easycrumbs.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{easycrumbs}
|
8
|
-
s.version = "1.
|
8
|
+
s.version = "1.1.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Stanis\305\202aw Kolarzowski"]
|
12
|
-
s.date = %q{2010-10-
|
12
|
+
s.date = %q{2010-10-31}
|
13
13
|
s.description = %q{Easy breadcrumbs for your website}
|
14
14
|
s.email = %q{stanislaw.kolarzowski@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -31,6 +31,7 @@ Gem::Specification.new do |s|
|
|
31
31
|
"lib/easycrumbs/view_helpers.rb",
|
32
32
|
"test/helper.rb",
|
33
33
|
"test/routes.rb",
|
34
|
+
"test/test_custom_collection.rb",
|
34
35
|
"test/test_easycrumbs.rb"
|
35
36
|
]
|
36
37
|
s.homepage = %q{http://github.com/staszek/easycrumbs}
|
@@ -41,6 +42,7 @@ Gem::Specification.new do |s|
|
|
41
42
|
s.test_files = [
|
42
43
|
"test/helper.rb",
|
43
44
|
"test/routes.rb",
|
45
|
+
"test/test_custom_collection.rb",
|
44
46
|
"test/test_easycrumbs.rb"
|
45
47
|
]
|
46
48
|
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class CustomCollection < EasyCrumbs::Collection
|
4
|
+
def initialize(request, options = {})
|
5
|
+
object = options[:object]
|
6
|
+
collection = []
|
7
|
+
path = {:action => 'show', :controller => 'countries'}
|
8
|
+
|
9
|
+
while(!object.nil?)
|
10
|
+
collection << Breadcrumb.new(object, options.merge(:path => path.merge(:id => object.id)))
|
11
|
+
object = object.parent
|
12
|
+
end
|
13
|
+
@breadcrumbs = collection.reverse
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
class TestCustomCollection < Test::Unit::TestCase
|
18
|
+
context "Custom collection tests" do
|
19
|
+
setup do
|
20
|
+
@usa = Country.create(:breadcrumb => "USA")
|
21
|
+
@usa_son = Country.create(:breadcrumb => "USA son")
|
22
|
+
@usa_grandson = Country.create(:breadcrumb => "USA grandson")
|
23
|
+
|
24
|
+
@usa_grandson.stubs(:parent => @usa_son, :id => 3)
|
25
|
+
@usa_son.stubs(:parent => @usa, :id => 2)
|
26
|
+
@usa.stubs(:parent => nil, :id => 1)
|
27
|
+
end
|
28
|
+
|
29
|
+
context "Collection of breadcrumbs" do
|
30
|
+
should "reurned names be proper" do
|
31
|
+
result = ['USA', "USA son", "USA grandson"]
|
32
|
+
assert_equal(result, CustomCollection.new('request object', {:object => @usa_grandson}).breadcrumbs.map(&:name))
|
33
|
+
end
|
34
|
+
|
35
|
+
should "reurned paths be proper" do
|
36
|
+
result = ['/countries/1', "/countries/2", "/countries/3"]
|
37
|
+
assert_equal(result, CustomCollection.new('request object', {:object => @usa_grandson}).breadcrumbs.map(&:path))
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: easycrumbs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 19
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 1
|
8
|
+
- 1
|
8
9
|
- 0
|
9
|
-
|
10
|
-
version: 1.0.0
|
10
|
+
version: 1.1.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- "Stanis\xC5\x82aw Kolarzowski"
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-10-
|
18
|
+
date: 2010-10-31 00:00:00 +02:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -56,6 +56,7 @@ files:
|
|
56
56
|
- lib/easycrumbs/view_helpers.rb
|
57
57
|
- test/helper.rb
|
58
58
|
- test/routes.rb
|
59
|
+
- test/test_custom_collection.rb
|
59
60
|
- test/test_easycrumbs.rb
|
60
61
|
has_rdoc: true
|
61
62
|
homepage: http://github.com/staszek/easycrumbs
|
@@ -94,4 +95,5 @@ summary: Easy breadcrumbs
|
|
94
95
|
test_files:
|
95
96
|
- test/helper.rb
|
96
97
|
- test/routes.rb
|
98
|
+
- test/test_custom_collection.rb
|
97
99
|
- test/test_easycrumbs.rb
|