crumbs 1.0.7 → 1.0.8

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fd2257e21c1a564cd87a4eb18980f6d6b9eadd18
4
- data.tar.gz: e4aeceb5449fa41acb0283bfdee6c420fc7f92c5
3
+ metadata.gz: 65c23c3a5031cc7aee4ea4f9345d356a920ae45a
4
+ data.tar.gz: 1eac4ee8c700f05faaa1686802121c7d4a6099c7
5
5
  SHA512:
6
- metadata.gz: 025e40e97ae86d03704cadf453dde0ee292ba0efee694f6ab1160d99ca743e621dc359c1cb6ab95f4ae11ebb213d99a3e477da83654574037a9f52d61226bf7e
7
- data.tar.gz: a5db02148cd3aadfda87f14e4327cebccd9ca580284f71d8ad0c8416d5399040e9965babe8fa15a03a81b9ecd03aff31ddfb509e311c55c3be66b5bbf87f8c35
6
+ metadata.gz: 11c1db3e6708873d5b70bdb8c852626e8db9ec0348b5e75d0e9c730fe5654fbd96f2037304451826bf63664f67eec1b1133c438d243f3c9530487e38908e9487
7
+ data.tar.gz: 15c226389376609305b7d1a26890df5788a67d4af6fbec7ad9e1a5e97b1e003072b5e3e6cd883594dfd2b0540d43c883b61e3918b42dd0a4b28e333b86a1dba0
data/README.rdoc CHANGED
@@ -17,7 +17,7 @@ Then bundle:
17
17
  In your controllers add crumbs to the actions you want to have a crumb:
18
18
  crumb :home, 'Home'
19
19
 
20
- You can use a proc if you want, will receive the corresponding url parameters:
20
+ You can use a lambda, proc or block too, will receive the corresponding url parameters:
21
21
  crumb :product, proc { |params| Product.find(params[:id]).name }
22
22
 
23
23
  Then in your views would be available a crumbs variable:
@@ -63,7 +63,7 @@ module Crumbs
63
63
 
64
64
  def join_parts(parts)
65
65
  path = parts.join('/')
66
- (path[0] != '/' ? "/#{path}" : path)
66
+ path[0] != '/' ? "/#{path}" : path
67
67
  end
68
68
 
69
69
  def is_last_referer?
@@ -109,8 +109,9 @@ module Crumbs
109
109
 
110
110
  protected
111
111
 
112
- def crumb(action, name)
112
+ def crumb(action, name = nil, &block)
113
113
  controller = self.name.gsub('::', '/').gsub('Controller', '').underscore
114
+ name = block_given? ? block : name
114
115
  History.add(controller, action, name)
115
116
  end
116
117
 
@@ -7,21 +7,24 @@ module Crumbs
7
7
  end
8
8
 
9
9
  def add(controller, action, name)
10
- unless all.has_key? controller.to_sym
11
- all[controller.to_sym] = { action.to_sym => name }
10
+ controller = controller.to_sym
11
+ action = action.to_sym
12
+ unless all.has_key? controller
13
+ all[controller] = { action => name }
12
14
  else
13
- all[controller.to_sym][action.to_sym] = name
15
+ all[controller][action] = name
14
16
  end
15
17
  end
16
18
 
17
19
  def get_name(controller, action, params)
18
- return false unless all.has_key? controller.to_sym and all[controller.to_sym].has_key? action.to_sym
19
- name = all[controller.to_sym][action.to_sym]
20
- case name
21
- when String
22
- value = name
23
- when Proc
20
+ controller = controller.to_sym
21
+ action = action.to_sym
22
+ return false unless all.has_key? controller and all[controller].has_key? action
23
+ name = all[controller][action]
24
+ if name.respond_to? :call
24
25
  value = name.call(params)
26
+ elsif
27
+ value = name
25
28
  end
26
29
  value ? value : ''
27
30
  end
@@ -1,5 +1,5 @@
1
1
  module Crumbs
2
2
 
3
- VERSION = '1.0.7'
3
+ VERSION = '1.0.8'
4
4
 
5
5
  end
@@ -1,9 +1,9 @@
1
1
  class PagesController < ApplicationController
2
2
 
3
3
  crumb :home, 'Home'
4
- crumb :static, 'Static'
5
- crumb :i18n, I18n.t('hello')
6
- crumb :nested, proc { |params| 'Nested' }
4
+ crumb(:static) { 'Static' }
5
+ crumb :i18n do I18n.t('hello') end
6
+ crumb :nested, ->(params) { 'Nested' }
7
7
  crumb :param, proc { |params| params[:param] }
8
8
 
9
9
  def home