navigation_builder 1.0.0.beta2 → 1.0.0.beta3

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -66,6 +66,38 @@ And in your layout:
66
66
  <%= nav.link_to 'Home', '#' %>
67
67
  <% end %>
68
68
 
69
+ #### I need to do something special after the third link! ####
70
+
71
+ <% navigation_for :main, do |nav| %>
72
+ <%= nav.link_to 'Home', '#' %>
73
+ <%- if nav.item_count = 3 -%>
74
+ Something Special
75
+ <%- end -%>
76
+ <% end %>
77
+
78
+ That's probably a poor example. The usefulness of the `item_count` attribute is more apparent when you create a custom NavigationBuilder.
79
+
80
+ For instance, you can use it to automatically add the class `"first"`:
81
+
82
+ module NavigationBuilders
83
+ class FancyPantsNavigation < ActionView::Helpers::NavigationBuilder
84
+
85
+ def link_to_in_html( name, options, html_options )
86
+ if item_count == 0
87
+ html_options[:item_html] ||= { :class => '' }
88
+ html_options[:item_html][:class] = " #{html_options[:item_html][:class]} first".strip
89
+ end
90
+
91
+ super
92
+ end
93
+
94
+ end
95
+ end
96
+
97
+ ##### You can do that with CSS you know... #####
98
+
99
+ If you don't have to support IE6, then yes, you can.
100
+
69
101
  #### Well... what if I need an Ordered List! ####
70
102
 
71
103
  <% navigation_for :main, :wrapper_tag => :ol do |nav| %>
@@ -80,7 +112,7 @@ Generates:
80
112
  </li>
81
113
  </ol>
82
114
 
83
- #### Nevermind, I hate lists. I just want DIVs. ####
115
+ #### Nevermind. I hate lists. I just want DIVs. ####
84
116
 
85
117
  <% navigation_for :main, :nav_item_tag => :div do |nav| %>
86
118
  <%= nav.link_to 'Home', '#' %>
@@ -102,7 +134,7 @@ Generates:
102
134
 
103
135
  <a href="#" class="selected">Home</a>
104
136
 
105
- #### Why didn't you name this Gem "Wolfman" ####
137
+ #### Why didn't you name this Gem ["Wolfman"](http://en.wikipedia.org/wiki/Top_Gun#Cast) ####
106
138
 
107
139
  Originally I was going to. But if you came across a method named "wolfman" in your view code, it would not be entirely clear as to what it was going to do.
108
140
  So I just went with something boring and generic.
@@ -115,5 +147,3 @@ TODOs
115
147
  =====
116
148
 
117
149
  * Rails 3 support
118
- * Add test for "selected" class when there is no item tag
119
- * Add test for thrown exception when setting a selected link after a nav block has already been rendered.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.0.beta2
1
+ 1.0.0.beta3
@@ -61,9 +61,12 @@ module ActionView
61
61
 
62
62
  class NavigationBuilder
63
63
 
64
+ attr_reader :item_count
65
+
64
66
  # Initializes the NavigationBuilder.
65
67
  # You'll mostly likely never call this method directly.
66
68
  def initialize( template, nav_name, options, proc )
69
+ @item_count = 0
67
70
  @template, @nav_name, @options, @proc = template, nav_name, options, proc
68
71
  end
69
72
 
@@ -72,6 +75,11 @@ module ActionView
72
75
  #
73
76
  # Example:
74
77
  # <%= nav.link_to 'Home', '#' %>
78
+ #
79
+ # This will also increment the item_count once the link's markup has been generated.
80
+ # This allows you to special case link_to options based on the index of current link
81
+ # in your customized implementations of the Navigation Builder.
82
+ # ---
75
83
  def link_to( *args, &link_block )
76
84
  if block_given?
77
85
  name = @template.capture(&link_block)
@@ -85,7 +93,7 @@ module ActionView
85
93
  html_options = args[2] || {}
86
94
 
87
95
  link_to_in_html( name, options, html_options )
88
- end
96
+ end.tap { @item_count += 1 } # Increment the number of links generated (and still return markup)
89
97
  end
90
98
 
91
99
  private
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{navigation_builder}
8
- s.version = "1.0.0.beta2"
8
+ s.version = "1.0.0.beta3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Derek Lindahl"]
12
- s.date = %q{2011-05-23}
12
+ s.date = %q{2011-05-26}
13
13
  s.description = %q{NavigationBuilder makes creating navigational links in a Rails application a breeze.}
14
14
  s.email = %q{dlindahl@customink.com}
15
15
  s.extra_rdoc_files = [
@@ -28,6 +28,17 @@ class TestNavigationBuilder < ActionView::TestCase
28
28
  assert_dom_equal expected, output_buffer
29
29
  end
30
30
 
31
+ should "know how many links have been rendered" do
32
+ count = 0
33
+ navigation_for :main do |nav|
34
+ concat nav.link_to( 'Foo', '#' )
35
+ concat nav.link_to( 'Bar', '#' )
36
+ count = nav.item_count
37
+ end
38
+
39
+ assert_equal 2, count
40
+ end
41
+
31
42
  should "generate HTML with custom wrapper tag name" do
32
43
  navigation_for :main, :wrapper_tag => :ol do |nav|
33
44
  concat nav.link_to( 'Foo', '#' )
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: navigation_builder
3
3
  version: !ruby/object:Gem::Version
4
- hash: 62196359
4
+ hash: 62196357
5
5
  prerelease: 6
6
6
  segments:
7
7
  - 1
8
8
  - 0
9
9
  - 0
10
10
  - beta
11
- - 2
12
- version: 1.0.0.beta2
11
+ - 3
12
+ version: 1.0.0.beta3
13
13
  platform: ruby
14
14
  authors:
15
15
  - Derek Lindahl
@@ -17,7 +17,7 @@ autorequire:
17
17
  bindir: bin
18
18
  cert_chain: []
19
19
 
20
- date: 2011-05-23 00:00:00 -04:00
20
+ date: 2011-05-26 00:00:00 -04:00
21
21
  default_executable:
22
22
  dependencies:
23
23
  - !ruby/object:Gem::Dependency