tabs_on_rails 1.2.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.rdoc CHANGED
@@ -1,6 +1,23 @@
1
1
  = Changelog
2
2
 
3
3
 
4
+ == Release 1.3.0
5
+
6
+ * ADDED: Ability to customize the behavior and the style of the li tab item
7
+ passing a hash of options.
8
+
9
+ <% tabs_tag do |tab| %>
10
+ <%= tab.home 'Homepage', root_path, :style => "padding: 10px" %>
11
+ <%= tab.dashboard 'Dashboard', dashboard_path %>
12
+ <% end %>
13
+
14
+ <ul>
15
+ <li style="padding: 10px"><a href="/">Homepage</a></li>
16
+ <li class="custom"><span>Dashboard</span></li>
17
+ <li><a href="/account">Account</a></li>
18
+ </ul>
19
+
20
+
4
21
  == Release 1.2.0
5
22
 
6
23
  * ADDED: Rails 3 compatibility.
data/README.rdoc CHANGED
@@ -72,7 +72,7 @@ The example above produces the following HTML output.
72
72
  </ul>
73
73
 
74
74
  The usage is similar to the Rails route file.
75
- You create named tabs with the syntax <tt>tab.name_of_tab</tt>.
75
+ You create named tabs with the syntax <tt>tab.name_of_tab</tt>.
76
76
 
77
77
  The name you use creating a tab is the same you're going to refer to in your controller
78
78
  when you want to mark a tab as the current tab.
@@ -85,7 +85,7 @@ Now, if the action belongs to <tt>DashboardController</tt>, the template will au
85
85
 
86
86
  <ul>
87
87
  <li><a href="/">Homepage</a></li>
88
- <li><span>Dashboard</span></li>
88
+ <li class="custom"><span>Dashboard</span></li>
89
89
  <li><a href="/account">Account</a></li>
90
90
  </ul>
91
91
 
@@ -98,7 +98,28 @@ Use the <tt>current_tab</tt> helper method if you need to access the value of cu
98
98
  # In your view
99
99
  <p>The name of current tab is <%= current_tab %>.</p>
100
100
 
101
- The open_tag can be customized with the <tt>:open_tabs</tt> option.
101
+ === Customizing a Tab
102
+
103
+ You can pass a hash of options to customize the style and the behavior of the tab item.
104
+ Behind the scenes, each time you create a tab, the <tt>#tab_for</tt>
105
+ method is invoked.
106
+
107
+ <% tabs_tag do |tab| %>
108
+ <%= tab.home 'Homepage', root_path, :style => "padding: 10px" %>
109
+ <%= tab.dashboard 'Dashboard', dashboard_path %>
110
+ <% end %>
111
+
112
+ <ul>
113
+ <li style="padding: 10px"><a href="/">Homepage</a></li>
114
+ <li class="custom"><span>Dashboard</span></li>
115
+ <li><a href="/account">Account</a></li>
116
+ </ul>
117
+
118
+ See <tt>TabsOnRails::Tabs::TabsBuilder#tab_for</tt> for more details.
119
+
120
+ === Customizing open_tabs and close_tabs
121
+
122
+ The open_tabs and the close_tabs methods can be customized with the <tt>:open_tabs</tt> and <tt>:close_tabs</tt> option.
102
123
 
103
124
  <% tabs_tag :open_tabs => { :id => "tabs", :class => "cool" } do |tab| %>
104
125
  <%= tab.home 'Homepage', root_path %>
@@ -112,6 +133,7 @@ The open_tag can be customized with the <tt>:open_tabs</tt> option.
112
133
  <li><a href="/account">Account</a></li>
113
134
  </ul>
114
135
 
136
+
115
137
  Further customizations require a custom <tt>Builder</tt> (see below).
116
138
 
117
139
 
@@ -144,7 +144,7 @@ module TabsOnRails
144
144
  #
145
145
  # <ul>
146
146
  # <li><a href="/">Homepage</a></li>
147
- # <li><span>Dashboard</span></li>
147
+ # <li class="custom"><span>Dashboard</span></li>
148
148
  # <li><a href="/account">Account</a></li>
149
149
  # </ul>
150
150
  #
@@ -158,7 +158,34 @@ module TabsOnRails
158
158
  # # In your view
159
159
  # <p>The name of current tab is <%= current_tab %>.</p>
160
160
  #
161
- # The open_tag can be customized with the <tt>:open_tabs</tt> option.
161
+ # === Customizing a Tab
162
+ #
163
+ # You can pass a hash of options to customize the style and the behavior of the tab item.
164
+ # Behind the scenes, each time you create a tab, the <tt>#tab_for</tt>
165
+ # method is invoked.
166
+ #
167
+ # <% tabs_tag do |tab| %>
168
+ # <%= tab.home 'Homepage', root_path, :style => "padding: 10px" %>
169
+ # <%= tab.dashboard 'Dashboard', dashboard_path %>
170
+ # <% end %>
171
+ #
172
+ # <ul>
173
+ # <li style="padding: 10px"><a href="/">Homepage</a></li>
174
+ # <li class="custom"><span>Dashboard</span></li>
175
+ # <li><a href="/account">Account</a></li>
176
+ # </ul>
177
+ #
178
+ # You can pass any option supported by the <li>content_tag</li> Rails helper.
179
+ # Additionally, the following options have a special meaning:
180
+ #
181
+ # * <tt>link_current</tt>: forces the current tab to be a link, instead of a span tag
182
+ #
183
+ # See <tt>TabsOnRails::Tabs::TabsBuilder#tab_for</tt> for more details.
184
+ #
185
+ # === Customizing open_tabs and close_tabs
186
+ #
187
+ # The open_tabs and the close_tabs methods can be customized
188
+ # with the <tt>:open_tabs</tt> and <tt>:close_tabs</tt> option.
162
189
  #
163
190
  # <% tabs_tag :open_tabs => { :id => "tabs", :class => "cool" } do |tab| %>
164
191
  # <%= tab.home 'Homepage', root_path %>
@@ -30,19 +30,27 @@ module TabsOnRails
30
30
  # current_tab? :foo # => true
31
31
  #
32
32
  # tab_for :foo, 'Foo', foo_path
33
- # # => <li><span>Foo</span></li>
33
+ # # => "<li class="current"><span>Foo</span></li>"
34
34
  #
35
35
  # tab_for :bar, 'Bar', bar_path
36
- # # => <li><a href="/link/to/bar">Bar</a></li>
36
+ # # => "<li><a href="/link/to/bar">Bar</a></li>"
37
37
  #
38
+ # You can pass a hash of <tt>item_options</tt>
39
+ # to customize the behavior and the style of the li element.
40
+ #
41
+ # # Pass a custom class to the element
42
+ # tab_for :bar, 'Bar', bar_path, :class => "custom"
43
+ # # => "<li class="custom"><a href="/link/to/bar">Bar</a></li>"
44
+ #
38
45
  # Implements Builder#tab_for.
39
46
  #
40
- def tab_for(tab, name, options)
47
+ def tab_for(tab, name, options, item_options = {})
48
+ item_options[:class] = item_options[:class].to_s.split(" ").push("current").join(" ") if current_tab?(tab)
41
49
  content = @context.link_to_unless(current_tab?(tab), name, options) do
42
50
  @context.content_tag(:span, name)
43
51
  end
44
- @context.content_tag(:li, content)
45
- end
52
+ @context.content_tag(:li, content, item_options)
53
+ end
46
54
 
47
55
  # Returns an unordered list open tag.
48
56
  #
@@ -18,7 +18,7 @@ module TabsOnRails
18
18
 
19
19
  module Version
20
20
  MAJOR = 1
21
- MINOR = 2
21
+ MINOR = 3
22
22
  PATCH = 0
23
23
  BUILD = nil
24
24
 
@@ -2,16 +2,16 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{tabs_on_rails}
5
- s.version = "1.1.0"
5
+ s.version = "1.2.0"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Simone Carletti"]
9
- s.date = %q{2010-08-09}
9
+ s.date = %q{2010-08-10}
10
10
  s.description = %q{ TabsOnRails is a simple Ruby on Rails plugin for creating and managing Tabs. It provides helpers for creating tabs with a flexible interface.
11
11
  }
12
12
  s.email = %q{weppos@weppos.net}
13
13
  s.extra_rdoc_files = ["CHANGELOG.rdoc", "LICENSE.rdoc", "README.rdoc"]
14
- s.files = ["Rakefile", "init.rb", "CHANGELOG.rdoc", "LICENSE.rdoc", "README.rdoc", "tabs_on_rails.gemspec", "test/controller_mixin_test.rb", "test/fixtures/mixin/default.html.erb", "test/fixtures/mixin/with_open_close_tabs.html.erb", "test/tabs/builder_test.rb", "test/tabs/tabs_builder_test.rb", "test/tabs_test.rb", "test/test_helper.rb", "lib/tabs_on_rails/controller_mixin.rb", "lib/tabs_on_rails/tabs/builder.rb", "lib/tabs_on_rails/tabs/tabs_builder.rb", "lib/tabs_on_rails/tabs.rb", "lib/tabs_on_rails/version.rb", "lib/tabs_on_rails.rb", "rails/init.rb"]
14
+ s.files = ["Rakefile", "init.rb", "CHANGELOG.rdoc", "LICENSE.rdoc", "README.rdoc", "tabs_on_rails.gemspec", "test/controller_mixin_test.rb", "test/fixtures/mixin/default.html.erb", "test/fixtures/mixin/with_open_close_tabs.html.erb", "test/tabs/builder_test.rb", "test/tabs/tabs_builder_test.rb", "test/tabs_test.rb", "test/test_helper.rb", "lib/tabs_on_rails/controller_mixin.rb", "lib/tabs_on_rails/railtie.rb", "lib/tabs_on_rails/tabs/builder.rb", "lib/tabs_on_rails/tabs/tabs_builder.rb", "lib/tabs_on_rails/tabs.rb", "lib/tabs_on_rails/version.rb", "lib/tabs_on_rails.rb", "rails/init.rb"]
15
15
  s.homepage = %q{http://www.simonecarletti.com/code/tabs_on_rails}
16
16
  s.rdoc_options = ["--main", "README.rdoc"]
17
17
  s.require_paths = ["lib"]
@@ -151,7 +151,7 @@ class ControllerMixinHelpersTest < ActionView::TestCase
151
151
  concat t.single('Single', '#')
152
152
  end
153
153
 
154
- assert_dom_equal('<span>Single</span>', content)
154
+ assert_dom_equal '<span>Single</span>', content
155
155
  end
156
156
 
157
157
  def test_tabs_tag_should_not_concat_open_tabs_when_nil
@@ -159,7 +159,7 @@ class ControllerMixinHelpersTest < ActionView::TestCase
159
159
  concat t.single('Single', '#')
160
160
  end
161
161
 
162
- assert_dom_equal('<span>Single</span><br />', content)
162
+ assert_dom_equal '<span>Single</span><br />', content
163
163
  end
164
164
 
165
165
  def test_tabs_tag_should_not_concat_close_tabs_when_nil
@@ -167,7 +167,7 @@ class ControllerMixinHelpersTest < ActionView::TestCase
167
167
  concat t.single('Single', '#')
168
168
  end
169
169
 
170
- assert_dom_equal('<br /><span>Single</span>', content)
170
+ assert_dom_equal '<br /><span>Single</span>', content
171
171
  end
172
172
 
173
173
  end
@@ -208,27 +208,35 @@ class ControllerMixinWithControllerTest < ActionController::TestCase
208
208
 
209
209
  def test_render_default
210
210
  get :action_dashboard
211
- assert_equal(%Q{<ul>
212
- <li><span>Dashboard</span></li>
211
+ assert_dom_equal(%Q{<ul>
212
+ <li class="current"><span>Dashboard</span></li>
213
213
  <li><a href="/w">Welcome</a></li>
214
214
  </ul>}, @response.body)
215
215
  end
216
216
 
217
217
  def test_render_with_open_close_tabs
218
218
  get :action_dashboard, :template => "with_open_close_tabs"
219
- assert_equal(%Q{<ul id="tabs">
220
- <li><span>Dashboard</span></li>
219
+ assert_dom_equal(%Q{<ul id="tabs">
220
+ <li class="current"><span>Dashboard</span></li>
221
221
  <li><a href="/w">Welcome</a></li>
222
222
  </ul>}, @response.body)
223
223
  end
224
224
 
225
+ def test_render_with_item_options
226
+ get :action_dashboard, :template => "with_item_options"
227
+ assert_dom_equal(%Q{<ul id="tabs">
228
+ <li class="custom current"><span>Dashboard</span></li>
229
+ <li class="custom"><a href="/w">Welcome</a></li>
230
+ </ul>}, @response.body)
231
+ end
232
+
225
233
 
226
234
  def test_set_tab
227
235
  get :action_dashboard
228
236
  assert_equal(:dashboard, controller.current_tab)
229
237
  assert_equal(:dashboard, controller.current_tab(:default))
230
- assert_equal(%Q{<ul>
231
- <li><span>Dashboard</span></li>
238
+ assert_dom_equal(%Q{<ul>
239
+ <li class="current"><span>Dashboard</span></li>
232
240
  <li><a href="/w">Welcome</a></li>
233
241
  </ul>}, @response.body)
234
242
  end
@@ -237,9 +245,9 @@ class ControllerMixinWithControllerTest < ActionController::TestCase
237
245
  get :action_welcome
238
246
  assert_equal(:welcome, controller.current_tab)
239
247
  assert_equal(:welcome, controller.current_tab(:default))
240
- assert_equal(%Q{<ul>
248
+ assert_dom_equal(%Q{<ul>
241
249
  <li><a href="/d">Dashboard</a></li>
242
- <li><span>Welcome</span></li>
250
+ <li class="current"><span>Welcome</span></li>
243
251
  </ul>}, @response.body)
244
252
  end
245
253
 
@@ -248,8 +256,8 @@ class ControllerMixinWithControllerTest < ActionController::TestCase
248
256
  assert_equal(:dashboard, controller.current_tab)
249
257
  assert_equal(:dashboard, controller.current_tab(:default))
250
258
  assert_equal(:homepage, controller.current_tab(:namespace))
251
- assert_equal(%Q{<ul>
252
- <li><span>Dashboard</span></li>
259
+ assert_dom_equal(%Q{<ul>
260
+ <li class="current"><span>Dashboard</span></li>
253
261
  <li><a href="/w">Welcome</a></li>
254
262
  </ul>}, @response.body)
255
263
  end
@@ -0,0 +1,4 @@
1
+ <% tabs_tag(:open_tabs => { :id => "tabs" }, :close_tabs => { :class => "ignored" }) do |tabs| %>
2
+ <%= tabs.dashboard 'Dashboard', '/d', :class => "custom" %>
3
+ <%= tabs.welcome 'Welcome', '/w', :class => "custom" %>
4
+ <% end -%>
@@ -49,15 +49,33 @@ class TabsBuilderTest < ActionView::TestCase
49
49
  def test_tab_for_should_return_link_to_unless_current_tab
50
50
  assert_dom_equal %Q{<li><a href="#">Welcome</a></li>},
51
51
  @builder.tab_for(:welcome, 'Welcome', '#')
52
- assert_dom_equal %Q{<li><a href="http://foobar.com/">Foo Bar</a></li>},
53
- @builder.tab_for(:welcome, 'Foo Bar', 'http://foobar.com/')
52
+ assert_dom_equal %Q{<li><a href="#">Foo Welcome</a></li>},
53
+ @builder.tab_for(:welcome, 'Foo Welcome', '#')
54
54
  end
55
55
 
56
56
  def test_tab_for_should_return_span_if_current_tab
57
- assert_dom_equal %Q{<li><span>Dashboard</span></li>},
57
+ assert_dom_equal %Q{<li class="current"><span>Dashboard</span></li>},
58
58
  @builder.tab_for(:dashboard, 'Dashboard', '#')
59
- assert_dom_equal %Q{<li><span>Foo Bar</span></li>},
60
- @builder.tab_for(:dashboard, 'Foo Bar', '#')
59
+ assert_dom_equal %Q{<li class="current"><span>Foo Dashboard</span></li>},
60
+ @builder.tab_for(:dashboard, 'Foo Dashboard', '#')
61
+ end
62
+
63
+ def test_tab_for_with_options_as_uri
64
+ assert_dom_equal %Q{<li><a href="http://welcome.com/">Foo Bar</a></li>},
65
+ @builder.tab_for(:welcome, 'Foo Bar', 'http://welcome.com/')
66
+ assert_dom_equal %Q{<li class="current"><span>Foo Bar</span></li>},
67
+ @builder.tab_for(:dashboard, 'Foo Bar', 'http://dashboard.com/')
68
+ end
69
+
70
+ def test_tab_for_with_item_options
71
+ assert_dom_equal %Q{<li class="custom current"><span>Dashboard</span></li>},
72
+ @builder.tab_for(:dashboard, "Dashboard", "#", :class => "custom")
73
+ assert_dom_equal %Q{<li class="custom"><a href="#">Welcome</a></li>},
74
+ @builder.tab_for(:welcome, "Welcome", "#", :class => "custom")
75
+ assert_dom_equal %Q{<li style="padding: 10px" class="current"><span>Dashboard</span></li>},
76
+ @builder.tab_for(:dashboard, "Dashboard", "#", :style => "padding: 10px")
77
+ assert_dom_equal %Q{<li style="padding: 10px"><a href="#">Welcome</a></li>},
78
+ @builder.tab_for(:welcome, "Welcome", "#", :style => "padding: 10px")
61
79
  end
62
80
 
63
81
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tabs_on_rails
3
3
  version: !ruby/object:Gem::Version
4
- hash: 31
4
+ hash: 27
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
- - 2
8
+ - 3
9
9
  - 0
10
- version: 1.2.0
10
+ version: 1.3.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Simone Carletti
@@ -38,6 +38,7 @@ files:
38
38
  - tabs_on_rails.gemspec
39
39
  - test/controller_mixin_test.rb
40
40
  - test/fixtures/mixin/default.html.erb
41
+ - test/fixtures/mixin/with_item_options.html.erb
41
42
  - test/fixtures/mixin/with_open_close_tabs.html.erb
42
43
  - test/tabs/builder_test.rb
43
44
  - test/tabs/tabs_builder_test.rb