gretel 2.0.0.beta1 → 2.0.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/.travis.yml +3 -1
- data/CHANGELOG.md +2 -1
- data/README.md +107 -47
- data/lib/gretel/crumb.rb +12 -5
- data/lib/gretel/crumbs.rb +6 -6
- data/lib/gretel/version.rb +1 -1
- data/lib/gretel/view_helpers.rb +8 -8
- data/test/dummy/app/helpers/application_helper.rb +3 -0
- data/test/dummy/config/initializers/breadcrumbs.rb +16 -3
- data/test/helper_methods_test.rb +68 -17
- metadata +9 -6
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -12,4 +12,5 @@ Version 2.0
|
|
12
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
13
|
* No longer supports procs for link text or URL as this is unnecessary when you can pass arguments to the block anyway.
|
14
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*).
|
15
|
+
* Breadcrumbs are now rendered with `<%= breadcrumbs %>`, although you can still use the old `<%= breadcrumb %>` (without *s*).
|
16
|
+
* You can now access view helpers from inside `Gretel::Crumbs.layout do .. end`.
|
data/README.md
CHANGED
@@ -12,6 +12,12 @@ In your *Gemfile*:
|
|
12
12
|
gem 'gretel', '2.0.0.beta1'
|
13
13
|
```
|
14
14
|
|
15
|
+
Or, if you want to run the stable version ([see documentation](https://github.com/lassebunk/gretel/tree/v1.2.1)):
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
gem 'gretel', '1.2.1'
|
19
|
+
```
|
20
|
+
|
15
21
|
And run:
|
16
22
|
|
17
23
|
```bash
|
@@ -29,6 +35,89 @@ $ rails generate gretel:install
|
|
29
35
|
|
30
36
|
Then, in *config/initializers/breadcrumbs.rb*:
|
31
37
|
|
38
|
+
```ruby
|
39
|
+
Gretel::Crumbs.layout do
|
40
|
+
# Root crumb
|
41
|
+
crumb :root do
|
42
|
+
link "Home", root_path
|
43
|
+
end
|
44
|
+
|
45
|
+
# Issue list
|
46
|
+
crumb :issues do
|
47
|
+
link "All issues", issues_path
|
48
|
+
end
|
49
|
+
|
50
|
+
# Issue
|
51
|
+
crumb :issue do |issue|
|
52
|
+
link issue.title, issue
|
53
|
+
parent :issues
|
54
|
+
end
|
55
|
+
end
|
56
|
+
```
|
57
|
+
|
58
|
+
At the top of *app/views/issues/show.html.erb*, set the current breadcrumb (assuming you have loaded `@issue` with an issue):
|
59
|
+
|
60
|
+
```erb
|
61
|
+
<% breadcrumb :issue, @issue %>
|
62
|
+
```
|
63
|
+
|
64
|
+
Then, in *app/views/layouts/application.html.erb*:
|
65
|
+
|
66
|
+
```erb
|
67
|
+
<%= breadcrumbs :pretext => "You are here: ",
|
68
|
+
:separator => " › " %>
|
69
|
+
```
|
70
|
+
|
71
|
+
This will generate the following HTML (indented for readability):
|
72
|
+
|
73
|
+
```html
|
74
|
+
<div class="breadcrumbs">
|
75
|
+
You are here:
|
76
|
+
<a href="/">Home</a> ›
|
77
|
+
<a href="/issues">All issues</a> ›
|
78
|
+
<span class="current">My Issue</span>
|
79
|
+
</div>
|
80
|
+
```
|
81
|
+
|
82
|
+
Options
|
83
|
+
-------
|
84
|
+
|
85
|
+
You can pass options to `<%= breadcrumbs %>`, e.g. `<%= breadcrumbs :pretext => "You are here: " %>`:
|
86
|
+
|
87
|
+
Option | Description | Default
|
88
|
+
---------------- | -------------------------------------------------------------------------------------------------------------------------- | -------
|
89
|
+
:pretext | Text to be rendered before breadcrumb, e.g. `"You are here: "` | None
|
90
|
+
:posttext | Text to be appended after breadcrumb, e.g. `"Text after breacrumb"` | None
|
91
|
+
:separator | Separator between links, e.g. `" › "` | `" > "`
|
92
|
+
:autoroot | Whether it should automatically link to the `:root` crumb if no parent is given. | True
|
93
|
+
:show_root_alone | Whether it should show `:root` if that is the only link. | False
|
94
|
+
:link_current | Whether the current crumb should be linked to. | False
|
95
|
+
:semantic | Whether it should generate [semantic breadcrumbs](http://support.google.com/webmasters/bin/answer.py?hl=en&answer=185417). | False
|
96
|
+
:id | ID for the breadcrumbs container. | None
|
97
|
+
:class | CSS class for the breadcrumbs container. | `"breadcrumbs"`
|
98
|
+
:current_class | CSS class for the current link or span. | `"current"`
|
99
|
+
|
100
|
+
Building the breadcrumbs manually
|
101
|
+
---------------------------------
|
102
|
+
|
103
|
+
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:
|
104
|
+
|
105
|
+
```erb
|
106
|
+
<% breadcrumbs do |links| %>
|
107
|
+
<% if links.any? %>
|
108
|
+
You are here:
|
109
|
+
<% links.each do |link| %>
|
110
|
+
<%= link_to link.text, link.url %> (<%= link.key %>)
|
111
|
+
<% end %>
|
112
|
+
<% end %>
|
113
|
+
<% end %>
|
114
|
+
```
|
115
|
+
|
116
|
+
More examples
|
117
|
+
-------------
|
118
|
+
|
119
|
+
In *config/initializers/breadcrumbs.rb*:
|
120
|
+
|
32
121
|
```ruby
|
33
122
|
Gretel::Crumbs.layout do
|
34
123
|
# Root crumb
|
@@ -80,63 +169,34 @@ Gretel::Crumbs.layout do
|
|
80
169
|
link "Test #{a}, #{b}, #{c}", test_path
|
81
170
|
parent :other_test, 3, 4, 5
|
82
171
|
end
|
83
|
-
end
|
84
|
-
```
|
85
|
-
|
86
|
-
At the top of *app/views/issues/show.html.erb*, set the current breadcrumb:
|
87
172
|
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
Then, in *app/views/layouts/application.html.erb*:
|
93
|
-
|
94
|
-
```erb
|
95
|
-
<%= breadcrumbs :pretext => "You are here: ",
|
96
|
-
:separator => " › ",
|
97
|
-
:semantic => true %>
|
98
|
-
```
|
99
|
-
|
100
|
-
This will generate a `<div class="breadcrumbs">` containing the breadcrumbs.
|
101
|
-
|
102
|
-
Building the breadcrumbs manually
|
103
|
-
---------------------------------
|
173
|
+
# Breadcrumb without link URL; will not generate a link
|
174
|
+
crumb :without_link do
|
175
|
+
link "Breadcrumb without link"
|
176
|
+
end
|
104
177
|
|
105
|
-
|
178
|
+
# Breadcrumb using view helper
|
179
|
+
module UsersHelper
|
180
|
+
def user_name_for(user)
|
181
|
+
user.name
|
182
|
+
end
|
183
|
+
end
|
106
184
|
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
<% links.each do |link| %>
|
112
|
-
<%= link_to link.text, link.url %> (<%= link.key %>) %>
|
113
|
-
<% end %>
|
114
|
-
<% end %>
|
115
|
-
<% end %>
|
185
|
+
crumb :user do |user|
|
186
|
+
link user_name_for(user), user
|
187
|
+
end
|
188
|
+
end
|
116
189
|
```
|
117
190
|
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
You can pass options to `<%= breadcrumb %>`, e.g. `<%= breadcrumb :pretext => "You are here:" %>`:
|
191
|
+
Access to view helpers
|
192
|
+
----------------------
|
122
193
|
|
123
|
-
|
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
|
194
|
+
When inside `Gretel::Crumbs.layout do .. end`, you have access to all view helpers of the current view where the breadcrumbs are inserted.
|
135
195
|
|
136
196
|
Documentation
|
137
197
|
-------------
|
138
198
|
|
139
|
-
* [Full documentation](http://rubydoc.info/
|
199
|
+
* [Full documentation](http://rubydoc.info/gems/gretel)
|
140
200
|
* [Changelog](https://github.com/lassebunk/gretel/blob/master/CHANGELOG.md)
|
141
201
|
|
142
202
|
Contributors
|
data/lib/gretel/crumb.rb
CHANGED
@@ -2,15 +2,16 @@ module Gretel
|
|
2
2
|
class Crumb
|
3
3
|
# Initializes a new crumb from the given +key+.
|
4
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)
|
5
|
+
def initialize(context, key, *args)
|
6
6
|
block = Gretel::Crumbs.crumbs[key]
|
7
7
|
raise ArgumentError, "Breadcrumb :#{key} not found." unless block
|
8
8
|
@key = key
|
9
|
+
@context = context
|
9
10
|
instance_exec *args, &block
|
10
11
|
end
|
11
12
|
|
12
13
|
# Sets link of the breadcrumb.
|
13
|
-
def link(text, url)
|
14
|
+
def link(text, url = nil)
|
14
15
|
links << Gretel::Link.new(key, text, url)
|
15
16
|
end
|
16
17
|
|
@@ -28,11 +29,17 @@ module Gretel
|
|
28
29
|
def parent(*args)
|
29
30
|
return @parent unless args.any?
|
30
31
|
key = args.shift
|
31
|
-
|
32
|
-
@parent
|
32
|
+
|
33
|
+
@parent = Gretel::Crumb.new(context, key, *args)
|
33
34
|
end
|
34
35
|
|
35
36
|
# Key of the breadcrumb.
|
36
37
|
attr_reader :key
|
38
|
+
attr_reader :context
|
39
|
+
|
40
|
+
# Proxy to view context
|
41
|
+
def method_missing(method, *args, &block)
|
42
|
+
context.send(method, *args, &block)
|
43
|
+
end
|
37
44
|
end
|
38
|
-
end
|
45
|
+
end
|
data/lib/gretel/crumbs.rb
CHANGED
@@ -4,17 +4,12 @@ module Gretel
|
|
4
4
|
# Lay out the breadcrumbs.
|
5
5
|
#
|
6
6
|
# Example:
|
7
|
-
#
|
8
7
|
# Gretel::Crumbs.layout do
|
9
8
|
# crumb :root do
|
10
9
|
# link "Home", root_path
|
11
10
|
# end
|
12
11
|
# end
|
13
12
|
def layout(&block)
|
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
|
18
13
|
instance_eval &block
|
19
14
|
end
|
20
15
|
|
@@ -27,6 +22,11 @@ module Gretel
|
|
27
22
|
def crumbs
|
28
23
|
@crumbs ||= {}
|
29
24
|
end
|
25
|
+
|
26
|
+
# Returns true if a crumb with the given key has been set.
|
27
|
+
def crumb_defined?(key)
|
28
|
+
crumbs.has_key?(key)
|
29
|
+
end
|
30
30
|
end
|
31
31
|
end
|
32
|
-
end
|
32
|
+
end
|
data/lib/gretel/version.rb
CHANGED
data/lib/gretel/view_helpers.rb
CHANGED
@@ -23,7 +23,7 @@ module Gretel
|
|
23
23
|
# <% if links.any? %>
|
24
24
|
# You are here:
|
25
25
|
# <% links.each do |link| %>
|
26
|
-
# <%= link_to link.text, link.url %> (<%= link.key %>)
|
26
|
+
# <%= link_to link.text, link.url %> (<%= link.key %>)
|
27
27
|
# <% end %>
|
28
28
|
# <% end %>
|
29
29
|
# <% end %>
|
@@ -40,9 +40,9 @@ module Gretel
|
|
40
40
|
# Returns an array of links for the path of the breadcrumb set by +breadcrumb+.
|
41
41
|
def get_breadcrumb_links(options = {})
|
42
42
|
return [] if @_breadcrumb_key.blank?
|
43
|
-
|
43
|
+
|
44
44
|
# Get breadcrumb set by the `breadcrumb` method
|
45
|
-
crumb = Gretel::Crumb.new(@_breadcrumb_key, *@_breadcrumb_args)
|
45
|
+
crumb = Gretel::Crumb.new(self, @_breadcrumb_key, *@_breadcrumb_args)
|
46
46
|
|
47
47
|
# Links of first crumb
|
48
48
|
links = crumb.links.dup
|
@@ -53,8 +53,8 @@ module Gretel
|
|
53
53
|
end
|
54
54
|
|
55
55
|
# Handle autoroot
|
56
|
-
if options[:autoroot] && links.map(&:key).exclude?(:root)
|
57
|
-
links.unshift *Gretel::Crumb.new(:root).links
|
56
|
+
if options[:autoroot] && links.map(&:key).exclude?(:root) && Gretel::Crumbs.crumb_defined?(:root)
|
57
|
+
links.unshift *Gretel::Crumb.new(self, :root).links
|
58
58
|
end
|
59
59
|
|
60
60
|
# Handle show root alone
|
@@ -86,7 +86,7 @@ module Gretel
|
|
86
86
|
content_tag(:div, html, :id => options[:id], :class => options[:class])
|
87
87
|
end
|
88
88
|
|
89
|
-
# Renders HTML for
|
89
|
+
# Renders HTML for a breadcrumb fragment, i.e. a breadcrumb link.
|
90
90
|
def render_breadcrumb_fragment(text, url, semantic, options = {})
|
91
91
|
if semantic
|
92
92
|
if url.present?
|
@@ -110,7 +110,7 @@ module Gretel
|
|
110
110
|
{ :pretext => "",
|
111
111
|
:posttext => "",
|
112
112
|
:separator => " > ",
|
113
|
-
:autoroot =>
|
113
|
+
:autoroot => true,
|
114
114
|
:show_root_alone => false,
|
115
115
|
:link_current => false,
|
116
116
|
:semantic => false,
|
@@ -119,4 +119,4 @@ module Gretel
|
|
119
119
|
:id => nil }
|
120
120
|
end
|
121
121
|
end
|
122
|
-
end
|
122
|
+
end
|
@@ -45,12 +45,12 @@ Gretel::Crumbs.layout do
|
|
45
45
|
link Proc.new { "Name from proc" }, Proc.new { "URL from proc" }
|
46
46
|
end
|
47
47
|
|
48
|
-
crumb :
|
48
|
+
crumb :with_multiple_arguments do |a, b, c|
|
49
49
|
link "#{a} and #{b} and #{c}", contact_path
|
50
|
-
parent :
|
50
|
+
parent :parent_with_multiple_arguments, a * 2, b * 2, c * 2
|
51
51
|
end
|
52
52
|
|
53
|
-
crumb :
|
53
|
+
crumb :parent_with_multiple_arguments do |d, e, f|
|
54
54
|
link "First #{d} then #{e} then #{f}", about_path
|
55
55
|
end
|
56
56
|
|
@@ -61,4 +61,17 @@ Gretel::Crumbs.layout do
|
|
61
61
|
crumb :with_safe_html do
|
62
62
|
link "Test <strong>bold text</strong>".html_safe, about_path
|
63
63
|
end
|
64
|
+
|
65
|
+
crumb :without_link do
|
66
|
+
link "Without link"
|
67
|
+
parent :parent_without_link
|
68
|
+
end
|
69
|
+
|
70
|
+
crumb :parent_without_link do
|
71
|
+
link "Also without link"
|
72
|
+
end
|
73
|
+
|
74
|
+
crumb :using_view_helper do
|
75
|
+
link times_two("Test"), about_path
|
76
|
+
end
|
64
77
|
end
|
data/test/helper_methods_test.rb
CHANGED
@@ -3,10 +3,11 @@ require 'test_helper'
|
|
3
3
|
class HelperMethodsTest < ActionView::TestCase
|
4
4
|
include Gretel::ViewHelpers
|
5
5
|
fixtures :all
|
6
|
+
helper :application
|
6
7
|
|
7
8
|
test "shows basic breadcrumb" do
|
8
9
|
breadcrumb :basic
|
9
|
-
assert_equal %{<div class="breadcrumbs"><span class="current">About</span></div>},
|
10
|
+
assert_equal %{<div class="breadcrumbs"><a href="/">Home</a> > <span class="current">About</span></div>},
|
10
11
|
breadcrumbs
|
11
12
|
end
|
12
13
|
|
@@ -18,31 +19,31 @@ class HelperMethodsTest < ActionView::TestCase
|
|
18
19
|
|
19
20
|
test "shows breadcrumb with parent" do
|
20
21
|
breadcrumb :with_parent
|
21
|
-
assert_equal %{<div class="breadcrumbs"><a href="/about">About</a> > <span class="current">Contact</span></div>},
|
22
|
+
assert_equal %{<div class="breadcrumbs"><a href="/">Home</a> > <a href="/about">About</a> > <span class="current">Contact</span></div>},
|
22
23
|
breadcrumbs
|
23
24
|
end
|
24
25
|
|
25
26
|
test "shows breadcrumb with autopath" do
|
26
27
|
breadcrumb :with_autopath, projects(:one)
|
27
|
-
assert_equal %{<div class="breadcrumbs"><span class="current">Test Project</span></div>},
|
28
|
+
assert_equal %{<div class="breadcrumbs"><a href="/">Home</a> > <span class="current">Test Project</span></div>},
|
28
29
|
breadcrumbs
|
29
30
|
end
|
30
31
|
|
31
32
|
test "shows breadcrumb with parent object" do
|
32
33
|
breadcrumb :with_parent_object, issues(:one)
|
33
|
-
assert_equal %{<div class="breadcrumbs"><a href="/projects/1">Test Project</a> > <span class="current">Test Issue</span></div>},
|
34
|
+
assert_equal %{<div class="breadcrumbs"><a href="/">Home</a> > <a href="/projects/1">Test Project</a> > <span class="current">Test Issue</span></div>},
|
34
35
|
breadcrumbs
|
35
36
|
end
|
36
37
|
|
37
38
|
test "shows multiple links" do
|
38
39
|
breadcrumb :multiple_links
|
39
|
-
assert_equal %{<div class="breadcrumbs"><a href="/about/contact">Contact</a> > <span class="current">Contact form</span></div>},
|
40
|
+
assert_equal %{<div class="breadcrumbs"><a href="/">Home</a> > <a href="/about/contact">Contact</a> > <span class="current">Contact form</span></div>},
|
40
41
|
breadcrumbs
|
41
42
|
end
|
42
43
|
|
43
44
|
test "shows multiple links with parent" do
|
44
45
|
breadcrumb :multiple_links_with_parent
|
45
|
-
assert_equal %{<div class="breadcrumbs"><a href="/about">About</a> > <a href="/about/contact">Contact</a> > <span class="current">Contact form</span></div>},
|
46
|
+
assert_equal %{<div class="breadcrumbs"><a href="/">Home</a> > <a href="/about">About</a> > <a href="/about/contact">Contact</a> > <span class="current">Contact form</span></div>},
|
46
47
|
breadcrumbs
|
47
48
|
end
|
48
49
|
|
@@ -52,6 +53,17 @@ class HelperMethodsTest < ActionView::TestCase
|
|
52
53
|
breadcrumbs(:semantic => true)
|
53
54
|
end
|
54
55
|
|
56
|
+
test "doesn't show root alone" do
|
57
|
+
breadcrumb :root
|
58
|
+
assert_equal "", breadcrumbs
|
59
|
+
end
|
60
|
+
|
61
|
+
test "shows root alone" do
|
62
|
+
breadcrumb :root
|
63
|
+
assert_equal %{<div class="breadcrumbs"><span class="current">Home</span></div>},
|
64
|
+
breadcrumbs(:show_root_alone => true)
|
65
|
+
end
|
66
|
+
|
55
67
|
test "shows no breadcrumb" do
|
56
68
|
assert_equal "", breadcrumbs
|
57
69
|
end
|
@@ -64,20 +76,20 @@ class HelperMethodsTest < ActionView::TestCase
|
|
64
76
|
|
65
77
|
test "shows pretext" do
|
66
78
|
breadcrumb :basic
|
67
|
-
assert_equal %{<div class="breadcrumbs">You are here: <span class="current">About</span></div>},
|
79
|
+
assert_equal %{<div class="breadcrumbs">You are here: <a href="/">Home</a> > <span class="current">About</span></div>},
|
68
80
|
breadcrumbs(:pretext => "You are here: ")
|
69
81
|
end
|
70
82
|
|
71
83
|
test "shows posttext" do
|
72
84
|
breadcrumb :basic
|
73
|
-
assert_equal %{<div class="breadcrumbs"><span class="current">About</span> - text after breadcrumbs</div>},
|
85
|
+
assert_equal %{<div class="breadcrumbs"><a href="/">Home</a> > <span class="current">About</span> - text after breadcrumbs</div>},
|
74
86
|
breadcrumbs(:posttext => " - text after breadcrumbs")
|
75
87
|
end
|
76
88
|
|
77
|
-
test "
|
89
|
+
test "autoroot disabled" do
|
78
90
|
breadcrumb :basic
|
79
|
-
assert_equal %{<div class="breadcrumbs"><
|
80
|
-
breadcrumbs(:autoroot =>
|
91
|
+
assert_equal %{<div class="breadcrumbs"><span class="current">About</span></div>},
|
92
|
+
breadcrumbs(:autoroot => false)
|
81
93
|
end
|
82
94
|
|
83
95
|
test "shows separator" do
|
@@ -88,38 +100,77 @@ class HelperMethodsTest < ActionView::TestCase
|
|
88
100
|
|
89
101
|
test "shows element id" do
|
90
102
|
breadcrumb :basic
|
91
|
-
assert_equal %{<div class="breadcrumbs" id="custom_id"><span class="current">About</span></div>},
|
103
|
+
assert_equal %{<div class="breadcrumbs" id="custom_id"><a href="/">Home</a> > <span class="current">About</span></div>},
|
92
104
|
breadcrumbs(:id => "custom_id")
|
93
105
|
end
|
94
106
|
|
107
|
+
test "shows custom container class" do
|
108
|
+
breadcrumb :basic
|
109
|
+
assert_equal %{<div class="custom_class"><a href="/">Home</a> > <span class="current">About</span></div>},
|
110
|
+
breadcrumbs(:class => "custom_class")
|
111
|
+
end
|
112
|
+
|
113
|
+
test "shows custom current class" do
|
114
|
+
breadcrumb :basic
|
115
|
+
assert_equal %{<div class="breadcrumbs"><a href="/">Home</a> > <span class="custom_current_class">About</span></div>},
|
116
|
+
breadcrumbs(:current_class => "custom_current_class")
|
117
|
+
end
|
118
|
+
|
95
119
|
test "unsafe html" do
|
96
120
|
breadcrumb :with_unsafe_html
|
97
|
-
assert_equal %{<div class="breadcrumbs"><span class="current">Test <strong>bold text</strong></span></div>},
|
121
|
+
assert_equal %{<div class="breadcrumbs"><a href="/">Home</a> > <span class="current">Test <strong>bold text</strong></span></div>},
|
98
122
|
breadcrumbs
|
99
123
|
end
|
100
124
|
|
101
125
|
test "safe html" do
|
102
126
|
breadcrumb :with_safe_html
|
103
|
-
assert_equal %{<div class="breadcrumbs"><span class="current">Test <strong>bold text</strong></span></div>},
|
127
|
+
assert_equal %{<div class="breadcrumbs"><a href="/">Home</a> > <span class="current">Test <strong>bold text</strong></span></div>},
|
104
128
|
breadcrumbs
|
105
129
|
end
|
106
130
|
|
107
131
|
test "works with legacy breadcrumb rendering method" do
|
108
132
|
breadcrumb :basic
|
109
|
-
assert_equal %{<div class="breadcrumbs"><span class="current">About</span></div>},
|
133
|
+
assert_equal %{<div class="breadcrumbs"><a href="/">Home</a> > <span class="current">About</span></div>},
|
110
134
|
breadcrumb
|
111
135
|
end
|
112
136
|
|
113
137
|
test "yields a block containing breadcrumb links array" do
|
114
138
|
breadcrumb :multiple_links_with_parent
|
115
139
|
|
116
|
-
out = nil # Needs to be defined here to be set inside block
|
140
|
+
out = nil # Needs to be defined here to be set inside block and then accessed outside
|
117
141
|
breadcrumbs do |links|
|
118
142
|
out = links.map { |link| [link.key, link.text, link.url] }
|
119
143
|
end
|
120
144
|
|
121
|
-
assert_equal [[:
|
145
|
+
assert_equal [[:root, "Home", "/"],
|
146
|
+
[:basic, "About", "/about"],
|
122
147
|
[:multiple_links_with_parent, "Contact", "/about/contact"],
|
123
148
|
[:multiple_links_with_parent, "Contact form", "/about/contact/form"]], out
|
124
149
|
end
|
150
|
+
|
151
|
+
test "without link" do
|
152
|
+
breadcrumb :without_link
|
153
|
+
assert_equal %{<div class="breadcrumbs"><a href="/">Home</a> > Also without link > <span class="current">Without link</span></div>},
|
154
|
+
breadcrumbs
|
155
|
+
end
|
156
|
+
|
157
|
+
test "view context" do
|
158
|
+
breadcrumb :using_view_helper
|
159
|
+
assert_equal %{<div class="breadcrumbs"><a href="/">Home</a> > <span class="current">TestTest</span></div>},
|
160
|
+
breadcrumbs
|
161
|
+
end
|
162
|
+
|
163
|
+
test "multiple arguments" do
|
164
|
+
breadcrumb :with_multiple_arguments, "One", "Two", "Three"
|
165
|
+
assert_equal %{<div class="breadcrumbs"><a href="/">Home</a> > <a href="/about">First OneOne then TwoTwo then ThreeThree</a> > <span class="current">One and Two and Three</span></div>},
|
166
|
+
breadcrumb
|
167
|
+
end
|
168
|
+
|
169
|
+
test "calling breadcrumbs helper twice" do
|
170
|
+
breadcrumb :with_parent
|
171
|
+
2.times do
|
172
|
+
assert_equal %{<div class="breadcrumbs"><a href="/">Home</a> > <a href="/about">About</a> > <span class="current">Contact</span></div>},
|
173
|
+
breadcrumbs
|
174
|
+
end
|
175
|
+
end
|
125
176
|
end
|
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gretel
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.0
|
5
|
-
prerelease:
|
4
|
+
version: 2.0.0
|
5
|
+
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Lasse Bunk
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-02-
|
12
|
+
date: 2013-02-25 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -125,13 +125,16 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
125
125
|
version: '0'
|
126
126
|
segments:
|
127
127
|
- 0
|
128
|
-
hash: -
|
128
|
+
hash: -3983291336719230651
|
129
129
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
130
130
|
none: false
|
131
131
|
requirements:
|
132
|
-
- - ! '
|
132
|
+
- - ! '>='
|
133
133
|
- !ruby/object:Gem::Version
|
134
|
-
version:
|
134
|
+
version: '0'
|
135
|
+
segments:
|
136
|
+
- 0
|
137
|
+
hash: -3983291336719230651
|
135
138
|
requirements: []
|
136
139
|
rubyforge_project:
|
137
140
|
rubygems_version: 1.8.25
|