gretel 2.2.0.rc2 → 3.0.0.beta1

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: 63912baa8d7b8687330b6469ca18b82fef24a6d9
4
- data.tar.gz: 93e5d1939577261f3ee204f6874749c4675d4c41
3
+ metadata.gz: 7b08f97b7c16a830427f2ccf1968732cfec834b6
4
+ data.tar.gz: 2cbf78c43a72b8cb525a2485287c09c123672913
5
5
  SHA512:
6
- metadata.gz: 2d99b7fe134a685a49f6eb4b6d167ebe9e6c22134e2851fac27f3bee17159ab51bd5290a9647400a64b0a52470630e31305a62443469b29983e792036e0ed2ac
7
- data.tar.gz: f17fdfdc5ab2a03578230b8d5c00b48b3094a611234621facbba87448c96b896b202e6ddc102d275583d6fa725b144f427a1c0f6c12eec9168f2f57d09a3bc26
6
+ metadata.gz: cbd0cf33abb351a39e3fa7dcb723cce2ee75e8f3c219406ceb28bcecdd693f0adeb77ab4f92553d261545a38cde87c6bd801a059eb9702cd16bdf85a99c4bafc
7
+ data.tar.gz: 5c2af9e0cd84b039965fb1389f234dd778cd994e7c056f385cd274c6384e4203c275d3572220dd6b221e9fd0a9350a4bdb4e81fcb395222b386193afdb911599
data/CHANGELOG.md CHANGED
@@ -1,8 +1,9 @@
1
1
  Changelog
2
2
  =========
3
3
 
4
- Version 2.2
4
+ Version 3.0
5
5
  -----------
6
+ * Support for `Gretel::Crumbs.layout do ... end` in an initializer has been removed. See the readme for details on how to upgrade.
6
7
  * Support for setting trails via the URL – `params[:trail]`. This makes it possible to link to a different breadcrumb trail than the one specified in your breadcrumb,
7
8
  for example if you have a store with products that have a default parent to their category, but when linking from the review section, you want to link back to the reviews instead.
8
9
  See the readme for more info.
data/README.md CHANGED
@@ -68,8 +68,8 @@ At the top of *app/views/issues/show.html.erb*, set the current breadcrumb (assu
68
68
  Then, in *app/views/layouts/application.html.erb*:
69
69
 
70
70
  ```erb
71
- <%= breadcrumbs :pretext => "You are here: ",
72
- :separator => " &rsaquo; " %>
71
+ <%= breadcrumbs pretext: "You are here: ",
72
+ separator: " &rsaquo; " %>
73
73
  ```
74
74
 
75
75
  This will generate the following HTML (indented for readability):
@@ -86,13 +86,14 @@ This will generate the following HTML (indented for readability):
86
86
  Options
87
87
  -------
88
88
 
89
- You can pass options to `<%= breadcrumbs %>`, e.g. `<%= breadcrumbs :pretext => "You are here: " %>`:
89
+ You can pass options to `<%= breadcrumbs %>`, e.g. `<%= breadcrumbs pretext: "You are here: " %>`:
90
90
 
91
91
  Option | Description | Default
92
92
  ---------------- | -------------------------------------------------------------------------------------------------------------------------- | -------
93
- :pretext | Text to be rendered before breadcrumb, e.g. `"You are here: "` | None
94
- :posttext | Text to be appended after breadcrumb, e.g. `"Text after breacrumb"` | None
95
- :separator | Separator between links, e.g. `" &rsaquo; "` | `" &gt; "`
93
+ :style | How to render the breadcrumbs. Can be `:default`, `:ol`, `:ul`, or `:bootstrap`. See below for more info. | `:default`
94
+ :pretext | Text to be rendered before breadcrumb, e.g. `"You are here: "`. | None
95
+ :posttext | Text to be appended after breadcrumb, e.g. `"Text after breacrumb"`, | None
96
+ :separator | Separator between links, e.g. `" &rsaquo; "`. | `" &rsaquo; "`
96
97
  :autoroot | Whether it should automatically link to the `:root` crumb if no parent is given. | True
97
98
  :show_root_alone | Whether it should show `:root` if that is the only link. | False
98
99
  :link_current | Whether the current crumb should be linked to. | False
@@ -101,6 +102,21 @@ Option | Description
101
102
  :class | CSS class for the breadcrumbs container. | `"breadcrumbs"`
102
103
  :current_class | CSS class for the current link or span. | `"current"`
103
104
 
105
+ ### Styles
106
+
107
+ These are the styles you can use with `breadcrumb style: :xx`.
108
+
109
+ Style | Description
110
+ ------------ | -----------
111
+ `:default` | Renders each link by itself with `&rsaquo` as the seperator.
112
+ `:ol` | Renders the links in `<li>` elements contained in an outer `<ol>`.
113
+ `:ul` | Renders the links in `<li>` elements contained in an outer `<ul>`.
114
+ `:bootstrap` | Renders the links for use in [Twitter Bootstrap](http://getbootstrap.com/).
115
+
116
+ Or you can build the breadcrumbs manually for full customization; see below.
117
+
118
+ If you add other widely used styles, please submit a [Pull Request](https://github.com/lassebunk/gretel/pulls) so others can use them too.
119
+
104
120
  More examples
105
121
  -------------
106
122
 
@@ -155,7 +171,7 @@ end
155
171
  # match the user's actual navigation path
156
172
  # URL: /products/123?q=my+search
157
173
  crumb :search do |keyword|
158
- link "Search for #{keyword}", search_path(:q => keyword)
174
+ link "Search for #{keyword}", search_path(q: keyword)
159
175
  end
160
176
 
161
177
  crumb :product do |product|
@@ -277,11 +293,11 @@ Since Gretel version 2.1.0, the breadcrumb configuration files are now reloaded
277
293
 
278
294
  Upgrading from version 2.0 or below
279
295
  -----------------------------------
296
+
280
297
  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).
281
298
  In the Rails development environment, these files are automatically reloaded when changed.
282
299
 
283
- Using the initializer (e.g. `config/initializers/breadcrumbs.rb`) is deprecated but still supported until Gretel version 3.0.
284
- If you want to silence the deprecation warning until you upgrade, you can set `Gretel.suppress_deprecation_warnings = true` before the layout block in your initializer.
300
+ Using the initializer (e.g. `config/initializers/breadcrumbs.rb`) was deprecated in Gretel version 2.1.0 and removed in version 3.0. It raises an error if you try to use it.
285
301
 
286
302
  To update to the latest version of Gretel, use `bundle update gretel`. Then remove the `Gretel::Crumbs.layout do ... end` block, so instead of:
287
303
 
data/Rakefile CHANGED
@@ -7,4 +7,4 @@ Rake::TestTask.new do |t|
7
7
  t.verbose = true
8
8
  end
9
9
 
10
- task :default => :test
10
+ task default: :test
data/lib/gretel.rb CHANGED
@@ -3,6 +3,7 @@ require 'gretel/crumbs'
3
3
  require 'gretel/crumb'
4
4
  require 'gretel/link'
5
5
  require 'gretel/trail'
6
+ require 'gretel/renderer'
6
7
  require 'gretel/view_helpers'
7
8
  require 'gretel/deprecated'
8
9
 
data/lib/gretel/crumbs.rb CHANGED
@@ -20,9 +20,6 @@ module Gretel
20
20
  def load_breadcrumbs
21
21
  @crumbs = {}
22
22
 
23
- # Deprecated in v2.1.0.
24
- instance_eval &deprecated_breadcrumbs_block
25
-
26
23
  loaded_file_mtimes.clear
27
24
  breadcrumb_files.each do |file|
28
25
  instance_eval open(file).read, file
@@ -2,7 +2,8 @@ module Gretel
2
2
  module Crumbs
3
3
  class << self
4
4
  # Lay out the breadcrumbs.
5
- # Deprecated since v2.1.0. Put breadcrumbs in +config/breadcrumbs.rb+ instead (see https://github.com/lassebunk/gretel/blob/master/README.md for details).
5
+ # Deprecated since v2.1.0 and removed in v3.0.0.
6
+ # Put breadcrumbs in +config/breadcrumbs.rb+ instead (see https://github.com/lassebunk/gretel/blob/master/README.md for details).
6
7
  #
7
8
  # Example:
8
9
  # Gretel::Crumbs.layout do
@@ -11,16 +12,11 @@ module Gretel
11
12
  # end
12
13
  # end
13
14
  def layout(&block)
14
- Gretel.show_deprecation_warning(
15
- "Gretel::Crumbs.layout has been deprecated and will be removed in Gretel version 3.0. " +
15
+ raise (
16
+ "Gretel::Crumbs.layout has been deprecated was removed in Gretel version 3.0. " +
16
17
  "Please put your breadcrumbs in `config/breadcrumbs.rb`. " +
17
18
  "This will also automatically reload your breadcrumbs when you change them in the development environment. " +
18
19
  "See https://github.com/lassebunk/gretel/blob/master/README.md for details.")
19
- @deprecated_breadcrumbs_block = block
20
- end
21
-
22
- def deprecated_breadcrumbs_block
23
- @deprecated_breadcrumbs_block ||= Proc.new {}
24
20
  end
25
21
  end
26
22
  end
@@ -0,0 +1,193 @@
1
+ module Gretel
2
+ class Renderer
3
+ DEFAULT_OPTIONS = {
4
+ style: :default,
5
+ pretext: "",
6
+ posttext: "",
7
+ separator: "",
8
+ autoroot: true,
9
+ show_root_alone: false,
10
+ link_current: false,
11
+ semantic: false,
12
+ class: "breadcrumbs",
13
+ current_class: "current",
14
+ id: nil
15
+ }
16
+
17
+ STYLES = {
18
+ # Default style
19
+ default: { container_tag: :div, separator: " &rsaquo; " },
20
+
21
+ # Ordered list
22
+ ol: { container_tag: :ol, fragment_tag: :li },
23
+
24
+ # Unordered list
25
+ ul: { container_tag: :ul, fragment_tag: :li },
26
+
27
+ # Twitter Bootstrap
28
+ bootstrap: { container_tag: :ol, fragment_tag: :li, class: "breadcrumb", current_class: "active" }
29
+ }
30
+
31
+ def initialize(context, breadcrumb_key, *breadcrumb_args)
32
+ @context = context
33
+ @breadcrumb_key = breadcrumb_key
34
+ @breadcrumb_args = breadcrumb_args
35
+ end
36
+
37
+ # Renders the breadcrumbs HTML.
38
+ def render(options)
39
+ options = options_for_render(options)
40
+ links = links_for_render(options)
41
+
42
+ return "" if links.empty?
43
+
44
+ # Array to hold the HTML fragments
45
+ fragments = []
46
+
47
+ # Loop through all but the last (current) link and build HTML of the fragments
48
+ links[0..-2].each do |link|
49
+ fragments << render_fragment(options[:fragment_tag], link.text, link.url, options[:semantic])
50
+ end
51
+
52
+ # The current link is handled a little differently, and is only linked if specified in the options
53
+ current_link = links.last
54
+ fragments << render_fragment(options[:fragment_tag], current_link.text, (options[:link_current] ? current_link.url : nil), options[:semantic], class: options[:current_class])
55
+
56
+ # Build the final HTML
57
+ html = (options[:pretext] + fragments.join(options[:separator]) + options[:posttext]).html_safe
58
+ content_tag(options[:container_tag], html, id: options[:id], class: options[:class])
59
+ end
60
+
61
+ # Yields an array of links to be used in a view.
62
+ def yield_links(options = {}, &block)
63
+ options = options_for_render(options)
64
+ yield links_for_render(options)
65
+ end
66
+
67
+ # Returns encoded trail for the breadcrumb.
68
+ def trail
69
+ @trail ||= Gretel::Trail.encode(links)
70
+ end
71
+
72
+ private
73
+
74
+ attr_reader :context, :breadcrumb_key, :breadcrumb_args
75
+
76
+ def options_for_render(options = {})
77
+ style = options_for_style(options[:style] || DEFAULT_OPTIONS[:style])
78
+ DEFAULT_OPTIONS.merge(style).merge(options)
79
+ end
80
+
81
+ # Returns options for the given +style_key+ and raises an exception if it's not found.
82
+ def options_for_style(style_key)
83
+ if style = STYLES[style_key]
84
+ style
85
+ else
86
+ raise ArgumentError, "Breadcrumbs style #{style_key.inspect} not found. Use any of #{STYLES.keys.inspect}."
87
+ end
88
+ end
89
+
90
+ # Array of links for the path of the breadcrumb.
91
+ # Also reloads the breadcrumb configuration if needed.
92
+ def links
93
+ return [] if @breadcrumb_key.blank?
94
+
95
+ @links ||= begin
96
+ # Reload breadcrumbs configuration if needed
97
+ Gretel::Crumbs.reload_if_needed
98
+
99
+ # Get breadcrumb set by the `breadcrumb` method
100
+ crumb = Gretel::Crumb.new(self, breadcrumb_key, *breadcrumb_args)
101
+
102
+ # Links of first crumb
103
+ links = crumb.links.dup
104
+
105
+ links.last.tap do |last|
106
+ last.url = request.try(:fullpath) || last.url
107
+ end
108
+
109
+ # Get trail
110
+ links.unshift *trail_for(crumb)
111
+
112
+ links
113
+ end
114
+ end
115
+
116
+ # Returns parent links for the crumb, or the trail from `params[:trail]` if it is set.
117
+ def trail_for(crumb)
118
+ if params[Gretel::Trail.trail_param].present?
119
+ # Decode trail from URL
120
+ Gretel::Trail.decode(params[Gretel::Trail.trail_param])
121
+ else
122
+ # Build parents
123
+ links = []
124
+ while crumb = crumb.parent
125
+ links.unshift *crumb.links
126
+ end
127
+ links
128
+ end
129
+ end
130
+
131
+ # Array of links with applied options.
132
+ def links_for_render(options = {})
133
+ out = links.dup
134
+
135
+ # Handle autoroot
136
+ if options[:autoroot] && out.map(&:key).exclude?(:root) && Gretel::Crumbs.crumb_defined?(:root)
137
+ out.unshift *Gretel::Crumb.new(self, :root).links
138
+ end
139
+
140
+ # Handle show root alone
141
+ if out.count == 1 && out.first.key == :root && !options[:show_root_alone]
142
+ out.shift
143
+ end
144
+
145
+ out
146
+ end
147
+
148
+ # Renders HTML for a breadcrumb fragment, i.e. a breadcrumb link.
149
+ def render_fragment(fragment_tag, text, url, semantic, options = {})
150
+ if semantic
151
+ render_semantic_fragment(fragment_tag, text, url, options)
152
+ else
153
+ render_nonsemantic_fragment(fragment_tag, text, url, options)
154
+ end
155
+ end
156
+
157
+ # Renders semantic fragment HTML.
158
+ def render_semantic_fragment(fragment_tag, text, url, options = {})
159
+ if fragment_tag
160
+ text = content_tag(:span, text, itemprop: "title")
161
+ text = link_to(text, url, itemprop: "url") if url.present?
162
+ content_tag(fragment_tag, text, class: options[:class], itemscope: "", itemtype: "http://data-vocabulary.org/Breadcrumb")
163
+ else
164
+ if url.present?
165
+ content_tag(:div, link_to(content_tag(:span, text, itemprop: "title"), url, class: options[:class], itemprop: "url"), itemscope: "", itemtype: "http://data-vocabulary.org/Breadcrumb")
166
+ else
167
+ content_tag(:div, content_tag(:span, text, class: options[:class], itemprop: "title"), itemscope: "", itemtype: "http://data-vocabulary.org/Breadcrumb")
168
+ end
169
+ end
170
+ end
171
+
172
+ # Renders regular, non-semantic fragment HTML.
173
+ def render_nonsemantic_fragment(fragment_tag, text, url, options = {})
174
+ if fragment_tag
175
+ text = link_to(text, url) if url.present?
176
+ content_tag(fragment_tag, text, class: options[:class])
177
+ else
178
+ if url.present?
179
+ 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
+ end
187
+
188
+ # Proxy to view context
189
+ def method_missing(method, *args, &block)
190
+ context.send(method, *args, &block)
191
+ end
192
+ end
193
+ end
data/lib/gretel/trail.rb CHANGED
@@ -47,7 +47,7 @@ module Gretel
47
47
 
48
48
  private
49
49
 
50
- # Encodes links array to Base64, internally using YAML for serialization.
50
+ # Encodes links array to Base64, internally using JSON for serialization.
51
51
  def encode_base64(links)
52
52
  arr = links.map { |link| [link.key, link.text, link.url] }
53
53
  Base64.urlsafe_encode64(arr.to_json)
@@ -1,3 +1,3 @@
1
1
  module Gretel
2
- VERSION = "2.2.0.rc2"
2
+ VERSION = "3.0.0.beta1"
3
3
  end
@@ -4,21 +4,12 @@ module Gretel
4
4
  # <%
5
5
  # breadcrumb :category, @category
6
6
  # %>
7
- def breadcrumb(*args)
8
- options = args.extract_options!
9
-
10
- if args.any?
11
- @_breadcrumb_key = args.shift
12
- @_breadcrumb_args = args
13
- @_breadcrumb_links = nil
14
- @_breadcrumb_trail = nil
15
- else
16
- breadcrumbs(options)
17
- end
7
+ def breadcrumb(key, *args)
8
+ @_gretel_renderer = Gretel::Renderer.new(self, key, *args)
18
9
  end
19
10
 
20
11
  # Renders the breadcrumbs HTML, for example in your layout. See the readme for default options.
21
- # <%= breadcrumbs :pretext => "You are here: " %>
12
+ # <%= breadcrumbs pretext: "You are here: " %>
22
13
  #
23
14
  # If you supply a block, it will yield an array with the breadcrumb links so you can build the breadcrumbs HTML manually:
24
15
  # <% breadcrumbs do |links| %>
@@ -29,124 +20,22 @@ module Gretel
29
20
  # <% end %>
30
21
  # <% end %>
31
22
  # <% end %>
32
- def breadcrumbs(options = {})
33
- options = default_breadcrumb_options.merge(options)
34
- links = breadcrumb_links_for_render(options)
23
+ def breadcrumbs(options = {}, &block)
35
24
  if block_given?
36
- yield links
25
+ gretel_renderer.yield_links(options, &block)
37
26
  else
38
- render_breadcrumbs(links, options)
27
+ gretel_renderer.render(options)
39
28
  end
40
29
  end
41
30
 
42
31
  def breadcrumb_trail
43
- @_breadcrumb_trail ||= Gretel::Trail.encode(breadcrumb_links)
32
+ gretel_renderer.trail
44
33
  end
45
34
 
46
35
  private
47
36
 
48
- def breadcrumb_links
49
- @_breadcrumb_links ||= begin
50
- Gretel::Crumbs.reload_if_needed
51
- get_breadcrumb_links
52
- end
53
- end
54
-
55
- def breadcrumb_links_for_render(options = {})
56
- links = breadcrumb_links.dup
57
-
58
- # Handle autoroot
59
- if options[:autoroot] && links.map(&:key).exclude?(:root) && Gretel::Crumbs.crumb_defined?(:root)
60
- links.unshift *Gretel::Crumb.new(self, :root).links
61
- end
62
-
63
- # Handle show root alone
64
- if links.count == 1 && links.first.key == :root && !options[:show_root_alone]
65
- links.shift
66
- end
67
-
68
- links
69
- end
70
-
71
- # Returns an array of links for the path of the breadcrumb set by +breadcrumb+.
72
- def get_breadcrumb_links
73
- return [] if @_breadcrumb_key.blank?
74
-
75
- # Get breadcrumb set by the `breadcrumb` method
76
- crumb = Gretel::Crumb.new(self, @_breadcrumb_key, *@_breadcrumb_args)
77
-
78
- # Links of first crumb
79
- links = crumb.links.dup
80
-
81
- links.last.tap do |last|
82
- last.url = request.try(:fullpath) || last.url
83
- end
84
-
85
- if params[Gretel::Trail.trail_param].present?
86
- # Decode trail from URL
87
- links.unshift *Gretel::Trail.decode(params[Gretel::Trail.trail_param])
88
- else
89
- # Build parents
90
- while crumb = crumb.parent
91
- links.unshift *crumb.links
92
- end
93
- end
94
-
95
- links
96
- end
97
-
98
- # Renders breadcrumbs HTML.
99
- def render_breadcrumbs(links, options)
100
- return "" if links.empty?
101
-
102
- # Array to hold the HTML fragments
103
- fragments = []
104
-
105
- # Loop through all but the last (current) link and build HTML of the fragments
106
- links[0..-2].each do |link|
107
- fragments << render_breadcrumb_fragment(link.text, link.url, options[:semantic])
108
- end
109
-
110
- # The current link is handled a little differently, and is only linked if specified in the options
111
- current_link = links.last
112
- fragments << render_breadcrumb_fragment(current_link.text, (options[:link_current] ? current_link.url : nil), options[:semantic], :class => options[:current_class])
113
-
114
- # Build the final HTML
115
- html = (options[:pretext] + fragments.join(options[:separator]) + options[:posttext]).html_safe
116
- content_tag(:div, html, :id => options[:id], :class => options[:class])
117
- end
118
-
119
- # Renders HTML for a breadcrumb fragment, i.e. a breadcrumb link.
120
- def render_breadcrumb_fragment(text, url, semantic, options = {})
121
- if semantic
122
- if url.present?
123
- content_tag(:div, link_to(content_tag(:span, text, :itemprop => "title"), url, :class => options[:class], :itemprop => "url"), :itemscope => "", :itemtype => "http://data-vocabulary.org/Breadcrumb")
124
- else
125
- content_tag(:div, content_tag(:span, text, :class => options[:class], :itemprop => "title"), :itemscope => "", :itemtype => "http://data-vocabulary.org/Breadcrumb")
126
- end
127
- else
128
- if url.present?
129
- link_to(text, url, :class => options[:class])
130
- elsif options[:class]
131
- content_tag(:span, text, :class => options[:class])
132
- else
133
- text
134
- end
135
- end
136
- end
137
-
138
- # Default options for the breadcrumb rendering.
139
- def default_breadcrumb_options
140
- { :pretext => "",
141
- :posttext => "",
142
- :separator => " &gt; ",
143
- :autoroot => true,
144
- :show_root_alone => false,
145
- :link_current => false,
146
- :semantic => false,
147
- :class => "breadcrumbs",
148
- :current_class => "current",
149
- :id => nil }
37
+ def gretel_renderer
38
+ @_gretel_renderer ||= Gretel::Renderer.new(self, nil)
150
39
  end
151
40
  end
152
41
  end
@@ -10,21 +10,9 @@ class DeprecatedTest < ActionView::TestCase
10
10
  end
11
11
 
12
12
  test "deprecated configuration block" do
13
- Gretel.suppress_deprecation_warnings = true
14
-
15
- Gretel::Crumbs.layout do
16
- crumb :deprecated_parent do
17
- link "Test deprecated", root_path
18
- end
19
-
20
- crumb :deprecated_child do
21
- link "Child", about_path
22
- parent :deprecated_parent
13
+ assert_raises RuntimeError do
14
+ Gretel::Crumbs.layout do
23
15
  end
24
16
  end
25
-
26
- breadcrumb :deprecated_child
27
- assert_equal %{<div class="breadcrumbs"><a href="/">Test deprecated</a> &gt; <span class="current">Child</span></div>},
28
- breadcrumbs(:autoroot => false)
29
17
  end
30
18
  end
@@ -1,6 +1,6 @@
1
1
  # Be sure to restart your server when you modify this file.
2
2
 
3
- Dummy::Application.config.session_store :cookie_store, :key => '_dummy_session'
3
+ Dummy::Application.config.session_store :cookie_store, key: '_dummy_session'
4
4
 
5
5
  # Use the database for sessions instead of the cookie-based default,
6
6
  # which shouldn't be used to store highly confidential information
@@ -5,7 +5,7 @@
5
5
 
6
6
  # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
7
7
  ActiveSupport.on_load(:action_controller) do
8
- wrap_parameters :format => [:json]
8
+ wrap_parameters format: [:json]
9
9
  end
10
10
 
11
11
  # Disable root element in JSON by default.
@@ -1,9 +1,9 @@
1
1
  Dummy::Application.routes.draw do
2
- root :to => "dummy#dummy"
2
+ root to: "dummy#dummy"
3
3
 
4
- match "about" => "dummy#dummy", :as => :about
5
- match "about/contact" => "dummy#dummy", :as => :contact
6
- match "about/contact/form" => "dummy#dummy", :as => :contact_form
4
+ match "about" => "dummy#dummy", as: :about
5
+ match "about/contact" => "dummy#dummy", as: :contact
6
+ match "about/contact/form" => "dummy#dummy", as: :contact_form
7
7
 
8
8
  resources :projects do
9
9
  resources :issues
@@ -11,19 +11,19 @@
11
11
  #
12
12
  # It's strongly recommended to check this file into your version control system.
13
13
 
14
- ActiveRecord::Schema.define(:version => 20130122163051) do
14
+ ActiveRecord::Schema.define(version: 20130122163051) do
15
15
 
16
- create_table "issues", :force => true do |t|
16
+ create_table "issues", force: true do |t|
17
17
  t.string "title"
18
18
  t.integer "project_id"
19
- t.datetime "created_at", :null => false
20
- t.datetime "updated_at", :null => false
19
+ t.datetime "created_at", null: false
20
+ t.datetime "updated_at", null: false
21
21
  end
22
22
 
23
- create_table "projects", :force => true do |t|
23
+ create_table "projects", force: true do |t|
24
24
  t.string "name"
25
- t.datetime "created_at", :null => false
26
- t.datetime "updated_at", :null => false
25
+ t.datetime "created_at", null: false
26
+ t.datetime "updated_at", null: false
27
27
  end
28
28
 
29
29
  end
@@ -10,52 +10,54 @@ class HelperMethodsTest < ActionView::TestCase
10
10
  Gretel::Trail.secret = "128107d341e912db791d98bbe874a8250f784b0a0b4dbc5d5032c0fc1ca7bda9c6ece667bd18d23736ee833ea79384176faeb54d2e0d21012898dde78631cdf1"
11
11
  end
12
12
 
13
+ # Breadcrumb generation
14
+
13
15
  test "shows basic breadcrumb" do
14
16
  breadcrumb :basic
15
- assert_equal %{<div class="breadcrumbs"><a href="/">Home</a> &gt; <span class="current">About</span></div>},
17
+ assert_equal %{<div class="breadcrumbs"><a href="/">Home</a> &rsaquo; <span class="current">About</span></div>},
16
18
  breadcrumbs
17
19
  end
18
20
 
19
21
  test "shows breadcrumb with root" do
20
22
  breadcrumb :with_root
21
- assert_equal %{<div class="breadcrumbs"><a href="/">Home</a> &gt; <span class="current">About</span></div>},
23
+ assert_equal %{<div class="breadcrumbs"><a href="/">Home</a> &rsaquo; <span class="current">About</span></div>},
22
24
  breadcrumbs
23
25
  end
24
26
 
25
27
  test "shows breadcrumb with parent" do
26
28
  breadcrumb :with_parent
27
- assert_equal %{<div class="breadcrumbs"><a href="/">Home</a> &gt; <a href="/about">About</a> &gt; <span class="current">Contact</span></div>},
29
+ assert_equal %{<div class="breadcrumbs"><a href="/">Home</a> &rsaquo; <a href="/about">About</a> &rsaquo; <span class="current">Contact</span></div>},
28
30
  breadcrumbs
29
31
  end
30
32
 
31
33
  test "shows breadcrumb with autopath" do
32
34
  breadcrumb :with_autopath, projects(:one)
33
- assert_equal %{<div class="breadcrumbs"><a href="/">Home</a> &gt; <span class="current">Test Project</span></div>},
35
+ assert_equal %{<div class="breadcrumbs"><a href="/">Home</a> &rsaquo; <span class="current">Test Project</span></div>},
34
36
  breadcrumbs
35
37
  end
36
38
 
37
39
  test "shows breadcrumb with parent object" do
38
40
  breadcrumb :with_parent_object, issues(:one)
39
- assert_equal %{<div class="breadcrumbs"><a href="/">Home</a> &gt; <a href="/projects/1">Test Project</a> &gt; <span class="current">Test Issue</span></div>},
41
+ 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>},
40
42
  breadcrumbs
41
43
  end
42
44
 
43
45
  test "shows multiple links" do
44
46
  breadcrumb :multiple_links
45
- assert_equal %{<div class="breadcrumbs"><a href="/">Home</a> &gt; <a href="/about/contact">Contact</a> &gt; <span class="current">Contact form</span></div>},
47
+ assert_equal %{<div class="breadcrumbs"><a href="/">Home</a> &rsaquo; <a href="/about/contact">Contact</a> &rsaquo; <span class="current">Contact form</span></div>},
46
48
  breadcrumbs
47
49
  end
48
50
 
49
51
  test "shows multiple links with parent" do
50
52
  breadcrumb :multiple_links_with_parent
51
- assert_equal %{<div class="breadcrumbs"><a href="/">Home</a> &gt; <a href="/about">About</a> &gt; <a href="/about/contact">Contact</a> &gt; <span class="current">Contact form</span></div>},
53
+ 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>},
52
54
  breadcrumbs
53
55
  end
54
56
 
55
57
  test "shows semantic breadcrumb" do
56
58
  breadcrumb :with_root
57
- assert_equal %{<div class="breadcrumbs"><div itemscope="" itemtype="http://data-vocabulary.org/Breadcrumb"><a href="/" itemprop="url"><span itemprop="title">Home</span></a></div> &gt; <div itemscope="" itemtype="http://data-vocabulary.org/Breadcrumb"><span class="current" itemprop="title">About</span></div></div>},
58
- breadcrumbs(:semantic => true)
59
+ 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>},
60
+ breadcrumbs(semantic: true)
59
61
  end
60
62
 
61
63
  test "doesn't show root alone" do
@@ -66,7 +68,7 @@ class HelperMethodsTest < ActionView::TestCase
66
68
  test "shows root alone" do
67
69
  breadcrumb :root
68
70
  assert_equal %{<div class="breadcrumbs"><span class="current">Home</span></div>},
69
- breadcrumbs(:show_root_alone => true)
71
+ breadcrumbs(show_root_alone: true)
70
72
  end
71
73
 
72
74
  test "shows no breadcrumb" do
@@ -75,70 +77,64 @@ class HelperMethodsTest < ActionView::TestCase
75
77
 
76
78
  test "links current breadcrumb" do
77
79
  breadcrumb :with_root
78
- assert_equal %{<div class="breadcrumbs"><a href="/">Home</a> &gt; <a href="/about" class="current">About</a></div>},
79
- breadcrumbs(:link_current => true)
80
+ assert_equal %{<div class="breadcrumbs"><a href="/">Home</a> &rsaquo; <a href="/about" class="current">About</a></div>},
81
+ breadcrumbs(link_current: true)
80
82
  end
81
83
 
82
84
  test "shows pretext" do
83
85
  breadcrumb :basic
84
- assert_equal %{<div class="breadcrumbs">You are here: <a href="/">Home</a> &gt; <span class="current">About</span></div>},
85
- breadcrumbs(:pretext => "You are here: ")
86
+ assert_equal %{<div class="breadcrumbs">You are here: <a href="/">Home</a> &rsaquo; <span class="current">About</span></div>},
87
+ breadcrumbs(pretext: "You are here: ")
86
88
  end
87
89
 
88
90
  test "shows posttext" do
89
91
  breadcrumb :basic
90
- assert_equal %{<div class="breadcrumbs"><a href="/">Home</a> &gt; <span class="current">About</span> - text after breadcrumbs</div>},
91
- breadcrumbs(:posttext => " - text after breadcrumbs")
92
+ assert_equal %{<div class="breadcrumbs"><a href="/">Home</a> &rsaquo; <span class="current">About</span> - text after breadcrumbs</div>},
93
+ breadcrumbs(posttext: " - text after breadcrumbs")
92
94
  end
93
95
 
94
96
  test "autoroot disabled" do
95
97
  breadcrumb :basic
96
98
  assert_equal %{<div class="breadcrumbs"><span class="current">About</span></div>},
97
- breadcrumbs(:autoroot => false)
99
+ breadcrumbs(autoroot: false)
98
100
  end
99
101
 
100
102
  test "shows separator" do
101
103
  breadcrumb :with_root
102
- assert_equal %{<div class="breadcrumbs"><a href="/">Home</a> &rsaquo; <span class="current">About</span></div>},
103
- breadcrumbs(:separator => " &rsaquo; ")
104
+ assert_equal %{<div class="breadcrumbs"><a href="/">Home</a> &raquo; <span class="current">About</span></div>},
105
+ breadcrumbs(separator: " &raquo; ")
104
106
  end
105
107
 
106
108
  test "shows element id" do
107
109
  breadcrumb :basic
108
- assert_equal %{<div class="breadcrumbs" id="custom_id"><a href="/">Home</a> &gt; <span class="current">About</span></div>},
109
- breadcrumbs(:id => "custom_id")
110
+ assert_equal %{<div class="breadcrumbs" id="custom_id"><a href="/">Home</a> &rsaquo; <span class="current">About</span></div>},
111
+ breadcrumbs(id: "custom_id")
110
112
  end
111
113
 
112
114
  test "shows custom container class" do
113
115
  breadcrumb :basic
114
- assert_equal %{<div class="custom_class"><a href="/">Home</a> &gt; <span class="current">About</span></div>},
115
- breadcrumbs(:class => "custom_class")
116
+ assert_equal %{<div class="custom_class"><a href="/">Home</a> &rsaquo; <span class="current">About</span></div>},
117
+ breadcrumbs(class: "custom_class")
116
118
  end
117
119
 
118
120
  test "shows custom current class" do
119
121
  breadcrumb :basic
120
- assert_equal %{<div class="breadcrumbs"><a href="/">Home</a> &gt; <span class="custom_current_class">About</span></div>},
121
- breadcrumbs(:current_class => "custom_current_class")
122
+ assert_equal %{<div class="breadcrumbs"><a href="/">Home</a> &rsaquo; <span class="custom_current_class">About</span></div>},
123
+ breadcrumbs(current_class: "custom_current_class")
122
124
  end
123
125
 
124
126
  test "unsafe html" do
125
127
  breadcrumb :with_unsafe_html
126
- assert_equal %{<div class="breadcrumbs"><a href="/">Home</a> &gt; <span class="current">Test &lt;strong&gt;bold text&lt;/strong&gt;</span></div>},
128
+ assert_equal %{<div class="breadcrumbs"><a href="/">Home</a> &rsaquo; <span class="current">Test &lt;strong&gt;bold text&lt;/strong&gt;</span></div>},
127
129
  breadcrumbs
128
130
  end
129
131
 
130
132
  test "safe html" do
131
133
  breadcrumb :with_safe_html
132
- assert_equal %{<div class="breadcrumbs"><a href="/">Home</a> &gt; <span class="current">Test <strong>bold text</strong></span></div>},
134
+ assert_equal %{<div class="breadcrumbs"><a href="/">Home</a> &rsaquo; <span class="current">Test <strong>bold text</strong></span></div>},
133
135
  breadcrumbs
134
136
  end
135
137
 
136
- test "works with legacy breadcrumb rendering method" do
137
- breadcrumb :basic
138
- assert_equal %{<div class="breadcrumbs"><a href="/">Home</a> &gt; <span class="current">About</span></div>},
139
- breadcrumb
140
- end
141
-
142
138
  test "yields a block containing breadcrumb links array" do
143
139
  breadcrumb :multiple_links_with_parent
144
140
 
@@ -154,30 +150,77 @@ class HelperMethodsTest < ActionView::TestCase
154
150
 
155
151
  test "without link" do
156
152
  breadcrumb :without_link
157
- assert_equal %{<div class="breadcrumbs"><a href="/">Home</a> &gt; Also without link &gt; <span class="current">Without link</span></div>},
153
+ assert_equal %{<div class="breadcrumbs"><a href="/">Home</a> &rsaquo; Also without link &rsaquo; <span class="current">Without link</span></div>},
158
154
  breadcrumbs
159
155
  end
160
156
 
161
157
  test "view context" do
162
158
  breadcrumb :using_view_helper
163
- assert_equal %{<div class="breadcrumbs"><a href="/">Home</a> &gt; <span class="current">TestTest</span></div>},
159
+ assert_equal %{<div class="breadcrumbs"><a href="/">Home</a> &rsaquo; <span class="current">TestTest</span></div>},
164
160
  breadcrumbs
165
161
  end
166
162
 
167
163
  test "multiple arguments" do
168
164
  breadcrumb :with_multiple_arguments, "One", "Two", "Three"
169
- assert_equal %{<div class="breadcrumbs"><a href="/">Home</a> &gt; <a href="/about">First OneOne then TwoTwo then ThreeThree</a> &gt; <span class="current">One and Two and Three</span></div>},
170
- breadcrumb
165
+ 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>},
166
+ breadcrumbs
171
167
  end
172
168
 
173
169
  test "calling breadcrumbs helper twice" do
174
170
  breadcrumb :with_parent
175
171
  2.times do
176
- assert_equal %{<div class="breadcrumbs"><a href="/">Home</a> &gt; <a href="/about">About</a> &gt; <span class="current">Contact</span></div>},
172
+ assert_equal %{<div class="breadcrumbs"><a href="/">Home</a> &rsaquo; <a href="/about">About</a> &rsaquo; <span class="current">Contact</span></div>},
177
173
  breadcrumbs
178
174
  end
179
175
  end
180
176
 
177
+ # Styles
178
+
179
+ test "default style" do
180
+ breadcrumb :basic
181
+ assert_equal %{<div class="breadcrumbs"><a href="/">Home</a> &rsaquo; <span class="current">About</span></div>},
182
+ breadcrumbs
183
+ end
184
+
185
+ test "ordered list style" do
186
+ breadcrumb :basic
187
+ assert_equal %{<ol class="breadcrumbs"><li><a href="/">Home</a></li><li class="current">About</li></ol>},
188
+ breadcrumbs(style: :ol)
189
+ end
190
+
191
+ test "unordered list style" do
192
+ breadcrumb :basic
193
+ assert_equal %{<ul class="breadcrumbs"><li><a href="/">Home</a></li><li class="current">About</li></ul>},
194
+ breadcrumbs(style: :ul)
195
+ end
196
+
197
+ test "bootstrap style" do
198
+ breadcrumb :basic
199
+ assert_equal %{<ol class="breadcrumb"><li><a href="/">Home</a></li><li class="active">About</li></ol>},
200
+ breadcrumbs(style: :bootstrap)
201
+ end
202
+
203
+ test "custom container and fragment tags" do
204
+ breadcrumb :basic
205
+ assert_equal %{<c class="breadcrumbs"><f><a href="/">Home</a></f> &rsaquo; <f class="current">About</f></c>},
206
+ breadcrumbs(container_tag: :c, fragment_tag: :f)
207
+ end
208
+
209
+ test "custom semantic container and fragment tags" do
210
+ breadcrumb :basic
211
+ 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>},
212
+ breadcrumbs(container_tag: :c, fragment_tag: :f, semantic: true)
213
+ end
214
+
215
+ test "unknown style" do
216
+ breadcrumb :basic
217
+ assert_raises ArgumentError do
218
+ breadcrumbs(style: :nonexistent)
219
+ end
220
+ end
221
+
222
+ # Trails
223
+
181
224
  test "trail helper" do
182
225
  breadcrumb :basic
183
226
 
@@ -188,7 +231,7 @@ class HelperMethodsTest < ActionView::TestCase
188
231
  params[:trail] = "12MoG3DY5eLzU_W1siYmFzaWMiLCJBYm91dCIsIi9hYm91dCJdXQ=="
189
232
  breadcrumb :multiple_links
190
233
 
191
- assert_equal %{<div class="breadcrumbs"><a href="/">Home</a> &gt; <a href="/about">About</a> &gt; <a href="/about/contact">Contact</a> &gt; <span class="current">Contact form</span></div>},
234
+ 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>},
192
235
  breadcrumbs
193
236
  end
194
237
 
@@ -197,10 +240,12 @@ class HelperMethodsTest < ActionView::TestCase
197
240
  params[:mytest] = "12MoG3DY5eLzU_W1siYmFzaWMiLCJBYm91dCIsIi9hYm91dCJdXQ=="
198
241
  breadcrumb :multiple_links
199
242
 
200
- assert_equal %{<div class="breadcrumbs"><a href="/">Home</a> &gt; <a href="/about">About</a> &gt; <a href="/about/contact">Contact</a> &gt; <span class="current">Contact form</span></div>},
243
+ 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>},
201
244
  breadcrumbs
202
245
  end
203
246
 
247
+ # Configuration reload
248
+
204
249
  test "reload configuration when file is changed" do
205
250
  path = setup_loading_from_tmp_folder
206
251
  Gretel.reload_environments << "test"
@@ -217,7 +262,7 @@ class HelperMethodsTest < ActionView::TestCase
217
262
  end
218
263
 
219
264
  breadcrumb :about
220
- assert_equal %{<div class="breadcrumbs"><a href="/">Home (loaded)</a> &gt; <span class="current">About (loaded)</span></div>}, breadcrumbs
265
+ assert_equal %{<div class="breadcrumbs"><a href="/">Home (loaded)</a> &rsaquo; <span class="current">About (loaded)</span></div>}, breadcrumbs
221
266
 
222
267
  sleep 1 # File change interval is 1 second
223
268
 
@@ -233,7 +278,7 @@ class HelperMethodsTest < ActionView::TestCase
233
278
  end
234
279
 
235
280
  breadcrumb :about
236
- assert_equal %{<div class="breadcrumbs"><a href="/test">Home (reloaded)</a> &gt; <span class="current">About (reloaded)</span></div>}, breadcrumbs
281
+ assert_equal %{<div class="breadcrumbs"><a href="/test">Home (reloaded)</a> &rsaquo; <span class="current">About (reloaded)</span></div>}, breadcrumbs
237
282
  end
238
283
 
239
284
  test "reload configuration when file is added" do
@@ -262,7 +307,7 @@ class HelperMethodsTest < ActionView::TestCase
262
307
  end
263
308
 
264
309
  breadcrumb :about
265
- assert_equal %{<div class="breadcrumbs"><a href="/">Home (loaded)</a> &gt; <span class="current">About (loaded)</span></div>}, breadcrumbs
310
+ assert_equal %{<div class="breadcrumbs"><a href="/">Home (loaded)</a> &rsaquo; <span class="current">About (loaded)</span></div>}, breadcrumbs
266
311
  end
267
312
 
268
313
  test "reload configuration when file is deleted" do
@@ -290,7 +335,7 @@ class HelperMethodsTest < ActionView::TestCase
290
335
  end
291
336
 
292
337
  breadcrumb :contact
293
- assert_equal %{<div class="breadcrumbs"><a href="/">Home (loaded)</a> &gt; <a href="/about">About (loaded)</a> &gt; <span class="current">Contact (loaded)</span></div>}, breadcrumbs
338
+ 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
294
339
 
295
340
  File.delete path.join("pages.rb")
296
341
 
@@ -300,7 +345,7 @@ class HelperMethodsTest < ActionView::TestCase
300
345
  end
301
346
 
302
347
  breadcrumb :about
303
- assert_equal %{<div class="breadcrumbs"><a href="/">Home (loaded)</a> &gt; <span class="current">About (loaded)</span></div>}, breadcrumbs
348
+ assert_equal %{<div class="breadcrumbs"><a href="/">Home (loaded)</a> &rsaquo; <span class="current">About (loaded)</span></div>}, breadcrumbs
304
349
  end
305
350
 
306
351
  test "reloads only in development environment" do
@@ -320,7 +365,7 @@ class HelperMethodsTest < ActionView::TestCase
320
365
  end
321
366
 
322
367
  breadcrumb :about
323
- assert_equal %{<div class="breadcrumbs"><a href="/">Home (loaded)</a> &gt; <span class="current">About (loaded)</span></div>}, breadcrumbs
368
+ assert_equal %{<div class="breadcrumbs"><a href="/">Home (loaded)</a> &rsaquo; <span class="current">About (loaded)</span></div>}, breadcrumbs
324
369
 
325
370
  sleep 1
326
371
 
@@ -336,7 +381,7 @@ class HelperMethodsTest < ActionView::TestCase
336
381
  end
337
382
 
338
383
  breadcrumb :about
339
- assert_equal %{<div class="breadcrumbs"><a href="/">Home (loaded)</a> &gt; <span class="current">About (loaded)</span></div>}, breadcrumbs
384
+ assert_equal %{<div class="breadcrumbs"><a href="/">Home (loaded)</a> &rsaquo; <span class="current">About (loaded)</span></div>}, breadcrumbs
340
385
  end
341
386
 
342
387
  private
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: 2.2.0.rc2
4
+ version: 3.0.0.beta1
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 00:00:00.000000000 Z
11
+ date: 2013-10-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -62,6 +62,7 @@ files:
62
62
  - lib/gretel/crumbs.rb
63
63
  - lib/gretel/deprecated.rb
64
64
  - lib/gretel/link.rb
65
+ - lib/gretel/renderer.rb
65
66
  - lib/gretel/trail.rb
66
67
  - lib/gretel/version.rb
67
68
  - lib/gretel/view_helpers.rb