rubyguy-simple_tabs 0.1.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.
data/README.rdoc ADDED
@@ -0,0 +1,83 @@
1
+ = SimpleTabs
2
+
3
+ Super simple plugin/gem to easily add tabbed navigation to your Ruby on Rails application.
4
+
5
+ == Installation
6
+
7
+ === As RubyGem:
8
+
9
+ In config/environment.rb:
10
+
11
+ config.gem 'rubyguy-simple_tabs', :version => '0.1.0', :source => 'http://gems.github.com/', :lib => 'simple_tabs'
12
+
13
+ And then run:
14
+
15
+ rake gems:install
16
+
17
+ === As Rails plugin:
18
+
19
+ script/plugin install git://github.com/rubyguy/simple_tabs.git
20
+
21
+ == Usage
22
+
23
+ In your layout:
24
+
25
+ <%
26
+ tabbed_menu do
27
+ tab 'Home', :root # A tab with no children that links to root_path
28
+ tab 'Our products', products_path do # A tab with one child that links to products_path
29
+ child :controller => 'products', :action => 'show' # This tab will not only be active when we're at the index action (products_path)
30
+ end
31
+
32
+ tab 'About', :controller => 'about', :action => 'index' do # A tab with one child with two actions that links to AboutController#index
33
+ child :controller => 'about', :action => ['company', 'contact']
34
+ end
35
+ end
36
+ %>
37
+
38
+ The output will look like this if we're at the show action of ProductsController:
39
+
40
+ <ul id="menu">
41
+ <li><a href="/">Home</a></li>
42
+ <li class="active"><a href="/products">Our products</a></li>
43
+ <li><a href="/about">About</a></li>
44
+ </ul>
45
+
46
+ But if we were at the show action, the output would look like this:
47
+
48
+ <ul id="menu">
49
+ <li><a href="/">Home</a></li>
50
+ <li class="active">Our products</a></li>
51
+ <li><a href="/about">About</a>
52
+ </ul>
53
+
54
+ Keep in mind:
55
+
56
+ 1. A tab is active if we're at the URL of the tab it self or any of its children.
57
+ 2. You can use symbols (:root instead of root_path) or hashes to specify URLs both in tabs and their children.
58
+ 3. You can specify as many children for a tab as you want.
59
+ 4. You can use arrays to (for example) specify multiple actions that will activate a child.
60
+ 5. The link itself will be generated by the Rails helper link_to_unless_current.
61
+
62
+ == License
63
+
64
+ Copyright (c) 2009 David Knorr
65
+
66
+ Permission is hereby granted, free of charge, to any person obtaining
67
+ a copy of this software and associated documentation files (the
68
+ "Software"), to deal in the Software without restriction, including
69
+ without limitation the rights to use, copy, modify, merge, publish,
70
+ distribute, sublicense, and/or sell copies of the Software, and to
71
+ permit persons to whom the Software is furnished to do so, subject to
72
+ the following conditions:
73
+
74
+ The above copyright notice and this permission notice shall be
75
+ included in all copies or substantial portions of the Software.
76
+
77
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
78
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
79
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
80
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
81
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
82
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
83
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,14 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'echoe'
4
+
5
+ Echoe.new('simple_tabs', '0.1.0') do |p|
6
+ p.description = 'Super simple plugin/gem to easily add tabbed navigation to your Ruby on Rails application.'
7
+ p.url = 'http://github.com/rubyguy/simple_tabs'
8
+ p.author = 'David Knorr'
9
+ p.email = 'rubyguy@ymail.com'
10
+ p.ignore_pattern = ['tmp/*', 'script/*']
11
+ p.development_dependencies = []
12
+ end
13
+
14
+ Dir["#{File.dirname(__FILE__)}/tasks/*.rake"].sort.each { |ext| load ext }
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ require 'simple_tabs'
@@ -0,0 +1,78 @@
1
+ module SimpleTabs
2
+ def tabbed_menu
3
+ concat tag(:ul, :id => 'menu')
4
+ yield
5
+ concat('</ul>')
6
+ end
7
+
8
+ def tab(name, url)
9
+ @active = false
10
+ url = url_to_string(url)
11
+ if current_page? url
12
+ concat tag(:li, :class => 'active')
13
+ else
14
+ if block_given?
15
+ yield
16
+ if @active
17
+ concat tag(:li, :class => 'active')
18
+ else
19
+ concat tag(:li)
20
+ end
21
+ else
22
+ concat tag(:li)
23
+ end
24
+ end
25
+ concat link_to_unless_current name, url
26
+ concat '</li>'
27
+ end
28
+
29
+ def child(url)
30
+ return if @active
31
+ url = url_to_string(url) unless url.is_a?(Hash)
32
+ if url.all? { |value| value.is_a?(String) || value.is_a?(Symbol) }
33
+ if current_page?(url)
34
+ @active = true
35
+ end
36
+ else
37
+ if params_matches?(url)
38
+ @active = true
39
+ end
40
+ end
41
+ end
42
+
43
+ private
44
+
45
+ def url_to_string(url)
46
+ return url if url.is_a? String
47
+ return send("#{url}_path") if url.is_a? Symbol
48
+ return url_for(url) if url.is_a?(Hash) || url.is_a?(Array)
49
+ end
50
+
51
+ def params_matches?(url)
52
+ if url.all? { |key, value| params[key] == value.to_s && !value.is_a?(Array) }
53
+ return true
54
+ else
55
+ output = false
56
+ url.each do |key, value|
57
+ if (value.is_a?(String) || value.is_a?(Symbol)) && params[key] == value.to_s
58
+ output = true
59
+ elsif value.is_a?(Array)
60
+ matched = false
61
+ value.each do |acceptable_value|
62
+ if params[key] == acceptable_value.to_s
63
+ matched = true
64
+ end
65
+ end
66
+ output = false unless matched
67
+ else
68
+ output = false
69
+ end
70
+ end
71
+ return output
72
+ end
73
+ end
74
+ end
75
+
76
+ class ActionView::Base
77
+ include SimpleTabs
78
+ end
@@ -0,0 +1,31 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{simple_tabs}
5
+ s.version = "0.1.0"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["David Knorr"]
9
+ s.date = %q{2009-03-28}
10
+ s.description = %q{Super simple plugin/gem to easily add tabbed navigation to your Ruby on Rails application.}
11
+ s.email = %q{rubyguy@ymail.com}
12
+ s.extra_rdoc_files = ["lib/simple_tabs.rb", "README.rdoc"]
13
+ s.files = ["init.rb", "lib/simple_tabs.rb", "Rakefile", "README.rdoc", "Manifest", "simple_tabs.gemspec"]
14
+ s.has_rdoc = true
15
+ s.homepage = %q{http://github.com/rubyguy/simple_tabs}
16
+ s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Simple_tabs", "--main", "README.rdoc"]
17
+ s.require_paths = ["lib"]
18
+ s.rubyforge_project = %q{simple_tabs}
19
+ s.rubygems_version = %q{1.3.1}
20
+ s.summary = %q{Super simple plugin/gem to easily add tabbed navigation to your Ruby on Rails application.}
21
+
22
+ if s.respond_to? :specification_version then
23
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
24
+ s.specification_version = 2
25
+
26
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
27
+ else
28
+ end
29
+ else
30
+ end
31
+ end
metadata ADDED
@@ -0,0 +1,64 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rubyguy-simple_tabs
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - David Knorr
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-03-28 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: Super simple plugin/gem to easily add tabbed navigation to your Ruby on Rails application.
17
+ email: rubyguy@ymail.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - lib/simple_tabs.rb
24
+ - README.rdoc
25
+ files:
26
+ - init.rb
27
+ - lib/simple_tabs.rb
28
+ - Rakefile
29
+ - README.rdoc
30
+ - Manifest
31
+ - simple_tabs.gemspec
32
+ has_rdoc: true
33
+ homepage: http://github.com/rubyguy/simple_tabs
34
+ post_install_message:
35
+ rdoc_options:
36
+ - --line-numbers
37
+ - --inline-source
38
+ - --title
39
+ - Simple_tabs
40
+ - --main
41
+ - README.rdoc
42
+ require_paths:
43
+ - lib
44
+ required_ruby_version: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: "0"
49
+ version:
50
+ required_rubygems_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: "1.2"
55
+ version:
56
+ requirements: []
57
+
58
+ rubyforge_project: simple_tabs
59
+ rubygems_version: 1.2.0
60
+ signing_key:
61
+ specification_version: 2
62
+ summary: Super simple plugin/gem to easily add tabbed navigation to your Ruby on Rails application.
63
+ test_files: []
64
+