breadcrumble 3.0.2 → 3.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -37,6 +37,18 @@ Second arugment passed url_for method for convenient use, except specify nil.
37
37
 
38
38
  You can use Proc object for arguments, the library calls proc with controller context as argument.
39
39
 
40
+ If you would like to use multiple breadcrumb, call `add_breadcrumb_to` method with breadcrumb trail index.
41
+
42
+ class SampleController
43
+
44
+ add_breadcrumb_to "level 1", "level 1 url", 0 # same as -> add_breadcrumb "level 1", "level 1 url"
45
+ add_breadcrumb_to "level 2", "level 2 url", 1
46
+
47
+ def index
48
+ add_breadcrumb "level 1 second item", "level 1 second url", 0
49
+ add_breadcrumb "level 2 second item", "level 2 second url", 1
50
+ end
51
+
40
52
  ### View
41
53
  In your view, you can render the breadcrumb navigation with the `render_breadcrumbs` helper.
42
54
 
@@ -44,6 +56,12 @@ In your view, you can render the breadcrumb navigation with the `render_breadcru
44
56
  <%= render_breadcrumbs %>
45
57
  </body>
46
58
 
59
+ You can render multiple breadcrumb by `render_breadcrumb_trails` helper.
60
+
61
+ <body>
62
+ <%= render_breadcrumb_trails %>
63
+ </body>
64
+
47
65
  ### Customizing layout
48
66
  Breadcrumble generates default partial template for your app.
49
67
 
@@ -0,0 +1,11 @@
1
+ <span itemscope="child" itemtype="http://data-vocabulary.org/Breadcrumb">
2
+ <% span_title = content_tag(:span, trail[0][:name], itemprop: "title") %>
3
+ <% if trail[0][:url] == nil %>
4
+ <%= span_title %>
5
+ <% else %>
6
+ <%= link_to_unless_current span_title, trail[0][:url], itemprop: "url" %>
7
+ <% end %>
8
+ <% if trail.size > 1 %>
9
+ ><%= render partial: 'breadcrumble/breadcrumb_trail', locals: { trail: trail.drop(1) } %>
10
+ <% end %>
11
+ </span>
@@ -0,0 +1,15 @@
1
+ <div>
2
+ <% breadcrumb_trails.each do |trail| %>
3
+ <div itemscope itemtype="http://data-vocabulary.org/Breadcrumb">
4
+ <% span_title = content_tag(:span, trail[0][:name], itemprop: "title") %>
5
+ <% if trail[0][:url] == nil %>
6
+ <%= span_title %>
7
+ <% else %>
8
+ <%= link_to_unless_current span_title, trail[0][:url], itemprop: "url" %>
9
+ <% end %>
10
+ <% if trail.size > 1 %>
11
+ ><%= render partial: 'breadcrumble/breadcrumb_trail', locals: { trail: trail.drop(1) } %>
12
+ <% end %>
13
+ </div>
14
+ <% end %>
15
+ </div>
@@ -3,7 +3,7 @@ module Breadcrumble
3
3
  extend ActiveSupport::Concern
4
4
 
5
5
  included do
6
- helper_method :add_breadcrumb, :breadcrumbs
6
+ helper_method :add_breadcrumb, :breadcrumbs, :breadcrumb_trails
7
7
  end
8
8
 
9
9
  module ClassMethods
@@ -13,6 +13,12 @@ module Breadcrumble
13
13
  end
14
14
  end
15
15
 
16
+ def add_breadcrumb_to name, url, trail_index
17
+ before_filter do |controller|
18
+ controller.send :add_breadcrumb_to, name, url, trail_index
19
+ end
20
+ end
21
+
16
22
  def add_breadcrumbs *args
17
23
  before_filter do |controller|
18
24
  args.each do |arg|
@@ -25,8 +31,13 @@ module Breadcrumble
25
31
  protected
26
32
 
27
33
  def add_breadcrumb name, url = nil
28
- @breadcrumbs ||= []
29
- @breadcrumbs << {
34
+ add_breadcrumb_to name, url, 0
35
+ end
36
+
37
+ def add_breadcrumb_to name, url, trail_index
38
+ @breadcrumb_trails ||= [[]]
39
+ @breadcrumb_trails[trail_index] ||= []
40
+ @breadcrumb_trails[trail_index] << {
30
41
  name: case name
31
42
  when Proc then name.call(self)
32
43
  else name
@@ -44,8 +55,12 @@ module Breadcrumble
44
55
  end
45
56
  end
46
57
 
58
+ def breadcrumb_trails
59
+ @breadcrumb_trails
60
+ end
61
+
47
62
  def breadcrumbs
48
- @breadcrumbs
63
+ @breadcrumb_trails.first
49
64
  end
50
65
  end
51
66
  end
@@ -3,5 +3,9 @@ module Breadcrumble
3
3
  def render_breadcrumbs options=nil
4
4
  render partial: 'breadcrumble/breadcrumb', locals: options
5
5
  end
6
+
7
+ def render_breadcrumb_trails options=nil
8
+ render partial: 'breadcrumble/breadcrumb_trails', locals: options
9
+ end
6
10
  end
7
11
  end
@@ -1,3 +1,3 @@
1
1
  module Breadcrumble
2
- VERSION = "3.0.2"
2
+ VERSION = "3.0.3"
3
3
  end
@@ -5,8 +5,10 @@ module Breadcrumble
5
5
  desc 'This generator generates breadcrumbs partial template.'
6
6
 
7
7
  def generate_views
8
- name = '_breadcrumb.html.erb'
9
- copy_file "#{name}", "app/views/breadcrumble/#{name}"
8
+ names = ['_breadcrumb.html.erb', '_breadcrumb_trails.html.erb', '_breadcrumb_trail.html.erb']
9
+ names.each do |name|
10
+ copy_file "#{name}", "app/views/breadcrumble/#{name}"
11
+ end
10
12
  end
11
13
  end
12
14
  end
@@ -4,6 +4,8 @@ describe ApplicationController do
4
4
  controller do
5
5
  add_breadcrumbs ['root', '/'], ['nil', nil]
6
6
  add_breadcrumb -> c { c.examples_url }, -> c { c.examples_path }
7
+ add_breadcrumb_to -> c { c.examples_url }, -> c { c.examples_path }, 1
8
+ add_breadcrumb_to 'multi third 1', 'multi third url 1', 2
7
9
 
8
10
  def index
9
11
  add_breadcrumb 'examples', controller: 'examples', action: 'index', only_path: true
@@ -11,6 +13,14 @@ describe ApplicationController do
11
13
  add_breadcrumbs ['crumb1'], ['crumb2', -> c { example_path(1234) }]
12
14
  render text: 'test'
13
15
  end
16
+
17
+ def show
18
+ add_breadcrumb_to 'examples', {controller: 'examples', action: 'index', only_path: true}, 1
19
+ add_breadcrumb_to 'example', example_path(123), 1
20
+ add_breadcrumb_to 'multi third 2', 'multi third url 2', 2
21
+ add_breadcrumb_to 'multi third 3', 'multi third url 3', 2
22
+ render text: 'test'
23
+ end
14
24
  end
15
25
 
16
26
  describe '#index' do
@@ -21,46 +31,61 @@ describe ApplicationController do
21
31
  context '.add_breadcrumbs' do
22
32
  it 'having breadcrumbs' do
23
33
  should be_success
24
- assigns(:breadcrumbs)[0][:name].should eq('root')
25
- assigns(:breadcrumbs)[0][:url].should eq('/')
34
+ assigns(:breadcrumb_trails)[0][0].should eq({name: 'root', url: '/'})
26
35
  end
27
36
 
28
37
  it 'url has nil value' do
29
38
  should be_success
30
- assigns(:breadcrumbs)[1][:name].should eq('nil')
31
- assigns(:breadcrumbs)[1][:url].should be_nil
39
+ assigns(:breadcrumb_trails)[0][1].should eq({name: 'nil', url: nil})
32
40
  end
33
41
  end
34
42
 
35
43
  context '.add_breadcrumb' do
36
44
  it 'execute lambda in controller instance context' do
37
45
  should be_success
38
- assigns(:breadcrumbs)[2][:name].should eq('http://test.host/examples')
39
- assigns(:breadcrumbs)[2][:url].should eq('/examples')
46
+ assigns(:breadcrumb_trails)[0][2].should eq({name: 'http://test.host/examples', url: '/examples'})
40
47
  end
41
48
  end
42
49
 
43
50
  context '#add_breadcrumb' do
44
51
  it 'url options' do
45
52
  should be_success
46
- assigns(:breadcrumbs)[3][:name].should eq('examples')
47
- assigns(:breadcrumbs)[3][:url].should eq('/examples')
53
+ assigns(:breadcrumb_trails)[0][3].should eq({name: 'examples', url: '/examples'})
48
54
  end
49
55
 
50
56
  it 'example_path' do
51
57
  should be_success
52
- assigns(:breadcrumbs)[4][:name].should eq('example')
53
- assigns(:breadcrumbs)[4][:url].should eq('/examples/123')
58
+ assigns(:breadcrumb_trails)[0][4].should eq({name: 'example', url: '/examples/123'})
54
59
  end
55
60
  end
56
61
 
57
62
  context '#add_breadcrumbs' do
58
63
  it 'sequence is starting from first argument' do
59
64
  should be_success
60
- assigns(:breadcrumbs)[5][:name].should eq('crumb1')
61
- assigns(:breadcrumbs)[5][:url].should be_nil
62
- assigns(:breadcrumbs)[6][:name].should eq('crumb2')
63
- assigns(:breadcrumbs)[6][:url].should eq('/examples/1234')
65
+ assigns(:breadcrumb_trails)[0][5].should eq({name: 'crumb1', url: nil})
66
+ assigns(:breadcrumb_trails)[0][6].should eq({name: 'crumb2', url: '/examples/1234'})
67
+ end
68
+ end
69
+ end
70
+
71
+ describe '#show' do
72
+ subject do
73
+ get :show, id: 1
74
+ end
75
+
76
+ context 'multiple breadcrumbs' do
77
+ it 'having breadcrumbs in second trail' do
78
+ should be_success
79
+ assigns(:breadcrumb_trails)[1][0].should eq({name: 'http://test.host/examples', url: '/examples'})
80
+ assigns(:breadcrumb_trails)[1][1].should eq({name: 'examples', url: '/examples'})
81
+ assigns(:breadcrumb_trails)[1][2].should eq({name: 'example', url: '/examples/123'})
82
+ end
83
+
84
+ it 'having breadcrumbs in third trail' do
85
+ should be_success
86
+ assigns(:breadcrumb_trails)[2][0].should eq({name: 'multi third 1', url: 'multi third url 1'})
87
+ assigns(:breadcrumb_trails)[2][1].should eq({name: 'multi third 2', url: 'multi third url 2'})
88
+ assigns(:breadcrumb_trails)[2][2].should eq({name: 'multi third 3', url: 'multi third url 3'})
64
89
  end
65
90
  end
66
91
  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.2
4
+ version: 3.0.3
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-15 00:00:00.000000000 Z
12
+ date: 2013-05-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -73,6 +73,8 @@ files:
73
73
  - README.md
74
74
  - Rakefile
75
75
  - app/views/breadcrumble/_breadcrumb.html.erb
76
+ - app/views/breadcrumble/_breadcrumb_trail.html.erb
77
+ - app/views/breadcrumble/_breadcrumb_trails.html.erb
76
78
  - breadcrumble.gemspec
77
79
  - lib/breadcrumble.rb
78
80
  - lib/breadcrumble/action_controller.rb
@@ -125,7 +127,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
125
127
  version: '0'
126
128
  segments:
127
129
  - 0
128
- hash: -2832618272314011603
130
+ hash: 3137348152079154786
129
131
  required_rubygems_version: !ruby/object:Gem::Requirement
130
132
  none: false
131
133
  requirements:
@@ -134,7 +136,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
134
136
  version: '0'
135
137
  segments:
136
138
  - 0
137
- hash: -2832618272314011603
139
+ hash: 3137348152079154786
138
140
  requirements: []
139
141
  rubyforge_project:
140
142
  rubygems_version: 1.8.23