gretel 3.0.5 → 3.0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1c82f3dde4a98f82f3eb6f0ce135a64a2ca7e8dc
4
- data.tar.gz: 44d2c6ec3b8405991c4f0c2b9fc837d8a2711b70
3
+ metadata.gz: 31c77ef551e13b999644f0b27d782987629ae7ab
4
+ data.tar.gz: 8bdf306a5ba44daaf9bcfb6b7b5f4830cbc8dd5d
5
5
  SHA512:
6
- metadata.gz: 01e17764cb6cdfc58a8010a114722d9941671b4933cb92ca6b221c20d29fc787652f7bd504454a753626faee3cfbb1e7c813558f172468766740c22c4cf1264a
7
- data.tar.gz: 6cd0c52eb47346f631916d66d9203857567b33c294adff6be93411eed6b3f72d1092349be8364d3915868bbf79890c523b439ebaead4317c957166f1c5892c97
6
+ metadata.gz: dfd56e69ce95e4fde666b9320fa5531275261804f2d74e623c3d98ca41996805aecc47907d27b64856243d79c7f123e2564c7542321a505fa6f8d47c1f49a804
7
+ data.tar.gz: ba35e16f9908e7259c01bdd9f174dfaf2e4aac45e99e2f61fbbe8b034f5e66dd52de75408733593775633ad4e257455465bc2e90c247f3c104d614fe4804225c
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## Version 3.0.6
4
+ * Pretext and posttext are now enclosed in spans with `<span class="pretext">` and `<span class="posttext">`.
5
+ * Semantic breadcrumbs are now rendered in spans instead of divs to enable easier styling.
6
+
3
7
  ## Version 3.0.3
4
8
  * Breadcrumbs can now be rendered for use in the [Foundation 5](http://foundation.zurb.com/) framework. Use `breadcrumbs style: :foundation5`.
5
9
  * Breadcrumbs are now automatically loaded from any engines' `config/breadcrumbs.rb` and `config/breadcrumbs/**/*.rb`. See the readme for details.
data/README.md CHANGED
@@ -97,7 +97,7 @@ You can pass options to `<%= breadcrumbs %>`, e.g. `<%= breadcrumbs pretext: "Yo
97
97
 
98
98
  Option | Description | Default
99
99
  ------------------------ | -------------------------------------------------------------------------------------------------------------------------- | -------
100
- :style | How to render the breadcrumbs. Can be `:default`, `:ol`, `:ul`, or `:bootstrap`. See below for more info. | `:default`
100
+ :style | How to render the breadcrumbs. Can be `:inline`, `:ol`, `:ul`, or `:bootstrap`. See below for more info. | `:inline`
101
101
  :pretext | Text to be rendered before breadcrumb, e.g. `"You are here: "`. | None
102
102
  :posttext | Text to be appended after breadcrumb, e.g. `"Text after breacrumb"`, | None
103
103
  :separator | Separator between links, e.g. `" &rsaquo; "`. | `" &rsaquo; "`
@@ -117,7 +117,7 @@ These are the styles you can use with `breadcrumbs style: :xx`.
117
117
 
118
118
  Style | Description
119
119
  -------------- | -----------
120
- `:default` | Renders each link by itself with `&rsaquo;` as the seperator.
120
+ `:inline` | Renders each link by itself with `&rsaquo;` as the seperator.
121
121
  `:ol` | Renders the links in `<li>` elements contained in an outer `<ol>`.
122
122
  `:ul` | Renders the links in `<li>` elements contained in an outer `<ul>`.
123
123
  `:bootstrap` | Renders the links for use in [Twitter Bootstrap](http://getbootstrap.com/).
data/gretel.gemspec CHANGED
@@ -18,6 +18,5 @@ Gem::Specification.new do |gem|
18
18
  gem.require_paths = ["lib"]
19
19
 
20
20
  gem.add_dependency "rails", ">= 3.2.0"
21
- gem.add_development_dependency "rails", "~> 3.2.13"
22
21
  gem.add_development_dependency "sqlite3"
23
22
  end
data/lib/gretel/crumb.rb CHANGED
@@ -51,7 +51,7 @@ module Gretel
51
51
  # The current view context.
52
52
  attr_reader :context
53
53
 
54
- # Proxy to view context
54
+ # Proxy to view context.
55
55
  def method_missing(method, *args, &block)
56
56
  context.send(method, *args, &block)
57
57
  end
@@ -1,2 +1 @@
1
- require "gretel/deprecated/layout"
2
- require "gretel/deprecated/show_root_alone"
1
+ Dir[File.dirname(__FILE__) + "/deprecated/*.rb"].each { |file| require file }
@@ -0,0 +1,11 @@
1
+ Gretel::Renderer.class_eval do
2
+ def options_for_style_with_default_style_key(style_key)
3
+ if style_key == :default
4
+ Gretel.show_deprecation_warning "The :default style key is now called :inline. Please use `breadcrumbs style: :inline` instead or omit it, as it is the default."
5
+ style_key = :inline
6
+ end
7
+ options_for_style_without_default_style_key(style_key)
8
+ end
9
+
10
+ alias_method_chain :options_for_style, :default_style_key
11
+ end
@@ -0,0 +1,20 @@
1
+ Gretel::ViewHelpers.class_eval do
2
+ def breadcrumbs_with_yield_links(options = {})
3
+ if block_given?
4
+ Gretel.show_deprecation_warning(
5
+ "Calling `breadcrumbs` with a block has been deprecated and will be removed in Gretel version 4.0. Please use `tap` instead. Example:\n" +
6
+ "\n" +
7
+ " breadcrumbs(autoroot: false).tap do |links|\n" +
8
+ " if links.any?\n" +
9
+ " # process links here\n" +
10
+ " end\n" +
11
+ " end\n"
12
+ )
13
+ yield gretel_renderer.render(options)
14
+ else
15
+ breadcrumbs_without_yield_links(options)
16
+ end
17
+ end
18
+
19
+ alias_method_chain :breadcrumbs, :yield_links
20
+ end
@@ -1,7 +1,7 @@
1
1
  module Gretel
2
2
  class Renderer
3
3
  DEFAULT_OPTIONS = {
4
- style: :default,
4
+ style: :inline,
5
5
  pretext: "",
6
6
  posttext: "",
7
7
  separator: "",
@@ -15,7 +15,7 @@ module Gretel
15
15
  }
16
16
 
17
17
  DEFAULT_STYLES = {
18
- default: { container_tag: :div, separator: " &rsaquo; " },
18
+ inline: { container_tag: :div, separator: " &rsaquo; " },
19
19
  ol: { container_tag: :ol, fragment_tag: :li },
20
20
  ul: { container_tag: :ul, fragment_tag: :li },
21
21
  bootstrap: { container_tag: :ol, fragment_tag: :li, class: "breadcrumb", current_class: "active" },
@@ -33,32 +33,17 @@ module Gretel
33
33
  options = options_for_render(options)
34
34
  links = links_for_render(options)
35
35
 
36
- return "" if links.empty?
37
-
38
- # Loop through all but the last (current) link and build HTML of the fragments
39
- fragments = links[0..-2].map do |link|
40
- render_fragment(options[:fragment_tag], link.text, link.url, options[:semantic])
41
- end
42
-
43
- # The current link is handled a little differently, and is only linked if specified in the options
44
- current_link = links.last
45
- fragments << render_fragment(options[:fragment_tag], current_link.text, (options[:link_current] ? current_link.url : nil), options[:semantic], class: options[:current_class])
46
-
47
- # Build the final HTML
48
- html = (options[:pretext] + fragments.join(options[:separator]) + options[:posttext]).html_safe
49
- content_tag(options[:container_tag], html, id: options[:id], class: options[:class])
36
+ LinkCollection.new(context, links, options)
50
37
  end
51
38
 
52
39
  # Yields links with applied options.
53
40
  def yield_links(options = {})
54
- options = options_for_render(options)
55
- yield links_for_render(options)
41
+ yield render(options)
56
42
  end
57
43
 
58
44
  # Returns the parent breadcrumb.
59
45
  def parent_breadcrumb(options = {})
60
- options = options_for_render(options)
61
- links_for_render(options)[-2]
46
+ render(options)[-2]
62
47
  end
63
48
 
64
49
  # Yields the parent breadcrumb if any.
@@ -68,11 +53,6 @@ module Gretel
68
53
  end
69
54
  end
70
55
 
71
- # Proxy for +context.link_to+ that can be overridden by plugins.
72
- def breadcrumb_link_to(name, url, options = {})
73
- context.link_to(name, url, options)
74
- end
75
-
76
56
  private
77
57
 
78
58
  attr_reader :context, :breadcrumb_key, :breadcrumb_args
@@ -148,43 +128,7 @@ module Gretel
148
128
  links
149
129
  end
150
130
 
151
- # Renders HTML for a breadcrumb fragment, i.e. a breadcrumb link.
152
- def render_fragment(fragment_tag, text, url, semantic, options = {})
153
- if semantic
154
- render_semantic_fragment(fragment_tag, text, url, options)
155
- else
156
- render_nonsemantic_fragment(fragment_tag, text, url, options)
157
- end
158
- end
159
-
160
- # Renders semantic fragment HTML.
161
- def render_semantic_fragment(fragment_tag, text, url, options = {})
162
- if fragment_tag
163
- text = content_tag(:span, text, itemprop: "title")
164
- text = breadcrumb_link_to(text, url, itemprop: "url") if url.present?
165
- content_tag(fragment_tag, text, class: options[:class], itemscope: "", itemtype: "http://data-vocabulary.org/Breadcrumb")
166
- elsif url.present?
167
- content_tag(:div, breadcrumb_link_to(content_tag(:span, text, itemprop: "title"), url, class: options[:class], itemprop: "url"), itemscope: "", itemtype: "http://data-vocabulary.org/Breadcrumb")
168
- else
169
- content_tag(:div, content_tag(:span, text, class: options[:class], itemprop: "title"), itemscope: "", itemtype: "http://data-vocabulary.org/Breadcrumb")
170
- end
171
- end
172
-
173
- # Renders regular, non-semantic fragment HTML.
174
- def render_nonsemantic_fragment(fragment_tag, text, url, options = {})
175
- if fragment_tag
176
- text = breadcrumb_link_to(text, url) if url.present?
177
- content_tag(fragment_tag, text, class: options[:class])
178
- elsif url.present?
179
- breadcrumb_link_to(text, url, class: options[:class])
180
- elsif options[:class].present?
181
- content_tag(:span, text, class: options[:class])
182
- else
183
- text
184
- end
185
- end
186
-
187
- # Proxy to view context
131
+ # Proxy to view context.
188
132
  def method_missing(method, *args, &block)
189
133
  context.send(method, *args, &block)
190
134
  end
@@ -204,5 +148,97 @@ module Gretel
204
148
  @styles ||= DEFAULT_STYLES
205
149
  end
206
150
  end
151
+
152
+ class LinkCollection < Array
153
+ attr_reader :context, :links, :options
154
+
155
+ def initialize(context, links, options = {})
156
+ @context, @links, @options = context, links, options
157
+ concat links
158
+ end
159
+
160
+ # Helper for returning all link keys to allow for simple testing.
161
+ def keys
162
+ map(&:key)
163
+ end
164
+
165
+ # Renders the links into breadcrumbs.
166
+ def render
167
+ return "" if links.empty?
168
+
169
+ # Loop through all but the last (current) link and build HTML of the fragments
170
+ fragments = links[0..-2].map do |link|
171
+ render_fragment(options[:fragment_tag], link.text, link.url, options[:semantic])
172
+ end
173
+
174
+ # The current link is handled a little differently, and is only linked if specified in the options
175
+ current_link = links.last
176
+ fragments << render_fragment(options[:fragment_tag], current_link.text, (options[:link_current] ? current_link.url : nil), options[:semantic], class: options[:current_class])
177
+
178
+ # Build the final HTML
179
+ html_fragments = []
180
+
181
+ if options[:pretext].present?
182
+ html_fragments << content_tag(:span, options[:pretext], class: "pretext")
183
+ end
184
+
185
+ html_fragments << fragments.join(options[:separator])
186
+
187
+ if options[:posttext].present?
188
+ html_fragments << content_tag(:span, options[:posttext], class: "posttext")
189
+ end
190
+
191
+ html = html_fragments.join(" ").html_safe
192
+ content_tag(options[:container_tag], html, id: options[:id], class: options[:class])
193
+ end
194
+
195
+ alias :to_s :render
196
+
197
+ # Renders HTML for a breadcrumb fragment, i.e. a breadcrumb link.
198
+ def render_fragment(fragment_tag, text, url, semantic, options = {})
199
+ if semantic
200
+ render_semantic_fragment(fragment_tag, text, url, options)
201
+ else
202
+ render_nonsemantic_fragment(fragment_tag, text, url, options)
203
+ end
204
+ end
205
+
206
+ # Renders semantic fragment HTML.
207
+ def render_semantic_fragment(fragment_tag, text, url, options = {})
208
+ if fragment_tag
209
+ text = content_tag(:span, text, itemprop: "title")
210
+ text = breadcrumb_link_to(text, url, itemprop: "url") if url.present?
211
+ content_tag(fragment_tag, text, class: options[:class], itemscope: "", itemtype: "http://data-vocabulary.org/Breadcrumb")
212
+ elsif url.present?
213
+ content_tag(:span, breadcrumb_link_to(content_tag(:span, text, itemprop: "title"), url, class: options[:class], itemprop: "url"), itemscope: "", itemtype: "http://data-vocabulary.org/Breadcrumb")
214
+ else
215
+ content_tag(:span, content_tag(:span, text, class: options[:class], itemprop: "title"), itemscope: "", itemtype: "http://data-vocabulary.org/Breadcrumb")
216
+ end
217
+ end
218
+
219
+ # Renders regular, non-semantic fragment HTML.
220
+ def render_nonsemantic_fragment(fragment_tag, text, url, options = {})
221
+ if fragment_tag
222
+ text = breadcrumb_link_to(text, url) if url.present?
223
+ content_tag(fragment_tag, text, class: options[:class])
224
+ elsif url.present?
225
+ breadcrumb_link_to(text, url, class: options[:class])
226
+ elsif options[:class].present?
227
+ content_tag(:span, text, class: options[:class])
228
+ else
229
+ text
230
+ end
231
+ end
232
+
233
+ # Proxy for +context.link_to+ that can be overridden by plugins.
234
+ def breadcrumb_link_to(name, url, options = {})
235
+ context.link_to(name, url, options)
236
+ end
237
+
238
+ # Proxy to view context.
239
+ def method_missing(method, *args, &block)
240
+ context.send(method, *args, &block)
241
+ end
242
+ end
207
243
  end
208
244
  end
@@ -1,3 +1,3 @@
1
1
  module Gretel
2
- VERSION = "3.0.5"
2
+ VERSION = "3.0.6"
3
3
  end
@@ -48,12 +48,8 @@ module Gretel
48
48
  # <% end %>
49
49
  # <% end %>
50
50
  # <% end %>
51
- def breadcrumbs(options = {}, &block)
52
- if block_given?
53
- gretel_renderer.yield_links(options, &block)
54
- else
55
- gretel_renderer.render(options)
56
- end
51
+ def breadcrumbs(options = {})
52
+ gretel_renderer.render(options)
57
53
  end
58
54
 
59
55
  # Returns or yields parent breadcrumb (second-to-last in the trail) if it is present.
@@ -13,7 +13,7 @@ class DeprecatedTest < ActionView::TestCase
13
13
  test "show root alone" do
14
14
  breadcrumb :root
15
15
  assert_equal %{<div class="breadcrumbs"><span class="current">Home</span></div>},
16
- breadcrumbs(show_root_alone: true)
16
+ breadcrumbs(show_root_alone: true).to_s
17
17
  end
18
18
 
19
19
  test "deprecated configuration block" do
@@ -22,4 +22,24 @@ class DeprecatedTest < ActionView::TestCase
22
22
  end
23
23
  end
24
24
  end
25
+
26
+ test ":default style key" do
27
+ breadcrumb :basic
28
+
29
+ assert_equal %{<div class="breadcrumbs"><a href="/">Home</a> &rsaquo; <span class="current">About</span></div>},
30
+ breadcrumbs(style: :default).to_s
31
+ end
32
+
33
+ test "yield links" do
34
+ breadcrumb :multiple_links_with_parent
35
+
36
+ out = breadcrumbs do |links|
37
+ links.map { |link| [link.key, link.text, link.url] }
38
+ end
39
+
40
+ assert_equal [[:root, "Home", "/"],
41
+ [:basic, "About", "/about"],
42
+ [:multiple_links_with_parent, "Contact", "/about/contact"],
43
+ [:multiple_links_with_parent, "Contact form", "/about/contact/form"]], out
44
+ end
25
45
  end
@@ -14,142 +14,129 @@ class HelperMethodsTest < ActionView::TestCase
14
14
  test "shows basic breadcrumb" do
15
15
  breadcrumb :basic
16
16
  assert_equal %{<div class="breadcrumbs"><a href="/">Home</a> &rsaquo; <span class="current">About</span></div>},
17
- breadcrumbs
17
+ breadcrumbs.to_s
18
18
  end
19
19
 
20
20
  test "shows breadcrumb with root" do
21
21
  breadcrumb :with_root
22
22
  assert_equal %{<div class="breadcrumbs"><a href="/">Home</a> &rsaquo; <span class="current">About</span></div>},
23
- breadcrumbs
23
+ breadcrumbs.to_s
24
24
  end
25
25
 
26
26
  test "shows breadcrumb with parent" do
27
27
  breadcrumb :with_parent
28
28
  assert_equal %{<div class="breadcrumbs"><a href="/">Home</a> &rsaquo; <a href="/about">About</a> &rsaquo; <span class="current">Contact</span></div>},
29
- breadcrumbs
29
+ breadcrumbs.to_s
30
30
  end
31
31
 
32
32
  test "shows breadcrumb with autopath" do
33
33
  breadcrumb :with_autopath, projects(:one)
34
34
  assert_equal %{<div class="breadcrumbs"><a href="/">Home</a> &rsaquo; <span class="current">Test Project</span></div>},
35
- breadcrumbs
35
+ breadcrumbs.to_s
36
36
  end
37
37
 
38
38
  test "shows breadcrumb with parent object" do
39
39
  breadcrumb :with_parent_object, issues(:one)
40
40
  assert_equal %{<div class="breadcrumbs"><a href="/">Home</a> &rsaquo; <a href="/projects/1">Test Project</a> &rsaquo; <span class="current">Test Issue</span></div>},
41
- breadcrumbs
41
+ breadcrumbs.to_s
42
42
  end
43
43
 
44
44
  test "shows multiple links" do
45
45
  breadcrumb :multiple_links
46
46
  assert_equal %{<div class="breadcrumbs"><a href="/">Home</a> &rsaquo; <a href="/about/contact">Contact</a> &rsaquo; <span class="current">Contact form</span></div>},
47
- breadcrumbs
47
+ breadcrumbs.to_s
48
48
  end
49
49
 
50
50
  test "shows multiple links with parent" do
51
51
  breadcrumb :multiple_links_with_parent
52
52
  assert_equal %{<div class="breadcrumbs"><a href="/">Home</a> &rsaquo; <a href="/about">About</a> &rsaquo; <a href="/about/contact">Contact</a> &rsaquo; <span class="current">Contact form</span></div>},
53
- breadcrumbs
53
+ breadcrumbs.to_s
54
54
  end
55
55
 
56
56
  test "shows semantic breadcrumb" do
57
57
  breadcrumb :with_root
58
- assert_equal %{<div class="breadcrumbs"><div itemscope="" itemtype="http://data-vocabulary.org/Breadcrumb"><a href="/" itemprop="url"><span itemprop="title">Home</span></a></div> &rsaquo; <div itemscope="" itemtype="http://data-vocabulary.org/Breadcrumb"><span class="current" itemprop="title">About</span></div></div>},
59
- breadcrumbs(semantic: true)
58
+ assert_equal %{<div class="breadcrumbs"><span itemscope="" itemtype="http://data-vocabulary.org/Breadcrumb"><a href="/" itemprop="url"><span itemprop="title">Home</span></a></span> &rsaquo; <span itemscope="" itemtype="http://data-vocabulary.org/Breadcrumb"><span class="current" itemprop="title">About</span></span></div>},
59
+ breadcrumbs(semantic: true).to_s
60
60
  end
61
61
 
62
62
  test "doesn't show root alone" do
63
63
  breadcrumb :root
64
- assert_equal "", breadcrumbs
64
+ assert_equal "", breadcrumbs.to_s
65
65
  end
66
66
 
67
67
  test "displays single fragment" do
68
68
  breadcrumb :root
69
69
  assert_equal %{<div class="breadcrumbs"><span class="current">Home</span></div>},
70
- breadcrumbs(display_single_fragment: true)
70
+ breadcrumbs(display_single_fragment: true).to_s
71
71
  end
72
72
 
73
73
  test "displays single non-root fragment" do
74
74
  breadcrumb :basic
75
75
  assert_equal %{<div class="breadcrumbs"><span class="current">About</span></div>},
76
- breadcrumbs(autoroot: false, display_single_fragment: true)
76
+ breadcrumbs(autoroot: false, display_single_fragment: true).to_s
77
77
  end
78
78
 
79
79
  test "shows no breadcrumb" do
80
- assert_equal "", breadcrumbs
80
+ assert_equal "", breadcrumbs.to_s
81
81
  end
82
82
 
83
83
  test "links current breadcrumb" do
84
84
  breadcrumb :with_root
85
85
  assert_equal %{<div class="breadcrumbs"><a href="/">Home</a> &rsaquo; <a href="/about" class="current">About</a></div>},
86
- breadcrumbs(link_current: true)
86
+ breadcrumbs(link_current: true).to_s
87
87
  end
88
88
 
89
89
  test "shows pretext" do
90
90
  breadcrumb :basic
91
- assert_equal %{<div class="breadcrumbs">You are here: <a href="/">Home</a> &rsaquo; <span class="current">About</span></div>},
92
- breadcrumbs(pretext: "You are here: ")
91
+ assert_equal %{<div class="breadcrumbs"><span class="pretext">You are here:</span> <a href="/">Home</a> &rsaquo; <span class="current">About</span></div>},
92
+ breadcrumbs(pretext: "You are here:").to_s
93
93
  end
94
94
 
95
95
  test "shows posttext" do
96
96
  breadcrumb :basic
97
- assert_equal %{<div class="breadcrumbs"><a href="/">Home</a> &rsaquo; <span class="current">About</span> - text after breadcrumbs</div>},
98
- breadcrumbs(posttext: " - text after breadcrumbs")
97
+ assert_equal %{<div class="breadcrumbs"><a href="/">Home</a> &rsaquo; <span class="current">About</span> <span class="posttext">text after breadcrumbs</span></div>},
98
+ breadcrumbs(posttext: "text after breadcrumbs").to_s
99
99
  end
100
100
 
101
101
  test "autoroot disabled" do
102
102
  breadcrumb :basic
103
- assert_equal "", breadcrumbs(autoroot: false)
103
+ assert_equal "", breadcrumbs(autoroot: false).to_s
104
104
  end
105
105
 
106
106
  test "shows separator" do
107
107
  breadcrumb :with_root
108
108
  assert_equal %{<div class="breadcrumbs"><a href="/">Home</a> &raquo; <span class="current">About</span></div>},
109
- breadcrumbs(separator: " &raquo; ")
109
+ breadcrumbs(separator: " &raquo; ").to_s
110
110
  end
111
111
 
112
112
  test "shows element id" do
113
113
  breadcrumb :basic
114
114
  assert_equal %{<div class="breadcrumbs" id="custom_id"><a href="/">Home</a> &rsaquo; <span class="current">About</span></div>},
115
- breadcrumbs(id: "custom_id")
115
+ breadcrumbs(id: "custom_id").to_s
116
116
  end
117
117
 
118
118
  test "shows custom container class" do
119
119
  breadcrumb :basic
120
120
  assert_equal %{<div class="custom_class"><a href="/">Home</a> &rsaquo; <span class="current">About</span></div>},
121
- breadcrumbs(class: "custom_class")
121
+ breadcrumbs(class: "custom_class").to_s
122
122
  end
123
123
 
124
124
  test "shows custom current class" do
125
125
  breadcrumb :basic
126
126
  assert_equal %{<div class="breadcrumbs"><a href="/">Home</a> &rsaquo; <span class="custom_current_class">About</span></div>},
127
- breadcrumbs(current_class: "custom_current_class")
127
+ breadcrumbs(current_class: "custom_current_class").to_s
128
128
  end
129
129
 
130
130
  test "unsafe html" do
131
131
  breadcrumb :with_unsafe_html
132
132
  assert_equal %{<div class="breadcrumbs"><a href="/">Home</a> &rsaquo; <span class="current">Test &lt;strong&gt;bold text&lt;/strong&gt;</span></div>},
133
- breadcrumbs
133
+ breadcrumbs.to_s
134
134
  end
135
135
 
136
136
  test "safe html" do
137
137
  breadcrumb :with_safe_html
138
138
  assert_equal %{<div class="breadcrumbs"><a href="/">Home</a> &rsaquo; <span class="current">Test <strong>bold text</strong></span></div>},
139
- breadcrumbs
140
- end
141
-
142
- test "yields a block containing breadcrumb links array" do
143
- breadcrumb :multiple_links_with_parent
144
-
145
- out = breadcrumbs do |links|
146
- links.map { |link| [link.key, link.text, link.url] }
147
- end
148
-
149
- assert_equal [[:root, "Home", "/"],
150
- [:basic, "About", "/about"],
151
- [:multiple_links_with_parent, "Contact", "/about/contact"],
152
- [:multiple_links_with_parent, "Contact form", "/about/contact/form"]], out
139
+ breadcrumbs.to_s
153
140
  end
154
141
 
155
142
  test "parent breadcrumb" do
@@ -186,20 +173,29 @@ class HelperMethodsTest < ActionView::TestCase
186
173
  assert_nil out
187
174
  end
188
175
 
189
- test "sets current on last link in array" do
190
- breadcrumb :multiple_links_with_parent
176
+ test "link keys" do
177
+ breadcrumb :basic
178
+ assert_equal [:root, :basic], breadcrumbs.keys
179
+ end
180
+
181
+ test "using breadcrumbs as array" do
182
+ breadcrumb :basic
191
183
 
192
- out = breadcrumbs do |links|
193
- links.map(&:current?)
184
+ breadcrumbs.tap do |links|
185
+ assert_kind_of Array, links
186
+ assert_equal 2, links.count
194
187
  end
188
+ end
195
189
 
196
- assert_equal [false, false, false, true], out
190
+ test "sets current on last link in array" do
191
+ breadcrumb :multiple_links_with_parent
192
+ assert_equal [false, false, false, true], breadcrumbs.map(&:current?)
197
193
  end
198
194
 
199
195
  test "passing options to links" do
200
196
  breadcrumb :with_link_options
201
197
 
202
- breadcrumbs(autoroot: false) do |links|
198
+ breadcrumbs(autoroot: false).tap do |links|
203
199
  links[0].tap do |link|
204
200
  assert link.title?
205
201
  assert_equal "My Title", link.title
@@ -218,53 +214,53 @@ class HelperMethodsTest < ActionView::TestCase
218
214
  end
219
215
 
220
216
  assert_equal %{<div class="breadcrumbs"><a href="/about">Test</a> &rsaquo; <span class="current">Other Link</span></div>},
221
- breadcrumbs(autoroot: false)
217
+ breadcrumbs(autoroot: false).to_s
222
218
  end
223
219
 
224
220
  test "without link" do
225
221
  breadcrumb :without_link
226
222
  assert_equal %{<div class="breadcrumbs"><a href="/">Home</a> &rsaquo; Also without link &rsaquo; <span class="current">Without link</span></div>},
227
- breadcrumbs
223
+ breadcrumbs.to_s
228
224
  end
229
225
 
230
226
  test "view context" do
231
227
  breadcrumb :using_view_helper
232
228
  assert_equal %{<div class="breadcrumbs"><a href="/">Home</a> &rsaquo; <span class="current">TestTest</span></div>},
233
- breadcrumbs
229
+ breadcrumbs.to_s
234
230
  end
235
231
 
236
232
  test "multiple arguments" do
237
233
  breadcrumb :with_multiple_arguments, "One", "Two", "Three"
238
234
  assert_equal %{<div class="breadcrumbs"><a href="/">Home</a> &rsaquo; <a href="/about">First OneOne then TwoTwo then ThreeThree</a> &rsaquo; <span class="current">One and Two and Three</span></div>},
239
- breadcrumbs
235
+ breadcrumbs.to_s
240
236
  end
241
237
 
242
238
  test "from views folder" do
243
239
  breadcrumb :from_views
244
240
  assert_equal %{<div class="breadcrumbs"><a href="/">Home</a> &rsaquo; <span class="current">Breadcrumb From View</span></div>},
245
- breadcrumbs
241
+ breadcrumbs.to_s
246
242
  end
247
243
 
248
244
  test "with_breadcrumb" do
249
245
  breadcrumb :basic
250
246
 
251
247
  assert_equal %{<div class="breadcrumbs"><a href="/">Home</a> &rsaquo; <span class="current">About</span></div>},
252
- breadcrumbs
248
+ breadcrumbs.to_s
253
249
 
254
250
  with_breadcrumb(:with_parent_object, issues(:one)) do
255
251
  assert_equal %{<div class="breadcrumbs"><a href="/">Home</a> &rsaquo; <a href="/projects/1">Test Project</a> &rsaquo; <span class="current">Test Issue</span></div>},
256
- breadcrumbs
252
+ breadcrumbs.to_s
257
253
  end
258
254
 
259
255
  assert_equal %{<div class="breadcrumbs"><a href="/">Home</a> &rsaquo; <span class="current">About</span></div>},
260
- breadcrumbs
256
+ breadcrumbs.to_s
261
257
  end
262
258
 
263
259
  test "calling breadcrumbs helper twice" do
264
260
  breadcrumb :with_parent
265
261
  2.times do
266
262
  assert_equal %{<div class="breadcrumbs"><a href="/">Home</a> &rsaquo; <a href="/about">About</a> &rsaquo; <span class="current">Contact</span></div>},
267
- breadcrumbs
263
+ breadcrumbs.to_s
268
264
  end
269
265
  end
270
266
 
@@ -279,7 +275,7 @@ class HelperMethodsTest < ActionView::TestCase
279
275
  self.request = OpenStruct.new(fullpath: "/testpath?a=1&b=2")
280
276
 
281
277
  breadcrumb :basic
282
- assert_equal "/testpath?a=1&b=2", breadcrumbs { |links| links.last.url }
278
+ assert_equal "/testpath?a=1&b=2", breadcrumbs.last.url
283
279
  end
284
280
 
285
281
  test "calling the breadcrumb method with wrong arguments" do
@@ -299,7 +295,7 @@ class HelperMethodsTest < ActionView::TestCase
299
295
  test "inferred breadcrumb" do
300
296
  breadcrumb Project.first
301
297
  assert_equal %{<div class="breadcrumbs"><a href="/">Home</a> &rsaquo; <span class="current">Test Project</span></div>},
302
- breadcrumbs
298
+ breadcrumbs.to_s
303
299
  end
304
300
 
305
301
  # Styles
@@ -307,43 +303,43 @@ class HelperMethodsTest < ActionView::TestCase
307
303
  test "default style" do
308
304
  breadcrumb :basic
309
305
  assert_equal %{<div class="breadcrumbs"><a href="/">Home</a> &rsaquo; <span class="current">About</span></div>},
310
- breadcrumbs
306
+ breadcrumbs.to_s
311
307
  end
312
308
 
313
309
  test "ordered list style" do
314
310
  breadcrumb :basic
315
311
  assert_equal %{<ol class="breadcrumbs"><li><a href="/">Home</a></li><li class="current">About</li></ol>},
316
- breadcrumbs(style: :ol)
312
+ breadcrumbs(style: :ol).to_s
317
313
  end
318
314
 
319
315
  test "unordered list style" do
320
316
  breadcrumb :basic
321
317
  assert_equal %{<ul class="breadcrumbs"><li><a href="/">Home</a></li><li class="current">About</li></ul>},
322
- breadcrumbs(style: :ul)
318
+ breadcrumbs(style: :ul).to_s
323
319
  end
324
320
 
325
321
  test "bootstrap style" do
326
322
  breadcrumb :basic
327
323
  assert_equal %{<ol class="breadcrumb"><li><a href="/">Home</a></li><li class="active">About</li></ol>},
328
- breadcrumbs(style: :bootstrap)
324
+ breadcrumbs(style: :bootstrap).to_s
329
325
  end
330
326
 
331
327
  test "foundation5 style" do
332
328
  breadcrumb :basic
333
329
  assert_equal %{<ul class="breadcrumbs"><li><a href="/">Home</a></li><li class="current">About</li></ul>},
334
- breadcrumbs(style: :foundation5)
330
+ breadcrumbs(style: :foundation5).to_s
335
331
  end
336
332
 
337
333
  test "custom container and fragment tags" do
338
334
  breadcrumb :basic
339
335
  assert_equal %{<c class="breadcrumbs"><f><a href="/">Home</a></f> &rsaquo; <f class="current">About</f></c>},
340
- breadcrumbs(container_tag: :c, fragment_tag: :f)
336
+ breadcrumbs(container_tag: :c, fragment_tag: :f).to_s
341
337
  end
342
338
 
343
339
  test "custom semantic container and fragment tags" do
344
340
  breadcrumb :basic
345
341
  assert_equal %{<c class="breadcrumbs"><f itemscope="" itemtype="http://data-vocabulary.org/Breadcrumb"><a href="/" itemprop="url"><span itemprop="title">Home</span></a></f> &rsaquo; <f class="current" itemscope="" itemtype="http://data-vocabulary.org/Breadcrumb"><span itemprop="title">About</span></f></c>},
346
- breadcrumbs(container_tag: :c, fragment_tag: :f, semantic: true)
342
+ breadcrumbs(container_tag: :c, fragment_tag: :f, semantic: true).to_s
347
343
  end
348
344
 
349
345
  test "unknown style" do
@@ -359,7 +355,7 @@ class HelperMethodsTest < ActionView::TestCase
359
355
  breadcrumb :basic
360
356
 
361
357
  assert_equal %{<one class="breadcrumbs"><two><a href="/">Home</a></two><two class="current">About</two></one>},
362
- breadcrumbs(style: :test_style)
358
+ breadcrumbs(style: :test_style).to_s
363
359
  end
364
360
 
365
361
  # Configuration reload
@@ -380,7 +376,7 @@ class HelperMethodsTest < ActionView::TestCase
380
376
  end
381
377
 
382
378
  breadcrumb :about
383
- assert_equal %{<div class="breadcrumbs"><a href="/">Home (loaded)</a> &rsaquo; <span class="current">About (loaded)</span></div>}, breadcrumbs
379
+ assert_equal %{<div class="breadcrumbs"><a href="/">Home (loaded)</a> &rsaquo; <span class="current">About (loaded)</span></div>}, breadcrumbs.to_s
384
380
 
385
381
  sleep 1 # File change interval is 1 second
386
382
 
@@ -396,7 +392,7 @@ class HelperMethodsTest < ActionView::TestCase
396
392
  end
397
393
 
398
394
  breadcrumb :about
399
- assert_equal %{<div class="breadcrumbs"><a href="/test">Home (reloaded)</a> &rsaquo; <span class="current">About (reloaded)</span></div>}, breadcrumbs
395
+ assert_equal %{<div class="breadcrumbs"><a href="/test">Home (reloaded)</a> &rsaquo; <span class="current">About (reloaded)</span></div>}, breadcrumbs.to_s
400
396
  end
401
397
 
402
398
  test "reload configuration when file is added" do
@@ -425,7 +421,7 @@ class HelperMethodsTest < ActionView::TestCase
425
421
  end
426
422
 
427
423
  breadcrumb :about
428
- assert_equal %{<div class="breadcrumbs"><a href="/">Home (loaded)</a> &rsaquo; <span class="current">About (loaded)</span></div>}, breadcrumbs
424
+ assert_equal %{<div class="breadcrumbs"><a href="/">Home (loaded)</a> &rsaquo; <span class="current">About (loaded)</span></div>}, breadcrumbs.to_s
429
425
  end
430
426
 
431
427
  test "reload configuration when file is deleted" do
@@ -453,7 +449,7 @@ class HelperMethodsTest < ActionView::TestCase
453
449
  end
454
450
 
455
451
  breadcrumb :contact
456
- assert_equal %{<div class="breadcrumbs"><a href="/">Home (loaded)</a> &rsaquo; <a href="/about">About (loaded)</a> &rsaquo; <span class="current">Contact (loaded)</span></div>}, breadcrumbs
452
+ assert_equal %{<div class="breadcrumbs"><a href="/">Home (loaded)</a> &rsaquo; <a href="/about">About (loaded)</a> &rsaquo; <span class="current">Contact (loaded)</span></div>}, breadcrumbs.to_s
457
453
 
458
454
  File.delete path.join("pages.rb")
459
455
 
@@ -463,7 +459,7 @@ class HelperMethodsTest < ActionView::TestCase
463
459
  end
464
460
 
465
461
  breadcrumb :about
466
- assert_equal %{<div class="breadcrumbs"><a href="/">Home (loaded)</a> &rsaquo; <span class="current">About (loaded)</span></div>}, breadcrumbs
462
+ assert_equal %{<div class="breadcrumbs"><a href="/">Home (loaded)</a> &rsaquo; <span class="current">About (loaded)</span></div>}, breadcrumbs.to_s
467
463
  end
468
464
 
469
465
  test "reloads only in development environment" do
@@ -483,7 +479,7 @@ class HelperMethodsTest < ActionView::TestCase
483
479
  end
484
480
 
485
481
  breadcrumb :about
486
- assert_equal %{<div class="breadcrumbs"><a href="/">Home (loaded)</a> &rsaquo; <span class="current">About (loaded)</span></div>}, breadcrumbs
482
+ assert_equal %{<div class="breadcrumbs"><a href="/">Home (loaded)</a> &rsaquo; <span class="current">About (loaded)</span></div>}, breadcrumbs.to_s
487
483
 
488
484
  sleep 1
489
485
 
@@ -499,7 +495,7 @@ class HelperMethodsTest < ActionView::TestCase
499
495
  end
500
496
 
501
497
  breadcrumb :about
502
- assert_equal %{<div class="breadcrumbs"><a href="/">Home (loaded)</a> &rsaquo; <span class="current">About (loaded)</span></div>}, breadcrumbs
498
+ assert_equal %{<div class="breadcrumbs"><a href="/">Home (loaded)</a> &rsaquo; <span class="current">About (loaded)</span></div>}, breadcrumbs.to_s
503
499
  end
504
500
 
505
501
  private
metadata CHANGED
@@ -1,55 +1,41 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gretel
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.5
4
+ version: 3.0.6
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-12-09 00:00:00.000000000 Z
11
+ date: 2014-04-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: 3.2.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: 3.2.0
27
- - !ruby/object:Gem::Dependency
28
- name: rails
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ~>
32
- - !ruby/object:Gem::Version
33
- version: 3.2.13
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ~>
39
- - !ruby/object:Gem::Version
40
- version: 3.2.13
41
27
  - !ruby/object:Gem::Dependency
42
28
  name: sqlite3
43
29
  requirement: !ruby/object:Gem::Requirement
44
30
  requirements:
45
- - - '>='
31
+ - - ">="
46
32
  - !ruby/object:Gem::Version
47
33
  version: '0'
48
34
  type: :development
49
35
  prerelease: false
50
36
  version_requirements: !ruby/object:Gem::Requirement
51
37
  requirements:
52
- - - '>='
38
+ - - ">="
53
39
  - !ruby/object:Gem::Version
54
40
  version: '0'
55
41
  description: Gretel is a Ruby on Rails plugin that makes it easy yet flexible to create
@@ -60,8 +46,8 @@ executables: []
60
46
  extensions: []
61
47
  extra_rdoc_files: []
62
48
  files:
63
- - .gitignore
64
- - .travis.yml
49
+ - ".gitignore"
50
+ - ".travis.yml"
65
51
  - CHANGELOG.md
66
52
  - Gemfile
67
53
  - LICENSE.txt
@@ -75,8 +61,10 @@ files:
75
61
  - lib/gretel/crumb.rb
76
62
  - lib/gretel/crumbs.rb
77
63
  - lib/gretel/deprecated.rb
64
+ - lib/gretel/deprecated/default_style_key.rb
78
65
  - lib/gretel/deprecated/layout.rb
79
66
  - lib/gretel/deprecated/show_root_alone.rb
67
+ - lib/gretel/deprecated/yield_links.rb
80
68
  - lib/gretel/link.rb
81
69
  - lib/gretel/renderer.rb
82
70
  - lib/gretel/resettable.rb
@@ -136,17 +124,17 @@ require_paths:
136
124
  - lib
137
125
  required_ruby_version: !ruby/object:Gem::Requirement
138
126
  requirements:
139
- - - '>='
127
+ - - ">="
140
128
  - !ruby/object:Gem::Version
141
129
  version: '0'
142
130
  required_rubygems_version: !ruby/object:Gem::Requirement
143
131
  requirements:
144
- - - '>='
132
+ - - ">="
145
133
  - !ruby/object:Gem::Version
146
134
  version: '0'
147
135
  requirements: []
148
136
  rubyforge_project:
149
- rubygems_version: 2.1.10
137
+ rubygems_version: 2.2.1
150
138
  signing_key:
151
139
  specification_version: 4
152
140
  summary: Flexible Ruby on Rails breadcrumbs plugin.