gretel 3.0.0.beta3 → 3.0.0.beta4

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a6dea6327b14a40f5f88c344548da90536778701
4
- data.tar.gz: c527f98356d7ca6febb761ea239c030d3cfc6365
3
+ metadata.gz: f60e571dd44601cf9e016949eaf99b93e7620c32
4
+ data.tar.gz: eb4b93afaf41a5faaccd58e7fb6996e692c87eda
5
5
  SHA512:
6
- metadata.gz: e99745536c8bae608186322664689156e303f569961b1086278da7d66cf7ea2cdbcd84565eef961d6ab966d6044988057861656f7c6cec5b35e5a2905dfa53f6
7
- data.tar.gz: e3eb531c6e4ac7e1a9e9c0d2e914f9b1321bdbb48f9aead24ff9a611fb3e5a4c93e6a26974c7fabd0529da3d6a89dbc7958af3f12449ad559c3b223f54610dc0
6
+ metadata.gz: e755b624fad2a00daf9aaf8fbd2deb7f094d0b3b6a14137edc0a6111ba209067349527aa1d66ad898a2ce7a47376c776026f700ce2eb77ea0cba9768e8805bd5
7
+ data.tar.gz: cbedcf2047c946abbbd64ae8b6d2a2c8086ca6f17d7a0a77b7c3b655b73911dbec6e3da248f14b433237b18f2a2620b0ed5a9d0f67ccefa446ad01d898b150de
@@ -11,6 +11,8 @@ Version 3.0
11
11
  * Support for rendering the breadcrumbs in different styles like ul- and ol lists, and for use with [Twitter Bootstrap](http://getbootstrap.com/). See the `:style` option in the readme for more info.
12
12
  * The `:show_root_alone` option is now called `:display_single_fragment` and can be used to display the breadcrumbs only when there are more than one link, also if it is not the root breadcrumb.
13
13
  * Links yielded from `<%= breadcrumbs do |links| %>` now have a `current?` helper that returns true if the link is the last in the trail.
14
+ * New view helper: `parent_breadcrumb` returns the parent breadcrumb link (with `#key`, `#text`, and `#url`). You can supply options like `:autoroot` etc.
15
+ If you supply a block, it will yield the parent breadcrumb if it is present.
14
16
 
15
17
  Version 2.1
16
18
  -----------
data/README.md CHANGED
@@ -17,8 +17,11 @@ New in version 3.0 :muscle:
17
17
  * Defining breadcrumbs using `Gretel::Crumbs.layout do ... end` in an initializer has been removed. See below for details on how to upgrade.
18
18
  * The `:show_root_alone` option is now called `:display_single_fragment` and can be used to hide the breadcrumbs when there is only one link, also if it is not the root breadcrumb.
19
19
  The old `:show_root_alone` option is still supported until Gretel version 4.0 and will show a deprecation warning when it's used.
20
+ * Links yielded from `<%= breadcrumbs do |links| %>` now have a `current?` helper that returns true if the link is the last in the trail.
21
+ * New view helper: `parent_breadcrumb` returns the parent breadcrumb link (with `#key`, `#text`, and `#url`). You can supply options like `:autoroot` etc.
22
+ If you supply a block, it will yield the parent breadcrumb if it is present.
20
23
 
21
- I hope you find these changes as useful as I did when I made them – if you have more suggestions, please create an [Issue](https://github.com/lassebunk/gretel/issues) or [Pull Request](https://github.com/lassebunk/gretel/pulls).
24
+ I hope you find these changes as useful as I did – if you have more suggestions, please create an [Issue](https://github.com/lassebunk/gretel/issues) or [Pull Request](https://github.com/lassebunk/gretel/pulls).
22
25
 
23
26
  See below for more info or the [changelog](https://github.com/lassebunk/gretel/blob/master/CHANGELOG.md) for less significant changes.
24
27
 
@@ -28,7 +31,7 @@ Installation
28
31
  In your *Gemfile*:
29
32
 
30
33
  ```ruby
31
- gem "gretel", "3.0.0.beta2"
34
+ gem "gretel", "3.0.0.beta4"
32
35
  ```
33
36
 
34
37
  And run:
@@ -230,6 +233,21 @@ If you supply a block to the `breadcrumbs` method, it will yield an array with t
230
233
  <% end %>
231
234
  ```
232
235
 
236
+ Getting the parent breadcrumb
237
+ -----------------------------
238
+
239
+ If you want to add a link to the parent breadcrumb in the trail, you can use the `parent_breadcrumb` view helper.
240
+ By default it returns a link instance that has the properties `#key`, `#text`, and `#url`.
241
+ You can supply options like `autoroot: false` etc.
242
+
243
+ If you supply a block, it will yield the link if it is present:
244
+
245
+ ```erb
246
+ <% parent_breadcrumb do |parent| %>
247
+ <%= link_to "Back to #{link.text}", link.url %>
248
+ <% end %>
249
+ ```
250
+
233
251
  Setting breadcrumb trails
234
252
  --------------------------------
235
253
 
@@ -277,7 +295,7 @@ The product view will now have the breadcrumb trail from the first page (reviews
277
295
  The default trail param is `params[:trail]`. You can change it in an initializer:
278
296
 
279
297
  ```ruby
280
- Gretel::Trail.trail_param = :other_param
298
+ Gretel.trail_param = :other_param
281
299
  ```
282
300
 
283
301
  ### Note
@@ -3,7 +3,8 @@ module Gretel
3
3
  attr_accessor :key, :text, :url
4
4
 
5
5
  def initialize(key, text, url)
6
- @key, @text, @url = key, text, url
6
+ # Use accessors so plugins can override their behavior
7
+ self.key, self.text, self.url = key, text, url
7
8
  end
8
9
 
9
10
  def current!
@@ -58,10 +58,10 @@ module Gretel
58
58
  content_tag(options[:container_tag], html, id: options[:id], class: options[:class])
59
59
  end
60
60
 
61
- # Yields an array of links to be used in a view.
62
- def yield_links(options = {}, &block)
61
+ # Array of links transformed by +options+ (like +:autoroot+ etc.) to be used in a view.
62
+ def links_with(options = {})
63
63
  options = options_for_render(options)
64
- yield links_for_render(options)
64
+ links_for_render(options)
65
65
  end
66
66
 
67
67
  # Returns encoded trail for the breadcrumb.
@@ -69,6 +69,11 @@ module Gretel
69
69
  @trail ||= Gretel::Trail.encode(links)
70
70
  end
71
71
 
72
+ # Proxy for +context.link_to+ that can be overridden by plugins.
73
+ def link_to(*args)
74
+ context.link_to(*args)
75
+ end
76
+
72
77
  private
73
78
 
74
79
  attr_reader :context, :breadcrumb_key, :breadcrumb_args
@@ -148,7 +153,7 @@ module Gretel
148
153
 
149
154
  # Handle autoroot
150
155
  if options[:autoroot] && out.map(&:key).exclude?(:root) && Gretel::Crumbs.crumb_defined?(:root)
151
- out.unshift *Gretel::Crumb.new(self, :root).links
156
+ out.unshift *Gretel::Crumb.new(context, :root).links
152
157
  end
153
158
 
154
159
  # Handle show root alone
@@ -172,10 +177,10 @@ module Gretel
172
177
  def render_semantic_fragment(fragment_tag, text, url, options = {})
173
178
  if fragment_tag
174
179
  text = content_tag(:span, text, itemprop: "title")
175
- text = render_link(text, url, itemprop: "url") if url.present?
180
+ text = link_to(text, url, itemprop: "url") if url.present?
176
181
  content_tag(fragment_tag, text, class: options[:class], itemscope: "", itemtype: "http://data-vocabulary.org/Breadcrumb")
177
182
  elsif url.present?
178
- content_tag(:div, render_link(content_tag(:span, text, itemprop: "title"), url, class: options[:class], itemprop: "url"), itemscope: "", itemtype: "http://data-vocabulary.org/Breadcrumb")
183
+ content_tag(:div, link_to(content_tag(:span, text, itemprop: "title"), url, class: options[:class], itemprop: "url"), itemscope: "", itemtype: "http://data-vocabulary.org/Breadcrumb")
179
184
  else
180
185
  content_tag(:div, content_tag(:span, text, class: options[:class], itemprop: "title"), itemscope: "", itemtype: "http://data-vocabulary.org/Breadcrumb")
181
186
  end
@@ -184,10 +189,10 @@ module Gretel
184
189
  # Renders regular, non-semantic fragment HTML.
185
190
  def render_nonsemantic_fragment(fragment_tag, text, url, options = {})
186
191
  if fragment_tag
187
- text = render_link(text, url) if url.present?
192
+ text = link_to(text, url) if url.present?
188
193
  content_tag(fragment_tag, text, class: options[:class])
189
194
  elsif url.present?
190
- render_link(text, url, class: options[:class])
195
+ link_to(text, url, class: options[:class])
191
196
  elsif options[:class].present?
192
197
  content_tag(:span, text, class: options[:class])
193
198
  else
@@ -195,12 +200,6 @@ module Gretel
195
200
  end
196
201
  end
197
202
 
198
- # Renders a link. It is really just a proxy for +link_to+, but this can be
199
- # used in plugins that want to change how links are rendered.
200
- def render_link(name, url, options = {})
201
- link_to(name, url, options)
202
- end
203
-
204
203
  # Proxy to view context
205
204
  def method_missing(method, *args, &block)
206
205
  context.send(method, *args, &block)
@@ -1,3 +1,3 @@
1
1
  module Gretel
2
- VERSION = "3.0.0.beta3"
2
+ VERSION = "3.0.0.beta4"
3
3
  end
@@ -25,12 +25,22 @@ module Gretel
25
25
  # <% end %>
26
26
  def breadcrumbs(options = {}, &block)
27
27
  if block_given?
28
- gretel_renderer.yield_links(options, &block)
28
+ yield gretel_renderer.links_with(options)
29
29
  else
30
30
  gretel_renderer.render(options)
31
31
  end
32
32
  end
33
33
 
34
+ # Returns or yields parent breadcrumb (second-to-last in the trail) if it is present.
35
+ def parent_breadcrumb(options = {}, &block)
36
+ parent = gretel_renderer.links_with(options)[-2]
37
+ if block_given? && parent
38
+ yield parent
39
+ else
40
+ parent
41
+ end
42
+ end
43
+
34
44
  # Encoded breadcrumb trail to be used in URLs.
35
45
  def breadcrumb_trail
36
46
  gretel_renderer.trail
@@ -153,6 +153,40 @@ class HelperMethodsTest < ActionView::TestCase
153
153
  [:multiple_links_with_parent, "Contact form", "/about/contact/form"]], out
154
154
  end
155
155
 
156
+ test "parent breadcrumb" do
157
+ breadcrumb :multiple_links_with_parent
158
+
159
+ parent = parent_breadcrumb
160
+ assert_equal [:multiple_links_with_parent, "Contact", "/about/contact"],
161
+ [parent.key, parent.text, parent.url]
162
+ end
163
+
164
+ test "yields parent breadcrumb" do
165
+ breadcrumb :multiple_links_with_parent
166
+
167
+ out = parent_breadcrumb do |parent|
168
+ [parent.key, parent.text, parent.url]
169
+ end
170
+ assert_equal [:multiple_links_with_parent, "Contact", "/about/contact"],
171
+ out
172
+ end
173
+
174
+ test "parent breadcrumb returns nil if not present" do
175
+ breadcrumb :basic
176
+
177
+ assert_nil parent_breadcrumb(autoroot: false)
178
+ end
179
+
180
+ test "parent breadcrumb yields only if present" do
181
+ breadcrumb :basic
182
+
183
+ out = parent_breadcrumb(autoroot: false) do
184
+ "yielded"
185
+ end
186
+
187
+ assert_nil out
188
+ end
189
+
156
190
  test "sets current on last link in array" do
157
191
  breadcrumb :multiple_links_with_parent
158
192
 
@@ -279,7 +313,7 @@ class HelperMethodsTest < ActionView::TestCase
279
313
  end
280
314
 
281
315
  test "different trail param" do
282
- Gretel::Trail.trail_param = :mytest
316
+ Gretel.trail_param = :mytest
283
317
  params[:mytest] = "667ea523f92bdb3a086494575b18f587170e482b_W1siYmFzaWMiLCJBYm91dCIsMCwiL2Fib3V0Il1d"
284
318
  breadcrumb :multiple_links
285
319
 
@@ -287,6 +321,14 @@ class HelperMethodsTest < ActionView::TestCase
287
321
  breadcrumbs
288
322
  end
289
323
 
324
+ test "unknown trail" do
325
+ params[:trail] = "notfound"
326
+ breadcrumb :multiple_links
327
+
328
+ assert_equal %{<div class="breadcrumbs"><a href="/">Home</a> &rsaquo; <a href="/about/contact">Contact</a> &rsaquo; <span class="current">Contact form</span></div>},
329
+ breadcrumbs
330
+ end
331
+
290
332
  # Configuration reload
291
333
 
292
334
  test "reload configuration when file is changed" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gretel
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0.beta3
4
+ version: 3.0.0.beta4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lasse Bunk