breadcrumble 3.0.0 → 3.0.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.
data/README.md CHANGED
@@ -23,16 +23,19 @@ In your controller, call `add_breadcrumb` to push a new crumb on the breadcrumb
23
23
  class SampleController
24
24
 
25
25
  add_breadcrumb "home", home_url
26
- add_breadcrumb "sample", sample_url
26
+ add_breadcrumb -> context { context.title }, -> context { context.sample_path }
27
27
 
28
28
  def index
29
- add_breadcrumb "index", index_url
29
+ add_breadcrumb "index", controller: 'sample', action: 'index'
30
+ add_breadcrumb "show", show_path(123)
30
31
  end
31
32
 
32
33
  end
33
34
 
34
35
  Second arugment passed url_for method for convenient use, except specify nil.
35
36
 
37
+ You can use Proc object for arguments, the library calls proc with controller context as argument.
38
+
36
39
  ### View
37
40
  In your view, you can render the breadcrumb navigation with the `render_breadcrumbs` helper.
38
41
 
@@ -18,7 +18,16 @@ module Breadcrumble
18
18
 
19
19
  def add_breadcrumb name, url = nil
20
20
  @breadcrumbs ||= []
21
- @breadcrumbs << { name: name, url: url ? url_for(url) : nil }
21
+ @breadcrumbs << {
22
+ name: case name
23
+ when Proc then name.call(self)
24
+ else name
25
+ end,
26
+ url: case url
27
+ when Proc then url.call(self)
28
+ else url ? url_for(url) : nil
29
+ end
30
+ }
22
31
  end
23
32
 
24
33
  def breadcrumbs
@@ -1,3 +1,3 @@
1
1
  module Breadcrumble
2
- VERSION = "3.0.0"
2
+ VERSION = "3.0.1"
3
3
  end
@@ -4,9 +4,11 @@ describe ApplicationController do
4
4
  controller do
5
5
  add_breadcrumb 'root', '/'
6
6
  add_breadcrumb 'nil', nil
7
+ add_breadcrumb -> c { c.examples_url }, -> c { c.examples_path }
7
8
 
8
9
  def index
9
10
  add_breadcrumb 'examples', controller: 'examples', action: 'index', only_path: true
11
+ add_breadcrumb 'example', example_path(123)
10
12
  render text: 'test'
11
13
  end
12
14
  end
@@ -28,13 +30,25 @@ describe ApplicationController do
28
30
  assigns(:breadcrumbs)[1][:name].should eq('nil')
29
31
  assigns(:breadcrumbs)[1][:url].should be_nil
30
32
  end
33
+
34
+ it 'execute lambda in controller instance context' do
35
+ should be_success
36
+ assigns(:breadcrumbs)[2][:name].should eq('http://test.host/examples')
37
+ assigns(:breadcrumbs)[2][:url].should eq('/examples')
38
+ end
31
39
  end
32
40
 
33
41
  context '#add_breadcrumb' do
34
42
  it 'url options' do
35
43
  should be_success
36
- assigns(:breadcrumbs)[2][:name].should eq('examples')
37
- assigns(:breadcrumbs)[2][:url].should eq('/examples')
44
+ assigns(:breadcrumbs)[3][:name].should eq('examples')
45
+ assigns(:breadcrumbs)[3][:url].should eq('/examples')
46
+ end
47
+
48
+ it 'example_path' do
49
+ should be_success
50
+ assigns(:breadcrumbs)[4][:name].should eq('example')
51
+ assigns(:breadcrumbs)[4][:url].should eq('/examples/123')
38
52
  end
39
53
  end
40
54
  end
@@ -3,4 +3,7 @@ class ExamplesController < ApplicationController
3
3
 
4
4
  def index
5
5
  end
6
+
7
+ def show
8
+ end
6
9
  end
@@ -1,3 +1,3 @@
1
1
  Dummy::Application.routes.draw do
2
- resources :examples, :only => :index
2
+ resources :examples, :only => [:index, :show]
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: breadcrumble
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0
4
+ version: 3.0.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-05-10 00:00:00.000000000 Z
12
+ date: 2013-05-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -125,7 +125,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
125
125
  version: '0'
126
126
  segments:
127
127
  - 0
128
- hash: -789322070461792342
128
+ hash: -2495426241204470398
129
129
  required_rubygems_version: !ruby/object:Gem::Requirement
130
130
  none: false
131
131
  requirements:
@@ -134,7 +134,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
134
134
  version: '0'
135
135
  segments:
136
136
  - 0
137
- hash: -789322070461792342
137
+ hash: -2495426241204470398
138
138
  requirements: []
139
139
  rubyforge_project:
140
140
  rubygems_version: 1.8.23