loaf 0.9.0 → 0.10.0

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
  SHA256:
3
- metadata.gz: f544810445fa9db426eb9d433df6bf0bd700d91a1f277f00ac22799805adced3
4
- data.tar.gz: 0aa946e6a0f5ea4beb5eee018d9953ff2246d2da603b386627b4e36fe2d7f059
3
+ metadata.gz: 194d167e400d76180e87b1d93637c9c3cf59048dbe03ea32c416d48236778e15
4
+ data.tar.gz: 7f5c9f0d0c5f92e541b282a281327ccd327f057b844d9970e8a086ee05b735d6
5
5
  SHA512:
6
- metadata.gz: db053ea3b9a1cb1681fad9370a2d2174fe249b5602367aab6d04ea3c7c04ebf9bb8b0bedef5a1326374c96c76c2c0d5593f62aba7273c00f981297f794934415
7
- data.tar.gz: 4f3e32da25d4cd0b3abac19b82133769d7b25c61778ac476d0ae06ace6be2ee219526416ff398d917653d7762505eab1a467d1b1aeded3d3c1b90f362749f2e6
6
+ metadata.gz: 30f9a6c9eb2e4ca2513d1ec3c95dff3038a10d4fd55f12391a9dac5568ad34eef28c23f3ef22a2fe8f810e954674a759e1537255929e18fe117dba550a644b0c
7
+ data.tar.gz: 47ea3af5b670ae2d02ecddae7a71d70a96206487f93ef415853d18a222dc2b63729d485743bd0d2249965fd6918150facfe80b4626c0c662f45f1d302af0004c
@@ -1,5 +1,16 @@
1
1
  # Change log
2
2
 
3
+ ## [v0.10.0] - 2020-11-21
4
+
5
+ ### Changed
6
+ * Reduce gem dependencies to `railties` by Christian Sutter (@csutter)
7
+ * Use `URI::DEFAULT_PARSER` instead of deprecated `URI.parser` by (@dsazup)
8
+ * Support Rails 6.1 in tests
9
+
10
+ ### Fixed
11
+ * Fix #breadcrumb_trail to allow overriding the match option
12
+ * Fix #breadcrumb_trail to return enumerator that includes passed in match option
13
+
3
14
  ## [v0.9.0] - 2020-01-19
4
15
 
5
16
  ### Changed
@@ -131,6 +142,7 @@
131
142
 
132
143
  * Initial implementation and release
133
144
 
145
+ [v0.10.0]: https://github.com/piotrmurach/loaf/compare/v0.9.0...v0.10.0
134
146
  [v0.9.0]: https://github.com/piotrmurach/loaf/compare/v0.8.1...v0.9.0
135
147
  [v0.8.1]: https://github.com/piotrmurach/loaf/compare/v0.8.0...v0.8.1
136
148
  [v0.8.0]: https://github.com/piotrmurach/loaf/compare/v0.7.0...v0.8.0
@@ -1,4 +1,4 @@
1
- Copyright (c) 2011 Piotr Murach
1
+ Copyright (c) 2011 Piotr Murach (https://piotrmurach.com)
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -1,17 +1,17 @@
1
1
  <div align="center">
2
- <img width="237" src="https://cdn.rawgit.com/piotrmurach/loaf/master/assets/loaf_logo.png" alt="loaf logo" />
2
+ <img width="237" src="https://github.com/piotrmurach/loaf/blob/master/assets/loaf_logo.png" alt="Loaf gem logo" />
3
3
  </div>
4
4
 
5
5
  # Loaf
6
6
 
7
7
  [![Gem Version](https://badge.fury.io/rb/loaf.svg)][gem]
8
- [![Build Status](https://secure.travis-ci.org/piotrmurach/loaf.svg?branch=master)][travis]
8
+ [![Actions CI](https://github.com/piotrmurach/loaf/workflows/CI/badge.svg?branch=master)][gh_actions_ci]
9
9
  [![Maintainability](https://api.codeclimate.com/v1/badges/966193dafa3895766977/maintainability)][codeclimate]
10
10
  [![Coverage Status](https://coveralls.io/repos/github/piotrmurach/loaf/badge.svg?branch=master)][coveralls]
11
11
  [![Inline docs](http://inch-ci.org/github/piotrmurach/loaf.svg?branch=master)][inchpages]
12
12
 
13
13
  [gem]: http://badge.fury.io/rb/loaf
14
- [travis]: http://travis-ci.org/piotrmurach/loaf
14
+ [gh_actions_ci]: https://github.com/piotrmurach/loaf/actions?query=workflow%3ACI
15
15
  [codeclimate]: https://codeclimate.com/github/piotrmurach/loaf/maintainability
16
16
  [coveralls]: https://coveralls.io/github/piotrmurach/loaf
17
17
  [inchpages]: http://inch-ci.org/github/piotrmurach/loaf
@@ -31,7 +31,7 @@
31
31
  Add this line to your application's Gemfile:
32
32
 
33
33
  ```ruby
34
- gem 'loaf'
34
+ gem "loaf"
35
35
  ```
36
36
 
37
37
  And then execute:
@@ -73,7 +73,7 @@ In order to add breadcrumbs in controller use `breadcrumb` method ([see 2.1](#21
73
73
  ```ruby
74
74
  class Blog::CategoriesController < ApplicationController
75
75
 
76
- breadcrumb 'Article Categories', :blog_categories_path, only: [:show]
76
+ breadcrumb "Article Categories", :blog_categories_path, only: [:show]
77
77
 
78
78
  def show
79
79
  breadcrumb @category.title, blog_category_path(@category)
@@ -94,7 +94,7 @@ The `breadcrumb` method takes at minimum two arguments: the first is a name for
94
94
  When using path variable `blog_categories_path`:
95
95
 
96
96
  ```ruby
97
- breadcrumb 'Categories', blog_categories_path
97
+ breadcrumb "Categories", blog_categories_path
98
98
  ```
99
99
 
100
100
  When using an instance `@category`:
@@ -112,7 +112,7 @@ breadcrumb @category.title, [:blog, @category]
112
112
  You can specify segments of the url:
113
113
 
114
114
  ```ruby
115
- breadcrumb @category.title, {controller: 'categories', action: 'show', id: @category.id}
115
+ breadcrumb @category.title, {controller: "categories", action: "show", id: @category.id}
116
116
  ```
117
117
 
118
118
  #### 2.1.1 controller
@@ -121,7 +121,7 @@ Breadcrumbs are inherited, so if you set a breadcrumb in `ApplicationController`
121
121
 
122
122
  ```ruby
123
123
  class ApplicationController < ActionController::Base
124
- breadcrumb 'Home', :root_path
124
+ breadcrumb "Home", :root_path
125
125
  end
126
126
  ```
127
127
 
@@ -129,7 +129,7 @@ Outside of controller actions the `breadcrumb` helper behaviour is similar to fi
129
129
 
130
130
  ```ruby
131
131
  class ArticlesController < ApplicationController
132
- breadcrumb 'All Articles', :articles_path, only: [:new, :create]
132
+ breadcrumb "All Articles", :articles_path, only: [:new, :create]
133
133
  end
134
134
  ```
135
135
 
@@ -137,12 +137,12 @@ Each time you call the `breadcrumb` helper, a new element is added to a breadcru
137
137
 
138
138
  ```ruby
139
139
  class ArticlesController < ApplicationController
140
- breadcrumb 'Home', :root_path
141
- breadcrumb 'All Articles', :articles_path
140
+ breadcrumb "Home", :root_path
141
+ breadcrumb "All Articles", :articles_path
142
142
 
143
143
  def show
144
- breadcrumb 'Article One', article_path(:one)
145
- breadcrumb 'Article Two', article_path(:two)
144
+ breadcrumb "Article One", article_path(:one)
145
+ breadcrumb "Article Two", article_path(:two)
146
146
  end
147
147
  end
148
148
  ```
@@ -155,11 +155,11 @@ class CommentsController < ApplicationController
155
155
  end
156
156
  ```
157
157
 
158
- Also, to dynamically evalute parameters inside the url argument do:
158
+ Also, to dynamically evaluate parameters inside the url argument do:
159
159
 
160
160
  ```ruby
161
161
  class CommentsController < ApplicationController
162
- breadcrumb 'All Comments', -> { post_comments_path(params[:post_id]) }
162
+ breadcrumb "All Comments", -> { post_comments_path(params[:post_id]) }
163
163
  end
164
164
  ```
165
165
 
@@ -191,25 +191,27 @@ The `:match` key accepts the following values:
191
191
 
192
192
  * `:inclusive` - the default value, which matches nested paths
193
193
  * `:exact` - matches only the exact same path
194
- * `:exclusive` - matches only direct path and its query params if present
194
+ * `:exclusive` - matches only direct path and its query parameters if present
195
195
  * `/regex/` - matches based on regular expression
196
- * `{foo: bar}` - match based on query params
196
+ * `{foo: bar}` - match based on query parameters
197
197
 
198
198
  For example, to force a breadcrumb to be the current regardless do:
199
199
 
200
200
  ```ruby
201
- breadcrumb 'New Post', new_post_path, match: :exact
201
+ breadcrumb "New Post", new_post_path, match: :exact
202
202
  ```
203
203
 
204
- To make a breadcrumb current based on the query params do:
204
+ To make a breadcrumb current based on the query parameters do:
205
205
 
206
206
  ```ruby
207
- breadcrumb 'Posts', posts_path(order: :desc), match: {order: :desc}
207
+ breadcrumb "Posts", posts_path(order: :desc), match: {order: :desc}
208
208
  ```
209
209
 
210
210
  ### 2.2 breadcrumb_trail
211
211
 
212
- In order to display breadcrumbs use the `breadcrumb_trail` view helper which as an argument accepts options and yields all breadcrumbs to a block:
212
+ In order to display breadcrumbs use the `breadcrumb_trail` view helper. It accepts optional argument of configuration options and can be used in two ways.
213
+
214
+ One way, given a block it will yield all the breadcrumbs in order of definition:
213
215
 
214
216
  ```ruby
215
217
  breadcrumb_trail do |crumb|
@@ -217,7 +219,7 @@ breadcrumb_trail do |crumb|
217
219
  end
218
220
  ```
219
221
 
220
- The yielded pararmeter is a `Loaf::Crumb` object that provides the following methods:
222
+ The yielded parameter is an instance of `Loaf::Crumb` object with the following methods:
221
223
 
222
224
  ```ruby
223
225
  crumb.name # => the name as string
@@ -230,43 +232,58 @@ For example, you can add the following semantic markup to show breadcrumbs using
230
232
 
231
233
  ```erb
232
234
  <nav aria-label="breadcrumb">
233
- <ol class='breadcrumbs'>
235
+ <ol class="breadcrumbs">
234
236
  <% breadcrumb_trail do |crumb| %>
235
- <li class="<%= crumb.current? ? 'current' : '' %>">
236
- <%= link_to crumb.name, crumb.url, (crumb.current? ? {'aria-current' => 'page'} : {}) %>
237
+ <li class="<%= crumb.current? ? "current" : "" %>">
238
+ <%= link_to crumb.name, crumb.url, (crumb.current? ? {"aria-current" => "page"} : {}) %>
237
239
  <% unless crumb.current? %><span>::</span><% end %>
238
240
  </li>
239
241
  <% end %>
240
242
  </ol>
241
243
  </nav>
242
244
  ```
245
+
243
246
  For Bootstrap 4:
244
247
 
245
248
  ```erb
246
249
  <% #erb %>
247
250
  <nav aria-label="breadcrumb">
248
- <ol class='breadcrumb'>
251
+ <ol class="breadcrumb">
249
252
  <% breadcrumb_trail do |crumb| %>
250
- <li class="breadcrumb-item <%= crumb.current? ? 'active' : '' %>">
251
- <%= link_to_unless crumb.current?, crumb.name, crumb.url, (crumb.current? ? {'aria-current' => 'page'} : {}) %>
253
+ <li class="breadcrumb-item <%= crumb.current? ? "active" : "" %>">
254
+ <%= link_to_unless crumb.current?, crumb.name, crumb.url, (crumb.current? ? {"aria-current" => "page"} : {}) %>
252
255
  </li>
253
256
  <% end %>
254
257
  </ol>
255
258
  </nav>
256
259
  ```
257
260
 
258
- and if you are using HAML do:
261
+ And, if you are using `HAML` do:
259
262
 
260
263
  ```haml
261
264
  - # haml
262
265
  %ol.breadcrumb
263
266
  - breadcrumb_trail do |crumb|
264
- %li.breadcrumb-item{class: crumb.current? ? 'active' : '' }
265
- = link_to_unless crumb.current?, crumb.name, crumb.url, (crumb.current? ? {'aria-current' => 'page'} : {})
267
+ %li.breadcrumb-item{class: crumb.current? ? "active" : "" }
268
+ = link_to_unless crumb.current?, crumb.name, crumb.url, (crumb.current? ? {"aria-current" => "page"} : {})
266
269
  ```
267
270
 
268
271
  Usually best practice is to put such snippet inside its own `_breadcrumbs.html.erb` partial.
269
272
 
273
+ The second way is to use the `breadcrumb_trail` without passing a block. In this case, the helper will return an enumerator that you can use to, for example, access an array of names pushed into the breadcrumb trail in order of addition. This can be handy for generating page titles from breadcrumb data.
274
+
275
+ For example, you can define a `breadcrumbs_to_title` method in `ApplicationHelper` like so:
276
+
277
+ ```ruby
278
+ module ApplicationHelper
279
+ def breadcrumbs_to_title
280
+ breadcrumb_trail.map(&:name).join(">")
281
+ end
282
+ end
283
+ ```
284
+
285
+ Use whichever of the two ways is more convenient given your application structure and needs.
286
+
270
287
  ## 3. Configuration
271
288
 
272
289
  There is a small set of custom opinionated defaults. The following options are valid parameters:
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Loaf
4
- VERSION = "0.9.0"
4
+ VERSION = "0.10.0"
5
5
  end # Loaf
@@ -45,14 +45,14 @@ module Loaf
45
45
  #
46
46
  # @api public
47
47
  def breadcrumb_trail(options = {})
48
- return enum_for(:breadcrumb_trail) unless block_given?
48
+ return enum_for(:breadcrumb_trail, options) unless block_given?
49
49
 
50
50
  valid?(options)
51
- options = Loaf.configuration.to_hash.merge(options)
51
+
52
52
  _breadcrumbs.each do |crumb|
53
53
  name = title_for(crumb.name)
54
54
  path = url_for(_expand_url(crumb.url))
55
- current = current_crumb?(path, crumb.match)
55
+ current = current_crumb?(path, options.fetch(:match) { crumb.match })
56
56
 
57
57
  yield(Loaf::Breadcrumb[name, path, current])
58
58
  end
@@ -68,10 +68,10 @@ module Loaf
68
68
  def current_crumb?(path, pattern = :inclusive)
69
69
  return false unless request.get? || request.head?
70
70
 
71
- origin_path = URI.parser.unescape(path).force_encoding(Encoding::BINARY)
71
+ origin_path = URI::DEFAULT_PARSER.unescape(path).force_encoding(Encoding::BINARY)
72
72
 
73
73
  request_uri = request.fullpath
74
- request_uri = URI.parser.unescape(request_uri)
74
+ request_uri = URI::DEFAULT_PARSER.unescape(request_uri)
75
75
  request_uri.force_encoding(Encoding::BINARY)
76
76
 
77
77
  # strip away trailing slash
metadata CHANGED
@@ -1,17 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: loaf
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 0.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Piotr Murach
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-01-19 00:00:00.000000000 Z
11
+ date: 2020-11-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: rails
14
+ name: railties
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - ">="
@@ -24,20 +24,6 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '3.2'
27
- - !ruby/object:Gem::Dependency
28
- name: bundler
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: '1.5'
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ">="
39
- - !ruby/object:Gem::Version
40
- version: '1.5'
41
27
  - !ruby/object:Gem::Dependency
42
28
  name: rake
43
29
  requirement: !ruby/object:Gem::Requirement
@@ -61,6 +47,8 @@ executables: []
61
47
  extensions: []
62
48
  extra_rdoc_files:
63
49
  - README.md
50
+ - CHANGELOG.md
51
+ - LICENSE.txt
64
52
  files:
65
53
  - CHANGELOG.md
66
54
  - LICENSE.txt