tabs_on_rails 2.2.0 → 3.0.0

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f8b05c093bf3ea463e7286064ae18e3f3b443785
4
+ data.tar.gz: b795ffa146e76d820ba77a693f8646787b11257d
5
+ SHA512:
6
+ metadata.gz: acb18c671a6d0ff4dca1d4ec50b510c070a520d9372a5db4815c52d7b905159aa395daa5bd2350e509eff7820e15064a85774df87be89450aded8ab7ad399a2c
7
+ data.tar.gz: a9c0c4e43a517f34534769ecde22c3f9c73e628237e6c93d722f355d773d7ac6f7ba12aa5705b7f6013f42c6960c62dcd13a61793eee004e4f1bd21bf952681b
data/.gitignore CHANGED
@@ -1,11 +1,12 @@
1
1
  # Bundler
2
- .bundle
3
- pkg/*
4
- Gemfile.lock
5
-
6
- # RVM
7
- .rvmrc
2
+ /.bundle/
3
+ /Gemfile.lock
4
+ gemfiles/*.gemfile.lock
8
5
 
9
6
  # YARD
10
- .yardoc
11
- yardoc/
7
+ /.yardoc
8
+ /_yardoc/
9
+
10
+ # Artifacts
11
+ /pkg/
12
+ /tmp/
@@ -0,0 +1 @@
1
+ tabs_on_rails
@@ -1,12 +1,15 @@
1
1
  rvm:
2
- - 1.8.7
3
- - 1.9.2
4
- - 1.9.3
5
- - ree
2
+ - 2.2.5
3
+ - 2.3.1
4
+ - 2.4.0
5
+
6
6
  gemfile:
7
- - gemfiles/3.0.gemfile
8
- - gemfiles/3.1.gemfile
9
- - gemfiles/3.2.gemfile
10
- notifications:
11
- recipients:
12
- - weppos@weppos.net
7
+ - gemfiles/4.2.gemfile
8
+ - gemfiles/5.0.gemfile
9
+
10
+ before_install:
11
+ - gem install bundler
12
+
13
+ env:
14
+ global:
15
+ - NOKOGIRI_USE_SYSTEM_LIBRARIES=true
data/Appraisals CHANGED
@@ -1,11 +1,6 @@
1
- appraise "3.0" do
2
- gem "activerecord", "~> 3.0"
1
+ appraise "4.2" do
2
+ gem "rails", "~> 4.2.0"
3
3
  end
4
-
5
- appraise "3.1" do
6
- gem "activerecord", "~> 3.1"
4
+ appraise "5.0" do
5
+ gem "rails", "~> 5.0.0"
7
6
  end
8
-
9
- appraise "3.2" do
10
- gem "activerecord", "~> 3.2"
11
- end
@@ -1,6 +1,12 @@
1
1
  # Changelog
2
2
 
3
3
 
4
+ ## Release 3.0.0
5
+
6
+ - CHANGED: Compatible with Rails 5.
7
+ - CHANGED: Dropped support for Rails before 4.2 and Ruby before 2.2.
8
+
9
+
4
10
  ## Release 2.2.0
5
11
 
6
12
  * NEW: Ability to configure a default builder (GH-20). [Thanks @ilstar]
data/Gemfile CHANGED
@@ -1,3 +1,3 @@
1
- source "http://rubygems.org"
1
+ source 'https://rubygems.org'
2
2
 
3
3
  gemspec
@@ -1,4 +1,4 @@
1
- Copyright (c) 2009-2013 Simone Carletti
1
+ Copyright (c) 2009-2017 Simone Carletti <weppos@weppos.net>
2
2
 
3
3
  MIT License
4
4
 
data/README.md CHANGED
@@ -1,81 +1,343 @@
1
1
  # Tabs on Rails
2
2
 
3
- *TabsOnRails* is a simple Rails plugin for creating tabs and navigation menus. It provides helpers for generating navigation menus with a flexible interface.
3
+ <tt>TabsOnRails</tt> is a simple Rails plugin for creating tabs and navigation menus. It provides helpers for generating navigation menus with a flexible interface.
4
4
 
5
5
 
6
6
  ## Requirements
7
7
 
8
- * Rails 3
8
+ - Rails 4.2 or Rails 5
9
9
 
10
- Please note
11
-
12
- * TabsOnRails 2.x requires Rails 3. Use TabsOnRails 1.3.x with Rails 2.
13
- * TabsOnRails doesn't work with Rails 2.1 or lower
14
- ([comment](http://www.simonecarletti.com/blog/2009/04/tabsonrails/#comment-2901) and [commit](http://github.com/weppos/tabs_on_rails/commit/d5ae9f401e3d0acc87251fa8957a8625e90ba4b3)).
10
+ For older versions of Ruby or Ruby on Rails, see the [CHANGELOG](CHANGELOG.md).
15
11
 
16
12
 
17
13
  ## Installation
18
14
 
19
- [RubyGems](http://rubygems.org) is the preferred way to install *TabsOnRails* and the best way if you want install a stable version.
15
+ Add this line to your application's `Gemfile`:
20
16
 
21
- $ gem install tabs_on_rails
17
+ gem "tabs_on_rails"
22
18
 
23
- Specify the Gem dependency in the [Bundler](http://gembundler.com) `Gemfile`.
19
+ And then execute `bundle` to install the dependencies:
24
20
 
25
- gem "tabs_on_rails"
21
+ $ bundle
26
22
 
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.
23
+ Use [Bundler](http://bundler.io/) and the `:git` option if you want to grab the latest version from the Git repository.
28
24
 
29
25
 
30
26
  ## Usage
31
27
 
32
28
  In your template use the `tabs_tag` helper to create your tab.
33
29
 
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 %>
30
+ ```ruby
31
+ <%= tabs_tag do |tab| %>
32
+ <%= tab.home 'Homepage', root_path %>
33
+ <%= tab.dashboard 'Dashboard', dashboard_path %>
34
+ <%= tab.account 'Account', account_path %>
35
+ <% end %>
36
+ ```
39
37
 
40
- The example above produces the following HTML output.
38
+ renders
41
39
 
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>
40
+ ```html
41
+ <ul>
42
+ <li><a href="/">Homepage</a></li>
43
+ <li><a href="/dashboard">Dashboard</a></li>
44
+ <li><a href="/account">Account</a></li>
45
+ </ul>
46
+ ```
47
47
 
48
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.
49
49
 
50
+ ```ruby
51
+ class DashboardController < ApplicationController
52
+ set_tab :dashboard
53
+ end
54
+ ```
55
+
50
56
  Now, if the action belongs to `DashboardController`, the template will automatically render the following HTML code.
51
57
 
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
+ ```html
59
+ <ul>
60
+ <li><a href="/">Homepage</a></li>
61
+ <li class="custom"><span>Dashboard</span></li>
62
+ <li><a href="/account">Account</a></li>
63
+ </ul>
64
+ ```
57
65
 
58
66
  Use the `current_tab` helper method if you need to access the value of current tab in your controller or template.
59
67
 
60
- class DashboardController < ApplicationController
61
- set_tab :dashboard
68
+ ```ruby
69
+ class DashboardController < ApplicationController
70
+ set_tab :dashboard
71
+ end
72
+ ```
73
+
74
+ In your view
75
+
76
+ ```html
77
+ <p>The name of current tab is <%= current_tab %>.</p>
78
+ ```
79
+
80
+ ### Customizing a Tab
81
+
82
+ You can pass a hash of options to customize the style and the behavior of the tab item.
83
+ Behind the scenes, each time you create a tab, the `#tab_for` method is invoked.
84
+
85
+ ```ruby
86
+ <%= tabs_tag do |tab| %>
87
+ <%= tab.home 'Homepage', root_path, :style => "padding: 10px" %>
88
+ <%= tab.dashboard 'Dashboard', dashboard_path %>
89
+ <% end %>
90
+ ```
91
+
92
+ renders
93
+
94
+ ```
95
+ <ul>
96
+ <li style="padding: 10px"><a href="/">Homepage</a></li>
97
+ <li class="custom"><span>Dashboard</span></li>
98
+ <li><a href="/account">Account</a></li>
99
+ </ul>
100
+ ```
101
+
102
+ See `TabsOnRails::Tabs::TabsBuilder#tab_for` for more details.
103
+
104
+ ### Customizing `open_tabs` and `close_tabs`
105
+
106
+ The `open_tabs` and the `close_tabs` methods can be customized with the `:open_tabs` and `:close_tabs` option.
107
+
108
+ ```ruby
109
+ <%= tabs_tag :open_tabs => { :id => "tabs", :class => "cool" } do |tab| %>
110
+ <%= tab.home 'Homepage', root_path %>
111
+ <%= tab.dashboard 'Dashboard', dashboard_path %>
112
+ <%= tab.account 'Account', account_path %>
113
+ <% end %>
114
+ ```
115
+
116
+ renders
117
+
118
+ ```html
119
+ <ul id="tabs" class="cool">
120
+ <li><a href="/">Homepage</a></li>
121
+ <li><a href="/dashboard">Dashboard</a></li>
122
+ <li><a href="/account">Account</a></li>
123
+ </ul>
124
+ ```
125
+
126
+ Further customizations require a custom `Builder` (see below).
127
+
128
+
129
+ ## Restricting `set_tab` scope
130
+
131
+ The `set_tab` method understands all options you are used to pass to a Rails controller filter.
132
+ In fact, behind the scenes this method uses a `before_filter` to store the tab in the `@tab_stack` variable.
133
+
134
+ Taking advantage of Rails filter options, you can restrict a tab to a selected group of actions in the same controller.
135
+
136
+ ```ruby
137
+ class PostsController < ApplicationController
138
+ set_tab :admin
139
+ set_tab :posts, :only => %w(index show)
140
+ end
141
+
142
+ class ApplicationController < ActionController::Base
143
+ set_tab :admin, :if => :admin_controller?
144
+
145
+ def admin_controller?
146
+ self.class.name =~ /^Admin(::|Controller)/
147
+ end
148
+ end
149
+ ```
150
+
151
+ ## Using Namespaces to create Multiple Tabs
152
+
153
+ Namespaces enable you to create and manage tabs in parallels. The best way to demonstrate namespace usage is with an example.
154
+
155
+ 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.
156
+
157
+ ```ruby
158
+ class HomeController
159
+ set_tab :home
160
+ end
161
+
162
+ class DashboardController
163
+ set_tab :dashboard
164
+ end
165
+
166
+ class ProjectsController
167
+ set_tab :projects
168
+
169
+ def first; end
170
+ def second; end
171
+ def third; end
172
+ end
173
+ ```
174
+
175
+ 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.
176
+
177
+ 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.
178
+ Let's call it :navigation.
179
+
180
+ ```ruby
181
+ class ProjectsController
182
+ set_tab :projects
183
+
184
+ # Create an other tab navigation level
185
+ set_tab :first, :navigation, :only => %w(first)
186
+ set_tab :second, :navigation, :only => %w(second)
187
+ set_tab :third, :navigation, :only => %w(third)
188
+
189
+ def first; end
190
+ def second; end
191
+ def third; end
192
+ end
193
+ ```
194
+
195
+ 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.
196
+
197
+ 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.
198
+
199
+ ```ruby
200
+ set_tab :projects
201
+ set_tab :projects, :default
202
+ ```
203
+
204
+ ### Rendering Tabs with Namespaces
205
+
206
+ To switch namespace in your template, just pass the `:namespace` option to the `tabs_tag` helper method.
207
+
208
+ ```ruby
209
+ <%= tabs_tag do |tab| %>
210
+ <%= tab.home 'Homepage', root_path %>
211
+ <%= tab.dashboard 'Dashboard', dashboard_path %>
212
+ <%= tab.projects 'Projects', projects_path %>
213
+ <% end %>
214
+
215
+ <%= tabs_tag :namespace => :navigation do |tab| %>
216
+ <%= tab.first 'First', project_first_path %>
217
+ <%= tab.second 'Second', project_second_path %>
218
+ <%= tab.third 'Account', project_third_path %>
219
+ <% end %>
220
+ ```
221
+
222
+ ### Namespace scope
223
+
224
+ As a bonus feature, the namespace needs to be unique within current request scope, not necessarily across the entire application.
225
+
226
+ 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.
227
+
228
+ ```ruby
229
+ class HomeController
230
+ set_tab :home
231
+ end
232
+
233
+ class DashboardController
234
+ set_tab :dashboard
235
+
236
+ set_tab :index, :navigation, :only => %w(index)
237
+ set_tab :common, :navigation, :only => %w(foo bar)
238
+
239
+ # ...
240
+ end
241
+
242
+ class ProjectsController
243
+ set_tab :projects
244
+
245
+ set_tab :first, :navigation, :only => %w(first)
246
+ set_tab :second, :navigation, :only => %w(second)
247
+ set_tab :third, :navigation, :only => %w(third)
248
+
249
+ # ...
250
+ end
251
+ ```
252
+
253
+
254
+ ## Tab Builders
255
+
256
+ The `Builder` is responsible for creating the tabs HTML code. This library is bundled with two `Builders`:
257
+
258
+ - `Tabs::Builder`: this is the abstract interface for any custom builder.
259
+ - `Tabs::TabsBuilder`: this is the default builder.
260
+
261
+ ### Understanding the Builder
262
+
263
+ Builders act as formatters. A Builder encapsulates all the logic behind the tab creation including the code required to toggle tabs status.
264
+
265
+ When the `tabs_tag` helper is called, it creates a new `Tabs` instance with selected Builder. If you don't provide a custom builder, then `Tabs::TabsBuilder` is used by default.
266
+
267
+ ### Creating a custom Builder
268
+
269
+ All builders must extend the base `Tabs::Builder` class and implement at least the `tab_for` method.
270
+ Additional overridable methods include:
271
+
272
+ - `open_tabs`: the method called before the tab set
273
+ - `close_tabs`: the method called after the tab set
274
+ - `tab_for`: the method called to create a single tab item
275
+
276
+ The following example creates a custom tab builder called `MenuTabBuilder`.
277
+
278
+ ```ruby
279
+ class MenuTabBuilder < TabsOnRails::Tabs::Builder
280
+ def open_tabs(options = {})
281
+ @context.tag("ul", options, open = true)
282
+ end
283
+
284
+ def close_tabs(options = {})
285
+ "</ul>".html_safe
286
+ end
287
+
288
+ def tab_for(tab, name, options, item_options = {})
289
+ item_options[:class] = (current_tab?(tab) ? 'active' : '')
290
+ @context.content_tag(:li, item_options) do
291
+ @context.link_to(name, options)
62
292
  end
293
+ end
294
+ end
295
+ ```
296
+
297
+ ### Using a custom Builder
298
+
299
+ In your view, simply pass the builder class to the `tabs_tag` method.
300
+
301
+ ```ruby
302
+ <%= tabs_tag(:builder => MenuTabBuilder) do |tab| %>
303
+ <%= tab.home 'Homepage', root_path %>
304
+ <%= tab.dashboard, 'Dashboard', dashboard_path %>
305
+ <%= tab.account 'Account', account_path, :style => 'float: right;' %>
306
+ <% end %>
307
+ ```
308
+
309
+ renders
310
+
311
+ ```html
312
+ <ul>
313
+ <li class=""><a href="/">Homepage</a></li>
314
+ <li class="active"><a href="/dashboard">Dashboard</a></li>
315
+ <li class="" style="float: right;"><a href="/account">Account</a></li>
316
+ </ul>
317
+ ```
318
+
319
+
320
+ ## Credits
321
+
322
+ <tt>TabsOnRails</tt> was created and is maintained by [Simone Carletti](https://simonecarletti.com/). Many improvements and bugfixes were contributed by the [open source community](https://github.com/weppos/tabs_on_rails/graphs/contributors).
323
+
324
+
325
+ ## Contributing
326
+
327
+ Direct questions and discussions to [Stack Overflow](http://stackoverflow.com/questions/tagged/tabs-on-rails).
63
328
 
64
- # In your view
65
- <p>The name of current tab is <%= current_tab %>.</p>
329
+ [Pull requests](https://github.com/weppos/tabs_on_rails) are very welcome! Please include tests for every patch, and create a topic branch for every separate change you make.
66
330
 
67
- Read the [documentation](http://www.simonecarletti.com/code/tabs_on_rails/docs/) to learn more about advanced usage, builders and namespaces.
331
+ Report issues or feature requests to [GitHub Issues](https://github.com/weppos/tabs_on_rails/issues).
68
332
 
69
333
 
70
- ## Resources
334
+ ## More Information
71
335
 
72
- * [Homepage](http://www.simonecarletti.com/code/tabs_on_rails)
73
- * [Documentation](http://www.simonecarletti.com/code/tabs_on_rails/docs/)
74
- * [API](http://rubydoc.info/gems/tabs_on_rails)
75
- * [Repository](https://github.com/weppos/tabs_on_rails)
76
- * [Issue Tracker](http://github.com/weppos/tabs_on_rails/issues)
336
+ - [Homepage](https://simonecarletti.com/code/tabs-on-rails)
337
+ - [RubyGems](https://rubygems.org/gems/tabs_on_rails)
338
+ - [Issues](https://github.com/weppos/tabs_on_rails/issues)
77
339
 
78
340
 
79
341
  ## License
80
342
 
81
- Copyright (c) 2009-2013 Simone Carletti. This is Free Software distributed under the MIT license.
343
+ Copyright (c) 2009-2017 Simone Carletti. This is Free Software distributed under the MIT license.