gretel 3.0.2 → 3.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/README.md +40 -7
- data/lib/gretel.rb +11 -2
- data/lib/gretel/crumb.rb +11 -2
- data/lib/gretel/link.rb +24 -3
- data/lib/gretel/renderer.rb +5 -7
- data/lib/gretel/version.rb +1 -1
- data/test/dummy/app/views/breadcrumbs/site.rb +3 -0
- data/test/dummy/config/breadcrumbs/test_crumbs.rb +5 -0
- data/test/gretel_test.rb +1 -1
- data/test/helper_methods_test.rb +38 -1
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8e6f73ad81f2db21b1b45557f25a6f9752874527
|
4
|
+
data.tar.gz: 1fde6352fb2a14d020295b5bf64e56d83b88c54e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 193c5462d11f70efa13f28512deb0268757c6f4367ff27b6d7440beb60a18d3f977fca9a4622eb8ebf2717ff7901be47d54e3a881949b0ba6ba72af8c5cc257a
|
7
|
+
data.tar.gz: 1ad2ee35b362c693da5c579f2a05d268f0dd6e0a45386c456aad3f31a55a380137eafaea60d52e9cf91424f9a8493c53edd816662be2f16b2eb7a4a3eb9820b6
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## Version 3.0.3
|
4
|
+
* Breadcrumbs can now be rendered for use in the [Foundation 5](http://foundation.zurb.com/) framework. Use `breadcrumbs style: :foundation5`.
|
5
|
+
* Breadcrumbs are now automatically loaded from any engines' `config/breadcrumbs.rb` and `config/breadcrumbs/**/*.rb`. See the readme for details.
|
6
|
+
* You can now pass options to links to be used when you render manually. See the readme for details.
|
7
|
+
* Breadcrumb configuration files can now be put in the `app/views/breadcrumbs/` folder. This is an experimental feature that may replace loading breadcrumbs from the `config` folder in the future.
|
8
|
+
|
3
9
|
## Version 3.0.2
|
4
10
|
* Inferring breadcrumbs is now supported on all instances of objects that respond to `model_name`.
|
5
11
|
|
data/README.md
CHANGED
@@ -115,12 +115,13 @@ Option | Description
|
|
115
115
|
|
116
116
|
These are the styles you can use with `breadcrumbs style: :xx`.
|
117
117
|
|
118
|
-
Style
|
119
|
-
|
120
|
-
`:default`
|
121
|
-
`:ol`
|
122
|
-
`:ul`
|
123
|
-
`:bootstrap`
|
118
|
+
Style | Description
|
119
|
+
-------------- | -----------
|
120
|
+
`:default` | Renders each link by itself with `›` as the seperator.
|
121
|
+
`:ol` | Renders the links in `<li>` elements contained in an outer `<ol>`.
|
122
|
+
`:ul` | Renders the links in `<li>` elements contained in an outer `<ul>`.
|
123
|
+
`:bootstrap` | Renders the links for use in [Twitter Bootstrap](http://getbootstrap.com/).
|
124
|
+
`:foundation5` | Renders the links for use in [Foundation 5](http://foundation.zurb.com/).
|
124
125
|
|
125
126
|
Or you can build the breadcrumbs manually for full customization; see below.
|
126
127
|
|
@@ -238,7 +239,7 @@ You can supply options like `autoroot: false` etc.
|
|
238
239
|
If you supply a block, it will yield the link if it is present:
|
239
240
|
|
240
241
|
```erb
|
241
|
-
<% parent_breadcrumb do |
|
242
|
+
<% parent_breadcrumb do |link| %>
|
242
243
|
<%= link_to "Back to #{link.text}", link.url %>
|
243
244
|
<% end %>
|
244
245
|
```
|
@@ -254,6 +255,11 @@ When configuring breadcrumbs inside a `crumb :xx do ... end` block, you have acc
|
|
254
255
|
If you have a large site and you want to split your breadcrumbs configuration over multiple files, you can create a folder named `config/breadcrumbs` and put your configuration files (e.g. `products.rb` or `frontend.rb`) in there.
|
255
256
|
The format is the same as `config/breadcrumbs.rb` which is also loaded.
|
256
257
|
|
258
|
+
### Loading breadcrumbs from engines
|
259
|
+
|
260
|
+
Breadcrumbs are automatically loaded from any engines' `config/breadcrumbs.rb` and `config/breadcrumbs/**/*.rb`.
|
261
|
+
Breadcrumbs defined in your main app will override breadcrumbs from engines.
|
262
|
+
|
257
263
|
### Inferring breadcrumbs
|
258
264
|
|
259
265
|
Breadcrumbs can be automatically inferred if you pass an instance of an object that responds to `model_name` (like an ActiveRecord model instance).
|
@@ -270,6 +276,33 @@ is short for
|
|
270
276
|
<% breadcrumb :product, @product %>
|
271
277
|
```
|
272
278
|
|
279
|
+
### Passing options to links
|
280
|
+
|
281
|
+
You can pass options to links to be used when you render breadcrumbs manually.
|
282
|
+
|
283
|
+
In *config/breadcrumbs.rb*:
|
284
|
+
|
285
|
+
```ruby
|
286
|
+
crumb :something do
|
287
|
+
link "My Link", my_path, title: "My Title", other: "My Other Option"
|
288
|
+
end
|
289
|
+
```
|
290
|
+
|
291
|
+
Example methods you can then use in the view:
|
292
|
+
|
293
|
+
```ruby
|
294
|
+
breadcrumbs do |links|
|
295
|
+
links.each do |link|
|
296
|
+
link.title? # => true
|
297
|
+
link.title # => "My Title"
|
298
|
+
link.other? # => true
|
299
|
+
link.other # => "My Other Option"
|
300
|
+
link.nonexisting_option? # => false
|
301
|
+
link.nonexisting_option # => nil
|
302
|
+
end
|
303
|
+
end
|
304
|
+
```
|
305
|
+
|
273
306
|
### Automatic reloading of breadcrumb configuration files
|
274
307
|
|
275
308
|
Since Gretel version 2.1.0, the breadcrumb configuration files are now reloaded in the Rails development environment if they change. In other environments, like production, the files are loaded once, when first needed.
|
data/lib/gretel.rb
CHANGED
@@ -11,9 +11,18 @@ module Gretel
|
|
11
11
|
class << self
|
12
12
|
include Resettable
|
13
13
|
|
14
|
-
# Returns the path from with breadcrumbs are loaded. Default is +config/breadcrumbs.rb
|
14
|
+
# Returns the path from with breadcrumbs are loaded. Default is +config/breadcrumbs.rb+
|
15
|
+
# in the app and all loaded engines. Breadcrumbs set in the app will override
|
16
|
+
# breadcrumbs set in engines.
|
15
17
|
def breadcrumb_paths
|
16
|
-
@breadcrumb_paths ||=
|
18
|
+
@breadcrumb_paths ||= begin
|
19
|
+
engine_roots = Rails::Application::Railties.engines.map { |e| e.config.root }
|
20
|
+
|
21
|
+
[Rails.root.join("app", "views", "breadcrumbs", "**", "*.rb")] +
|
22
|
+
[*engine_roots, Rails.root].map do |root|
|
23
|
+
[root.join("config", "breadcrumbs.rb"), root.join("config", "breadcrumbs", "**", "*.rb")]
|
24
|
+
end.flatten
|
25
|
+
end
|
17
26
|
end
|
18
27
|
|
19
28
|
# Sets the path from with breadcrumbs are loaded. Default is +config/breadcrumbs.rb+.
|
data/lib/gretel/crumb.rb
CHANGED
@@ -11,11 +11,20 @@ module Gretel
|
|
11
11
|
end
|
12
12
|
|
13
13
|
# Sets link of the breadcrumb.
|
14
|
-
|
14
|
+
# You can supply an optional options hash that will be available on the links
|
15
|
+
# so you can pass info when rendering the breadcrumbs manually.
|
16
|
+
#
|
17
|
+
# link "My Link", my_link_path
|
18
|
+
# link "Without URL"
|
19
|
+
# link "With Options", my_path, title: "Test", other: "Some other value"
|
20
|
+
def link(*args)
|
21
|
+
options = args.extract_options!
|
22
|
+
text, url = args
|
23
|
+
|
15
24
|
# Transform objects to real paths.
|
16
25
|
url = url_for(url) if url
|
17
26
|
|
18
|
-
links << Gretel::Link.new(key, text, url)
|
27
|
+
links << Gretel::Link.new(key, text, url, options)
|
19
28
|
end
|
20
29
|
|
21
30
|
# Holds all of the breadcrumb's links as a breadcrumb can have multiple links.
|
data/lib/gretel/link.rb
CHANGED
@@ -1,18 +1,39 @@
|
|
1
1
|
module Gretel
|
2
2
|
class Link
|
3
|
-
attr_accessor :key, :text, :url
|
3
|
+
attr_accessor :key, :text, :url, :options
|
4
4
|
|
5
|
-
def initialize(key, text, url)
|
5
|
+
def initialize(key, text, url, options = {})
|
6
6
|
# Use accessors so plugins can override their behavior
|
7
|
-
self.key, self.text, self.url = key, text, url
|
7
|
+
self.key, self.text, self.url, self.options = key, text, url, options
|
8
8
|
end
|
9
9
|
|
10
|
+
# Sets current so +current?+ will return +true+.
|
10
11
|
def current!
|
11
12
|
@current = true
|
12
13
|
end
|
13
14
|
|
15
|
+
# Returns +true+ if this is the last link in the breadcrumb trail.
|
14
16
|
def current?
|
15
17
|
!!@current
|
16
18
|
end
|
19
|
+
|
20
|
+
# Enables accessors and predicate methods for values in the +options+ hash.
|
21
|
+
# This can be used to pass information to links when rendering breadcrumbs
|
22
|
+
# manually.
|
23
|
+
#
|
24
|
+
# link = Link.new(:my_crumb, "My Crumb", my_path, title: "Test Title", other_value: "Other")
|
25
|
+
# link.title? # => true
|
26
|
+
# link.title # => "Test Title"
|
27
|
+
# link.other_value? # => true
|
28
|
+
# link.other_value # => "Other"
|
29
|
+
# link.some_other? # => false
|
30
|
+
# link.some_other # => nil
|
31
|
+
def method_missing(method, *args, &block)
|
32
|
+
if method =~ /(.+)\?$/
|
33
|
+
options[$1.to_sym].present?
|
34
|
+
else
|
35
|
+
options[method]
|
36
|
+
end
|
37
|
+
end
|
17
38
|
end
|
18
39
|
end
|
data/lib/gretel/renderer.rb
CHANGED
@@ -18,7 +18,8 @@ module Gretel
|
|
18
18
|
default: { container_tag: :div, separator: " › " },
|
19
19
|
ol: { container_tag: :ol, fragment_tag: :li },
|
20
20
|
ul: { container_tag: :ul, fragment_tag: :li },
|
21
|
-
bootstrap: { container_tag: :ol, fragment_tag: :li, class: "breadcrumb", current_class: "active" }
|
21
|
+
bootstrap: { container_tag: :ol, fragment_tag: :li, class: "breadcrumb", current_class: "active" },
|
22
|
+
foundation5: { container_tag: :ul, fragment_tag: :li, class: "breadcrumb", current_class: "current" }
|
22
23
|
}
|
23
24
|
|
24
25
|
def initialize(context, breadcrumb_key, *breadcrumb_args)
|
@@ -34,12 +35,9 @@ module Gretel
|
|
34
35
|
|
35
36
|
return "" if links.empty?
|
36
37
|
|
37
|
-
# Array to hold the HTML fragments
|
38
|
-
fragments = []
|
39
|
-
|
40
38
|
# Loop through all but the last (current) link and build HTML of the fragments
|
41
|
-
links[0..-2].
|
42
|
-
|
39
|
+
fragments = links[0..-2].map do |link|
|
40
|
+
render_fragment(options[:fragment_tag], link.text, link.url, options[:semantic])
|
43
41
|
end
|
44
42
|
|
45
43
|
# The current link is handled a little differently, and is only linked if specified in the options
|
@@ -207,4 +205,4 @@ module Gretel
|
|
207
205
|
end
|
208
206
|
end
|
209
207
|
end
|
210
|
-
end
|
208
|
+
end
|
data/lib/gretel/version.rb
CHANGED
data/test/gretel_test.rb
CHANGED
@@ -7,7 +7,7 @@ class GretelTest < ActiveSupport::TestCase
|
|
7
7
|
|
8
8
|
test "defaults" do
|
9
9
|
assert_equal [Rails.root.join("config", "breadcrumbs.rb"), Rails.root.join("config", "breadcrumbs", "**", "*.rb")],
|
10
|
-
Gretel.breadcrumb_paths
|
10
|
+
Gretel.breadcrumb_paths[-2..-1]
|
11
11
|
assert_equal ["development"], Gretel.reload_environments
|
12
12
|
assert !Gretel.suppress_deprecation_warnings?
|
13
13
|
end
|
data/test/helper_methods_test.rb
CHANGED
@@ -196,6 +196,31 @@ class HelperMethodsTest < ActionView::TestCase
|
|
196
196
|
assert_equal [false, false, false, true], out
|
197
197
|
end
|
198
198
|
|
199
|
+
test "passing options to links" do
|
200
|
+
breadcrumb :with_link_options
|
201
|
+
|
202
|
+
breadcrumbs(autoroot: false) do |links|
|
203
|
+
links[0].tap do |link|
|
204
|
+
assert link.title?
|
205
|
+
assert_equal "My Title", link.title
|
206
|
+
|
207
|
+
assert link.other?
|
208
|
+
assert_equal "Other Option", link.other
|
209
|
+
|
210
|
+
assert !link.nonexistent?
|
211
|
+
assert_nil link.nonexistent
|
212
|
+
end
|
213
|
+
|
214
|
+
links[1].tap do |link|
|
215
|
+
assert link.some_option?
|
216
|
+
assert_equal "Test", link.some_option
|
217
|
+
end
|
218
|
+
end
|
219
|
+
|
220
|
+
assert_equal %{<div class="breadcrumbs"><a href="/about">Test</a> › <span class="current">Other Link</span></div>},
|
221
|
+
breadcrumbs(autoroot: false)
|
222
|
+
end
|
223
|
+
|
199
224
|
test "without link" do
|
200
225
|
breadcrumb :without_link
|
201
226
|
assert_equal %{<div class="breadcrumbs"><a href="/">Home</a> › Also without link › <span class="current">Without link</span></div>},
|
@@ -214,6 +239,12 @@ class HelperMethodsTest < ActionView::TestCase
|
|
214
239
|
breadcrumbs
|
215
240
|
end
|
216
241
|
|
242
|
+
test "from views folder" do
|
243
|
+
breadcrumb :from_views
|
244
|
+
assert_equal %{<div class="breadcrumbs"><a href="/">Home</a> › <span class="current">Breadcrumb From View</span></div>},
|
245
|
+
breadcrumbs
|
246
|
+
end
|
247
|
+
|
217
248
|
test "with_breadcrumb" do
|
218
249
|
breadcrumb :basic
|
219
250
|
|
@@ -297,6 +328,12 @@ class HelperMethodsTest < ActionView::TestCase
|
|
297
328
|
breadcrumbs(style: :bootstrap)
|
298
329
|
end
|
299
330
|
|
331
|
+
test "foundation5 style" do
|
332
|
+
breadcrumb :basic
|
333
|
+
assert_equal %{<ul class="breadcrumb"><li><a href="/">Home</a></li><li class="current">About</li></ul>},
|
334
|
+
breadcrumbs(style: :foundation5)
|
335
|
+
end
|
336
|
+
|
300
337
|
test "custom container and fragment tags" do
|
301
338
|
breadcrumb :basic
|
302
339
|
assert_equal %{<c class="breadcrumbs"><f><a href="/">Home</a></f> › <f class="current">About</f></c>},
|
@@ -476,4 +513,4 @@ private
|
|
476
513
|
|
477
514
|
path
|
478
515
|
end
|
479
|
-
end
|
516
|
+
end
|
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.
|
4
|
+
version: 3.0.3
|
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-
|
11
|
+
date: 2013-12-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -92,6 +92,7 @@ files:
|
|
92
92
|
- test/dummy/app/models/.gitkeep
|
93
93
|
- test/dummy/app/models/issue.rb
|
94
94
|
- test/dummy/app/models/project.rb
|
95
|
+
- test/dummy/app/views/breadcrumbs/site.rb
|
95
96
|
- test/dummy/config.ru
|
96
97
|
- test/dummy/config/application.rb
|
97
98
|
- test/dummy/config/boot.rb
|
@@ -145,7 +146,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
145
146
|
version: '0'
|
146
147
|
requirements: []
|
147
148
|
rubyforge_project:
|
148
|
-
rubygems_version: 2.
|
149
|
+
rubygems_version: 2.0.3
|
149
150
|
signing_key:
|
150
151
|
specification_version: 4
|
151
152
|
summary: Flexible Ruby on Rails breadcrumbs plugin.
|
@@ -160,6 +161,7 @@ test_files:
|
|
160
161
|
- test/dummy/app/models/.gitkeep
|
161
162
|
- test/dummy/app/models/issue.rb
|
162
163
|
- test/dummy/app/models/project.rb
|
164
|
+
- test/dummy/app/views/breadcrumbs/site.rb
|
163
165
|
- test/dummy/config.ru
|
164
166
|
- test/dummy/config/application.rb
|
165
167
|
- test/dummy/config/boot.rb
|