Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Update docs

  • Loading branch information...
commit 356e0f946efdd9de8e4a0139ac7329798664bff9 1 parent 327ef4c
Simone Carletti authored February 03, 2012
4  CHANGELOG.md
Source Rendered
... ...
@@ -1,7 +1,9 @@
1 1
 # Changelog
2 2
 
3 3
 
4  
-## Master
  4
+## Release 2.1.0
  5
+
  6
+* NEW: Support for Rails 3.2.
5 7
 
6 8
 * FIXED: Fixed Rails 3.2 ActiveSupport::Concern deprecation warning (GH-18).
7 9
 
312  README.md
Source Rendered
... ...
@@ -1,10 +1,9 @@
1  
-= Tabs on Rails
  1
+# Tabs on Rails
2 2
 
3  
-*TabsOnRails* is a simple Rails plugin for creating tabs and navigation menus.
4  
-It provides helpers for generating navigation menus with a flexible interface.
  3
+*TabsOnRails* is a simple Rails plugin for creating tabs and navigation menus. It provides helpers for generating navigation menus with a flexible interface.
5 4
 
6 5
 
7  
-== Requirements
  6
+## Requirements
8 7
 
9 8
 * Rails 3
10 9
 
@@ -12,297 +11,76 @@ Please note
12 11
 
13 12
 * TabsOnRails 2.x requires Rails 3. Use TabsOnRails 1.3.x with Rails 2.
14 13
 * TabsOnRails doesn't work with Rails 2.1 or lower
15  
-("comment":http://www.simonecarletti.com/blog/2009/04/tabsonrails/#comment-2901 and "commit":http://github.com/weppos/tabs_on_rails/commit/d5ae9f401e3d0acc87251fa8957a8625e90ba4b3).
  14
+([comment](http://www.simonecarletti.com/blog/2009/04/tabsonrails/#comment-2901) and [commit](http://github.com/weppos/tabs_on_rails/commit/d5ae9f401e3d0acc87251fa8957a8625e90ba4b3)).
16 15
 
17 16
 
18  
-== Installation
  17
+## Installation
19 18
 
20  
-"RubyGems":http://rubygems.org is the preferred way to install *TabsOnRails* and the best way if you want install a stable version.
  19
+[RubyGems](http://rubygems.org) is the preferred way to install *TabsOnRails* and the best way if you want install a stable version.
21 20
 
22  
-  $ gem install tabs_on_rails
  21
+    $ gem install tabs_on_rails
23 22
 
24  
-Specify the Gem dependency in the "Bundler":http://gembundler.com Gemfile.
  23
+Specify the Gem dependency in the [Bundler](http://gembundler.com) `Gemfile`.
25 24
 
26  
-  gem "tabs_on_rails"
  25
+    gem "tabs_on_rails"
27 26
 
28  
-Use "Bundler":http://gembundler.com and the ":git option":http://gembundler.com/v1.0/git.html if you want to grab the latest version from the Git repository.
  27
+Use [Bundler](http://gembundler.com) and the [:git option](http://gembundler.com/v1.0/git.html) if you want to grab the latest version from the Git repository.
29 28
 
30 29
 
31  
-== Usage
  30
+## Usage
32 31
 
33  
-In your template use the <tt>tabs_tag</tt> helper to create your tab.
  32
+In your template use the `tabs_tag` helper to create your tab.
34 33
 
35  
-  <%= tabs_tag do |tab| %>
36  
-    <%= tab.home      'Homepage', root_path %>
37  
-    <%= tab.dashboard 'Dashboard', dashboard_path %>
38  
-    <%= tab.account   'Account', account_path %>
39  
-  <% end %>
  34
+    <%= tabs_tag do |tab| %>
  35
+      <%= tab.home      'Homepage', root_path %>
  36
+      <%= tab.dashboard 'Dashboard', dashboard_path %>
  37
+      <%= tab.account   'Account', account_path %>
  38
+    <% end %>
40 39
 
41 40
 The example above produces the following HTML output.
42 41
 
43  
-  <ul>
44  
-    <li><a href="/">Homepage</a></li>
45  
-    <li><a href="/dashboard">Dashboard</a></li>
46  
-    <li><a href="/account">Account</a></li>
47  
-  </ul>
  42
+    <ul>
  43
+      <li><a href="/">Homepage</a></li>
  44
+      <li><a href="/dashboard">Dashboard</a></li>
  45
+      <li><a href="/account">Account</a></li>
  46
+    </ul>
48 47
 
49  
-The usage is similar to the Rails route file.
50  
-You create named tabs with the syntax <tt>tab.name_of_tab</tt>.
  48
+The usage is similar to the Rails route file. You create named tabs with the syntax `tab.name_of_tab`. The name you use creating a tab is the same you're going to refer to in your controller when you want to mark a tab as the current tab.
51 49
 
52  
-The name you use creating a tab is the same you're going to refer to
53  
-in your controller when you want to mark a tab as the current tab.
  50
+Now, if the action belongs to `DashboardController`, the template will automatically render the following HTML code.
54 51
 
55  
-  class DashboardController < ApplicationController
56  
-    set_tab :dashboard
57  
-  end
  52
+    <ul>
  53
+      <li><a href="/">Homepage</a></li>
  54
+      <li class="custom"><span>Dashboard</span></li>
  55
+      <li><a href="/account">Account</a></li>
  56
+    </ul>
58 57
 
59  
-Now, if the action belongs to <tt>DashboardController</tt>,
60  
-the template will automatically render the following HTML code.
  58
+Use the `current_tab` helper method if you need to access the value of current tab in your controller or template.
61 59
 
62  
-  <ul>
63  
-    <li><a href="/">Homepage</a></li>
64  
-    <li class="custom"><span>Dashboard</span></li>
65  
-    <li><a href="/account">Account</a></li>
66  
-  </ul>
67  
-
68  
-Use the <tt>current_tab</tt> helper method if you need to access
69  
-the value of current tab in your controller or template.
70  
-
71  
-  class DashboardController < ApplicationController
72  
-    set_tab :dashboard
73  
-  end
74  
-
75  
-  # In your view
76  
-  <p>The name of current tab is <%= current_tab %>.</p>
77  
-
78  
-=== Customizing a Tab
79  
-
80  
-You can pass a hash of options to customize the style and the behavior of the tab item.
81  
-Behind the scenes, each time you create a tab, the <tt>#tab_for</tt> 
82  
-method is invoked.
83  
-
84  
-  <%= tabs_tag do |tab| %>
85  
-    <%= tab.home      'Homepage', root_path, :style => "padding: 10px" %>
86  
-    <%= tab.dashboard 'Dashboard', dashboard_path %>
87  
-  <% end %>
88  
-
89  
-  <ul>
90  
-    <li style="padding: 10px"><a href="/">Homepage</a></li>
91  
-    <li class="custom"><span>Dashboard</span></li>
92  
-    <li><a href="/account">Account</a></li>
93  
-  </ul>
94  
-
95  
-See <tt>TabsOnRails::Tabs::TabsBuilder#tab_for</tt> for more details.
96  
-
97  
-=== Customizing open_tabs and close_tabs
98  
-
99  
-The open_tabs and the close_tabs methods can be customized with the <tt>:open_tabs</tt> and <tt>:close_tabs</tt> option.
100  
-
101  
-  <%= tabs_tag :open_tabs => { :id => "tabs", :class => "cool" } do |tab| %>
102  
-    <%= tab.home      'Homepage', root_path %>
103  
-    <%= tab.dashboard 'Dashboard', dashboard_path %>
104  
-    <%= tab.account   'Account', account_path %>
105  
-  <% end %>
106  
-
107  
-  <ul id="tabs" class="cool">
108  
-    <li><a href="/">Homepage</a></li>
109  
-    <li><a href="/dashboard">Dashboard</a></li>
110  
-    <li><a href="/account">Account</a></li>
111  
-  </ul>
112  
-
113  
-
114  
-Further customizations require a custom <tt>Builder</tt> (see below).
115  
-
116  
-
117  
-== Restricting set_tab scope
118  
-
119  
-The <tt>set_tab</tt> method understands all options you are used to pass to a Rails controller filter.
120  
-In fact, behind the scenes this method uses a <tt>before_filter</tt> to store the tab in the <tt>@tab_stack</tt> variable.
121  
-
122  
-Taking advantage of Rails filter options, you can restrict a tab to a selected group of actions in the same controller.
123  
-
124  
-  class PostsController < ApplicationController
125  
-    set_tab :admin
126  
-    set_tab :posts, :only => %w(index show)
127  
-  end
128  
-  
129  
-  class ApplicationController < ActionController::Base
130  
-    set_tab :admin, :if => :admin_controller?
131  
-    
132  
-    def admin_controller?
133  
-      self.class.name =~ /^Admin(::|Controller)/
134  
-    end
135  
-  end
136  
-
137  
-
138  
-== Using Namespaces to create Multiple Tabs
139  
-
140  
-Namespaces enable you to create and manage tabs in parallels. The best way to demonstrate namespace usage is with an example.
141  
-
142  
-Let's assume your application provides a first level navigation menu with 3 elements: :home, :dashboard, :projects. The relationship between your tabs and your controllers is 1:1 so you should end up with the following source code.
143  
-
144  
-  class HomeController
145  
-    set_tab :home
146  
-  end
147  
-
148  
-  class DashboardController
149  
-    set_tab :dashboard
150  
-  end
151  
-
152  
-  class ProjectsController
153  
-    set_tab :projects
154  
-    
155  
-    def first; end
156  
-    def second; end
157  
-    def third; end
158  
-  end
159  
-
160  
-The project controller contains 3 actions and you might want to create a second-level navigation menu. This menu should reflect the navigation status of the user in the project page.
161  
-
162  
-Without namespaces, you wouldn't be able to accomplish this task because you already set the current tab value to :projects. You need to create a parallel navigation menu and uniquely identify it with a custom namespace.
163  
-Let's call it :navigation.
164  
-
165  
-  class ProjectsController
166  
-    set_tab :projects
167  
-    
168  
-    # Create an other tab navigation level
169  
-    set_tab :first, :navigation, :only => %w(first)
170  
-    set_tab :second, :navigation, :only => %w(second)
171  
-    set_tab :third, :navigation, :only => %w(third)
172  
-    
173  
-    def first; end
174  
-    def second; end
175  
-    def third; end
176  
-  end
177  
-
178  
-Voilà! That's all you need to do. And you can create an unlimited number of namespaces as long as you use an unique name to identify them.
179  
-
180  
-The default namespace is called :default. Passing :default as name is the same as don't using any namespace at all. The following lines are equivalent.
181  
-
182  
-  set_tab :projects
183  
-  set_tab :projects, :default
184  
-
185  
-
186  
-=== Rendering Tabs with Namespaces
187  
-
188  
-To switch namespace in your template, just pass the :namespace option to the <tt>tabs_tag</tt> helper method.
189  
-
190  
-  <%= tabs_tag do |tab| %>
191  
-    <%= tab.home      'Homepage', root_path %>
192  
-    <%= tab.dashboard 'Dashboard', dashboard_path %>
193  
-    <%= tab.projects  'Projects', projects_path %>
194  
-  <% end %>
195  
-
196  
-  <%= tabs_tag :namespace => :navigation do |tab| %>
197  
-    <%= tab.first   'First', first_project_path %>
198  
-    <%= tab.second  'Second', second_project_path %>
199  
-    <%= tab.third   'Account', third_project_path %>
200  
-  <% end %>
201  
-
202  
-=== Namespace scope
203  
-
204  
-As a bonus feature, the namespace needs to be unique within current request scope, not necessarily across the entire application.
205  
-
206  
-Back to the previous example, you can reuse the same namespace in the other controllers. In this way, you can reuse your templates as well.
207  
-
208  
-  class HomeController
209  
-    set_tab :home
210  
-  end
211  
-
212  
-  class DashboardController
213  
-    set_tab :dashboard
214  
-
215  
-    set_tab :index,  :navigation, :only => %w(index)
216  
-    set_tab :common, :navigation, :only => %w(foo bar)
217  
-    
218  
-    # ...
219  
-  end
220  
-
221  
-  class ProjectsController
222  
-    set_tab :projects
223  
-  
224  
-    set_tab :first,  :navigation, :only => %w(first)
225  
-    set_tab :second, :navigation, :only => %w(second)
226  
-    set_tab :third,  :navigation, :only => %w(third)
227  
-    
228  
-    # ...
229  
-  end
230  
-
231  
-== Tab Builders
232  
-
233  
-The <tt>Builder</tt> is responsible for creating the tabs HTML code. This library is bundled with two <tt>Builders</tt>:
234  
-
235  
-<tt>Tabs::Builder</tt>:: this is the abstract interface for any custom builder.
236  
-<tt>Tabs::TabsBuilder</tt>:: this is the default builder.
237  
-
238  
-=== Understanding the Builder
239  
-
240  
-Builders act as formatters. A Builder encapsulates all the logic behind the tab creation including the code required to toggle tabs status.
241  
-
242  
-When the <tt>tabs_tag</tt> helper is called, it creates a new <tt>Tabs</tt> instance with selected Builder.
243  
-If you don't provide a custom builder, then <tt>Tabs::TabsBuilder</tt> is used by default.
244  
-
245  
-=== Creating a custom Builder
246  
-
247  
-All builders must extend the base <tt>Tabs::Builder</tt> class and implement at least the <tt>tab_for</tt> method.
248  
-Additional overridable methods include:
249  
-
250  
-<tt>open_tabs</tt>:: the method called before the tab set
251  
-<tt>close_tabs</tt>:: the method called after the tab set
252  
-<tt>tab_for</tt>:: the method called to create a single tab item
253  
-
254  
-The following example creates a custom tab builder called <tt>MenuTabBuilder</tt>.
255  
-
256  
-  class MenuTabBuilder < TabsOnRails::Tabs::Builder
257  
-    def open_tabs(options = {})
258  
-      @context.tag("ul", options, open = true)
259  
-    end
260  
-
261  
-    def close_tabs(options = {})
262  
-      "</ul>".html_safe
  60
+    class DashboardController < ApplicationController
  61
+      set_tab :dashboard
263 62
     end
264 63
 
265  
-    def tab_for(tab, name, options, item_options = {})
266  
-      item_options[:class] = (current_tab?(tab) ? 'active' : '')
267  
-      @context.content_tag(:li, item_options) do
268  
-        @context.link_to(name, options)
269  
-      end
270  
-    end
271  
-  end
272  
-
273  
-=== Using a custom Builder
274  
-
275  
-In your view, simply pass the builder class to the <tt>tabs_tag</tt> method.
276  
-
277  
-  <%= tabs_tag(:builder => MenuTabBuilder) do |tab| %>
278  
-    <%= tab.home        'Homepage', root_path %>
279  
-    <%= tab.dashboard,  'Dashboard', dashboard_path %>
280  
-    <%= tab.account     'Account', account_path, :style => 'float: right;' %>
281  
-  <% end %>
282  
-  
283  
-This is the final result.
  64
+    # In your view
  65
+    <p>The name of current tab is <%= current_tab %>.</p>
284 66
 
285  
-  <ul>
286  
-    <li class=""><a href="/">Homepage</a></li>
287  
-    <li class="active"><a href="/dashboard">Dashboard</a></li>
288  
-    <li class="" style="float: right;"><a href="/account">Account</a></li>
289  
-  </ul>
  67
+Read the [documentation](/code/tabs_on_rails/docs/) to learn more about advanced usage, builders and namespaces.
290 68
 
291 69
 
292  
-== Author
  70
+## Credits
293 71
 
294  
-* {Simone Carletti}[http://www.simonecarletti.com] <weppos@weppos.net>
  72
+* [Simone Carletti](http://www.simonecarletti.com/) <weppos@weppos.net> - The Author
295 73
 
296 74
 
297  
-== Resources
  75
+## Resources
298 76
 
299  
-* {Homepage}[http://www.simonecarletti.com/code/tabs_on_rails]
300  
-* {Source}[http://github.com/weppos/tabs_on_rails]
301  
-* {API Documentation}[http://www.simonecarletti.com/code/tabs_on_rails/api/]
302  
-* {Bugs & Features}[http://github.com/weppos/tabs_on_rails/issues]
  77
+* [Homepage](http://www.simonecarletti.com/code/tabs_on_rails)
  78
+* [Documentation](http://www.simonecarletti.com/code/tabs_on_rails/docs/)
  79
+* [API](http://rubydoc.info/gems/tabs_on_rails)
  80
+* [Repository](https://github.com/weppos/tabs_on_rails)
  81
+* [Issue Tracker](http://github.com/weppos/tabs_on_rails/issues)
303 82
 
304 83
 
305  
-== License
  84
+## License
306 85
 
307  
-TabsOnRails is Copyright (c) 2009-2011 Simone Carletti.
308  
-This is Free Software distributed under the MIT license.
  86
+*TabsOnRails* is Copyright (c) 2009-2012 Simone Carletti. This is Free Software distributed under the MIT license.
14  lib/tabs_on_rails.rb
... ...
@@ -1,16 +1,9 @@
1  
-# 
2  
-# = Tabs on Rails
  1
+#--
  2
+# Tabs on Rails
3 3
 #
4 4
 # A simple Ruby on Rails plugin for creating and managing Tabs.
5  
-# 
6  
-#
7  
-# Category::    Rails
8  
-# Package::     TabsOnRails
9  
-# Author::      Simone Carletti <weppos@weppos.net>
10  
-# License::     MIT License
11 5
 #
12  
-#--
13  
-# 
  6
+# Copyright (c) 2009-2012 Simone Carletti <weppos@weppos.net>
14 7
 #++
15 8
 
16 9
 
@@ -19,6 +12,7 @@
19 12
 require 'tabs_on_rails/action_controller'
20 13
 require 'tabs_on_rails/railtie'
21 14
 
  15
+
22 16
 module TabsOnRails
23 17
 
24 18
   NAME            = "Tabs on Rails"
19  lib/tabs_on_rails/action_controller.rb
... ...
@@ -1,16 +1,9 @@
1  
-#
2  
-# = Tabs on Rails
  1
+#--
  2
+# Tabs on Rails
3 3
 #
4 4
 # A simple Ruby on Rails plugin for creating and managing Tabs.
5 5
 #
6  
-#
7  
-# Category::    Rails
8  
-# Package::     TabsOnRails
9  
-# Author::      Simone Carletti <weppos@weppos.net>
10  
-# License::     MIT License
11  
-#
12  
-#--
13  
-#
  6
+# Copyright (c) 2009-2012 Simone Carletti <weppos@weppos.net>
14 7
 #++
15 8
 
16 9
 
@@ -68,7 +61,7 @@ def current_tab(namespace = nil)
68 61
     #
69 62
     # Returns a Boolean.
70 63
     def current_tab?(name, namespace = nil)
71  
-      current_tab(namespace).to_s == name.to_s
  64
+      current_tab(namespace).to_s ## name.to_s
72 65
     end
73 66
 
74 67
     # Initializes and/or returns the tab stack.
@@ -163,7 +156,7 @@ module HelperMethods
163 156
       #   # In your view
164 157
       #   <p>The name of current tab is <%= current_tab %>.</p>
165 158
       #
166  
-      # === Customizing a Tab
  159
+      # ### Customizing a Tab
167 160
       #
168 161
       # You can pass a hash of options to customize the style and the behavior of the tab item.
169 162
       # Behind the scenes, each time you create a tab, the <tt>#tab_for</tt> 
@@ -188,7 +181,7 @@ module HelperMethods
188 181
       #
189 182
       # See <tt>TabsOnRails::Tabs::TabsBuilder#tab_for</tt> for more details.
190 183
       #
191  
-      # === Customizing open_tabs and close_tabs
  184
+      # ### Customizing open_tabs and close_tabs
192 185
       #
193 186
       # The open_tabs and the close_tabs methods can be customized 
194 187
       # with the <tt>:open_tabs</tt> and <tt>:close_tabs</tt> option.
13  lib/tabs_on_rails/railtie.rb
... ...
@@ -1,16 +1,9 @@
1  
-#
2  
-# = Tabs on Rails
  1
+#--
  2
+# Tabs on Rails
3 3
 #
4 4
 # A simple Ruby on Rails plugin for creating and managing Tabs.
5 5
 #
6  
-#
7  
-# Category::    Rails
8  
-# Package::     TabsOnRails
9  
-# Author::      Simone Carletti <weppos@weppos.net>
10  
-# License::     MIT License
11  
-#
12  
-#--
13  
-#
  6
+# Copyright (c) 2009-2012 Simone Carletti <weppos@weppos.net>
14 7
 #++
15 8
 
16 9
 
14  lib/tabs_on_rails/tabs.rb
... ...
@@ -1,22 +1,16 @@
1  
-#
2  
-# = Tabs on Rails
  1
+#--
  2
+# Tabs on Rails
3 3
 #
4 4
 # A simple Ruby on Rails plugin for creating and managing Tabs.
5 5
 #
6  
-#
7  
-# Category::    Rails
8  
-# Package::     TabsOnRails
9  
-# Author::      Simone Carletti <weppos@weppos.net>
10  
-# License::     MIT License
11  
-#
12  
-#--
13  
-#
  6
+# Copyright (c) 2009-2012 Simone Carletti <weppos@weppos.net>
14 7
 #++
15 8
 
16 9
 
17 10
 require 'tabs_on_rails/tabs/builder'
18 11
 require 'tabs_on_rails/tabs/tabs_builder'
19 12
 
  13
+
20 14
 module TabsOnRails
21 15
 
22 16
   class Tabs
15  lib/tabs_on_rails/tabs/builder.rb
... ...
@@ -1,16 +1,9 @@
1  
-#
2  
-# = Tabs on Rails
  1
+#--
  2
+# Tabs on Rails
3 3
 #
4 4
 # A simple Ruby on Rails plugin for creating and managing Tabs.
5 5
 #
6  
-#
7  
-# Category::    Rails
8  
-# Package::     TabsOnRails
9  
-# Author::      Simone Carletti <weppos@weppos.net>
10  
-# License::     MIT License
11  
-#
12  
-#--
13  
-#
  6
+# Copyright (c) 2009-2012 Simone Carletti <weppos@weppos.net>
14 7
 #++
15 8
 
16 9
 
@@ -59,7 +52,7 @@ def initialize(context, options = {})
59 52
       #   current_tab? 'bar'  # => false
60 53
       #
61 54
       def current_tab?(tab)
62  
-        tab.to_s == @context.current_tab(@namespace).to_s
  55
+        tab.to_s ## @context.current_tab(@namespace).to_s
63 56
       end
64 57
 
65 58
 
13  lib/tabs_on_rails/tabs/tabs_builder.rb
... ...
@@ -1,16 +1,9 @@
1  
-#
2  
-# = Tabs on Rails
  1
+#--
  2
+# Tabs on Rails
3 3
 #
4 4
 # A simple Ruby on Rails plugin for creating and managing Tabs.
5 5
 #
6  
-#
7  
-# Category::    Rails
8  
-# Package::     TabsOnRails
9  
-# Author::      Simone Carletti <weppos@weppos.net>
10  
-# License::     MIT License
11  
-#
12  
-#--
13  
-#
  6
+# Copyright (c) 2009-2012 Simone Carletti <weppos@weppos.net>
14 7
 #++
15 8
 
16 9
 
13  lib/tabs_on_rails/version.rb
... ...
@@ -1,16 +1,9 @@
1  
-# 
2  
-# = Tabs on Rails
  1
+#--
  2
+# Tabs on Rails
3 3
 #
4 4
 # A simple Ruby on Rails plugin for creating and managing Tabs.
5  
-# 
6  
-#
7  
-# Category::    Rails
8  
-# Package::     TabsOnRails
9  
-# Author::      Simone Carletti <weppos@weppos.net>
10  
-# License::     MIT License
11  
-#
12  
-#--
13 5
 #
  6
+# Copyright (c) 2009-2012 Simone Carletti <weppos@weppos.net>
14 7
 #++
15 8
 
16 9
 

0 notes on commit 356e0f9

Please sign in to comment.
Something went wrong with that request. Please try again.