crumbs 1.0.8 → 1.0.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/MIT-LICENSE +1 -1
- data/README.rdoc +1 -1
- data/lib/crumbs/action_controller/base.rb +40 -87
- data/lib/crumbs/definitions.rb +26 -0
- data/lib/crumbs/version.rb +1 -1
- data/lib/crumbs.rb +1 -2
- data/test/dummy/app/controllers/pages_controller.rb +1 -1
- data/test/dummy/log/test.log +13928 -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/with_last_test.rb +45 -45
- data/test/without_last_test.rb +40 -40
- metadata +20 -20
- data/lib/crumbs/history.rb +0 -34
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 23f731609ef462cb58727f9e67be6eac84f2475e
|
4
|
+
data.tar.gz: 954a7f6708787612add650639e15176c389aea0e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 89edb12b5f957aed754ff382564ce7f90f754f63179f53021720ce6615820bb33a39df9ce961b583d41cc49e26c438b4195f9b500a62e64a703f3bebd9e44a08
|
7
|
+
data.tar.gz: c6b1b02a804178b9e813059873da429532298834a4862667f315d1effd18f43899fa91ad0701bfd1e33621acf3123b33a07caa2f5e031bac531dc31262867595
|
data/MIT-LICENSE
CHANGED
data/README.rdoc
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
{<img src="https://codeclimate.com/github/
|
1
|
+
{<img src="https://badge.fury.io/rb/crumbs.png" alt="Gem Version" />}[http://badge.fury.io/rb/crumbs] {<img src="https://codeclimate.com/github/museways/crumbs.png" />}[https://codeclimate.com/github/museways/crumbs] {<img src="https://travis-ci.org/museways/crumbs.png?branch=master" alt="Build Status" />}[https://travis-ci.org/museways/crumbs] {<img src="https://gemnasium.com/museways/crumbs.png" alt="Dependency Status" />}[https://gemnasium.com/museways/crumbs]
|
2
2
|
|
3
3
|
= Crumbs
|
4
4
|
|
@@ -7,114 +7,67 @@ module Crumbs
|
|
7
7
|
before_filter :define_crumbs
|
8
8
|
end
|
9
9
|
|
10
|
-
protected
|
10
|
+
protected
|
11
11
|
|
12
|
-
def define_crumbs
|
13
|
-
|
12
|
+
def define_crumbs
|
13
|
+
update_referers
|
14
14
|
parts = request.path.split('/')
|
15
15
|
parts.pop unless Rails.application.config.crumbs.show_last
|
16
16
|
@crumbs = []
|
17
17
|
while parts.size > 0
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
path = session[:referer][index][:fullpath]
|
23
|
-
end
|
24
|
-
@crumbs << { name: name, path: path }
|
25
|
-
end
|
26
|
-
end
|
27
|
-
parts.pop
|
28
|
-
end
|
29
|
-
@crumbs.reverse!
|
30
|
-
end
|
31
|
-
|
32
|
-
def find_path_params(path)
|
33
|
-
begin
|
34
|
-
Rails.application.routes.recognize_path(request.base_url + path)
|
35
|
-
rescue
|
36
|
-
false
|
18
|
+
if crumb = find_crumb(parts.size == 1 ? '/' : parts.join('/'))
|
19
|
+
@crumbs << crumb
|
20
|
+
end
|
21
|
+
parts.pop
|
37
22
|
end
|
23
|
+
@crumbs.reverse!
|
38
24
|
end
|
39
25
|
|
40
|
-
def
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
elsif index = in_referer_tree?
|
49
|
-
session[:referer] = session[:referer].slice(Range.new(0, index))
|
50
|
-
add_to_referer
|
51
|
-
else
|
52
|
-
reset_referer
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
def add_to_referer
|
57
|
-
session[:referer] << { base_url: request.base_url, path: request.path, fullpath: request.fullpath }
|
58
|
-
end
|
59
|
-
|
60
|
-
def reset_referer
|
61
|
-
session[:referer] = [{ base_url: request.base_url, path: request.path, fullpath: request.fullpath }]
|
62
|
-
end
|
63
|
-
|
64
|
-
def join_parts(parts)
|
65
|
-
path = parts.join('/')
|
66
|
-
path[0] != '/' ? "/#{path}" : path
|
67
|
-
end
|
68
|
-
|
69
|
-
def is_last_referer?
|
70
|
-
last = session[:referer].last
|
71
|
-
last[:base_url] == request.base_url and last[:path] == request.path
|
26
|
+
def find_crumb(path)
|
27
|
+
params = Rails.application.routes.recognize_path(request.base_url + path) rescue return
|
28
|
+
if name = Crumbs::Definitions.find(params[:controller], params[:action], params)
|
29
|
+
if index = find_referer_index(path)
|
30
|
+
path = referers[index][:fullpath]
|
31
|
+
end
|
32
|
+
{ name: name, path: path }
|
33
|
+
end
|
72
34
|
end
|
73
|
-
|
74
|
-
def
|
75
|
-
|
76
|
-
parts = request.path.split('/')
|
77
|
-
parts.size > 0 and last[:path] == join_parts(parts.slice(0, parts.size - 1))
|
35
|
+
|
36
|
+
def referers
|
37
|
+
session[:referers] ||= []
|
78
38
|
end
|
79
39
|
|
80
|
-
def
|
81
|
-
|
40
|
+
def referers=(value)
|
41
|
+
session[:referers] = value
|
82
42
|
end
|
83
|
-
|
84
|
-
def
|
85
|
-
|
86
|
-
parts.pop
|
87
|
-
while parts.size > 0
|
88
|
-
index = find_in_referer_tree(parts)
|
89
|
-
return index unless index.nil?
|
90
|
-
parts.pop
|
91
|
-
end
|
43
|
+
|
44
|
+
def find_referer_index(path)
|
45
|
+
referers.index { |referer| referer[:base_url] == request.base_url and referer[:path] == path }
|
92
46
|
end
|
93
47
|
|
94
|
-
def
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
referer[:path] != request.path
|
48
|
+
def update_referers
|
49
|
+
if referers.empty? or index = find_referer_index(request.path) or (referers.last[:path].count('/') == 1 ? '/' : request.path[0...request.path.rindex('/')])
|
50
|
+
if index == 0
|
51
|
+
self.referers = []
|
52
|
+
elsif index
|
53
|
+
self.referers = referers[0...index]
|
54
|
+
end
|
55
|
+
referers << { base_url: request.base_url, path: request.path, fullpath: request.fullpath }
|
56
|
+
else
|
57
|
+
self.referers = [{ base_url: request.base_url, path: request.path, fullpath: request.fullpath }]
|
105
58
|
end
|
106
59
|
end
|
107
|
-
|
60
|
+
|
108
61
|
module ClassMethods
|
109
|
-
|
62
|
+
|
110
63
|
protected
|
111
|
-
|
112
|
-
def crumb(action, name
|
64
|
+
|
65
|
+
def crumb(action, name=nil, &block)
|
113
66
|
controller = self.name.gsub('::', '/').gsub('Controller', '').underscore
|
114
67
|
name = block_given? ? block : name
|
115
|
-
|
68
|
+
Crumbs::Definitions.add controller.to_s, action.to_s, name
|
116
69
|
end
|
117
|
-
|
70
|
+
|
118
71
|
end
|
119
72
|
end
|
120
73
|
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Crumbs
|
2
|
+
class Definitions
|
3
|
+
class << self
|
4
|
+
|
5
|
+
def all
|
6
|
+
@all ||= {}
|
7
|
+
end
|
8
|
+
|
9
|
+
def add(controller, action, name)
|
10
|
+
if all.has_key? controller
|
11
|
+
all[controller][action] = name
|
12
|
+
else
|
13
|
+
all[controller] = { action => name }
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def find(controller, action, params)
|
18
|
+
if all.has_key? controller and all[controller].has_key? action
|
19
|
+
name = all[controller][action]
|
20
|
+
name.is_a?(Proc) ? name.call(params) : name
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/lib/crumbs/version.rb
CHANGED
data/lib/crumbs.rb
CHANGED
@@ -4,7 +4,7 @@ class PagesController < ApplicationController
|
|
4
4
|
crumb(:static) { 'Static' }
|
5
5
|
crumb :i18n do I18n.t('hello') end
|
6
6
|
crumb :nested, ->(params) { 'Nested' }
|
7
|
-
crumb :param, proc { |params| params[:param] }
|
7
|
+
crumb :param, proc { |params| "Param#{params[:param]}" }
|
8
8
|
|
9
9
|
def home
|
10
10
|
render :crumbs
|