gretel 1.2.1 → 2.0.0.beta1
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/.gitignore +23 -0
- data/.travis.yml +6 -0
- data/CHANGELOG.md +15 -0
- data/Gemfile +17 -0
- data/Gemfile.lock +98 -0
- data/{MIT-LICENSE → LICENSE.txt} +3 -1
- data/README.md +56 -62
- data/Rakefile +6 -34
- data/gretel.gemspec +22 -0
- data/lib/generators/gretel/templates/initializer.rb +2 -3
- data/lib/gretel/crumb.rb +33 -4
- data/lib/gretel/crumbs.rb +20 -40
- data/lib/gretel/link.rb +4 -4
- data/lib/gretel/version.rb +3 -0
- data/lib/gretel/view_helpers.rb +122 -0
- data/lib/gretel.rb +4 -5
- data/test/dummy/app/mailers/.gitkeep +0 -0
- data/test/dummy/app/models/.gitkeep +0 -0
- data/test/dummy/config/initializers/breadcrumbs.rb +21 -0
- data/test/dummy/config/initializers/session_store.rb +1 -1
- data/test/dummy/config/initializers/wrap_parameters.rb +1 -1
- data/test/dummy/lib/assets/.gitkeep +0 -0
- data/test/dummy/log/.gitkeep +0 -0
- data/test/helper_methods_test.rb +76 -51
- metadata +38 -48
- data/lib/gretel/helper_methods.rb +0 -122
- data/lib/gretel/parent.rb +0 -9
- data/lib/gretel/view_link.rb +0 -13
- data/test/dummy/db/development.sqlite3 +0 -0
- data/test/dummy/db/test.sqlite3 +0 -0
- data/test/dummy/log/development.log +0 -899
- data/test/dummy/log/test.log +0 -9038
- data/test/dummy/tmp/cache/assets/CD0/C10/sprockets%2F54298310314d4114afd54d090ef4eae3 +0 -0
- data/test/dummy/tmp/cache/assets/CD8/370/sprockets%2F357970feca3ac29060c1e3861e2c0953 +0 -0
- data/test/dummy/tmp/cache/assets/D11/910/sprockets%2Fa4743dda75a6c1d923065da98d729f21 +0 -0
- data/test/dummy/tmp/cache/assets/D32/A10/sprockets%2F13fe41fee1fe35b49d145bcc06610705 +0 -0
- data/test/dummy/tmp/cache/assets/D4E/1B0/sprockets%2Ff7cbd26ba1d28d48de824f0e94586655 +0 -0
- data/test/dummy/tmp/cache/assets/D5A/EA0/sprockets%2Fd771ace226fc8215a3572e0aa35bb0d6 +0 -0
- data/test/dummy/tmp/cache/assets/D5F/7E0/sprockets%2F25f5ca97d1c1c044514dd8d2c5cb6d02 +0 -0
- data/test/dummy/tmp/cache/assets/D79/060/sprockets%2Fa2cf91ba98db7115dd35bcd7881934f8 +0 -0
- data/test/dummy/tmp/cache/assets/DDC/400/sprockets%2Fcffd775d018f68ce5dba1ee0d951a994 +0 -0
- data/test/dummy/tmp/cache/assets/E04/890/sprockets%2F2f5173deea6c795b8fdde723bb4b63af +0 -0
data/.gitignore
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
log/*.log
|
19
|
+
test/dummy/db/*.sqlite3
|
20
|
+
test/dummy/log/*.log
|
21
|
+
test/dummy/tmp/
|
22
|
+
test/dummy/.sass-cache
|
23
|
+
.DS_Store
|
data/.travis.yml
ADDED
data/CHANGELOG.md
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
Changelog
|
2
|
+
=========
|
3
|
+
|
4
|
+
Version 2.0
|
5
|
+
-----------
|
6
|
+
|
7
|
+
* Totally rewritten for better structure.
|
8
|
+
* `options[:autoroot]` is now `true` by default which means it will automatically link to the `:root` breadcrumb if no parent is specified.
|
9
|
+
* Now accepts `options[:class]` for specifying the CSS class for the breadcrumbs container. Default: `"breadcrumbs"`.
|
10
|
+
* Now accepts `options[:current_class]` for specifying the CSS class for the current link / span. Default: `"current"`.
|
11
|
+
* `options[:link_last]` was deprecated in a previous version and is now removed. Use `options[:link_current]` instead.
|
12
|
+
* The `link` method in `crumb :xx do ... end` no longer takes HTML options. The method for this is now by building the breadcrumbs manually (see the readme).
|
13
|
+
* No longer supports procs for link text or URL as this is unnecessary when you can pass arguments to the block anyway.
|
14
|
+
* It now accepts multiple arguments for `crumb` and `parent` (see the readme).
|
15
|
+
* Breadcrumbs are now rendered with `<%= breadcrumbs %>`, although you can still use the old `<%= breadcrumb %>` (without *s*).
|
data/Gemfile
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
|
3
|
+
# Declare your gem's dependencies in gretel.gemspec.
|
4
|
+
# Bundler will treat runtime dependencies like base dependencies, and
|
5
|
+
# development dependencies will be added by default to the :development group.
|
6
|
+
gemspec
|
7
|
+
|
8
|
+
# jquery-rails is used by the dummy application
|
9
|
+
gem "jquery-rails"
|
10
|
+
|
11
|
+
# Declare any dependencies that are still in development here instead of in
|
12
|
+
# your gemspec. These might include edge Rails or gems from your path or
|
13
|
+
# Git. Remember to move these dependencies to your gemspec before releasing
|
14
|
+
# your gem to rubygems.org.
|
15
|
+
|
16
|
+
# To use debugger
|
17
|
+
# gem 'debugger'
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
gretel (2.0.0.beta1)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: http://rubygems.org/
|
8
|
+
specs:
|
9
|
+
actionmailer (3.2.11)
|
10
|
+
actionpack (= 3.2.11)
|
11
|
+
mail (~> 2.4.4)
|
12
|
+
actionpack (3.2.11)
|
13
|
+
activemodel (= 3.2.11)
|
14
|
+
activesupport (= 3.2.11)
|
15
|
+
builder (~> 3.0.0)
|
16
|
+
erubis (~> 2.7.0)
|
17
|
+
journey (~> 1.0.4)
|
18
|
+
rack (~> 1.4.0)
|
19
|
+
rack-cache (~> 1.2)
|
20
|
+
rack-test (~> 0.6.1)
|
21
|
+
sprockets (~> 2.2.1)
|
22
|
+
activemodel (3.2.11)
|
23
|
+
activesupport (= 3.2.11)
|
24
|
+
builder (~> 3.0.0)
|
25
|
+
activerecord (3.2.11)
|
26
|
+
activemodel (= 3.2.11)
|
27
|
+
activesupport (= 3.2.11)
|
28
|
+
arel (~> 3.0.2)
|
29
|
+
tzinfo (~> 0.3.29)
|
30
|
+
activeresource (3.2.11)
|
31
|
+
activemodel (= 3.2.11)
|
32
|
+
activesupport (= 3.2.11)
|
33
|
+
activesupport (3.2.11)
|
34
|
+
i18n (~> 0.6)
|
35
|
+
multi_json (~> 1.0)
|
36
|
+
arel (3.0.2)
|
37
|
+
builder (3.0.4)
|
38
|
+
erubis (2.7.0)
|
39
|
+
hike (1.2.1)
|
40
|
+
i18n (0.6.1)
|
41
|
+
journey (1.0.4)
|
42
|
+
jquery-rails (2.2.0)
|
43
|
+
railties (>= 3.0, < 5.0)
|
44
|
+
thor (>= 0.14, < 2.0)
|
45
|
+
json (1.7.6)
|
46
|
+
mail (2.4.4)
|
47
|
+
i18n (>= 0.4.0)
|
48
|
+
mime-types (~> 1.16)
|
49
|
+
treetop (~> 1.4.8)
|
50
|
+
mime-types (1.19)
|
51
|
+
multi_json (1.5.0)
|
52
|
+
polyglot (0.3.3)
|
53
|
+
rack (1.4.4)
|
54
|
+
rack-cache (1.2)
|
55
|
+
rack (>= 0.4)
|
56
|
+
rack-ssl (1.3.2)
|
57
|
+
rack
|
58
|
+
rack-test (0.6.2)
|
59
|
+
rack (>= 1.0)
|
60
|
+
rails (3.2.11)
|
61
|
+
actionmailer (= 3.2.11)
|
62
|
+
actionpack (= 3.2.11)
|
63
|
+
activerecord (= 3.2.11)
|
64
|
+
activeresource (= 3.2.11)
|
65
|
+
activesupport (= 3.2.11)
|
66
|
+
bundler (~> 1.0)
|
67
|
+
railties (= 3.2.11)
|
68
|
+
railties (3.2.11)
|
69
|
+
actionpack (= 3.2.11)
|
70
|
+
activesupport (= 3.2.11)
|
71
|
+
rack-ssl (~> 1.3.2)
|
72
|
+
rake (>= 0.8.7)
|
73
|
+
rdoc (~> 3.4)
|
74
|
+
thor (>= 0.14.6, < 2.0)
|
75
|
+
rake (10.0.3)
|
76
|
+
rdoc (3.12)
|
77
|
+
json (~> 1.4)
|
78
|
+
sprockets (2.2.2)
|
79
|
+
hike (~> 1.2)
|
80
|
+
multi_json (~> 1.0)
|
81
|
+
rack (~> 1.0)
|
82
|
+
tilt (~> 1.1, != 1.3.0)
|
83
|
+
sqlite3 (1.3.7)
|
84
|
+
thor (0.16.0)
|
85
|
+
tilt (1.3.3)
|
86
|
+
treetop (1.4.12)
|
87
|
+
polyglot
|
88
|
+
polyglot (>= 0.3.1)
|
89
|
+
tzinfo (0.3.35)
|
90
|
+
|
91
|
+
PLATFORMS
|
92
|
+
ruby
|
93
|
+
|
94
|
+
DEPENDENCIES
|
95
|
+
gretel!
|
96
|
+
jquery-rails
|
97
|
+
rails (~> 3.2.11)
|
98
|
+
sqlite3
|
data/{MIT-LICENSE → LICENSE.txt}
RENAMED
@@ -1,5 +1,7 @@
|
|
1
1
|
Copyright (c) 2010-2013 Lasse Bunk
|
2
2
|
|
3
|
+
MIT License
|
4
|
+
|
3
5
|
Permission is hereby granted, free of charge, to any person obtaining
|
4
6
|
a copy of this software and associated documentation files (the
|
5
7
|
"Software"), to deal in the Software without restriction, including
|
@@ -17,4 +19,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
17
19
|
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
20
|
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
21
|
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
[](http://travis-ci.org/lassebunk/gretel)
|
2
|
+
|
1
3
|
Gretel is a [Ruby on Rails](http://rubyonrails.org) plugin that makes it easy yet flexible to create breadcrumbs.
|
2
4
|
|
3
5
|
|
@@ -7,11 +9,14 @@ Installation
|
|
7
9
|
In your *Gemfile*:
|
8
10
|
|
9
11
|
```ruby
|
10
|
-
gem 'gretel'
|
12
|
+
gem 'gretel', '2.0.0.beta1'
|
11
13
|
```
|
12
14
|
|
13
|
-
And run
|
15
|
+
And run:
|
14
16
|
|
17
|
+
```bash
|
18
|
+
$ bundle install
|
19
|
+
```
|
15
20
|
|
16
21
|
Example
|
17
22
|
-------
|
@@ -26,36 +31,29 @@ Then, in *config/initializers/breadcrumbs.rb*:
|
|
26
31
|
|
27
32
|
```ruby
|
28
33
|
Gretel::Crumbs.layout do
|
29
|
-
|
30
|
-
# root crumb
|
34
|
+
# Root crumb
|
31
35
|
crumb :root do
|
32
36
|
link "Home", root_path
|
33
37
|
end
|
34
38
|
|
35
|
-
#
|
39
|
+
# Regular crumb
|
36
40
|
crumb :projects do
|
37
|
-
link "Projects", projects_path
|
41
|
+
link "Projects", projects_path
|
38
42
|
end
|
39
43
|
|
40
|
-
#
|
41
|
-
crumb :project do |project|
|
42
|
-
link lambda { |project| "#{project.name} (#{project.id.to_s})" }, project_path(project)
|
43
|
-
parent :projects
|
44
|
-
end
|
45
|
-
|
46
|
-
# parent crumbs
|
44
|
+
# Parent crumbs
|
47
45
|
crumb :project_issues do |project|
|
48
46
|
link "Issues", project_issues_path(project)
|
49
47
|
parent :project, project
|
50
48
|
end
|
51
49
|
|
52
|
-
#
|
50
|
+
# Child
|
53
51
|
crumb :issue do |issue|
|
54
52
|
link issue.name, issue_path(issue)
|
55
53
|
parent :project_issues, issue.project
|
56
54
|
end
|
57
55
|
|
58
|
-
#
|
56
|
+
# Multiple links per crumb (recursive links for parent categories)
|
59
57
|
crumb :category do |category|
|
60
58
|
parents = [category]
|
61
59
|
|
@@ -71,83 +69,79 @@ Gretel::Crumbs.layout do
|
|
71
69
|
parent :categories
|
72
70
|
end
|
73
71
|
|
74
|
-
#
|
72
|
+
# Product crumb with recursive parent categories
|
75
73
|
crumb :product do |product|
|
76
74
|
link product.name, product
|
77
75
|
parent :category, product.category
|
78
76
|
end
|
77
|
+
|
78
|
+
# Multiple arguments
|
79
|
+
crumb :multiple_test do |a, b, c|
|
80
|
+
link "Test #{a}, #{b}, #{c}", test_path
|
81
|
+
parent :other_test, 3, 4, 5
|
82
|
+
end
|
79
83
|
end
|
80
84
|
```
|
81
85
|
|
82
|
-
At the top of *app/views/issues/show.html.erb
|
86
|
+
At the top of *app/views/issues/show.html.erb*, set the current breadcrumb:
|
83
87
|
|
84
88
|
```erb
|
85
89
|
<% breadcrumb :issue, @issue %>
|
86
90
|
```
|
87
91
|
|
88
|
-
|
92
|
+
Then, in *app/views/layouts/application.html.erb*:
|
89
93
|
|
90
94
|
```erb
|
91
|
-
<%=
|
92
|
-
|
93
|
-
|
94
|
-
:autoroot => true,
|
95
|
-
:show_root_alone => true,
|
96
|
-
:link_current => false,
|
97
|
-
:semantic => true,
|
98
|
-
:id => "topcrumbs"
|
99
|
-
%>
|
95
|
+
<%= breadcrumbs :pretext => "You are here: ",
|
96
|
+
:separator => " › ",
|
97
|
+
:semantic => true %>
|
100
98
|
```
|
101
99
|
|
102
|
-
This will generate a `<div>` containing the breadcrumbs.
|
100
|
+
This will generate a `<div class="breadcrumbs">` containing the breadcrumbs.
|
101
|
+
|
102
|
+
Building the breadcrumbs manually
|
103
|
+
---------------------------------
|
103
104
|
|
104
|
-
|
105
|
+
If you supply a block to the `breadcrumbs` method, it will yield an array with the breadcrumb links so you can build the breadcrumbs HTML manually:
|
105
106
|
|
106
107
|
```erb
|
107
|
-
<% breadcrumbs
|
108
|
-
<% if
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
108
|
+
<% breadcrumbs do |links| %>
|
109
|
+
<% if links.any? %>
|
110
|
+
You are here:
|
111
|
+
<% links.each do |link| %>
|
112
|
+
<%= link_to link.text, link.url %> (<%= link.key %>) %>
|
113
|
+
<% end %>
|
113
114
|
<% end %>
|
114
115
|
<% end %>
|
115
116
|
```
|
116
117
|
|
117
|
-
Options
|
118
|
-
|
119
|
-
**:pretext**
|
120
|
-
Text to be rendered before breadcrumb, if any. Default: none
|
121
|
-
|
122
|
-
**:posttext**
|
123
|
-
Text to be appended after breadrcumb, if any: Default: none
|
124
|
-
|
125
|
-
**:separator**
|
126
|
-
Separator between links. Default: `>`
|
127
|
-
|
128
|
-
**:autoroot**
|
129
|
-
Whether it should automatically link to :root if no root parent is given. Default: false
|
118
|
+
Options
|
119
|
+
-------
|
130
120
|
|
131
|
-
|
132
|
-
Whether it should show :root if this is the only link. Default: false
|
121
|
+
You can pass options to `<%= breadcrumb %>`, e.g. `<%= breadcrumb :pretext => "You are here:" %>`:
|
133
122
|
|
134
|
-
|
135
|
-
|
123
|
+
Option | Description | Default
|
124
|
+
---------------- | -------------------------------------------------------------------------------------------------------------------------- | -------
|
125
|
+
:pretext | Text to be rendered before breadcrumb, e.g. `"You are here: "` | None
|
126
|
+
:posttext | Text to be appended after breadcrumb, e.g. `"Text after breacrumb"` | None
|
127
|
+
:separator | Separator between links, e.g. `" › "` | `" > "`
|
128
|
+
:autoroot | Whether it should automatically link to the `:root` crumb if no parent is given. | False
|
129
|
+
:show_root_alone | Whether it should show `:root` if that is the only link. | False
|
130
|
+
:link_current | Whether the current crumb should be linked to. | False
|
131
|
+
:semantic | Whether it should generate [semantic breadcrumbs](http://support.google.com/webmasters/bin/answer.py?hl=en&answer=185417). | False
|
132
|
+
:class | CSS class for the breadcrumbs container. | `"breadcrumbs"`
|
133
|
+
:current_class | CSS class for the current link / span. | `"current"`
|
134
|
+
:id | ID for the `<div class="breadcrumbs">` element. | None
|
136
135
|
|
137
|
-
|
138
|
-
|
139
|
-
Default: false
|
136
|
+
Documentation
|
137
|
+
-------------
|
140
138
|
|
141
|
-
|
142
|
-
|
139
|
+
* [Full documentation](http://rubydoc.info/github/lassebunk/gretel)
|
140
|
+
* [Changelog](https://github.com/lassebunk/gretel/blob/master/CHANGELOG.md)
|
143
141
|
|
144
142
|
Contributors
|
145
143
|
------------
|
146
144
|
|
147
|
-
*
|
148
|
-
* Alan Larkin
|
149
|
-
* David Doan
|
150
|
-
* Carl Johnson
|
151
|
-
* Tom Canham
|
145
|
+
* [See the list of contributors](https://github.com/lassebunk/gretel/graphs/contributors)
|
152
146
|
|
153
147
|
Copyright (c) 2010-2013 [Lasse Bunk](http://lassebunk.dk), released under the MIT license
|
data/Rakefile
CHANGED
@@ -1,38 +1,10 @@
|
|
1
|
-
#!/usr/bin/env rake
|
2
|
-
begin
|
3
|
-
require 'bundler/setup'
|
4
|
-
rescue LoadError
|
5
|
-
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
6
|
-
end
|
7
|
-
begin
|
8
|
-
require 'rdoc/task'
|
9
|
-
rescue LoadError
|
10
|
-
require 'rdoc/rdoc'
|
11
|
-
require 'rake/rdoctask'
|
12
|
-
RDoc::Task = Rake::RDocTask
|
13
|
-
end
|
14
|
-
|
15
|
-
RDoc::Task.new(:rdoc) do |rdoc|
|
16
|
-
rdoc.rdoc_dir = 'rdoc'
|
17
|
-
rdoc.title = 'Gretel'
|
18
|
-
rdoc.options << '--line-numbers'
|
19
|
-
rdoc.rdoc_files.include('README.rdoc')
|
20
|
-
rdoc.rdoc_files.include('lib/**/*.rb')
|
21
|
-
end
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
Bundler::GemHelper.install_tasks
|
27
|
-
|
28
1
|
require 'rake/testtask'
|
2
|
+
require 'bundler/gem_tasks'
|
29
3
|
|
30
|
-
Rake::TestTask.new
|
31
|
-
t.libs <<
|
32
|
-
t.
|
33
|
-
t.
|
34
|
-
t.verbose = false
|
4
|
+
Rake::TestTask.new do |t|
|
5
|
+
t.libs << "test"
|
6
|
+
t.test_files = FileList['test/*_test.rb']
|
7
|
+
t.verbose = true
|
35
8
|
end
|
36
9
|
|
37
|
-
|
38
|
-
task :default => :test
|
10
|
+
task :default => :test
|
data/gretel.gemspec
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'gretel/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "gretel"
|
8
|
+
gem.version = Gretel::VERSION
|
9
|
+
gem.authors = ["Lasse Bunk"]
|
10
|
+
gem.email = ["lassebunk@gmail.com"]
|
11
|
+
gem.description = %q{Gretel is a Ruby on Rails plugin that makes it easy yet flexible to create breadcrumbs.}
|
12
|
+
gem.summary = %q{Flexible Ruby on Rails breadcrumbs plugin.}
|
13
|
+
gem.homepage = "http://github.com/lassebunk/gretel"
|
14
|
+
gem.license = "MIT"
|
15
|
+
|
16
|
+
gem.files = `git ls-files`.split($/)
|
17
|
+
gem.test_files = gem.files.grep(%r{^test/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
|
20
|
+
gem.add_development_dependency "rails", "~> 3.2.11"
|
21
|
+
gem.add_development_dependency "sqlite3"
|
22
|
+
end
|
data/lib/gretel/crumb.rb
CHANGED
@@ -1,9 +1,38 @@
|
|
1
1
|
module Gretel
|
2
2
|
class Crumb
|
3
|
-
|
4
|
-
|
5
|
-
def initialize(
|
6
|
-
|
3
|
+
# Initializes a new crumb from the given +key+.
|
4
|
+
# It finds the breadcrumb created in +Gretel::Crumbs.layout+ and renders the block using the arguments supplied in +args+.
|
5
|
+
def initialize(key, *args)
|
6
|
+
block = Gretel::Crumbs.crumbs[key]
|
7
|
+
raise ArgumentError, "Breadcrumb :#{key} not found." unless block
|
8
|
+
@key = key
|
9
|
+
instance_exec *args, &block
|
7
10
|
end
|
11
|
+
|
12
|
+
# Sets link of the breadcrumb.
|
13
|
+
def link(text, url)
|
14
|
+
links << Gretel::Link.new(key, text, url)
|
15
|
+
end
|
16
|
+
|
17
|
+
# Holds all of the breadcrumb's links as a breadcrumb can have multiple links.
|
18
|
+
def links
|
19
|
+
@links ||= []
|
20
|
+
end
|
21
|
+
|
22
|
+
# Sets or gets the parent breadcrumb.
|
23
|
+
# If you supply a parent key and optional arguments, it will set the parent.
|
24
|
+
# If nothing is supplied, it will return the parent, if this has been set.
|
25
|
+
#
|
26
|
+
# Example:
|
27
|
+
# parent :category, category
|
28
|
+
def parent(*args)
|
29
|
+
return @parent unless args.any?
|
30
|
+
key = args.shift
|
31
|
+
|
32
|
+
@parent ||= Gretel::Crumb.new(key, *args)
|
33
|
+
end
|
34
|
+
|
35
|
+
# Key of the breadcrumb.
|
36
|
+
attr_reader :key
|
8
37
|
end
|
9
38
|
end
|
data/lib/gretel/crumbs.rb
CHANGED
@@ -1,51 +1,31 @@
|
|
1
1
|
module Gretel
|
2
|
-
|
2
|
+
module Crumbs
|
3
3
|
class << self
|
4
|
+
# Lay out the breadcrumbs.
|
5
|
+
#
|
6
|
+
# Example:
|
7
|
+
#
|
8
|
+
# Gretel::Crumbs.layout do
|
9
|
+
# crumb :root do
|
10
|
+
# link "Home", root_path
|
11
|
+
# end
|
12
|
+
# end
|
4
13
|
def layout(&block)
|
5
|
-
# needs to be done here because
|
6
|
-
|
7
|
-
|
14
|
+
# The URL helpers include needs to be done here because
|
15
|
+
# Rails.application isn't set when this file is required
|
16
|
+
# TODO: Can this be done otherwise?
|
17
|
+
Gretel::Crumb.send :include, Rails.application.routes.url_helpers
|
8
18
|
instance_eval &block
|
9
19
|
end
|
10
|
-
|
11
|
-
def all
|
12
|
-
@crumbs ||= {}
|
13
|
-
end
|
14
20
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
def get_crumb(name, object = nil)
|
20
|
-
crumb = all[name]
|
21
|
-
raise ArgumentError, "Breadcrumb :#{name} not found." unless crumb
|
22
|
-
|
23
|
-
@object = object # share the object so we can call it from link() and parent()
|
24
|
-
@parent = nil
|
25
|
-
|
26
|
-
crumb.call(object)
|
27
|
-
Gretel::Crumb.new(@links, @parent)
|
21
|
+
# Stores the supplied block for later use.
|
22
|
+
def crumb(key, &block)
|
23
|
+
crumbs[key] = block
|
28
24
|
end
|
29
|
-
|
30
|
-
def link(*args)
|
31
|
-
options = args.extract_options!
|
32
|
-
text = args[0]
|
33
|
-
url = args[1]
|
34
|
-
|
35
|
-
text = text.call(@object) if text.is_a?(Proc)
|
36
|
-
url = url.call(@object) if url.is_a?(Proc)
|
37
|
-
|
38
|
-
@links ||= []
|
39
|
-
@links << Gretel::Link.new(text, url, options)
|
40
|
-
|
41
|
-
@links
|
42
|
-
end
|
43
|
-
|
44
|
-
def parent(name, object = nil)
|
45
|
-
name = name.call(@object) if name.is_a?(Proc)
|
46
|
-
object = object.call(@object) if object.is_a?(Proc)
|
47
25
|
|
48
|
-
|
26
|
+
# Returns an array of all stored crumb blocks.
|
27
|
+
def crumbs
|
28
|
+
@crumbs ||= {}
|
49
29
|
end
|
50
30
|
end
|
51
31
|
end
|
data/lib/gretel/link.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
module Gretel
|
2
2
|
class Link
|
3
|
-
attr_accessor :
|
4
|
-
|
5
|
-
def initialize(text, url
|
6
|
-
@
|
3
|
+
attr_accessor :key, :text, :url
|
4
|
+
|
5
|
+
def initialize(key, text, url)
|
6
|
+
@key, @text, @url = key, text, url
|
7
7
|
end
|
8
8
|
end
|
9
9
|
end
|