gretel 3.0.5 → 4.0.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
- SHA1:
3
- metadata.gz: 1c82f3dde4a98f82f3eb6f0ce135a64a2ca7e8dc
4
- data.tar.gz: 44d2c6ec3b8405991c4f0c2b9fc837d8a2711b70
2
+ SHA256:
3
+ metadata.gz: e6b2a5d8a3fd0fbb357c690e1d0189c54ab90ad1619c6ea5910b59f9cf718e89
4
+ data.tar.gz: d5c633b783445c773bb031dbd2377ca8af9265ced45f9aaafeabebc853c754d6
5
5
  SHA512:
6
- metadata.gz: 01e17764cb6cdfc58a8010a114722d9941671b4933cb92ca6b221c20d29fc787652f7bd504454a753626faee3cfbb1e7c813558f172468766740c22c4cf1264a
7
- data.tar.gz: 6cd0c52eb47346f631916d66d9203857567b33c294adff6be93411eed6b3f72d1092349be8364d3915868bbf79890c523b439ebaead4317c957166f1c5892c97
6
+ metadata.gz: 5816c2df05e992e54868150d8f6689af7c2d2cb0af33b588c9ef552d54771efcf81b29a9b9f2bca223e784644288caf24987f8b38f546ea0b3a4be1944a73b1e
7
+ data.tar.gz: 80497833712a92ac207f663ab544761ebf65b7a93d8d5fd7712e3bb8b3c8785b72ee85020ead35cd2e118a03f09e81a3d844c7dbbd629a3cf6cfb1b3d78669ba
data/.gitignore CHANGED
@@ -4,9 +4,9 @@
4
4
  .config
5
5
  .yardoc
6
6
  Gemfile.lock
7
+ gemfiles/*.lock
7
8
  InstalledFiles
8
9
  _yardoc
9
- coverage
10
10
  doc/
11
11
  lib/bundler/man
12
12
  pkg
@@ -20,4 +20,9 @@ test/dummy/db/*.sqlite3
20
20
  test/dummy/log/*.log
21
21
  test/dummy/tmp/
22
22
  test/dummy/.sass-cache
23
- .DS_Store
23
+ .DS_Store
24
+
25
+ /coverage/index.html
26
+ /coverage/assets
27
+ /coverage/*.json
28
+ /coverage/*.json.lock
@@ -1,8 +1,14 @@
1
1
  language: ruby
2
+ sudo: false
2
3
  rvm:
3
- - 2.0.0
4
- - 1.9.3
4
+ - 2.7
5
+ - 2.6
6
+ - 2.5
7
+ env:
8
+ - RAILS="~> '5.1.0'"
9
+ - RAILS="~> '5.2.0'"
10
+ - RAILS="~> '6.0.0'"
5
11
  before_script:
6
12
  - "cd test/dummy; rake db:migrate; rake db:test:prepare; cd ../.."
7
13
  notifications:
8
- email: false
14
+ email: false
@@ -1,5 +1,33 @@
1
1
  # Changelog
2
2
 
3
+ ## Version 4.0.0
4
+ * Support Bootstrap 4. See the `:style` option in the readme for more info
5
+ * CSS class for fragment link or span is now customizable. See the `:fragment_class` option in the readme for more info
6
+ * Drop support Ruby < 2.5
7
+ * Drop support Rails < 5.1
8
+ * Deprecated codes have been removed:
9
+ * `breadcrumbs` is no longer accept block, use `tap` instead
10
+ * `breadcrumbs` is no longer accept `style: :default`, use `style: :inline` instead
11
+ * `breadcrumbs` is no longer accept `:show_root_alone` option, use `:display_single_fragment` option instead
12
+
13
+ ## Version 3.0.9
14
+ * Adds breadcrumbs option `link_current_to_request_path` to link the current breadcrumb to the request path(#28 via #29)
15
+ * Fixes semantic breadcrumbs when the last item has no link (via #55)
16
+ * Downgrades Rails dependency to 3.1 (via #56)
17
+ * Fixes jRuby issue with `Rails::Application` constant (via #50)
18
+ * Fixes deprecation warnings for `alias_method_chain` (via #66)
19
+ * Updated coprights (via #63)
20
+
21
+ ## Version 3.0.8
22
+ * Parent breadcrumbs can now also be inferred from models responding to `model_name`.
23
+
24
+ ## Version 3.0.7
25
+ * Pretext and posttext classes are now customizable with `<%= breadcrumbs pretext_class: "some-class" %>` and `<%= breadcrumbs posttext_class: "some-other-class" %>`.
26
+
27
+ ## Version 3.0.6
28
+ * Pretext and posttext are now enclosed in spans with `<span class="pretext">` and `<span class="posttext">`.
29
+ * Semantic breadcrumbs are now rendered in spans instead of divs to enable easier styling.
30
+
3
31
  ## Version 3.0.3
4
32
  * Breadcrumbs can now be rendered for use in the [Foundation 5](http://foundation.zurb.com/) framework. Use `breadcrumbs style: :foundation5`.
5
33
  * Breadcrumbs are now automatically loaded from any engines' `config/breadcrumbs.rb` and `config/breadcrumbs/**/*.rb`. See the readme for details.
@@ -35,4 +63,4 @@
35
63
  * No longer supports procs for link text or URL as this is unnecessary when you can pass arguments to the block anyway.
36
64
  * It now accepts multiple arguments for `crumb` and `parent` (see the readme).
37
65
  * Breadcrumbs are now rendered with `<%= breadcrumbs %>`, although you can still use the old `<%= breadcrumb %>` (without *s*).
38
- * You can now access view helpers from inside `Gretel::Crumbs.layout do .. end`.
66
+ * You can now access view helpers from inside `Gretel::Crumbs.layout do .. end`.
data/Gemfile CHANGED
@@ -1,17 +1,6 @@
1
1
  source "http://rubygems.org"
2
2
 
3
- # Declare your gem's dependencies in gretel.gemspec.
4
- # Bundler will treat runtime dependencies like base dependencies, and
5
- # development dependencies will be added by default to the :development group.
6
3
  gemspec
7
4
 
8
- # jquery-rails is used by the dummy application
9
- gem "jquery-rails"
10
-
11
- # Declare any dependencies that are still in development here instead of in
12
- # your gemspec. These might include edge Rails or gems from your path or
13
- # Git. Remember to move these dependencies to your gemspec before releasing
14
- # your gem to rubygems.org.
15
-
16
- # To use debugger
17
- # gem 'debugger'
5
+ rails_version = ENV['RAILS_VERSION'] || '>= 0'
6
+ gem 'rails', rails_version
@@ -1,4 +1,4 @@
1
- Copyright (c) 2010-2013 Lasse Bunk
1
+ Copyright (c) 2010-2020 Lasse Bunk
2
2
 
3
3
  MIT License
4
4
 
@@ -19,4 +19,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
19
  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
20
  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
21
  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- <a href="http://travis-ci.org/lassebunk/gretel"><img src="https://secure.travis-ci.org/lassebunk/gretel.png" alt="Build Status" /></a>
1
+ <a href="http://travis-ci.org/kzkn/gretel"><img src="https://secure.travis-ci.org/kzkn/gretel.png" alt="Build Status" /></a>
2
2
 
3
3
  <img src="http://i.imgur.com/CAKEaBM.png" alt="Handle breadcrumb trails... like a boss :)" />
4
4
 
@@ -6,24 +6,7 @@
6
6
  It is based around the idea that breadcrumbs are a concern of the view, so you define a set of breadcrumbs in *config/breadcrumbs.rb* (or multiple files; see below) and specify in the view which breadcrumb to use.
7
7
  Gretel also supports [semantic breadcrumbs](http://support.google.com/webmasters/bin/answer.py?hl=en&answer=185417) (those used in Google results).
8
8
 
9
- Have fun! And please do write, if you (dis)like it – [lassebunk@gmail.com](mailto:lassebunk@gmail.com).
10
-
11
- ## New in version 3.0
12
-
13
- * Breadcrumbs can now be rendered in different styles like ul- and ol lists, and for use with the [Twitter Bootstrap](http://getbootstrap.com/) framework. See the `:style` option below for more info.
14
- * Defining breadcrumbs using `Gretel::Crumbs.layout do ... end` in an initializer has been removed. See below for details on how to upgrade.
15
- * The `:show_root_alone` option is now called `:display_single_fragment` and can be used to hide the breadcrumbs when there is only one link, also if it is not the root breadcrumb.
16
- The old `:show_root_alone` option is still supported until Gretel version 4.0 and will show a deprecation warning when it's used.
17
- * Links yielded from `<%= breadcrumbs do |links| %>` now have a `current?` helper that returns true if the link is the last in the trail.
18
- * New view helper: `parent_breadcrumb` returns the parent breadcrumb link (with `#key`, `#text`, and `#url`). This can for example be used to create a dynamic back link.
19
- You can supply options like `:autoroot` etc.
20
- If you supply a block, it will yield the parent breadcrumb if it is present.
21
- * Breadcrumbs can now be inferred if you pass in an instance of an object that responds to `model_name` (like an ActiveRecord model instance). E.g. `breadcrumb @product` is short for `breadcrumb :product, @product`.
22
-
23
-
24
- I hope you find these changes as useful as I did – if you have more suggestions, please create an [Issue](https://github.com/lassebunk/gretel/issues) or [Pull Request](https://github.com/lassebunk/gretel/pulls).
25
-
26
- See below for more info or the [changelog](https://github.com/lassebunk/gretel/blob/master/CHANGELOG.md) for less significant changes.
9
+ Have fun!
27
10
 
28
11
  ## Installation
29
12
 
@@ -84,7 +67,7 @@ This will generate the following HTML (indented for readability):
84
67
 
85
68
  ```html
86
69
  <div class="breadcrumbs">
87
- You are here:
70
+ <span class="pretext">You are here:</span>
88
71
  <a href="/">Home</a> &rsaquo;
89
72
  <a href="/issues">All issues</a> &rsaquo;
90
73
  <span class="current">My Issue</span>
@@ -97,17 +80,21 @@ You can pass options to `<%= breadcrumbs %>`, e.g. `<%= breadcrumbs pretext: "Yo
97
80
 
98
81
  Option | Description | Default
99
82
  ------------------------ | -------------------------------------------------------------------------------------------------------------------------- | -------
100
- :style | How to render the breadcrumbs. Can be `:default`, `:ol`, `:ul`, or `:bootstrap`. See below for more info. | `:default`
83
+ :style | How to render the breadcrumbs. Can be `:inline`, `:ol`, `:ul`, or `:bootstrap`. See below for more info. | `:inline`
101
84
  :pretext | Text to be rendered before breadcrumb, e.g. `"You are here: "`. | None
102
85
  :posttext | Text to be appended after breadcrumb, e.g. `"Text after breacrumb"`, | None
103
86
  :separator | Separator between links, e.g. `" &rsaquo; "`. | `" &rsaquo; "`
104
87
  :autoroot | Whether it should automatically link to the `:root` crumb if no parent is given. | True
105
88
  :display_single_fragment | Whether it should display the breadcrumb if it includes only one link. | False
106
89
  :link_current | Whether the current crumb should be linked to. | False
90
+ :link_current_to_request_path | Whether the current crumb should always link to the current request path. *Note:* This option will have no effect unless `:link_current` is set to `true`. | True
107
91
  :semantic | Whether it should generate [semantic breadcrumbs](http://support.google.com/webmasters/bin/answer.py?hl=en&answer=185417). | False
108
92
  :id | ID for the breadcrumbs container. | None
109
- :class | CSS class for the breadcrumbs container. | `"breadcrumbs"`
110
- :current_class | CSS class for the current link or span. | `"current"`
93
+ :class | CSS class for the breadcrumbs container. Can be set to `nil` for no class. | `"breadcrumbs"`
94
+ :fragment_class | CSS class for the fragment link or span. Can be set to `nil` for no class. | None
95
+ :current_class | CSS class for the current link or span. Can be set to `nil` for no class. | `"current"`
96
+ :pretext_class | CSS class for the pretext, if given. Can be set to `nil` for no class. | `"pretext"`
97
+ :posttext_class | CSS class for the posttext, if given. Can be set to `nil` for no class. | `"posttext"`
111
98
  :container_tag | Tag type that contains the breadcrumbs. | `:div`
112
99
  :fragment_tag | Tag type to contain each breadcrumb fragment/link. | None
113
100
 
@@ -117,15 +104,16 @@ These are the styles you can use with `breadcrumbs style: :xx`.
117
104
 
118
105
  Style | Description
119
106
  -------------- | -----------
120
- `:default` | Renders each link by itself with `&rsaquo;` as the seperator.
107
+ `:inline` | Renders each link by itself with `&rsaquo;` as the seperator.
121
108
  `:ol` | Renders the links in `<li>` elements contained in an outer `<ol>`.
122
109
  `:ul` | Renders the links in `<li>` elements contained in an outer `<ul>`.
123
110
  `:bootstrap` | Renders the links for use in [Twitter Bootstrap](http://getbootstrap.com/).
111
+ `:bootstrap4` | Renders the links for use in [Bootstrap v4](https://getbootstrap.com/).
124
112
  `:foundation5` | Renders the links for use in [Foundation 5](http://foundation.zurb.com/).
125
113
 
126
114
  Or you can build the breadcrumbs manually for full customization; see below.
127
115
 
128
- If you add other widely used styles, please submit a [Pull Request](https://github.com/lassebunk/gretel/pulls) so others can use them too.
116
+ If you add other widely used styles, please submit a [Pull Request](https://github.com/kzkn/gretel/pulls) so others can use them too.
129
117
 
130
118
  ## More examples
131
119
 
@@ -145,10 +133,10 @@ end
145
133
  # Parent crumbs
146
134
  crumb :project_issues do |project|
147
135
  link "Issues", project_issues_path(project)
148
- parent :project, project
136
+ parent project # inferred to :project
149
137
  end
150
138
 
151
- # Child
139
+ # Child
152
140
  crumb :issue do |issue|
153
141
  link issue.name, issue_path(issue)
154
142
  parent :project_issues, issue.project
@@ -158,7 +146,7 @@ end
158
146
  crumb :category do |category|
159
147
  link category.name, category
160
148
  if category.parent
161
- parent :category, category.parent
149
+ parent category.parent # inferred to :category
162
150
  else
163
151
  parent :categories
164
152
  end
@@ -167,7 +155,7 @@ end
167
155
  # Product crumb with recursive parent categories (as defined above)
168
156
  crumb :product do |product|
169
157
  link product.name, product
170
- parent :category, product.category
158
+ parent product.category # inferred to :category
171
159
  end
172
160
 
173
161
  # Crumb with multiple links
@@ -188,7 +176,7 @@ crumb :product do |product|
188
176
  if keyword = params[:q].presence
189
177
  parent :search, keyword
190
178
  else # default
191
- parent :category, product.category
179
+ parent product.category # inferred to :category
192
180
  end
193
181
  end
194
182
 
@@ -217,10 +205,10 @@ end
217
205
 
218
206
  ## Building the breadcrumbs manually
219
207
 
220
- If you supply a block to the `breadcrumbs` method, it will yield an array with the breadcrumb links so you can build the breadcrumbs HTML manually:
208
+ You can use the `breadcrumbs` method directly as an array. It will return an array with the breadcrumb links so you can build the breadcrumbs HTML manually:
221
209
 
222
210
  ```erb
223
- <% breadcrumbs do |links| %>
211
+ <% breadcrumbs.tap do |links| %>
224
212
  <% if links.any? %>
225
213
  You are here:
226
214
  <% links.each do |link| %>
@@ -347,7 +335,8 @@ in `config/breadcrumbs.rb`.
347
335
  ## Documentation
348
336
 
349
337
  * [Full documentation](http://rubydoc.info/gems/gretel)
350
- * [Changelog](https://github.com/lassebunk/gretel/blob/master/CHANGELOG.md)
338
+ * [Changelog](https://github.com/kzkn/gretel/blob/master/CHANGELOG.md)
339
+ * [Tutorial on using Gretel](http://www.sitepoint.com/breadcrumbs-rails-gretel/) (Sitepoint)
351
340
 
352
341
  ## Versioning
353
342
 
@@ -362,17 +351,22 @@ To contribute:
362
351
  1. Fork the project
363
352
  2. Create your feature branch (`git checkout -b my-new-feature`)
364
353
  3. Make your changes
365
- 4. Add tests
366
- 5. Run `rake` to make sure all tests pass
367
- 6. Commit your changes (`git commit -am 'Add new feature'`)
368
- 7. Push to the branch (`git push origin my-new-feature`)
369
- 8. Create new pull request
354
+ 4. Add/Fix tests
355
+ 5. Prepare database for testing: `cd test/dummy; rake db:migrate; rake db:test:prepare; cd ../..`
356
+ 6. Run `rake` to make sure all tests pass
357
+ 7. Be sure to check in the changes to `coverage/coverage.txt`
358
+ 8. Commit your changes (`git commit -am 'Add new feature'`)
359
+ 9. Push to the branch (`git push origin my-new-feature`)
360
+ 10. Create new pull request
370
361
 
371
362
  Thanks.
372
363
 
373
364
  ## Contributors
374
365
 
375
- * [See the list of contributors](https://github.com/lassebunk/gretel/graphs/contributors)
366
+ Gretel was created by [@lassebunk](https://github.com/lassebunk) and was maintained by [@WilHall](https://github.com/WilHall).
367
+ And it is maintained by [@kzkn](https://github.com/kzkn).
368
+
369
+ [See the list of contributors](https://github.com/kzkn/gretel/graphs/contributors)
376
370
 
377
371
  ## And then
378
372
 
@@ -380,4 +374,4 @@ Thanks.
380
374
 
381
375
  Have fun!
382
376
 
383
- Copyright (c) 2010-2013 [Lasse Bunk](http://lassebunk.dk), released under the MIT license
377
+ Copyright (c) 2010-2020 [Lasse Bunk](http://lassebunk.dk), released under the MIT license
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
@@ -0,0 +1,6 @@
1
+ --------------------------------------------------------------------------------
2
+ Incomplete test coverage
3
+ --------------------------------------------------------------------------------
4
+
5
+ /lib/gretel/renderer.rb: 99.12% (missed: 45)
6
+ /test/helper_methods_test.rb: 99.24% (missed: 17,196)
@@ -6,18 +6,21 @@ require 'gretel/version'
6
6
  Gem::Specification.new do |gem|
7
7
  gem.name = "gretel"
8
8
  gem.version = Gretel::VERSION
9
- gem.authors = ["Lasse Bunk"]
10
- gem.email = ["lassebunk@gmail.com"]
9
+ gem.authors = ["Lasse Bunk", "Kazuki Nishikawa"]
10
+ gem.email = ["kzkn@users.noreply.github.com"]
11
11
  gem.description = %q{Gretel is a Ruby on Rails plugin that makes it easy yet flexible to create breadcrumbs.}
12
12
  gem.summary = %q{Flexible Ruby on Rails breadcrumbs plugin.}
13
- gem.homepage = "http://github.com/lassebunk/gretel"
13
+ gem.homepage = "http://github.com/kzkn/gretel"
14
14
  gem.license = "MIT"
15
15
 
16
16
  gem.files = `git ls-files`.split($/)
17
17
  gem.test_files = gem.files.grep(%r{^test/})
18
18
  gem.require_paths = ["lib"]
19
19
 
20
- gem.add_dependency "rails", ">= 3.2.0"
21
- gem.add_development_dependency "rails", "~> 3.2.13"
20
+ gem.add_dependency "rails", ">= 5.1"
22
21
  gem.add_development_dependency "sqlite3"
23
- end
22
+ gem.add_development_dependency "jquery-rails"
23
+ gem.add_development_dependency "test-unit", "~> 3.0"
24
+ gem.add_development_dependency "simplecov", "~> 0.18.0"
25
+ gem.add_development_dependency "simplecov-erb", "~> 0.1"
26
+ end
@@ -5,7 +5,6 @@ require 'gretel/crumb'
5
5
  require 'gretel/link'
6
6
  require 'gretel/renderer'
7
7
  require 'gretel/view_helpers'
8
- require 'gretel/deprecated'
9
8
 
10
9
  module Gretel
11
10
  class << self
@@ -16,7 +15,9 @@ module Gretel
16
15
  # breadcrumbs set in engines.
17
16
  def breadcrumb_paths
18
17
  @breadcrumb_paths ||= begin
19
- engine_roots = Rails::Application::Railties.engines.map { |e| e.config.root }
18
+ engines = Rails::Engine.subclasses.map(&:instance)
19
+
20
+ engine_roots = engines.map { |e| e.config.root }
20
21
 
21
22
  [*engine_roots, Rails.root].map do |root|
22
23
  [root.join("config", "breadcrumbs.rb"),
@@ -31,24 +32,6 @@ module Gretel
31
32
  @breadcrumb_paths = paths
32
33
  end
33
34
 
34
- # Whether to suppress deprecation warnings.
35
- def suppress_deprecation_warnings?
36
- !!@suppress_deprecation_warnings
37
- end
38
-
39
- # Sets whether to suppress deprecation warnings.
40
- def suppress_deprecation_warnings=(value)
41
- @suppress_deprecation_warnings = value
42
- end
43
-
44
- # Shows a deprecation warning.
45
- def show_deprecation_warning(message)
46
- return if suppress_deprecation_warnings?
47
- message = "[Gretel] #{message}"
48
- puts message
49
- Rails.logger.warn message
50
- end
51
-
52
35
  # Array of Rails environment names with automatic configuration reload. Default is +["development"]+.
53
36
  def reload_environments
54
37
  @reload_environments ||= ["development"]
@@ -75,4 +58,4 @@ module Gretel
75
58
  end
76
59
  end
77
60
 
78
- ActionView::Base.send :include, Gretel::ViewHelpers
61
+ ActionView::Base.send :include, Gretel::ViewHelpers
@@ -3,6 +3,12 @@ module Gretel
3
3
  # Initializes a new crumb from the given +key+.
4
4
  # It finds the breadcrumb created in +Gretel::Crumbs.layout+ and renders the block using the arguments supplied in +args+.
5
5
  def initialize(context, key, *args)
6
+ if key.class.respond_to?(:model_name)
7
+ # Enables calling `breadcrumb @product` instead of `breadcrumb :product, @product`
8
+ args.unshift key
9
+ key = key.class.model_name.to_s.underscore.to_sym
10
+ end
11
+
6
12
  block = Gretel::Crumbs.crumbs[key]
7
13
  raise ArgumentError, "Breadcrumb :#{key} not found." unless block
8
14
  @key = key
@@ -38,6 +44,9 @@ module Gretel
38
44
  #
39
45
  # Example:
40
46
  # parent :category, category
47
+ #
48
+ # Or short, which will infer the key from the model's `model_name`:
49
+ # parent category
41
50
  def parent(*args)
42
51
  return @parent if args.empty?
43
52
  key = args.shift
@@ -51,7 +60,7 @@ module Gretel
51
60
  # The current view context.
52
61
  attr_reader :context
53
62
 
54
- # Proxy to view context
63
+ # Proxy to view context.
55
64
  def method_missing(method, *args, &block)
56
65
  context.send(method, *args, &block)
57
66
  end
@@ -1,24 +1,28 @@
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: "",
8
8
  autoroot: true,
9
9
  display_single_fragment: false,
10
10
  link_current: false,
11
+ link_current_to_request_path: true,
11
12
  semantic: false,
12
13
  class: "breadcrumbs",
13
14
  current_class: "current",
15
+ pretext_class: "pretext",
16
+ posttext_class: "posttext",
14
17
  id: nil
15
18
  }
16
19
 
17
20
  DEFAULT_STYLES = {
18
- default: { container_tag: :div, separator: " &rsaquo; " },
21
+ inline: { container_tag: :div, separator: " &rsaquo; " },
19
22
  ol: { container_tag: :ol, fragment_tag: :li },
20
23
  ul: { container_tag: :ul, fragment_tag: :li },
21
24
  bootstrap: { container_tag: :ol, fragment_tag: :li, class: "breadcrumb", current_class: "active" },
25
+ bootstrap4: { container_tag: :ol, fragment_tag: :li, class: "breadcrumb", fragment_class: "breadcrumb-item", current_class: "active" },
22
26
  foundation5: { container_tag: :ul, fragment_tag: :li, class: "breadcrumbs", current_class: "current" }
23
27
  }
24
28
 
@@ -33,32 +37,17 @@ module Gretel
33
37
  options = options_for_render(options)
34
38
  links = links_for_render(options)
35
39
 
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])
40
+ LinkCollection.new(context, links, options)
50
41
  end
51
42
 
52
43
  # Yields links with applied options.
53
44
  def yield_links(options = {})
54
- options = options_for_render(options)
55
- yield links_for_render(options)
45
+ yield render(options)
56
46
  end
57
47
 
58
48
  # Returns the parent breadcrumb.
59
49
  def parent_breadcrumb(options = {})
60
- options = options_for_render(options)
61
- links_for_render(options)[-2]
50
+ render(options)[-2]
62
51
  end
63
52
 
64
53
  # Yields the parent breadcrumb if any.
@@ -68,11 +57,6 @@ module Gretel
68
57
  end
69
58
  end
70
59
 
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
60
  private
77
61
 
78
62
  attr_reader :context, :breadcrumb_key, :breadcrumb_args
@@ -102,7 +86,7 @@ module Gretel
102
86
  end
103
87
 
104
88
  # Set current link to actual path
105
- if out.any? && request
89
+ if options[:link_current_to_request_path] && out.any? && request
106
90
  out.last.url = request.fullpath
107
91
  end
108
92
 
@@ -129,7 +113,7 @@ module Gretel
129
113
 
130
114
  # Links of first crumb
131
115
  links = crumb.links.dup
132
-
116
+
133
117
  # Get parent links
134
118
  links.unshift *parent_links_for(crumb)
135
119
 
@@ -148,52 +132,16 @@ module Gretel
148
132
  links
149
133
  end
150
134
 
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
135
+ # Proxy to view context.
188
136
  def method_missing(method, *args, &block)
189
137
  context.send(method, *args, &block)
190
138
  end
191
139
 
192
140
  class << self
193
141
  include Resettable
194
-
142
+
195
143
  # Registers a style for later use.
196
- #
144
+ #
197
145
  # Gretel::Renderer.register_style :ul, { container_tag: :ul, fragment_tag: :li }
198
146
  def register_style(style_key, options)
199
147
  styles[style_key] = options
@@ -204,5 +152,110 @@ module Gretel
204
152
  @styles ||= DEFAULT_STYLES
205
153
  end
206
154
  end
155
+
156
+ class LinkCollection < Array
157
+ attr_reader :context, :links, :options
158
+
159
+ def initialize(context, links, options = {})
160
+ @context, @links, @options = context, links, options
161
+ concat links
162
+ end
163
+
164
+ # Helper for returning all link keys to allow for simple testing.
165
+ def keys
166
+ map(&:key)
167
+ end
168
+
169
+ # Renders the links into breadcrumbs.
170
+ def render
171
+ return "" if links.empty?
172
+
173
+ # Loop through all but the last (current) link and build HTML of the fragments
174
+ fragments = links[0..-2].map do |link|
175
+ render_fragment(options[:fragment_tag], link.text, link.url, options[:semantic], fragment_class: options[:fragment_class])
176
+ end
177
+
178
+ # The current link is handled a little differently, and is only linked if specified in the options
179
+ current_link = links.last
180
+ fragments << render_fragment(options[:fragment_tag], current_link.text, (options[:link_current] ? current_link.url : nil), options[:semantic], fragment_class: options[:fragment_class], class: options[:current_class], current_link: current_link.url)
181
+
182
+ # Build the final HTML
183
+ html_fragments = []
184
+
185
+ if options[:pretext].present?
186
+ html_fragments << content_tag(:span, options[:pretext], class: options[:pretext_class])
187
+ end
188
+
189
+ html_fragments << fragments.join(options[:separator])
190
+
191
+ if options[:posttext].present?
192
+ html_fragments << content_tag(:span, options[:posttext], class: options[:posttext_class])
193
+ end
194
+
195
+ html = html_fragments.join(" ").html_safe
196
+ content_tag(options[:container_tag], html, id: options[:id], class: options[:class])
197
+ end
198
+
199
+ alias :to_s :render
200
+
201
+ # Renders HTML for a breadcrumb fragment, i.e. a breadcrumb link.
202
+ def render_fragment(fragment_tag, text, url, semantic, options = {})
203
+ if semantic
204
+ render_semantic_fragment(fragment_tag, text, url, options)
205
+ else
206
+ render_nonsemantic_fragment(fragment_tag, text, url, options)
207
+ end
208
+ end
209
+
210
+ # Renders semantic fragment HTML.
211
+ def render_semantic_fragment(fragment_tag, text, url, options = {})
212
+ fragment_class = [options[:fragment_class], options[:class]].join(' ').strip
213
+ fragment_class = nil if fragment_class.blank?
214
+
215
+ if fragment_tag
216
+ text = content_tag(:span, text, itemprop: "title")
217
+
218
+ if url.present?
219
+ text = breadcrumb_link_to(text, url, itemprop: "url")
220
+ elsif options[:current_link].present?
221
+ current_url = "#{root_url}#{options[:current_link].gsub(/^\//, '')}"
222
+ text = text + tag(:meta, itemprop: "url", content: current_url)
223
+ end
224
+
225
+ content_tag(fragment_tag, text, class: fragment_class, itemscope: "", itemtype: "http://data-vocabulary.org/Breadcrumb")
226
+ elsif url.present?
227
+ content_tag(:span, breadcrumb_link_to(content_tag(:span, text, itemprop: "title"), url, class: fragment_class, itemprop: "url"), itemscope: "", itemtype: "http://data-vocabulary.org/Breadcrumb")
228
+ else
229
+ content_tag(:span, content_tag(:span, text, class: fragment_class, itemprop: "title"), itemscope: "", itemtype: "http://data-vocabulary.org/Breadcrumb")
230
+ end
231
+ end
232
+
233
+ # Renders regular, non-semantic fragment HTML.
234
+ def render_nonsemantic_fragment(fragment_tag, text, url, options = {})
235
+ fragment_class = [options[:fragment_class], options[:class]].join(' ').strip
236
+ fragment_class = nil if fragment_class.blank?
237
+
238
+ if fragment_tag
239
+ text = breadcrumb_link_to(text, url) if url.present?
240
+ content_tag(fragment_tag, text, class: fragment_class)
241
+ elsif url.present?
242
+ breadcrumb_link_to(text, url, class: fragment_class)
243
+ elsif options[:class].present?
244
+ content_tag(:span, text, class: fragment_class)
245
+ else
246
+ text
247
+ end
248
+ end
249
+
250
+ # Proxy for +context.link_to+ that can be overridden by plugins.
251
+ def breadcrumb_link_to(name, url, options = {})
252
+ context.link_to(name, url, options)
253
+ end
254
+
255
+ # Proxy to view context.
256
+ def method_missing(method, *args, &block)
257
+ context.send(method, *args, &block)
258
+ end
259
+ end
207
260
  end
208
261
  end