crumbs 1.1.2 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +67 -0
- data/lib/crumbs/action_controller/base.rb +6 -8
- data/lib/crumbs/definitions.rb +4 -4
- data/lib/crumbs/railtie.rb +0 -3
- data/lib/crumbs/version.rb +1 -1
- data/lib/crumbs.rb +15 -1
- data/lib/generators/crumbs/install_generator.rb +13 -0
- data/lib/generators/crumbs/templates/crumbs.rb +2 -0
- data/test/dummy/log/test.log +1485 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/13fe41fee1fe35b49d145bcc06610705 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/2f5173deea6c795b8fdde723bb4b63af +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/357970feca3ac29060c1e3861e2c0953 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/cffd775d018f68ce5dba1ee0d951a994 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/d771ace226fc8215a3572e0aa35bb0d6 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/f7cbd26ba1d28d48de824f0e94586655 +0 -0
- data/test/generator_test.rb +18 -0
- data/test/with_last_test.rb +8 -8
- data/test/without_last_test.rb +8 -8
- metadata +9 -5
- data/README.rdoc +0 -31
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 081d368a0f3413cccc92fedb8eeec622b626ee1a
|
4
|
+
data.tar.gz: b8f970e0e85570aab1f4cb493c050b0126625bd0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3f195ea732621d1be2cb8761d978baa3b1227c3581d0ecf7e63a523e28c080750743538882055827355c1f9472d277f070ed3b8274c7b2493d0312281266acbd
|
7
|
+
data.tar.gz: 3d91bb86d4a4a38f9d88ea4261c0dc65eecfd64780a741dd9091fb3b607adee49b9ac1b591a046a57c87e46f8d2bda2302dae812f9da549bb93433688677eb8d
|
data/README.md
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
[](http://badge.fury.io/rb/crumbs) [](https://codeclimate.com/github/museways/crumbs) [](https://travis-ci.org/museways/crumbs)
|
2
|
+
|
3
|
+
# Crumbs
|
4
|
+
|
5
|
+
Adds a handy crumbs variable available in your views in rails.
|
6
|
+
|
7
|
+
## Install
|
8
|
+
|
9
|
+
Put this line in your Gemfile:
|
10
|
+
```ruby
|
11
|
+
gem 'crumbs'
|
12
|
+
```
|
13
|
+
|
14
|
+
Then bundle:
|
15
|
+
```
|
16
|
+
$ bundle
|
17
|
+
```
|
18
|
+
|
19
|
+
## Configuration
|
20
|
+
|
21
|
+
Generate the configuration file:
|
22
|
+
```
|
23
|
+
rails g crumbs:install
|
24
|
+
```
|
25
|
+
|
26
|
+
The defaults values are:
|
27
|
+
```ruby
|
28
|
+
Crumbs.configure do |config|
|
29
|
+
config.show_last = false
|
30
|
+
end
|
31
|
+
```
|
32
|
+
|
33
|
+
## Usage
|
34
|
+
|
35
|
+
In your controllers add crumbs to the actions you want:
|
36
|
+
```ruby
|
37
|
+
crumb :home, 'Home'
|
38
|
+
```
|
39
|
+
|
40
|
+
You can use a lambda, proc or block too, will receive the corresponding url parameters:
|
41
|
+
```ruby
|
42
|
+
crumb :product, proc { |params| Product.find(params[:id]).name }
|
43
|
+
```
|
44
|
+
|
45
|
+
Then in your views would be available a crumbs variable:
|
46
|
+
```erb
|
47
|
+
<% @crumbs.each do |crumb| %>
|
48
|
+
> <%= link_to crumb[:name], crumb[:path] %>
|
49
|
+
<% end %>
|
50
|
+
```
|
51
|
+
|
52
|
+
## Last crumb
|
53
|
+
|
54
|
+
If you want to show the last crumb, change the default:
|
55
|
+
```ruby
|
56
|
+
Crumbs.configure do |config|
|
57
|
+
config.crumbs.show_last = true
|
58
|
+
end
|
59
|
+
```
|
60
|
+
|
61
|
+
## Credits
|
62
|
+
|
63
|
+
This gem is maintained and funded by [museways](http://museways.com).
|
64
|
+
|
65
|
+
## License
|
66
|
+
|
67
|
+
It is free software, and may be redistributed under the terms specified in the MIT-LICENSE file.
|
@@ -22,7 +22,7 @@ module Crumbs
|
|
22
22
|
elsif
|
23
23
|
session[:referers] = [referer]
|
24
24
|
end
|
25
|
-
paths.pop unless
|
25
|
+
paths.pop unless Crumbs.config.show_last
|
26
26
|
@crumbs = []
|
27
27
|
paths.each do |path|
|
28
28
|
params = Rails.application.routes.recognize_path("#{request.base_url}#{path}") rescue next
|
@@ -39,17 +39,15 @@ module Crumbs
|
|
39
39
|
paths = [paths] unless paths.is_a? Array
|
40
40
|
session[:referers].rindex { |referer| paths.include? referer[:path] }
|
41
41
|
end
|
42
|
-
|
42
|
+
|
43
43
|
module ClassMethods
|
44
|
-
|
44
|
+
|
45
45
|
protected
|
46
|
-
|
46
|
+
|
47
47
|
def crumb(action, name=nil, &block)
|
48
|
-
|
49
|
-
name = block_given? ? block : name
|
50
|
-
Crumbs::Definitions.add controller.to_s, action.to_s, name
|
48
|
+
Crumbs::Definitions.add controller_path, action.to_s, (block_given? ? block : name)
|
51
49
|
end
|
52
|
-
|
50
|
+
|
53
51
|
end
|
54
52
|
end
|
55
53
|
end
|
data/lib/crumbs/definitions.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
module Crumbs
|
2
2
|
class Definitions
|
3
3
|
class << self
|
4
|
-
|
4
|
+
|
5
5
|
def all
|
6
6
|
@all ||= {}
|
7
7
|
end
|
8
|
-
|
8
|
+
|
9
9
|
def add(controller, action, name)
|
10
10
|
if all.has_key? controller
|
11
11
|
all[controller][action] = name
|
@@ -13,14 +13,14 @@ module Crumbs
|
|
13
13
|
all[controller] = { action => name }
|
14
14
|
end
|
15
15
|
end
|
16
|
-
|
16
|
+
|
17
17
|
def find(controller, action, params)
|
18
18
|
if all.has_key? controller and all[controller].has_key? action
|
19
19
|
name = all[controller][action]
|
20
20
|
name.is_a?(Proc) ? name.call(params) : name
|
21
21
|
end
|
22
22
|
end
|
23
|
-
|
23
|
+
|
24
24
|
end
|
25
25
|
end
|
26
26
|
end
|
data/lib/crumbs/railtie.rb
CHANGED
data/lib/crumbs/version.rb
CHANGED
data/lib/crumbs.rb
CHANGED
@@ -1,7 +1,21 @@
|
|
1
1
|
require 'crumbs/action_controller/base'
|
2
2
|
require 'crumbs/definitions'
|
3
3
|
require 'crumbs/railtie'
|
4
|
-
require 'crumbs/version'
|
5
4
|
|
6
5
|
module Crumbs
|
6
|
+
class << self
|
7
|
+
|
8
|
+
def configure
|
9
|
+
yield config
|
10
|
+
end
|
11
|
+
|
12
|
+
def config
|
13
|
+
@config ||= begin
|
14
|
+
ActiveSupport::OrderedOptions.new.tap do |config|
|
15
|
+
config.show_last = false
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
7
21
|
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
|
3
|
+
module Crumbs
|
4
|
+
class InstallGenerator < Rails::Generators::Base
|
5
|
+
|
6
|
+
source_root File.expand_path('../templates', __FILE__)
|
7
|
+
|
8
|
+
def create_initializer
|
9
|
+
copy_file 'crumbs.rb', 'config/initializers/crumbs.rb'
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
13
|
+
end
|