crumbs 1.2.1 → 2.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (29) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +15 -5
  3. data/lib/crumbs/action_controller/base.rb +2 -11
  4. data/lib/crumbs/controller.rb +21 -0
  5. data/lib/crumbs/proxy.rb +9 -0
  6. data/lib/crumbs/version.rb +1 -1
  7. data/lib/crumbs.rb +21 -1
  8. data/lib/generators/crumbs/templates/crumbs.rb +1 -1
  9. data/test/dummy/app/controllers/pages_controller.rb +0 -6
  10. data/test/dummy/config/initializers/crumbs.rb +19 -0
  11. data/test/dummy/log/test.log +2346 -0
  12. data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/0CfsnjV9PTgwlR5hr0ZJ0lNFInsx4qr_zgDnI8wYXdA.cache +0 -0
  13. data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/3_I2jn5YxLciv3GtK_auIHda4TWNhZGieWePNoABWag.cache +3 -0
  14. data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/8pLqt1nXpM0CADV6_EF0KDbq4JiQCmjMIxj6pPZgm40.cache +0 -0
  15. data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/9_0iCm3DZpig3DFydwsV8-3vCsUegD9B-YR_kxfWuxg.cache +0 -0
  16. data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/DtXc_gTNuqlMogm9DYo1deRm00jNXPf0fyilnnre4mo.cache +1 -0
  17. data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/KuObwG9-kiiTC9uTe_Y_WcDUv6iru-sTemI6-k4K-VI.cache +1 -0
  18. data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/NB1P923S_ERHEViNCpWJ8SWQPVGhGQbnoEZDFXAsMkU.cache +2 -0
  19. data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/NRB4IoGG5vlEQSlxE-fq7JjM5DiMsZgx53bfpX9Qa-Q.cache +3 -0
  20. data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/PeALxNvJVmSUZlRLwsDzjXcHYkYl7swdEPX25zaZ4Sk.cache +2 -0
  21. data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/SaR332UYmMwbCg2uCE2kc8IdAy0fz1Z0rzVjjdcHBfc.cache +1 -0
  22. data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/UWBHdOtGfj0EG8YqQJFo4VXX78gdxQ9UKQckSjlh2Xk.cache +0 -0
  23. data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/fg8Lpn3VSU1Cz0bY6ek8PqNXJKwHE4tH-_pxSZSVHoc.cache +1 -0
  24. data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/j633CDb2pirQ_kRgsBIUuO9xrlJnPoE5wSh_Sk7a0B8.cache +0 -0
  25. data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/oL3tj9Cx76XI84KeuRvNWkE8SRDP7uTSGgeKXBJfwi4.cache +1 -0
  26. data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/p8gRJoCgrplMxf3cIeQwVnrXECPodO1XmZT3b9iaId0.cache +0 -0
  27. data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/wZymCZN9x4UDexGqYG57Pp_5dfraxUy5TuEtv9bQzaE.cache +0 -0
  28. metadata +42 -7
  29. data/lib/crumbs/definitions.rb +0 -30
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3c715baffe0b9150974ecaf21136eaafa4658fce
4
- data.tar.gz: 3ffe476295357d0fc7340023bc8ad2de8090a538
3
+ metadata.gz: a340edbee8381a599cfed3c3c5f495b0bf0bd156
4
+ data.tar.gz: 3d74d95648151946cc7bf9c11de2d7e3f0dcc63f
5
5
  SHA512:
6
- metadata.gz: f57b8383972f6e81684f64ce2b52cc20484614f5b42395b3a8aae56bd4904f2e45d8f7d5367962f4ab49f92b62e247e7d0e98c7a7f204b2f246c6ae83951e551
7
- data.tar.gz: 2b50d86d388bd2a28efc7a3d58a3638208ead254458c80208ea68b7de03eb70382cf47ae5bdde7545b591f531e341249c1ee8ffa8b8fb84cbc6ab52909d85630
6
+ metadata.gz: 1628bf8db851169079ee1dfdd3ab1435dbdc60989bd1c8629a2225ecbee046e68812069be363155c680d54061ee78705470470c57ebb8d4e58f594cf9e811fa3
7
+ data.tar.gz: 24e176e3328621d1cf08c47b386a281c9ee618baa886186b0d733a752104eb33d2fa9cfd0fd35cecec26a7c3cc2ef6225bfa307dfc4f6c780cf3b69388066ea0
data/README.md CHANGED
@@ -18,12 +18,12 @@ $ bundle
18
18
 
19
19
  ## Configuration
20
20
 
21
- Generate the configuration file:
21
+ Generate the initialization file:
22
22
  ```
23
23
  rails g crumbs:install
24
24
  ```
25
25
 
26
- The defaults values are:
26
+ The defaults configuration values are:
27
27
  ```ruby
28
28
  Crumbs.configure do |config|
29
29
  config.show_last = false
@@ -32,14 +32,24 @@ end
32
32
 
33
33
  ## Usage
34
34
 
35
- In your controllers add crumbs to the actions you want:
35
+ In your initialization file add crumbs referencing the controller and action with the dsl:
36
36
  ```ruby
37
- crumb :home, 'Home'
37
+ Crumbs.define do
38
+ controller :site do
39
+ action :home, 'Home'
40
+ end
41
+ end
38
42
  ```
39
43
 
40
44
  You can use a lambda, proc or block too, will receive the corresponding url parameters:
41
45
  ```ruby
42
- crumb :product, proc { |params| Product.find(params[:id]).name }
46
+ Crumbs.define do
47
+ controller :site do
48
+ action :product do |params|
49
+ Product.find(params[:id]).name
50
+ end
51
+ end
52
+ end
43
53
  ```
44
54
 
45
55
  Then in your views would be available a crumbs variable:
@@ -26,7 +26,7 @@ module Crumbs
26
26
  @crumbs = []
27
27
  paths.each do |path|
28
28
  params = Rails.application.routes.recognize_path("#{request.base_url}#{path}") rescue next
29
- if name = Crumbs::Definitions.find(params[:controller], params[:action], params)
29
+ if name = Crumbs.find(params[:controller], params[:action], params)
30
30
  if index = find_referer_index(path)
31
31
  path = session[:referers][index][:fullpath]
32
32
  end
@@ -41,16 +41,7 @@ module Crumbs
41
41
  paths.include? referer[:path]
42
42
  end
43
43
  end
44
-
45
- module ClassMethods
46
-
47
- protected
48
-
49
- def crumb(action, name=nil, &block)
50
- Crumbs::Definitions.add controller_path, action.to_s, (block_given? ? block : name)
51
- end
52
-
53
- end
54
44
  end
45
+
55
46
  end
56
47
  end
@@ -0,0 +1,21 @@
1
+ module Crumbs
2
+ class Controller
3
+
4
+ def initialize(controller)
5
+ @controller = controller
6
+ end
7
+
8
+ def action(action, name=nil, &block)
9
+ controller = @controller.to_s
10
+ action = action.to_s
11
+ name = (block_given? ? block : name)
12
+ all = Crumbs.all
13
+ if all.has_key? controller
14
+ all[controller][action] = name
15
+ else
16
+ all[controller] = { action => name }
17
+ end
18
+ end
19
+
20
+ end
21
+ end
@@ -0,0 +1,9 @@
1
+ module Crumbs
2
+ class Proxy
3
+
4
+ def controller(name, &block)
5
+ Controller.new(name).instance_eval(&block)
6
+ end
7
+
8
+ end
9
+ end
@@ -1,5 +1,5 @@
1
1
  module Crumbs
2
2
 
3
- VERSION = '1.2.1'
3
+ VERSION = '2.0.2'
4
4
 
5
5
  end
data/lib/crumbs.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'crumbs/action_controller/base'
2
- require 'crumbs/definitions'
2
+ require 'crumbs/proxy'
3
+ require 'crumbs/controller'
3
4
  require 'crumbs/railtie'
4
5
 
5
6
  module Crumbs
@@ -17,5 +18,24 @@ module Crumbs
17
18
  end
18
19
  end
19
20
 
21
+ def define(&block)
22
+ Proxy.new.instance_eval &block
23
+ end
24
+
25
+ def find(controller, action, params)
26
+ if all.has_key? controller and all[controller].has_key? action
27
+ name = all[controller][action]
28
+ if name.is_a? Proc
29
+ name.call params
30
+ else
31
+ name
32
+ end
33
+ end
34
+ end
35
+
36
+ def all
37
+ @all ||= {}
38
+ end
39
+
20
40
  end
21
41
  end
@@ -1,2 +1,2 @@
1
- Crumbs.configure do |config|
1
+ Crumbs.define do
2
2
  end
@@ -1,11 +1,5 @@
1
1
  class PagesController < ApplicationController
2
2
 
3
- crumb :home, 'Home'
4
- crumb(:static) { 'Static' }
5
- crumb :i18n do I18n.t('hello') end
6
- crumb :nested, ->(params) { 'Nested' }
7
- crumb :param, proc { |params| "Param#{params[:param]}" }
8
-
9
3
  def home
10
4
  render :crumbs
11
5
  end
@@ -0,0 +1,19 @@
1
+ Crumbs.define do
2
+
3
+ controller :pages do
4
+ action :home, 'Home'
5
+ action :static do
6
+ 'Static'
7
+ end
8
+ action :i18n do
9
+ I18n.t('hello')
10
+ end
11
+ action :nested do |params|
12
+ 'Nested'
13
+ end
14
+ action :param do |params|
15
+ "Param#{params[:param]}"
16
+ end
17
+ end
18
+
19
+ end