gretel 4.0.0 → 4.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +52 -0
- data/.gitignore +7 -6
- data/CHANGELOG.md +20 -0
- data/Gemfile +3 -1
- data/README.md +46 -44
- data/Rakefile +3 -7
- data/coverage/coverage.txt +1 -2
- data/gretel.gemspec +9 -11
- data/lib/gretel.rb +1 -7
- data/lib/gretel/crumb.rb +5 -2
- data/lib/gretel/crumbs.rb +26 -7
- data/lib/gretel/railtie.rb +11 -0
- data/lib/gretel/renderer.rb +65 -33
- data/lib/gretel/version.rb +1 -1
- data/lib/gretel/view_helpers.rb +2 -0
- metadata +37 -112
- data/.travis.yml +0 -14
- data/test/dummy/Rakefile +0 -7
- data/test/dummy/app/assets/config/manifest.js +0 -0
- data/test/dummy/app/assets/javascripts/application.js +0 -15
- data/test/dummy/app/assets/stylesheets/application.css +0 -13
- data/test/dummy/app/controllers/application_controller.rb +0 -3
- data/test/dummy/app/helpers/application_helper.rb +0 -5
- data/test/dummy/app/mailers/.gitkeep +0 -0
- data/test/dummy/app/models/.gitkeep +0 -0
- data/test/dummy/app/models/issue.rb +0 -3
- data/test/dummy/app/models/project.rb +0 -3
- data/test/dummy/app/views/breadcrumbs/site.rb +0 -3
- data/test/dummy/config.ru +0 -4
- data/test/dummy/config/application.rb +0 -14
- data/test/dummy/config/boot.rb +0 -10
- data/test/dummy/config/breadcrumbs.rb +0 -3
- data/test/dummy/config/breadcrumbs/test_crumbs.rb +0 -85
- data/test/dummy/config/database.yml +0 -25
- data/test/dummy/config/environment.rb +0 -5
- data/test/dummy/config/environments/development.rb +0 -2
- data/test/dummy/config/environments/production.rb +0 -2
- data/test/dummy/config/environments/test.rb +0 -2
- data/test/dummy/config/initializers/backtrace_silencers.rb +0 -7
- data/test/dummy/config/initializers/inflections.rb +0 -15
- data/test/dummy/config/initializers/mime_types.rb +0 -5
- data/test/dummy/config/initializers/secret_token.rb +0 -7
- data/test/dummy/config/initializers/session_store.rb +0 -8
- data/test/dummy/config/initializers/wrap_parameters.rb +0 -14
- data/test/dummy/config/locales/en.yml +0 -5
- data/test/dummy/config/routes.rb +0 -11
- data/test/dummy/db/migrate/20130122163007_create_projects.rb +0 -9
- data/test/dummy/db/migrate/20130122163051_create_issues.rb +0 -10
- data/test/dummy/db/schema.rb +0 -28
- data/test/dummy/lib/assets/.gitkeep +0 -0
- data/test/dummy/log/.gitkeep +0 -0
- data/test/dummy/public/404.html +0 -26
- data/test/dummy/public/422.html +0 -26
- data/test/dummy/public/500.html +0 -25
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/script/rails +0 -6
- data/test/fixtures/issues.yml +0 -4
- data/test/fixtures/projects.yml +0 -3
- data/test/gretel_test.rb +0 -23
- data/test/helper_methods_test.rb +0 -558
- data/test/test_helper.rb +0 -23
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c1fe62ed99bb8f03e6a00a782f55adc5f6b6fcf84a444d77aa1c771b41d148a9
|
4
|
+
data.tar.gz: 1660db0b73ddbf77dac315c8d1466fb66958b9ebab59629c96f999536f17b824
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4bddd221544196836669a1309c97d536ad2d2b11ef10c74a265e034d0a1463ba5b4955651235ad395b9c37249a9d5eff2ef9ec9b659ab896a8fbca959b199924
|
7
|
+
data.tar.gz: ebd6e183dc3597f83c9ac8b22399d0ad52e345da6586b9de59c2386c8b5116d40199fcf494c44cd8d094a25ed543d5ee21397506d1979ebf851a973e23da3ced
|
@@ -0,0 +1,52 @@
|
|
1
|
+
name: CI
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
pull_request:
|
6
|
+
schedule:
|
7
|
+
- cron: '0 0 * * 0'
|
8
|
+
|
9
|
+
jobs:
|
10
|
+
test:
|
11
|
+
runs-on: ubuntu-latest
|
12
|
+
strategy:
|
13
|
+
matrix:
|
14
|
+
rails_version: [5.1.0, 5.2.0, 6.0.0, 6.1.0, master]
|
15
|
+
ruby_version: [3.0, 2.7, 2.6, 2.5]
|
16
|
+
exclude:
|
17
|
+
- ruby_version: 2.5
|
18
|
+
rails_version: master
|
19
|
+
- ruby_version: 2.6
|
20
|
+
rails_version: master
|
21
|
+
- ruby_version: 3.0
|
22
|
+
rails_version: 5.1.0
|
23
|
+
- ruby_version: 3.0
|
24
|
+
rails_version: 5.2.0
|
25
|
+
|
26
|
+
steps:
|
27
|
+
- uses: actions/checkout@v2
|
28
|
+
|
29
|
+
- name: Setup Ruby
|
30
|
+
uses: ruby/setup-ruby@v1
|
31
|
+
with:
|
32
|
+
ruby-version: ${{ matrix.ruby_version }}
|
33
|
+
|
34
|
+
- name: Run test
|
35
|
+
env:
|
36
|
+
RAILS_VERSION: ${{ matrix.rails_version }}
|
37
|
+
run: |
|
38
|
+
bundle update
|
39
|
+
cd spec/dummy; rake db:migrate db:test:prepare; cd ../..
|
40
|
+
bundle exec rake
|
41
|
+
|
42
|
+
- name: Upload coverage
|
43
|
+
uses: actions/upload-artifact@v2
|
44
|
+
if: always()
|
45
|
+
with:
|
46
|
+
name: coverage-ruby-${{ matrix.ruby_version }}-rails-${{ matrix.rails_version }}
|
47
|
+
path: coverage
|
48
|
+
|
49
|
+
- name: Show coverage
|
50
|
+
if: always()
|
51
|
+
run: |
|
52
|
+
cat coverage/coverage.txt
|
data/.gitignore
CHANGED
@@ -12,17 +12,18 @@ lib/bundler/man
|
|
12
12
|
pkg
|
13
13
|
rdoc
|
14
14
|
spec/reports
|
15
|
-
|
16
|
-
|
15
|
+
spec/tmp
|
16
|
+
spec/version_tmp
|
17
17
|
tmp
|
18
18
|
log/*.log
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
19
|
+
spec/dummy/db/*.sqlite3
|
20
|
+
spec/dummy/log/*.log
|
21
|
+
spec/dummy/tmp/
|
22
|
+
spec/dummy/.sass-cache
|
23
23
|
.DS_Store
|
24
24
|
|
25
25
|
/coverage/index.html
|
26
26
|
/coverage/assets
|
27
27
|
/coverage/*.json
|
28
28
|
/coverage/*.json.lock
|
29
|
+
/.ruby-version
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,25 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## Version 4.3.0
|
4
|
+
* Support generating `aria-current` attribute. It's disabled by default. See the readme for more info
|
5
|
+
|
6
|
+
## Version 4.2.0
|
7
|
+
* Support generating JSON-LD structured data. See the readme for more info (via #26, thanks @dkniffin)
|
8
|
+
|
9
|
+
## Version 4.1.0
|
10
|
+
* Depends only `railties` and `actionview`, not `rails` (via #7)
|
11
|
+
* Include `Gretel::ViewHelpers` module in `ActiveSupport.on_load(:action_view)` block
|
12
|
+
* Fix ruby 2.7 keywords warning (via #24, thanks @aki77)
|
13
|
+
* Fix multithreaded environment issue (via #13)
|
14
|
+
* `breadcrumbs.rb` is now evaluated in a instance of `Gretel::Crumbs::Builder`. If you want to call methods from `breadcrumbs.rb` other than `crumb`, `crumbs` and `crumb_defined?`, you need to call it via full reference like `Gretel::Crumbs.xxxx`
|
15
|
+
|
16
|
+
## Version 4.0.2
|
17
|
+
* The return value of `breadcrumbs` is `html_safe` now (via #22)
|
18
|
+
* For the slim template engine users: You don't need to use `==` instead of `=` for `breadcrumbs`
|
19
|
+
|
20
|
+
## Version 4.0.1
|
21
|
+
* Replaces data-vocabulary markup as google doesn't support it and now uses schema.org markup (via #17)
|
22
|
+
|
3
23
|
## Version 4.0.0
|
4
24
|
* Support Bootstrap 4. See the `:style` option in the readme for more info
|
5
25
|
* CSS class for fragment link or span is now customizable. See the `:fragment_class` option in the readme for more info
|
data/Gemfile
CHANGED
@@ -3,4 +3,6 @@ source "http://rubygems.org"
|
|
3
3
|
gemspec
|
4
4
|
|
5
5
|
rails_version = ENV['RAILS_VERSION'] || '>= 0'
|
6
|
-
|
6
|
+
rails_version = "~> #{rails_version}" if rails_version =~ /^\d/
|
7
|
+
|
8
|
+
gem 'rails', rails_version == 'master' ? { github: 'rails/rails' } : rails_version
|
data/README.md
CHANGED
@@ -1,10 +1,11 @@
|
|
1
|
-
|
1
|
+
[![Gem Version](https://badge.fury.io/rb/gretel.svg)](http://badge.fury.io/rb/gretel)
|
2
|
+
![](https://github.com/kzkn/gretel/workflows/CI/badge.svg)
|
2
3
|
|
3
4
|
<img src="http://i.imgur.com/CAKEaBM.png" alt="Handle breadcrumb trails... like a boss :)" />
|
4
5
|
|
5
6
|
([TL;DR](http://i.imgur.com/nH25yiH.png)) Gretel is a [Ruby on Rails](http://rubyonrails.org) plugin that makes it easy yet flexible to create breadcrumbs.
|
6
7
|
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
|
-
Gretel also supports [semantic breadcrumbs](
|
8
|
+
Gretel also supports [semantic breadcrumbs](https://developers.google.com/search/docs/data-types/breadcrumb) (those used in Google results).
|
8
9
|
|
9
10
|
Have fun!
|
10
11
|
|
@@ -88,7 +89,7 @@ Option | Description
|
|
88
89
|
:display_single_fragment | Whether it should display the breadcrumb if it includes only one link. | False
|
89
90
|
:link_current | Whether the current crumb should be linked to. | False
|
90
91
|
: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
|
91
|
-
:semantic | Whether it should generate [semantic breadcrumbs](
|
92
|
+
:semantic | Whether it should generate [semantic breadcrumbs](https://developers.google.com/search/docs/data-types/breadcrumb). | False
|
92
93
|
:id | ID for the breadcrumbs container. | None
|
93
94
|
:class | CSS class for the breadcrumbs container. Can be set to `nil` for no class. | `"breadcrumbs"`
|
94
95
|
:fragment_class | CSS class for the fragment link or span. Can be set to `nil` for no class. | None
|
@@ -97,6 +98,7 @@ Option | Description
|
|
97
98
|
:posttext_class | CSS class for the posttext, if given. Can be set to `nil` for no class. | `"posttext"`
|
98
99
|
:container_tag | Tag type that contains the breadcrumbs. | `:div`
|
99
100
|
:fragment_tag | Tag type to contain each breadcrumb fragment/link. | None
|
101
|
+
:aria_current | Value of `aria-current` attribute. | None
|
100
102
|
|
101
103
|
### Styles
|
102
104
|
|
@@ -104,12 +106,12 @@ These are the styles you can use with `breadcrumbs style: :xx`.
|
|
104
106
|
|
105
107
|
Style | Description
|
106
108
|
-------------- | -----------
|
107
|
-
`:inline` | Renders each link by itself with `›` as the seperator.
|
109
|
+
`:inline` | Default. Renders each link by itself with `›` as the seperator.
|
108
110
|
`:ol` | Renders the links in `<li>` elements contained in an outer `<ol>`.
|
109
111
|
`:ul` | Renders the links in `<li>` elements contained in an outer `<ul>`.
|
110
|
-
`:bootstrap` | Renders the links for use in [
|
112
|
+
`:bootstrap` | Renders the links for use in [Bootstrap v3](https://getbootstrap.com/docs/3.4/).
|
111
113
|
`:bootstrap4` | Renders the links for use in [Bootstrap v4](https://getbootstrap.com/).
|
112
|
-
`:foundation5` | Renders the links for use in [Foundation 5](
|
114
|
+
`:foundation5` | Renders the links for use in [Foundation 5](https://get.foundation/).
|
113
115
|
|
114
116
|
Or you can build the breadcrumbs manually for full customization; see below.
|
115
117
|
|
@@ -201,6 +203,11 @@ end
|
|
201
203
|
crumb :user do |user|
|
202
204
|
link user_name_for(user), user
|
203
205
|
end
|
206
|
+
|
207
|
+
# I18n
|
208
|
+
crumb :home do
|
209
|
+
link t("breadcrumbs.home"), root_path
|
210
|
+
end
|
204
211
|
```
|
205
212
|
|
206
213
|
## Building the breadcrumbs manually
|
@@ -218,6 +225,23 @@ You can use the `breadcrumbs` method directly as an array. It will return an arr
|
|
218
225
|
<% end %>
|
219
226
|
```
|
220
227
|
|
228
|
+
If you use this approach, you lose the built-in semantic breadcrumb functionality. One way to
|
229
|
+
add them back is to use JSON-LD structured data:
|
230
|
+
|
231
|
+
```erb
|
232
|
+
<script type="application/ld+json">
|
233
|
+
<%= breadcrumbs.structured_data(url_base: "https://example.com") %>
|
234
|
+
</script>
|
235
|
+
```
|
236
|
+
|
237
|
+
Or, you can infer `url_base` from `request`:
|
238
|
+
|
239
|
+
```erb
|
240
|
+
<script type="application/ld+json">
|
241
|
+
<%= breadcrumbs.structured_data(url_base: "#{request.protocol}#{request.host_with_port}") %>
|
242
|
+
</script>
|
243
|
+
```
|
244
|
+
|
221
245
|
## Getting the parent breadcrumb
|
222
246
|
|
223
247
|
If you want to add a link to the parent breadcrumb, you can use the `parent_breadcrumb` view helper.
|
@@ -291,56 +315,34 @@ breadcrumbs do |links|
|
|
291
315
|
end
|
292
316
|
```
|
293
317
|
|
294
|
-
###
|
295
|
-
|
296
|
-
Since Gretel version 2.1.0, the breadcrumb configuration files are now reloaded in the Rails development environment if they change. In other environments, like production, the files are loaded once, when first needed.
|
297
|
-
|
298
|
-
### Setting breadcrumb trails
|
299
|
-
|
300
|
-
The [gretel-trails](https://github.com/lassebunk/gretel-trails) gem can handle adding and hiding trails from the URL automatically. This makes it possible to link back to a different breadcrumb trail than the one specified in your breadcrumb, for example if you have a
|
301
|
-
store with products that have a default parent to the category breadcrumb, but when visiting from the reviews section, you want to link back to the reviews instead.
|
302
|
-
|
303
|
-
You can apply trails to select links by adding a simple JS selector (`js-append-trail` or another you choose), and after each page load it hides the trail from the URL, so the server sees it but the users don't.
|
304
|
-
|
305
|
-
Check out the gem [here](https://github.com/lassebunk/gretel-trails).
|
306
|
-
|
307
|
-
|
308
|
-
## Upgrading from version 2.0 or below
|
309
|
-
|
310
|
-
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).
|
311
|
-
In the Rails development environment, these files are automatically reloaded when changed.
|
318
|
+
### ARIA support
|
312
319
|
|
313
|
-
|
320
|
+
You can improve the accessibility of your page with the markup that specified in [ARIA](https://www.w3.org/TR/wai-aria-practices/examples/breadcrumb/index.html). Gretel supports generating `aria-current` attribute:
|
314
321
|
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
Gretel::Crumbs.layout do
|
319
|
-
crumb :root do
|
320
|
-
link "Home", root_path
|
321
|
-
end
|
322
|
-
end
|
322
|
+
```erb
|
323
|
+
<% breadcrumb :issue, @issue %>
|
324
|
+
<%= breadcrumbs aria_current: "page" %>
|
323
325
|
```
|
324
326
|
|
325
|
-
|
327
|
+
This will generate the following HTML (indented for readability):
|
326
328
|
|
327
|
-
```
|
328
|
-
|
329
|
-
|
330
|
-
|
329
|
+
```html
|
330
|
+
<div class="breadcrumbs">
|
331
|
+
<a href="/">Home</a> ›
|
332
|
+
<a href="/issues">All issues</a> ›
|
333
|
+
<span class="current" aria-current="page">My Issue</span>
|
334
|
+
</div>
|
331
335
|
```
|
332
336
|
|
333
|
-
in `config/breadcrumbs.rb`.
|
334
|
-
|
335
337
|
## Documentation
|
336
338
|
|
337
|
-
* [Full documentation](
|
339
|
+
* [Full documentation](https://rubydoc.info/gems/gretel)
|
338
340
|
* [Changelog](https://github.com/kzkn/gretel/blob/master/CHANGELOG.md)
|
339
|
-
* [Tutorial on using Gretel](
|
341
|
+
* [Tutorial on using Gretel](https://www.sitepoint.com/breadcrumbs-rails-gretel/) (Sitepoint)
|
340
342
|
|
341
343
|
## Versioning
|
342
344
|
|
343
|
-
Follows [semantic versioning](
|
345
|
+
Follows [semantic versioning](https://semver.org/).
|
344
346
|
|
345
347
|
## Contributing
|
346
348
|
|
@@ -352,7 +354,7 @@ To contribute:
|
|
352
354
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
353
355
|
3. Make your changes
|
354
356
|
4. Add/Fix tests
|
355
|
-
5. Prepare database for testing: `cd
|
357
|
+
5. Prepare database for testing: `cd spec/dummy; rake db:migrate; rake db:test:prepare; cd ../..`
|
356
358
|
6. Run `rake` to make sure all tests pass
|
357
359
|
7. Be sure to check in the changes to `coverage/coverage.txt`
|
358
360
|
8. Commit your changes (`git commit -am 'Add new feature'`)
|
data/Rakefile
CHANGED
@@ -1,10 +1,6 @@
|
|
1
|
-
require 'rake/testtask'
|
2
1
|
require 'bundler/gem_tasks'
|
2
|
+
require "rspec/core/rake_task"
|
3
3
|
|
4
|
-
|
5
|
-
t.libs << "test"
|
6
|
-
t.test_files = FileList['test/**/*_test.rb']
|
7
|
-
t.verbose = true
|
8
|
-
end
|
4
|
+
RSpec::Core::RakeTask.new(:spec)
|
9
5
|
|
10
|
-
task default: :
|
6
|
+
task default: :spec
|
data/coverage/coverage.txt
CHANGED
data/gretel.gemspec
CHANGED
@@ -1,7 +1,4 @@
|
|
1
|
-
|
2
|
-
lib = File.expand_path('../lib', __FILE__)
|
3
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require 'gretel/version'
|
1
|
+
require_relative 'lib/gretel/version'
|
5
2
|
|
6
3
|
Gem::Specification.new do |gem|
|
7
4
|
gem.name = "gretel"
|
@@ -13,14 +10,15 @@ Gem::Specification.new do |gem|
|
|
13
10
|
gem.homepage = "http://github.com/kzkn/gretel"
|
14
11
|
gem.license = "MIT"
|
15
12
|
|
16
|
-
gem.files =
|
17
|
-
|
13
|
+
gem.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
14
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
15
|
+
end
|
18
16
|
gem.require_paths = ["lib"]
|
19
17
|
|
20
|
-
gem.add_dependency "
|
18
|
+
gem.add_dependency "railties", [">= 5.1", "< 7.0"]
|
19
|
+
gem.add_dependency "actionview", [">= 5.1", "< 7.0"]
|
21
20
|
gem.add_development_dependency "sqlite3"
|
22
|
-
gem.add_development_dependency "
|
23
|
-
gem.add_development_dependency "
|
24
|
-
gem.add_development_dependency "simplecov"
|
25
|
-
gem.add_development_dependency "simplecov-erb", "~> 0.1"
|
21
|
+
gem.add_development_dependency "rspec-rails"
|
22
|
+
gem.add_development_dependency "simplecov"
|
23
|
+
gem.add_development_dependency "simplecov-erb"
|
26
24
|
end
|
data/lib/gretel.rb
CHANGED
@@ -1,10 +1,6 @@
|
|
1
1
|
require 'gretel/version'
|
2
2
|
require 'gretel/resettable'
|
3
|
-
require 'gretel/
|
4
|
-
require 'gretel/crumb'
|
5
|
-
require 'gretel/link'
|
6
|
-
require 'gretel/renderer'
|
7
|
-
require 'gretel/view_helpers'
|
3
|
+
require 'gretel/railtie'
|
8
4
|
|
9
5
|
module Gretel
|
10
6
|
class << self
|
@@ -57,5 +53,3 @@ module Gretel
|
|
57
53
|
end
|
58
54
|
end
|
59
55
|
end
|
60
|
-
|
61
|
-
ActionView::Base.send :include, Gretel::ViewHelpers
|
data/lib/gretel/crumb.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'gretel/link'
|
2
|
+
|
1
3
|
module Gretel
|
2
4
|
class Crumb
|
3
5
|
# Initializes a new crumb from the given +key+.
|
@@ -13,7 +15,7 @@ module Gretel
|
|
13
15
|
raise ArgumentError, "Breadcrumb :#{key} not found." unless block
|
14
16
|
@key = key
|
15
17
|
@context = context
|
16
|
-
instance_exec
|
18
|
+
instance_exec(*args, &block)
|
17
19
|
end
|
18
20
|
|
19
21
|
# Sets link of the breadcrumb.
|
@@ -29,7 +31,7 @@ module Gretel
|
|
29
31
|
|
30
32
|
# Transform objects to real paths.
|
31
33
|
url = url_for(url) if url
|
32
|
-
|
34
|
+
|
33
35
|
links << Gretel::Link.new(key, text, url, options)
|
34
36
|
end
|
35
37
|
|
@@ -64,5 +66,6 @@ module Gretel
|
|
64
66
|
def method_missing(method, *args, &block)
|
65
67
|
context.send(method, *args, &block)
|
66
68
|
end
|
69
|
+
ruby2_keywords(:method_missing) if respond_to?(:ruby2_keywords, true)
|
67
70
|
end
|
68
71
|
end
|
data/lib/gretel/crumbs.rb
CHANGED
@@ -3,11 +3,6 @@ module Gretel
|
|
3
3
|
class << self
|
4
4
|
include Resettable
|
5
5
|
|
6
|
-
# Stores the supplied block for later use.
|
7
|
-
def crumb(key, &block)
|
8
|
-
crumbs[key] = block
|
9
|
-
end
|
10
|
-
|
11
6
|
# Returns a hash of all stored crumb blocks.
|
12
7
|
def crumbs
|
13
8
|
@crumbs ||= {}
|
@@ -20,14 +15,15 @@ module Gretel
|
|
20
15
|
|
21
16
|
# Loads the breadcrumb configuration files.
|
22
17
|
def load_breadcrumbs
|
23
|
-
|
18
|
+
builder = Builder.new
|
24
19
|
|
25
20
|
loaded_file_mtimes.clear
|
26
21
|
breadcrumb_files.each do |file|
|
27
|
-
instance_eval open(file).read, file
|
22
|
+
builder.instance_eval open(file).read, file
|
28
23
|
loaded_file_mtimes << File.mtime(file)
|
29
24
|
end
|
30
25
|
|
26
|
+
@crumbs = builder.crumbs
|
31
27
|
@loaded = true
|
32
28
|
end
|
33
29
|
|
@@ -59,6 +55,29 @@ module Gretel
|
|
59
55
|
def loaded_file_mtimes
|
60
56
|
@loaded_file_mtimes ||= []
|
61
57
|
end
|
58
|
+
|
59
|
+
class Builder
|
60
|
+
attr_reader :crumbs
|
61
|
+
|
62
|
+
def initialize
|
63
|
+
@crumbs = {}
|
64
|
+
end
|
65
|
+
|
66
|
+
# Stores the supplied block for later use.
|
67
|
+
def crumb(key, &block)
|
68
|
+
crumbs[key] = block
|
69
|
+
end
|
70
|
+
|
71
|
+
# Returns a hash of all stored crumb blocks.
|
72
|
+
def crumbs
|
73
|
+
@crumbs ||= {}
|
74
|
+
end
|
75
|
+
|
76
|
+
# Returns true if a crumb with the given key has been set.
|
77
|
+
def crumb_defined?(key)
|
78
|
+
crumbs.has_key?(key)
|
79
|
+
end
|
80
|
+
end
|
62
81
|
end
|
63
82
|
end
|
64
83
|
end
|