tab_menu 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/.rspec +1 -0
- data/.rvmrc +1 -0
- data/.travis.yml +3 -0
- data/Gemfile +4 -0
- data/Guardfile +5 -0
- data/README.textile +71 -0
- data/Rakefile +15 -0
- data/init.rb +2 -0
- data/install.rb +1 -0
- data/lib/tab_menu/rails.rb +8 -0
- data/lib/tab_menu/tab_builder.rb +23 -0
- data/lib/tab_menu/version.rb +3 -0
- data/lib/tab_menu/view_helpers.rb +18 -0
- data/lib/tab_menu.rb +1 -0
- data/spec/debug.log +1 -0
- data/spec/spec_helper.rb +9 -0
- data/spec/tab_menu/tab_builder_spec.rb +58 -0
- data/spec/tab_menu/view_helpers_spec.rb +69 -0
- data/tab_menu.gemspec +25 -0
- data/uninstall.rb +1 -0
- metadata +142 -0
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm use default@tab_menu --create
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Guardfile
ADDED
data/README.textile
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
h1. TabMenu
|
2
|
+
|
3
|
+
TabMenu is an easy way to create tabs for your Rails Application. It requires Rails 3 or greater
|
4
|
+
|
5
|
+
"!https://secure.travis-ci.org/dpickett/tab_menu.png!":http://travis-ci.org/dpickett/tab_menu
|
6
|
+
|
7
|
+
h2. Examples
|
8
|
+
|
9
|
+
<pre>
|
10
|
+
<%- tab_menu "user_menu tabbed" do |t| -%>
|
11
|
+
<%= t.tab "Profile", "/account" %>
|
12
|
+
<%= t.tab "Change Settings", "/account/edit" %>
|
13
|
+
<%- end -%>
|
14
|
+
</pre>
|
15
|
+
|
16
|
+
This will render:
|
17
|
+
|
18
|
+
<pre>
|
19
|
+
<ul class="user_menu tabbed">
|
20
|
+
<li class="active"><a href="/account">Profile</a></li>
|
21
|
+
<li><a href="/account/edit">Change Settings</li>
|
22
|
+
</ul>
|
23
|
+
</pre>
|
24
|
+
|
25
|
+
You can now set the current tab like so:
|
26
|
+
|
27
|
+
<pre>
|
28
|
+
<%- tab_menu "user_menu", :current_tab => "profile" do |t| -%>
|
29
|
+
<%= t.tab "Profile", "/account" %>
|
30
|
+
<%= t.tab "Change Settings", "/account/edit" %>
|
31
|
+
<%- end -%>
|
32
|
+
</pre>
|
33
|
+
|
34
|
+
note the active class is designated for the current url and that url helpers are allowed in the second argument
|
35
|
+
|
36
|
+
h2. TODO
|
37
|
+
|
38
|
+
* Submenus
|
39
|
+
|
40
|
+
h2. Thanks
|
41
|
+
|
42
|
+
* Josh Goebel for identifying a hack in Rails 2.2 to resolve output buffer issues
|
43
|
+
* Ryan Angilly for reporting defects
|
44
|
+
|
45
|
+
h2. Contribution
|
46
|
+
|
47
|
+
You are welcomed to contribute. All changes and revisions are assigned under copyright below
|
48
|
+
|
49
|
+
If you use this plugin and you're happy with it, please recommend me on <a href="http://workingwithrails.com/recommendation/new/person/8076-dan-pickett">Working With Rails</a>
|
50
|
+
|
51
|
+
h2. MIT License
|
52
|
+
|
53
|
+
h3. Copyright (c) 2008 Enlight Solutions, Inc.
|
54
|
+
|
55
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
56
|
+
this software and associated documentation files (the "Software"), to deal in
|
57
|
+
the Software without restriction, including without limitation the rights to
|
58
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
59
|
+
of the Software, and to permit persons to whom the Software is furnished to do
|
60
|
+
so, subject to the following conditions:
|
61
|
+
|
62
|
+
The above copyright notice and this permission notice shall be included in all
|
63
|
+
copies or substantial portions of the Software.
|
64
|
+
|
65
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
66
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
67
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
68
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
69
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
70
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
71
|
+
SOFTWARE.
|
data/Rakefile
ADDED
data/init.rb
ADDED
data/install.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# Install hook code here
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module TabMenu
|
2
|
+
class TabBuilder
|
3
|
+
include ActionView::Helpers::TagHelper
|
4
|
+
include ActionView::Helpers::CaptureHelper
|
5
|
+
|
6
|
+
attr_accessor :output_buffer
|
7
|
+
def initialize(controller, current_tab = nil)
|
8
|
+
@controller = controller
|
9
|
+
@current_tab = current_tab
|
10
|
+
end
|
11
|
+
|
12
|
+
def tab(name, url, li_html_options = {}, link_to_options = {})
|
13
|
+
#append current to the contentli class attribute if its the current page
|
14
|
+
if (!@current_tab.nil? && @current_tab.downcase == name.downcase) || (@current_tab.nil? && @controller.current_page?(url))
|
15
|
+
li_html_options[:class] = [li_html_options[:class], "current"].join(" ").strip()
|
16
|
+
end
|
17
|
+
|
18
|
+
content_tag(:li, name, li_html_options) do
|
19
|
+
@controller.link_to name, url, link_to_options
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'tab_menu/tab_builder'
|
2
|
+
|
3
|
+
module TabMenu
|
4
|
+
module ViewHelpers
|
5
|
+
include ActionView::Helpers::TagHelper
|
6
|
+
include ActionView::Helpers::UrlHelper
|
7
|
+
include ActionView::Helpers::CaptureHelper
|
8
|
+
|
9
|
+
def tab_menu(tab_name = "", html_options = {}, options = {}, &block)
|
10
|
+
html_options[:class] ||= tab_name.blank? ? nil : tab_name
|
11
|
+
|
12
|
+
content_tag(:ul, html_options) do
|
13
|
+
yield(TabBuilder.new(self, options[:current_tab]))
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
data/lib/tab_menu.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "tab_menu/rails" if defined?(Rails)
|
data/spec/debug.log
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# Logfile created on Wed Oct 15 11:53:48 -0400 2008 by /
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'action_controller'
|
3
|
+
require 'action_view'
|
4
|
+
require 'action_view/base'
|
5
|
+
require 'action_view/template'
|
6
|
+
require 'action_view/helpers/capture_helper'
|
7
|
+
|
8
|
+
require 'net/http'
|
9
|
+
require 'net/https'
|
10
|
+
|
11
|
+
class TabMenuController < ActionController::Base
|
12
|
+
include TabMenu
|
13
|
+
|
14
|
+
def index
|
15
|
+
render :text => "index"
|
16
|
+
end
|
17
|
+
|
18
|
+
def show
|
19
|
+
render :text => "show"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe TabMenu::TabBuilder do
|
24
|
+
include TabMenu::ViewHelpers
|
25
|
+
|
26
|
+
before(:each) do
|
27
|
+
@controller = TabMenuController.new
|
28
|
+
self.stub!(:current_page?).and_return(false)
|
29
|
+
@builder = TabMenu::TabBuilder.new(self)
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should create an li" do
|
33
|
+
@builder.tab("Test", "/").should =~ /^<li/
|
34
|
+
@builder.tab("Test", "/").should =~ /<\/li>$/
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should create an li with the first argument as the text" do
|
38
|
+
@builder.tab("Test", "/").should =~ />Test</
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should create an li with a link inside it" do
|
42
|
+
@builder.tab("Test", "/").should =~ /<a/
|
43
|
+
@builder.tab("Test", "/").should =~ /<\/a>/
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should create an a with an href to the specified url" do
|
47
|
+
@builder.tab("Test", "/").should =~ /href=\"\/\"/
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should set a tab as current if it is the current url" do
|
51
|
+
self.should_receive(:current_page?).with("/").once.and_return true
|
52
|
+
@builder.tab("Test", "/").should =~ /class=\"current\"/
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should allow link_html_options" do
|
56
|
+
@builder.tab("Test", "/", {}, method: :delete).should =~ /data-method=\"delete\"/
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
require 'tab_menu/view_helpers'
|
4
|
+
|
5
|
+
describe TabMenu::ViewHelpers, "helper" do
|
6
|
+
include ActionView::Helpers::UrlHelper
|
7
|
+
include ActionView::Helpers::TextHelper
|
8
|
+
include ActionView::Helpers::TagHelper
|
9
|
+
include TabMenu::ViewHelpers
|
10
|
+
|
11
|
+
attr_accessor :output_buffer
|
12
|
+
|
13
|
+
before(:each) do
|
14
|
+
self.stub!(:current_page?).and_return(false)
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should create an unordered list" do
|
18
|
+
menu = tab_menu do |t|
|
19
|
+
t.tab "Test", "/"
|
20
|
+
end
|
21
|
+
|
22
|
+
menu.should =~ /^<ul/
|
23
|
+
menu.should =~ /<\/ul>$/
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should optionally take a name which will create a subsequent class for the ul" do
|
27
|
+
menu = tab_menu("test") do |t|
|
28
|
+
t.tab "Test", "/"
|
29
|
+
end
|
30
|
+
|
31
|
+
menu.should =~ /<ul class=\"test\">/
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe TabMenu::ViewHelpers, "erb", :type => :helper do
|
36
|
+
include ActionView::Helpers::UrlHelper
|
37
|
+
include ActionView::Helpers::TextHelper
|
38
|
+
include ActionView::Helpers::TagHelper
|
39
|
+
include TabMenu::ViewHelpers
|
40
|
+
|
41
|
+
before(:each) do
|
42
|
+
pending("must figure out how to mock definition of erbout - is this worth it with defect fix pending?")
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should create an unordered list" do
|
46
|
+
menu = helper.tab_menu do |t|
|
47
|
+
t.tab "Test", "/"
|
48
|
+
end
|
49
|
+
|
50
|
+
menu.should =~ /^<ul>/
|
51
|
+
menu.should =~ /<\/ul>$/
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should optionally take a name which will create a subsequent class for the ul" do
|
55
|
+
menu = tab_menu("test") do |t|
|
56
|
+
t.tab "Test", "/"
|
57
|
+
end
|
58
|
+
|
59
|
+
menu.should =~ /<ul class=\"test\">/
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should optionally take a list of names which will create a subsequent class for the ul" do
|
63
|
+
menu = tab_menu("test foo") do |t|
|
64
|
+
t.tab "Test", "/"
|
65
|
+
end
|
66
|
+
|
67
|
+
menu.should =~ /<ul class=\"test\sfoo\">/
|
68
|
+
end
|
69
|
+
end
|
data/tab_menu.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/tab_menu/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Dan Pickett"]
|
6
|
+
gem.email = ["dpickett@enlightsolutions.com"]
|
7
|
+
gem.description = %q{Rails Gem to generate tabs}
|
8
|
+
gem.summary = %q{Rails Gem to generate tabs}
|
9
|
+
gem.homepage = ""
|
10
|
+
|
11
|
+
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
12
|
+
gem.files = `git ls-files`.split("\n")
|
13
|
+
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
14
|
+
gem.name = "tab_menu"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = TabMenu::VERSION
|
17
|
+
|
18
|
+
gem.add_dependency "rake"
|
19
|
+
gem.add_dependency "actionpack"
|
20
|
+
|
21
|
+
gem.add_development_dependency "rspec"
|
22
|
+
gem.add_development_dependency "mocha"
|
23
|
+
gem.add_development_dependency "rails"
|
24
|
+
gem.add_development_dependency "guard-rspec"
|
25
|
+
end
|
data/uninstall.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# Uninstall hook code here
|
metadata
ADDED
@@ -0,0 +1,142 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: tab_menu
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Dan Pickett
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-12-29 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rake
|
16
|
+
requirement: &2153707040 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *2153707040
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: actionpack
|
27
|
+
requirement: &2153705540 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *2153705540
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: rspec
|
38
|
+
requirement: &2153704340 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
type: :development
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *2153704340
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: mocha
|
49
|
+
requirement: &2153703320 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
type: :development
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *2153703320
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: rails
|
60
|
+
requirement: &2153702540 !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ! '>='
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
type: :development
|
67
|
+
prerelease: false
|
68
|
+
version_requirements: *2153702540
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: guard-rspec
|
71
|
+
requirement: &2153701740 !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ! '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: *2153701740
|
80
|
+
description: Rails Gem to generate tabs
|
81
|
+
email:
|
82
|
+
- dpickett@enlightsolutions.com
|
83
|
+
executables: []
|
84
|
+
extensions: []
|
85
|
+
extra_rdoc_files: []
|
86
|
+
files:
|
87
|
+
- .gitignore
|
88
|
+
- .rspec
|
89
|
+
- .rvmrc
|
90
|
+
- .travis.yml
|
91
|
+
- Gemfile
|
92
|
+
- Guardfile
|
93
|
+
- README.textile
|
94
|
+
- Rakefile
|
95
|
+
- init.rb
|
96
|
+
- install.rb
|
97
|
+
- lib/tab_menu.rb
|
98
|
+
- lib/tab_menu/rails.rb
|
99
|
+
- lib/tab_menu/tab_builder.rb
|
100
|
+
- lib/tab_menu/version.rb
|
101
|
+
- lib/tab_menu/view_helpers.rb
|
102
|
+
- spec/debug.log
|
103
|
+
- spec/spec_helper.rb
|
104
|
+
- spec/tab_menu/tab_builder_spec.rb
|
105
|
+
- spec/tab_menu/view_helpers_spec.rb
|
106
|
+
- tab_menu.gemspec
|
107
|
+
- uninstall.rb
|
108
|
+
homepage: ''
|
109
|
+
licenses: []
|
110
|
+
post_install_message:
|
111
|
+
rdoc_options: []
|
112
|
+
require_paths:
|
113
|
+
- lib
|
114
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
115
|
+
none: false
|
116
|
+
requirements:
|
117
|
+
- - ! '>='
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
version: '0'
|
120
|
+
segments:
|
121
|
+
- 0
|
122
|
+
hash: -2696424801541203648
|
123
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
124
|
+
none: false
|
125
|
+
requirements:
|
126
|
+
- - ! '>='
|
127
|
+
- !ruby/object:Gem::Version
|
128
|
+
version: '0'
|
129
|
+
segments:
|
130
|
+
- 0
|
131
|
+
hash: -2696424801541203648
|
132
|
+
requirements: []
|
133
|
+
rubyforge_project:
|
134
|
+
rubygems_version: 1.8.6
|
135
|
+
signing_key:
|
136
|
+
specification_version: 3
|
137
|
+
summary: Rails Gem to generate tabs
|
138
|
+
test_files:
|
139
|
+
- spec/debug.log
|
140
|
+
- spec/spec_helper.rb
|
141
|
+
- spec/tab_menu/tab_builder_spec.rb
|
142
|
+
- spec/tab_menu/view_helpers_spec.rb
|