crumbs 2.0.2 → 2.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +39 -8
- data/lib/crumbs/action_controller/base.rb +2 -2
- data/lib/crumbs/dsl/controller.rb +27 -0
- data/lib/crumbs/dsl/namespace.rb +16 -0
- data/lib/crumbs/proxy.rb +11 -2
- data/lib/crumbs/railtie.rb +4 -0
- data/lib/crumbs/version.rb +1 -1
- data/lib/crumbs.rb +17 -6
- data/lib/generators/crumbs/install_generator.rb +2 -1
- data/lib/generators/crumbs/templates/configure.rb +2 -0
- data/test/dummy/app/controllers/namespace/pages_controller.rb +8 -0
- data/test/dummy/app/controllers/pages_controller.rb +1 -1
- data/test/dummy/config/crumbs.rb +21 -0
- data/test/dummy/config/locales/en.yml +3 -1
- data/test/dummy/config/routes.rb +3 -1
- data/test/dummy/log/test.log +9417 -0
- data/test/generator_test.rb +2 -1
- data/test/with_last_test.rb +19 -0
- data/test/without_last_test.rb +17 -0
- metadata +10 -50
- data/lib/crumbs/controller.rb +0 -21
- data/test/dummy/config/initializers/crumbs.rb +0 -19
- 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/dummy/tmp/cache/assets/test/sprockets/v3.0/0CfsnjV9PTgwlR5hr0ZJ0lNFInsx4qr_zgDnI8wYXdA.cache +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/3_I2jn5YxLciv3GtK_auIHda4TWNhZGieWePNoABWag.cache +0 -3
- data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/8pLqt1nXpM0CADV6_EF0KDbq4JiQCmjMIxj6pPZgm40.cache +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/9_0iCm3DZpig3DFydwsV8-3vCsUegD9B-YR_kxfWuxg.cache +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/DtXc_gTNuqlMogm9DYo1deRm00jNXPf0fyilnnre4mo.cache +0 -1
- data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/KuObwG9-kiiTC9uTe_Y_WcDUv6iru-sTemI6-k4K-VI.cache +0 -1
- data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/NB1P923S_ERHEViNCpWJ8SWQPVGhGQbnoEZDFXAsMkU.cache +0 -2
- data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/NRB4IoGG5vlEQSlxE-fq7JjM5DiMsZgx53bfpX9Qa-Q.cache +0 -3
- data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/PeALxNvJVmSUZlRLwsDzjXcHYkYl7swdEPX25zaZ4Sk.cache +0 -2
- data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/SaR332UYmMwbCg2uCE2kc8IdAy0fz1Z0rzVjjdcHBfc.cache +0 -1
- data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/UWBHdOtGfj0EG8YqQJFo4VXX78gdxQ9UKQckSjlh2Xk.cache +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/fg8Lpn3VSU1Cz0bY6ek8PqNXJKwHE4tH-_pxSZSVHoc.cache +0 -1
- data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/j633CDb2pirQ_kRgsBIUuO9xrlJnPoE5wSh_Sk7a0B8.cache +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/oL3tj9Cx76XI84KeuRvNWkE8SRDP7uTSGgeKXBJfwi4.cache +0 -1
- data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/p8gRJoCgrplMxf3cIeQwVnrXECPodO1XmZT3b9iaId0.cache +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/wZymCZN9x4UDexGqYG57Pp_5dfraxUy5TuEtv9bQzaE.cache +0 -0
- /data/lib/generators/crumbs/templates/{crumbs.rb → define.rb} +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ee9ed2bb2383f091cd3122b573be9d7e2eb37b4c
|
4
|
+
data.tar.gz: 31cd1e7ba8675ccddcd534c5c300471f6a3500c2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d54d109fe0722703174e00e9fc14a2bb980dc87cd624470027d30ef0141ae6e1421e9861a32cb574575e792c737f92428ecd1ab2abce8d783b380f76d05236bb
|
7
|
+
data.tar.gz: 61e26356f6bdc4090ff067150320ce8e011cd9dd23c30edb0ea480a7f5056ca4e540086712968dd3178df219b08cfa8fc629cccd097e0558faf04e8506c9634b
|
data/README.md
CHANGED
@@ -18,7 +18,7 @@ $ bundle
|
|
18
18
|
|
19
19
|
## Configuration
|
20
20
|
|
21
|
-
Generate the initialization
|
21
|
+
Generate the initialization and definition files:
|
22
22
|
```
|
23
23
|
rails g crumbs:install
|
24
24
|
```
|
@@ -30,29 +30,60 @@ Crumbs.configure do |config|
|
|
30
30
|
end
|
31
31
|
```
|
32
32
|
|
33
|
-
##
|
33
|
+
## DSL
|
34
34
|
|
35
|
-
In your
|
35
|
+
In your config/crumbs.rb file add crumbs referencing the controller and action with the dsl:
|
36
36
|
```ruby
|
37
37
|
Crumbs.define do
|
38
38
|
controller :site do
|
39
|
-
action :
|
39
|
+
action :index, 'Home'
|
40
40
|
end
|
41
41
|
end
|
42
42
|
```
|
43
43
|
|
44
|
-
|
44
|
+
To translate names you can use the t method (keys starting with dot are prepended with 'crumbs.'):
|
45
45
|
```ruby
|
46
46
|
Crumbs.define do
|
47
47
|
controller :site do
|
48
|
-
action :
|
48
|
+
action :index, t('.home')
|
49
|
+
end
|
50
|
+
end
|
51
|
+
```
|
52
|
+
|
53
|
+
If you don't like to prepend the namespace of the controller:
|
54
|
+
```ruby
|
55
|
+
Crumbs.define do
|
56
|
+
namespace :admin do
|
57
|
+
controller :products do
|
58
|
+
action :index, 'Products'
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
```
|
63
|
+
|
64
|
+
You can use a block for dynamic names, will receive the corresponding url parameters:
|
65
|
+
```ruby
|
66
|
+
Crumbs.define do
|
67
|
+
controller :products do
|
68
|
+
action :show do |params|
|
49
69
|
Product.find(params[:id]).name
|
50
70
|
end
|
51
71
|
end
|
52
72
|
end
|
53
73
|
```
|
54
74
|
|
55
|
-
|
75
|
+
## Performance
|
76
|
+
|
77
|
+
To disable crumbs for any controller or action:
|
78
|
+
```ruby
|
79
|
+
class Api::BaseController < ApplicationController
|
80
|
+
skip_before_action :set_crumbs
|
81
|
+
end
|
82
|
+
```
|
83
|
+
|
84
|
+
## Views
|
85
|
+
|
86
|
+
In your views would be available a crumbs variable:
|
56
87
|
```erb
|
57
88
|
<% @crumbs.each do |crumb| %>
|
58
89
|
> <%= link_to crumb[:name], crumb[:path] %>
|
@@ -61,7 +92,7 @@ Then in your views would be available a crumbs variable:
|
|
61
92
|
|
62
93
|
## Last crumb
|
63
94
|
|
64
|
-
If you want to show the last crumb, change the default:
|
95
|
+
If you want to show the last crumb, change the default in your config/initializers/crumbs.rb:
|
65
96
|
```ruby
|
66
97
|
Crumbs.configure do |config|
|
67
98
|
config.crumbs.show_last = true
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Crumbs
|
2
|
+
module DSL
|
3
|
+
class Controller
|
4
|
+
|
5
|
+
def initialize(controller, &block)
|
6
|
+
@controller = controller
|
7
|
+
instance_eval &block
|
8
|
+
end
|
9
|
+
|
10
|
+
def action(action, name=nil, &block)
|
11
|
+
Crumbs.add(
|
12
|
+
@controller.to_s,
|
13
|
+
action.to_s,
|
14
|
+
(block_given? ? block : name)
|
15
|
+
)
|
16
|
+
end
|
17
|
+
|
18
|
+
def t(key)
|
19
|
+
if key.starts_with? '.'
|
20
|
+
key.prepend 'crumbs'
|
21
|
+
end
|
22
|
+
I18n.t(key)
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Crumbs
|
2
|
+
module DSL
|
3
|
+
class Namespace
|
4
|
+
|
5
|
+
def initialize(namespace, &block)
|
6
|
+
@namespace = namespace
|
7
|
+
instance_eval &block
|
8
|
+
end
|
9
|
+
|
10
|
+
def controller(name, &block)
|
11
|
+
Controller.new("#{@namespace}/#{name}", &block)
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/lib/crumbs/proxy.rb
CHANGED
@@ -1,8 +1,17 @@
|
|
1
1
|
module Crumbs
|
2
2
|
class Proxy
|
3
3
|
|
4
|
-
def
|
5
|
-
|
4
|
+
def initialize(&block)
|
5
|
+
instance_eval &block
|
6
|
+
end
|
7
|
+
|
8
|
+
%w(
|
9
|
+
namespace
|
10
|
+
controller
|
11
|
+
).each do |name|
|
12
|
+
define_method name do |*args, &block|
|
13
|
+
DSL.const_get(name.to_s.classify).new(*args, &block)
|
14
|
+
end
|
6
15
|
end
|
7
16
|
|
8
17
|
end
|
data/lib/crumbs/railtie.rb
CHANGED
data/lib/crumbs/version.rb
CHANGED
data/lib/crumbs.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'crumbs/action_controller/base'
|
2
2
|
require 'crumbs/proxy'
|
3
|
-
require 'crumbs/
|
3
|
+
require 'crumbs/dsl/namespace'
|
4
|
+
require 'crumbs/dsl/controller'
|
4
5
|
require 'crumbs/railtie'
|
5
6
|
|
6
7
|
module Crumbs
|
@@ -19,12 +20,12 @@ module Crumbs
|
|
19
20
|
end
|
20
21
|
|
21
22
|
def define(&block)
|
22
|
-
Proxy.new
|
23
|
+
Proxy.new(&block)
|
23
24
|
end
|
24
25
|
|
25
26
|
def find(controller, action, params)
|
26
|
-
if
|
27
|
-
name =
|
27
|
+
if registry.has_key? controller and registry[controller].has_key? action
|
28
|
+
name = registry[controller][action]
|
28
29
|
if name.is_a? Proc
|
29
30
|
name.call params
|
30
31
|
else
|
@@ -33,8 +34,18 @@ module Crumbs
|
|
33
34
|
end
|
34
35
|
end
|
35
36
|
|
36
|
-
def
|
37
|
-
|
37
|
+
def add(controller, action, name)
|
38
|
+
if registry.has_key? controller
|
39
|
+
registry[controller][action] = name
|
40
|
+
else
|
41
|
+
registry[controller] = { action => name }
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
protected
|
46
|
+
|
47
|
+
def registry
|
48
|
+
@registry ||= {}
|
38
49
|
end
|
39
50
|
|
40
51
|
end
|
@@ -6,7 +6,8 @@ module Crumbs
|
|
6
6
|
source_root File.expand_path('../templates', __FILE__)
|
7
7
|
|
8
8
|
def create_initializer
|
9
|
-
copy_file '
|
9
|
+
copy_file 'configure.rb', 'config/initializers/crumbs.rb'
|
10
|
+
copy_file 'define.rb', 'config/crumbs.rb'
|
10
11
|
end
|
11
12
|
|
12
13
|
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
Crumbs.define do
|
2
|
+
|
3
|
+
namespace :namespace do
|
4
|
+
controller :pages do
|
5
|
+
action :index, 'Namespaced Home'
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
controller :pages do
|
10
|
+
action :index, 'Home'
|
11
|
+
action :nested, 'Nested'
|
12
|
+
action :i18n, t('.hello')
|
13
|
+
action :static do
|
14
|
+
t('.static')
|
15
|
+
end
|
16
|
+
action :param do |params|
|
17
|
+
"Param#{params[:param]}"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
data/test/dummy/config/routes.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Dummy::Application.routes.draw do
|
2
2
|
|
3
|
-
root to: 'pages#
|
3
|
+
root to: 'pages#index'
|
4
4
|
|
5
5
|
get 'static', to: 'pages#static'
|
6
6
|
get 'static/nested', to: 'pages#nested'
|
@@ -15,6 +15,8 @@ Dummy::Application.routes.draw do
|
|
15
15
|
get 'i18n', to: 'pages#i18n'
|
16
16
|
get 'i18n/nested', to: 'pages#nested'
|
17
17
|
|
18
|
+
get 'namespaced', to: 'namespace/pages#index'
|
19
|
+
|
18
20
|
# The priority is based upon order of creation: first created -> highest priority.
|
19
21
|
# See how all your routes lay out with "rake routes".
|
20
22
|
|