crumbs 2.0.2 → 2.1.1

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.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +39 -8
  3. data/lib/crumbs/action_controller/base.rb +2 -2
  4. data/lib/crumbs/dsl/controller.rb +27 -0
  5. data/lib/crumbs/dsl/namespace.rb +16 -0
  6. data/lib/crumbs/proxy.rb +11 -2
  7. data/lib/crumbs/railtie.rb +4 -0
  8. data/lib/crumbs/version.rb +1 -1
  9. data/lib/crumbs.rb +17 -6
  10. data/lib/generators/crumbs/install_generator.rb +2 -1
  11. data/lib/generators/crumbs/templates/configure.rb +2 -0
  12. data/test/dummy/app/controllers/namespace/pages_controller.rb +8 -0
  13. data/test/dummy/app/controllers/pages_controller.rb +1 -1
  14. data/test/dummy/config/crumbs.rb +21 -0
  15. data/test/dummy/config/locales/en.yml +3 -1
  16. data/test/dummy/config/routes.rb +3 -1
  17. data/test/dummy/log/test.log +9417 -0
  18. data/test/generator_test.rb +2 -1
  19. data/test/with_last_test.rb +19 -0
  20. data/test/without_last_test.rb +17 -0
  21. metadata +10 -50
  22. data/lib/crumbs/controller.rb +0 -21
  23. data/test/dummy/config/initializers/crumbs.rb +0 -19
  24. data/test/dummy/tmp/cache/assets/test/sprockets/13fe41fee1fe35b49d145bcc06610705 +0 -0
  25. data/test/dummy/tmp/cache/assets/test/sprockets/2f5173deea6c795b8fdde723bb4b63af +0 -0
  26. data/test/dummy/tmp/cache/assets/test/sprockets/357970feca3ac29060c1e3861e2c0953 +0 -0
  27. data/test/dummy/tmp/cache/assets/test/sprockets/cffd775d018f68ce5dba1ee0d951a994 +0 -0
  28. data/test/dummy/tmp/cache/assets/test/sprockets/d771ace226fc8215a3572e0aa35bb0d6 +0 -0
  29. data/test/dummy/tmp/cache/assets/test/sprockets/f7cbd26ba1d28d48de824f0e94586655 +0 -0
  30. data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/0CfsnjV9PTgwlR5hr0ZJ0lNFInsx4qr_zgDnI8wYXdA.cache +0 -0
  31. data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/3_I2jn5YxLciv3GtK_auIHda4TWNhZGieWePNoABWag.cache +0 -3
  32. data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/8pLqt1nXpM0CADV6_EF0KDbq4JiQCmjMIxj6pPZgm40.cache +0 -0
  33. data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/9_0iCm3DZpig3DFydwsV8-3vCsUegD9B-YR_kxfWuxg.cache +0 -0
  34. data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/DtXc_gTNuqlMogm9DYo1deRm00jNXPf0fyilnnre4mo.cache +0 -1
  35. data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/KuObwG9-kiiTC9uTe_Y_WcDUv6iru-sTemI6-k4K-VI.cache +0 -1
  36. data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/NB1P923S_ERHEViNCpWJ8SWQPVGhGQbnoEZDFXAsMkU.cache +0 -2
  37. data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/NRB4IoGG5vlEQSlxE-fq7JjM5DiMsZgx53bfpX9Qa-Q.cache +0 -3
  38. data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/PeALxNvJVmSUZlRLwsDzjXcHYkYl7swdEPX25zaZ4Sk.cache +0 -2
  39. data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/SaR332UYmMwbCg2uCE2kc8IdAy0fz1Z0rzVjjdcHBfc.cache +0 -1
  40. data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/UWBHdOtGfj0EG8YqQJFo4VXX78gdxQ9UKQckSjlh2Xk.cache +0 -0
  41. data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/fg8Lpn3VSU1Cz0bY6ek8PqNXJKwHE4tH-_pxSZSVHoc.cache +0 -1
  42. data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/j633CDb2pirQ_kRgsBIUuO9xrlJnPoE5wSh_Sk7a0B8.cache +0 -0
  43. data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/oL3tj9Cx76XI84KeuRvNWkE8SRDP7uTSGgeKXBJfwi4.cache +0 -1
  44. data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/p8gRJoCgrplMxf3cIeQwVnrXECPodO1XmZT3b9iaId0.cache +0 -0
  45. data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/wZymCZN9x4UDexGqYG57Pp_5dfraxUy5TuEtv9bQzaE.cache +0 -0
  46. /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: a340edbee8381a599cfed3c3c5f495b0bf0bd156
4
- data.tar.gz: 3d74d95648151946cc7bf9c11de2d7e3f0dcc63f
3
+ metadata.gz: ee9ed2bb2383f091cd3122b573be9d7e2eb37b4c
4
+ data.tar.gz: 31cd1e7ba8675ccddcd534c5c300471f6a3500c2
5
5
  SHA512:
6
- metadata.gz: 1628bf8db851169079ee1dfdd3ab1435dbdc60989bd1c8629a2225ecbee046e68812069be363155c680d54061ee78705470470c57ebb8d4e58f594cf9e811fa3
7
- data.tar.gz: 24e176e3328621d1cf08c47b386a281c9ee618baa886186b0d733a752104eb33d2fa9cfd0fd35cecec26a7c3cc2ef6225bfa307dfc4f6c780cf3b69388066ea0
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 file:
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
- ## Usage
33
+ ## DSL
34
34
 
35
- In your initialization file add crumbs referencing the controller and action with the dsl:
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 :home, 'Home'
39
+ action :index, 'Home'
40
40
  end
41
41
  end
42
42
  ```
43
43
 
44
- You can use a lambda, proc or block too, will receive the corresponding url parameters:
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 :product do |params|
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
- Then in your views would be available a crumbs variable:
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
  &gt; <%= 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
@@ -4,10 +4,10 @@ module Crumbs
4
4
  extend ActiveSupport::Concern
5
5
 
6
6
  included do
7
- before_filter :set_crumbs
7
+ append_before_action :set_crumbs
8
8
  end
9
9
 
10
- protected
10
+ protected
11
11
 
12
12
  def set_crumbs
13
13
  paths = [request.path]
@@ -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 controller(name, &block)
5
- Controller.new(name).instance_eval(&block)
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
@@ -5,5 +5,9 @@ module Crumbs
5
5
  ::ActionController::Base.send :include, Crumbs::ActionController::Base
6
6
  end
7
7
 
8
+ config.after_initialize do
9
+ load Rails.root.join('config/crumbs.rb')
10
+ end
11
+
8
12
  end
9
13
  end
@@ -1,5 +1,5 @@
1
1
  module Crumbs
2
2
 
3
- VERSION = '2.0.2'
3
+ VERSION = '2.1.1'
4
4
 
5
5
  end
data/lib/crumbs.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require 'crumbs/action_controller/base'
2
2
  require 'crumbs/proxy'
3
- require 'crumbs/controller'
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.instance_eval &block
23
+ Proxy.new(&block)
23
24
  end
24
25
 
25
26
  def find(controller, action, params)
26
- if all.has_key? controller and all[controller].has_key? action
27
- name = all[controller][action]
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 all
37
- @all ||= {}
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 'crumbs.rb', 'config/initializers/crumbs.rb'
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,2 @@
1
+ Crumbs.configure do
2
+ end
@@ -0,0 +1,8 @@
1
+ class Namespace::PagesController < ApplicationController
2
+
3
+ def index
4
+ render template: 'pages/crumbs'
5
+ end
6
+
7
+ end
8
+
@@ -1,6 +1,6 @@
1
1
  class PagesController < ApplicationController
2
2
 
3
- def home
3
+ def index
4
4
  render :crumbs
5
5
  end
6
6
 
@@ -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
@@ -20,4 +20,6 @@
20
20
  # available at http://guides.rubyonrails.org/i18n.html.
21
21
 
22
22
  en:
23
- hello: "Hello world"
23
+ crumbs:
24
+ hello: "Hello world"
25
+ static: "Static"
@@ -1,6 +1,6 @@
1
1
  Dummy::Application.routes.draw do
2
2
 
3
- root to: 'pages#home'
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