gretel 3.0.0.beta5 → 3.0.0.beta6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +12 -24
- data/lib/gretel.rb +3 -20
- data/lib/gretel/crumbs.rb +2 -5
- data/lib/gretel/renderer.rb +36 -29
- data/lib/gretel/resettable.rb +13 -0
- data/lib/gretel/version.rb +1 -1
- data/lib/gretel/view_helpers.rb +18 -0
- data/test/helper_methods_test.rb +24 -0
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bfc2f52236380030c267c75b1c8aba7e9d8a7b84
|
4
|
+
data.tar.gz: e6f06f5449009b772d4afeb5489f7e6de8c57d7a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 84a25e66d9e93c6e525252668e85bfcd0f7546e1f41807fbe8dcab9a15ea7e08b04ecbdd9a67a6506ba7a29c318d6f290a936dfb4bd8faf4f0a1a1c4f230ddd4
|
7
|
+
data.tar.gz: b661508b6442f2b83966e105a0e7dfc6aa6ca2a77a29d48649cf37e8e50c94cddde3991b430e35956a0e58397509d3b64a1a6b84ec3595a4dd578b29733abbfc
|
data/README.md
CHANGED
@@ -7,8 +7,7 @@ Gretel also supports [semantic breadcrumbs](http://support.google.com/webmasters
|
|
7
7
|
|
8
8
|
Have fun! And please do write, if you (dis)like it – [lassebunk@gmail.com](mailto:lassebunk@gmail.com).
|
9
9
|
|
10
|
-
New in version 3.0
|
11
|
-
---------------------------
|
10
|
+
## New in version 3.0
|
12
11
|
|
13
12
|
* Breadcrumbs can now be rendered in different styles like ul- and ol lists, and for use with the [Twitter Bootstrap](http://getbootstrap.com/) framework. See the `:style` option below for more info.
|
14
13
|
* Defining breadcrumbs using `Gretel::Crumbs.layout do ... end` in an initializer has been removed. See below for details on how to upgrade.
|
@@ -23,8 +22,7 @@ I hope you find these changes as useful as I did – if you have more suggestion
|
|
23
22
|
|
24
23
|
See below for more info or the [changelog](https://github.com/lassebunk/gretel/blob/master/CHANGELOG.md) for less significant changes.
|
25
24
|
|
26
|
-
Installation
|
27
|
-
------------
|
25
|
+
## Installation
|
28
26
|
|
29
27
|
In your *Gemfile*:
|
30
28
|
|
@@ -38,8 +36,7 @@ And run:
|
|
38
36
|
$ bundle install
|
39
37
|
```
|
40
38
|
|
41
|
-
Example
|
42
|
-
-------
|
39
|
+
## Example
|
43
40
|
|
44
41
|
Start by generating breadcrumbs configuration file:
|
45
42
|
|
@@ -91,8 +88,7 @@ This will generate the following HTML (indented for readability):
|
|
91
88
|
</div>
|
92
89
|
```
|
93
90
|
|
94
|
-
Options
|
95
|
-
-------
|
91
|
+
## Options
|
96
92
|
|
97
93
|
You can pass options to `<%= breadcrumbs %>`, e.g. `<%= breadcrumbs pretext: "You are here: " %>`:
|
98
94
|
|
@@ -127,8 +123,7 @@ Or you can build the breadcrumbs manually for full customization; see below.
|
|
127
123
|
|
128
124
|
If you add other widely used styles, please submit a [Pull Request](https://github.com/lassebunk/gretel/pulls) so others can use them too.
|
129
125
|
|
130
|
-
More examples
|
131
|
-
-------------
|
126
|
+
## More examples
|
132
127
|
|
133
128
|
In *config/breadcrumbs.rb*:
|
134
129
|
|
@@ -216,8 +211,7 @@ crumb :user do |user|
|
|
216
211
|
end
|
217
212
|
```
|
218
213
|
|
219
|
-
Building the breadcrumbs manually
|
220
|
-
---------------------------------
|
214
|
+
## Building the breadcrumbs manually
|
221
215
|
|
222
216
|
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:
|
223
217
|
|
@@ -232,8 +226,7 @@ If you supply a block to the `breadcrumbs` method, it will yield an array with t
|
|
232
226
|
<% end %>
|
233
227
|
```
|
234
228
|
|
235
|
-
Getting the parent breadcrumb
|
236
|
-
-----------------------------
|
229
|
+
## Getting the parent breadcrumb
|
237
230
|
|
238
231
|
If you want to add a link to the parent breadcrumb, you can use the `parent_breadcrumb` view helper.
|
239
232
|
By default it returns a link instance that has the properties `#key`, `#text`, and `#url`.
|
@@ -247,8 +240,7 @@ If you supply a block, it will yield the link if it is present:
|
|
247
240
|
<% end %>
|
248
241
|
```
|
249
242
|
|
250
|
-
Nice to know
|
251
|
-
------------
|
243
|
+
## Nice to know
|
252
244
|
|
253
245
|
### Access to view methods
|
254
246
|
|
@@ -273,8 +265,7 @@ You can apply trails to select links by adding a simple JS selector (`js-append-
|
|
273
265
|
Check out the gem [here](https://github.com/lassebunk/gretel-trails).
|
274
266
|
|
275
267
|
|
276
|
-
Upgrading from version 2.0 or below
|
277
|
-
-----------------------------------
|
268
|
+
## Upgrading from version 2.0 or below
|
278
269
|
|
279
270
|
Instead of using the initializer that in Gretel version 2.0 and below required restarting the application after breadcrumb configuration changes, the configuration of the breadcrumbs is now loaded from `config/breadcrumbs.rb` (and `config/breadcrumbs/*.rb` if you want to split your breadcrumbs configuration across multiple files).
|
280
271
|
In the Rails development environment, these files are automatically reloaded when changed.
|
@@ -301,19 +292,16 @@ end
|
|
301
292
|
|
302
293
|
in `config/breadcrumbs.rb`.
|
303
294
|
|
304
|
-
Documentation
|
305
|
-
-------------
|
295
|
+
## Documentation
|
306
296
|
|
307
297
|
* [Full documentation](http://rubydoc.info/gems/gretel)
|
308
298
|
* [Changelog](https://github.com/lassebunk/gretel/blob/master/CHANGELOG.md)
|
309
299
|
|
310
|
-
Versioning
|
311
|
-
----------
|
300
|
+
## Versioning
|
312
301
|
|
313
302
|
Follows [semantic versioning](http://semver.org/).
|
314
303
|
|
315
|
-
Contributors
|
316
|
-
------------
|
304
|
+
## Contributors
|
317
305
|
|
318
306
|
* [See the list of contributors](https://github.com/lassebunk/gretel/graphs/contributors)
|
319
307
|
|
data/lib/gretel.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'gretel/version'
|
2
|
+
require 'gretel/resettable'
|
2
3
|
require 'gretel/crumbs'
|
3
4
|
require 'gretel/crumb'
|
4
5
|
require 'gretel/link'
|
@@ -8,6 +9,8 @@ require 'gretel/deprecated'
|
|
8
9
|
|
9
10
|
module Gretel
|
10
11
|
class << self
|
12
|
+
include Resettable
|
13
|
+
|
11
14
|
# Returns the path from with breadcrumbs are loaded. Default is +config/breadcrumbs.rb+.
|
12
15
|
def breadcrumb_paths
|
13
16
|
@breadcrumb_paths ||= [Rails.root.join("config", "breadcrumbs.rb"), Rails.root.join("config", "breadcrumbs", "**", "*.rb")]
|
@@ -59,27 +62,7 @@ module Gretel
|
|
59
62
|
def configure
|
60
63
|
yield self
|
61
64
|
end
|
62
|
-
|
63
|
-
# Resets all changes made to +Gretel+, +Gretel::Crumbs+, and +Gretel::Trail+. Used for testing.
|
64
|
-
def reset!
|
65
|
-
instance_variables.each { |var| remove_instance_variable var }
|
66
|
-
Crumbs.reset!
|
67
|
-
end
|
68
65
|
end
|
69
66
|
end
|
70
67
|
|
71
|
-
Gretel.configure do |config|
|
72
|
-
# Default style
|
73
|
-
config.register_style :default, { container_tag: :div, separator: " › " }
|
74
|
-
|
75
|
-
# Ordered list
|
76
|
-
config.register_style :ol, { container_tag: :ol, fragment_tag: :li }
|
77
|
-
|
78
|
-
# Unordered list
|
79
|
-
config.register_style :ul, { container_tag: :ul, fragment_tag: :li }
|
80
|
-
|
81
|
-
# Twitter Bootstrap
|
82
|
-
config.register_style :bootstrap, { container_tag: :ol, fragment_tag: :li, class: "breadcrumb", current_class: "active" }
|
83
|
-
end
|
84
|
-
|
85
68
|
ActionView::Base.send :include, Gretel::ViewHelpers
|
data/lib/gretel/crumbs.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
module Gretel
|
2
2
|
module Crumbs
|
3
3
|
class << self
|
4
|
+
include Resettable
|
5
|
+
|
4
6
|
# Stores the supplied block for later use.
|
5
7
|
def crumb(key, &block)
|
6
8
|
crumbs[key] = block
|
@@ -52,11 +54,6 @@ module Gretel
|
|
52
54
|
Dir[*Gretel.breadcrumb_paths]
|
53
55
|
end
|
54
56
|
|
55
|
-
# Resets all changes made to +Gretel::Crumbs+. Used for testing.
|
56
|
-
def reset!
|
57
|
-
instance_variables.each { |var| remove_instance_variable var }
|
58
|
-
end
|
59
|
-
|
60
57
|
private
|
61
58
|
|
62
59
|
def loaded_file_mtimes
|
data/lib/gretel/renderer.rb
CHANGED
@@ -14,6 +14,13 @@ module Gretel
|
|
14
14
|
id: nil
|
15
15
|
}
|
16
16
|
|
17
|
+
DEFAULT_STYLES = {
|
18
|
+
default: { container_tag: :div, separator: " › " },
|
19
|
+
ol: { container_tag: :ol, fragment_tag: :li },
|
20
|
+
ul: { container_tag: :ul, fragment_tag: :li },
|
21
|
+
bootstrap: { container_tag: :ol, fragment_tag: :li, class: "breadcrumb", current_class: "active" }
|
22
|
+
}
|
23
|
+
|
17
24
|
def initialize(context, breadcrumb_key, *breadcrumb_args)
|
18
25
|
@context = context
|
19
26
|
@breadcrumb_key = breadcrumb_key
|
@@ -64,8 +71,8 @@ module Gretel
|
|
64
71
|
end
|
65
72
|
|
66
73
|
# Proxy for +context.link_to+ that can be overridden by plugins.
|
67
|
-
def breadcrumb_link_to(
|
68
|
-
context.link_to(
|
74
|
+
def breadcrumb_link_to(name, url, options = {})
|
75
|
+
context.link_to(name, url, options)
|
69
76
|
end
|
70
77
|
|
71
78
|
private
|
@@ -96,43 +103,41 @@ module Gretel
|
|
96
103
|
out.unshift *Gretel::Crumb.new(context, :root).links
|
97
104
|
end
|
98
105
|
|
106
|
+
# Set current link to actual path
|
107
|
+
if out.any? && request
|
108
|
+
out.last.url = request.fullpath
|
109
|
+
end
|
110
|
+
|
99
111
|
# Handle show root alone
|
100
112
|
if out.size == 1 && !options[:display_single_fragment]
|
101
113
|
out.shift
|
102
114
|
end
|
103
115
|
|
116
|
+
# Set last link to current
|
117
|
+
out.last.try(:current!)
|
118
|
+
|
104
119
|
out
|
105
120
|
end
|
106
121
|
|
107
122
|
# Array of links for the path of the breadcrumb.
|
108
123
|
# Also reloads the breadcrumb configuration if needed.
|
109
124
|
def links
|
110
|
-
@links ||=
|
111
|
-
if
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
# Get parent links
|
127
|
-
links.unshift *parent_links_for(crumb)
|
128
|
-
|
129
|
-
# Set last link to current
|
130
|
-
links.last.try(:current!)
|
131
|
-
|
132
|
-
links
|
133
|
-
else
|
134
|
-
[]
|
135
|
-
end
|
125
|
+
@links ||= if @breadcrumb_key.present?
|
126
|
+
# Reload breadcrumbs configuration if needed
|
127
|
+
Gretel::Crumbs.reload_if_needed
|
128
|
+
|
129
|
+
# Get breadcrumb set by the `breadcrumb` method
|
130
|
+
crumb = Gretel::Crumb.new(context, breadcrumb_key, *breadcrumb_args)
|
131
|
+
|
132
|
+
# Links of first crumb
|
133
|
+
links = crumb.links.dup
|
134
|
+
|
135
|
+
# Get parent links
|
136
|
+
links.unshift *parent_links_for(crumb)
|
137
|
+
|
138
|
+
links
|
139
|
+
else
|
140
|
+
[]
|
136
141
|
end
|
137
142
|
end
|
138
143
|
|
@@ -187,6 +192,8 @@ module Gretel
|
|
187
192
|
end
|
188
193
|
|
189
194
|
class << self
|
195
|
+
include Resettable
|
196
|
+
|
190
197
|
# Registers a style for later use.
|
191
198
|
#
|
192
199
|
# Gretel::Renderer.register_style :ul, { container_tag: :ul, fragment_tag: :li }
|
@@ -196,7 +203,7 @@ module Gretel
|
|
196
203
|
|
197
204
|
# Hash of registered styles.
|
198
205
|
def styles
|
199
|
-
@styles ||=
|
206
|
+
@styles ||= DEFAULT_STYLES
|
200
207
|
end
|
201
208
|
end
|
202
209
|
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Gretel
|
2
|
+
module Resettable
|
3
|
+
# Resets all instance variables and calls +reset!+ on all child modules and
|
4
|
+
# classes. Used for testing.
|
5
|
+
def reset!
|
6
|
+
instance_variables.each { |var| remove_instance_variable var }
|
7
|
+
constants.each do |c|
|
8
|
+
c = const_get(c)
|
9
|
+
c.reset! if c.respond_to?(:reset!)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
data/lib/gretel/version.rb
CHANGED
data/lib/gretel/view_helpers.rb
CHANGED
@@ -11,6 +11,24 @@ module Gretel
|
|
11
11
|
@_gretel_renderer = Gretel::Renderer.new(self, key, *args)
|
12
12
|
end
|
13
13
|
|
14
|
+
# Yields a block where inside the block you have a different breadcrumb than outside.
|
15
|
+
#
|
16
|
+
# <% breadcrumb :about %>
|
17
|
+
#
|
18
|
+
# <%= breadcrumbs # shows the :about breadcrumb %>
|
19
|
+
#
|
20
|
+
# <% with_breadcrumb :product, Product.first do %>
|
21
|
+
# <%= breadcrumbs # shows the :product breadcrumb %>
|
22
|
+
# <% end %>
|
23
|
+
#
|
24
|
+
# <%= breadcrumbs # shows the :about breadcrumb %>
|
25
|
+
def with_breadcrumb(key, *args, &block)
|
26
|
+
original_renderer = @_gretel_renderer
|
27
|
+
@_gretel_renderer = Gretel::Renderer.new(self, key, *args)
|
28
|
+
yield
|
29
|
+
@_gretel_renderer = original_renderer
|
30
|
+
end
|
31
|
+
|
14
32
|
# Renders the breadcrumbs HTML, for example in your layout. See the readme for default options.
|
15
33
|
# <%= breadcrumbs pretext: "You are here: " %>
|
16
34
|
#
|
data/test/helper_methods_test.rb
CHANGED
@@ -214,6 +214,21 @@ class HelperMethodsTest < ActionView::TestCase
|
|
214
214
|
breadcrumbs
|
215
215
|
end
|
216
216
|
|
217
|
+
test "with_breadcrumb" do
|
218
|
+
breadcrumb :basic
|
219
|
+
|
220
|
+
assert_equal %{<div class="breadcrumbs"><a href="/">Home</a> › <span class="current">About</span></div>},
|
221
|
+
breadcrumbs
|
222
|
+
|
223
|
+
with_breadcrumb(:with_parent_object, issues(:one)) do
|
224
|
+
assert_equal %{<div class="breadcrumbs"><a href="/">Home</a> › <a href="/projects/1">Test Project</a> › <span class="current">Test Issue</span></div>},
|
225
|
+
breadcrumbs
|
226
|
+
end
|
227
|
+
|
228
|
+
assert_equal %{<div class="breadcrumbs"><a href="/">Home</a> › <span class="current">About</span></div>},
|
229
|
+
breadcrumbs
|
230
|
+
end
|
231
|
+
|
217
232
|
test "calling breadcrumbs helper twice" do
|
218
233
|
breadcrumb :with_parent
|
219
234
|
2.times do
|
@@ -295,6 +310,15 @@ class HelperMethodsTest < ActionView::TestCase
|
|
295
310
|
end
|
296
311
|
end
|
297
312
|
|
313
|
+
test "register style" do
|
314
|
+
Gretel.register_style :test_style, { container_tag: :one, fragment_tag: :two }
|
315
|
+
|
316
|
+
breadcrumb :basic
|
317
|
+
|
318
|
+
assert_equal %{<one class="breadcrumbs"><two><a href="/">Home</a></two><two class="current">About</two></one>},
|
319
|
+
breadcrumbs(style: :test_style)
|
320
|
+
end
|
321
|
+
|
298
322
|
# Configuration reload
|
299
323
|
|
300
324
|
test "reload configuration when file is changed" do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gretel
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0.0.
|
4
|
+
version: 3.0.0.beta6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lasse Bunk
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-10-
|
11
|
+
date: 2013-10-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -79,6 +79,7 @@ files:
|
|
79
79
|
- lib/gretel/deprecated/show_root_alone.rb
|
80
80
|
- lib/gretel/link.rb
|
81
81
|
- lib/gretel/renderer.rb
|
82
|
+
- lib/gretel/resettable.rb
|
82
83
|
- lib/gretel/version.rb
|
83
84
|
- lib/gretel/view_helpers.rb
|
84
85
|
- test/deprecated_test.rb
|
@@ -144,7 +145,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
144
145
|
version: 1.3.1
|
145
146
|
requirements: []
|
146
147
|
rubyforge_project:
|
147
|
-
rubygems_version: 2.
|
148
|
+
rubygems_version: 2.1.10
|
148
149
|
signing_key:
|
149
150
|
specification_version: 4
|
150
151
|
summary: Flexible Ruby on Rails breadcrumbs plugin.
|