innetra-easy_navigation 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Manifest +5 -0
- data/README.rdoc +76 -0
- data/Rakefile +12 -0
- data/easy_navigation.gemspec +31 -0
- data/init.rb +3 -0
- data/lib/easy_navigation.rb +172 -0
- metadata +64 -0
data/Manifest
ADDED
data/README.rdoc
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
= Uniquify
|
2
|
+
|
3
|
+
Rails gem/plugin for generating a tabbed navigation for Rails.
|
4
|
+
|
5
|
+
== Requirements
|
6
|
+
|
7
|
+
This gem/plugin is intented to be used with Rails 2.2 as it uses i18n
|
8
|
+
|
9
|
+
== Install
|
10
|
+
|
11
|
+
gem install innetra-easy_navigation --source http://gems.github.com
|
12
|
+
|
13
|
+
== Usage
|
14
|
+
|
15
|
+
Once installed simply create config/initializers/easy_navigation.rb file like
|
16
|
+
this:
|
17
|
+
|
18
|
+
EasyNavigation::Builder.config do |map|
|
19
|
+
map.navigation :default, :separator => true do |navigation|
|
20
|
+
navigation.tab :home, :url => { :controller => "dashboard", :action => "index" } do |tab|
|
21
|
+
tab.menu :index, :url => { :controller => "dashboard", :action => "index" } do |menu|
|
22
|
+
menu.connect :except => "new" # if :controller not specified it asumes is the same from tab
|
23
|
+
end
|
24
|
+
end
|
25
|
+
navigation.tab :post, :url => { :controller => "posts", :action => "index" } do |tab|
|
26
|
+
tab.menu :index, :url => { :controller => "posts", :action => "index" } do |menu|
|
27
|
+
menu.connect :except => "new"
|
28
|
+
end
|
29
|
+
tab.menu :new, :url => { :controller => "posts", :action => "new" } do |menu|
|
30
|
+
menu.connect :only => "new"
|
31
|
+
end
|
32
|
+
tab.menu :rss, :url => { :controller => "post_rss", :action => "atom" } do |menu|
|
33
|
+
menu.connect :only => "show"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
For internationalization, edit your en.yml file lique this (NOT TESTED JET):
|
40
|
+
|
41
|
+
easy_navigation:
|
42
|
+
default:
|
43
|
+
home:
|
44
|
+
index: "Home"
|
45
|
+
|
46
|
+
|
47
|
+
As an example, to render you newly created menu called :default in your
|
48
|
+
layout/application.erb :
|
49
|
+
|
50
|
+
<% render_navigation :default %>
|
51
|
+
|
52
|
+
Pretty easy, right?
|
53
|
+
|
54
|
+
== License
|
55
|
+
|
56
|
+
Copyright (c) 2008 Ivan Torres, Innetra Consultancy Services, S.C.
|
57
|
+
|
58
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
59
|
+
a copy of this software and associated documentation files (the
|
60
|
+
"Software"), to deal in the Software without restriction, including
|
61
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
62
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
63
|
+
permit persons to whom the Software is furnished to do so, subject to
|
64
|
+
the following conditions:
|
65
|
+
|
66
|
+
The above copyright notice and this permission notice shall be
|
67
|
+
included in all copies or substantial portions of the Software.
|
68
|
+
|
69
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
70
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
71
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
72
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
73
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
74
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
75
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
76
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
require 'echoe'
|
4
|
+
|
5
|
+
Echoe.new('easy_navigation', '0.1.0') do |e|
|
6
|
+
e.description = "Easy navigation for ruby on rails 2.2 (i18n)"
|
7
|
+
e.url = "http://github.com/innetra/easy_navigation"
|
8
|
+
e.author = "Ivan Torres"
|
9
|
+
e.email = "mexpolk@gmail.com"
|
10
|
+
e.ignore_pattern = ["tmp/*", "script/*"]
|
11
|
+
e.development_dependencies = []
|
12
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{easy_navigation}
|
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 = ["Ivan Torres"]
|
9
|
+
s.date = %q{2008-12-18}
|
10
|
+
s.description = %q{Easy navigation for ruby on rails 2.2 (i18n)}
|
11
|
+
s.email = %q{mexpolk@gmail.com}
|
12
|
+
s.extra_rdoc_files = ["README.rdoc", "lib/easy_navigation.rb"]
|
13
|
+
s.files = ["Manifest", "README.rdoc", "Rakefile", "init.rb", "lib/easy_navigation.rb", "easy_navigation.gemspec"]
|
14
|
+
s.has_rdoc = true
|
15
|
+
s.homepage = %q{http://github.com/innetra/easy_navigation}
|
16
|
+
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Easy_navigation", "--main", "README.rdoc"]
|
17
|
+
s.require_paths = ["lib"]
|
18
|
+
s.rubyforge_project = %q{easy_navigation}
|
19
|
+
s.rubygems_version = %q{1.3.1}
|
20
|
+
s.summary = %q{Easy navigation for ruby on rails 2.2 (i18n)}
|
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
|
data/init.rb
ADDED
@@ -0,0 +1,172 @@
|
|
1
|
+
module EasyNavigation
|
2
|
+
|
3
|
+
module Helper
|
4
|
+
|
5
|
+
def render_navigation(name)
|
6
|
+
|
7
|
+
html = ""
|
8
|
+
class_name = ""
|
9
|
+
|
10
|
+
EasyNavigation::Builder.navigation[name][:tabs].each do |tab|
|
11
|
+
menus_html = ""
|
12
|
+
current_tab = false
|
13
|
+
tab[:menus].each do |menu|
|
14
|
+
class_name = "menu"
|
15
|
+
if current_menu?(menu)
|
16
|
+
class_name << " current"
|
17
|
+
current_tab = true
|
18
|
+
end
|
19
|
+
menus_html << content_tag("li", link_to(t(menu[:text]), menu[:url]),
|
20
|
+
:class => class_name, :id => menu[:name])
|
21
|
+
if EasyNavigation::Builder.navigation[name][:options][:separator]
|
22
|
+
menus_html << content_tag("li", "|", :class => "separator")
|
23
|
+
end
|
24
|
+
end
|
25
|
+
class_name = "tab"
|
26
|
+
class_name << " current" if current_tab
|
27
|
+
html << content_tag("li",
|
28
|
+
"#{link_to(t(tab[:text]), tab[:url])} #{content_tag("ul", menus_html)}",
|
29
|
+
:class => class_name, :id => tab[:name])
|
30
|
+
end
|
31
|
+
content_tag("ul", html, :id => "navigation")
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def current_menu?(menu)
|
37
|
+
current = controller.controller_name == menu[:url][:controller] &&
|
38
|
+
(controller.action_name == menu[:url][:action] || menu[:url][:action] == nil)
|
39
|
+
if menu.has_key?:on
|
40
|
+
(menu[:on].is_a?(Array) ? menu[:on] : [menu[:on]]).each do |controllers|
|
41
|
+
(controllers.is_a?(Array) ? controllers : [controllers]).each do |c|
|
42
|
+
current |= controller.controller_name == c[:controller]
|
43
|
+
if c.has_key?:only
|
44
|
+
current &= (c[:only].is_a?(Array) ? c[:only] : [c[:only]]).include?controller.action_name
|
45
|
+
end
|
46
|
+
if c.has_key?:except
|
47
|
+
current &= !((c[:except].is_a?(Array) ? c[:except] : [c[:except]]).include?controller.action_name)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
current
|
53
|
+
end
|
54
|
+
|
55
|
+
end # EasyNavigation::Helper
|
56
|
+
|
57
|
+
class Configuration
|
58
|
+
|
59
|
+
attr_accessor :navigation
|
60
|
+
|
61
|
+
def initialize
|
62
|
+
self.navigation = {}
|
63
|
+
end
|
64
|
+
|
65
|
+
def config(&block)
|
66
|
+
builder = Builder.new
|
67
|
+
yield builder
|
68
|
+
builder.navigations.each { |tmp|
|
69
|
+
self.navigation[tmp[:name]] = tmp
|
70
|
+
}
|
71
|
+
end
|
72
|
+
|
73
|
+
class Builder
|
74
|
+
|
75
|
+
attr_accessor :navigations
|
76
|
+
|
77
|
+
def initialize
|
78
|
+
self.navigations = []
|
79
|
+
end
|
80
|
+
|
81
|
+
def navigation(name, options = {}, &block)
|
82
|
+
navigation = Navigation.new(name, options.merge!(:prefix => "navigation"))
|
83
|
+
yield navigation
|
84
|
+
self.navigations << navigation.build
|
85
|
+
end
|
86
|
+
|
87
|
+
def build
|
88
|
+
{ :navigations => navigations }
|
89
|
+
end
|
90
|
+
|
91
|
+
class Navigation
|
92
|
+
|
93
|
+
attr_accessor :tabs, :name, :options, :prefix
|
94
|
+
|
95
|
+
def initialize(name, options = {})
|
96
|
+
self.tabs = []
|
97
|
+
self.name = name
|
98
|
+
self.options = options
|
99
|
+
self.prefix = options[:prefix]
|
100
|
+
end
|
101
|
+
|
102
|
+
def tab(name, options = {}, &block)
|
103
|
+
tab = Tab.new(name, options.merge!(:prefix => [self.prefix, self.name]))
|
104
|
+
yield tab
|
105
|
+
self.tabs << tab.build
|
106
|
+
end
|
107
|
+
|
108
|
+
def build
|
109
|
+
self.options[:separator] = false unless self.options.has_key?(:separator)
|
110
|
+
{ :name => self.name.to_sym, :tabs => self.tabs, :options => self.options }
|
111
|
+
end
|
112
|
+
|
113
|
+
class Tab
|
114
|
+
|
115
|
+
attr_accessor :menus, :name, :url, :options, :prefix
|
116
|
+
|
117
|
+
def initialize(name, options = {})
|
118
|
+
self.menus = []
|
119
|
+
self.name = name
|
120
|
+
self.url = options[:url]
|
121
|
+
self.options = options
|
122
|
+
self.prefix = options[:prefix]
|
123
|
+
end
|
124
|
+
|
125
|
+
def menu(name, options = {}, &block)
|
126
|
+
menu = Menu.new(name, options.merge!(:prefix => [self.prefix, self.name]))
|
127
|
+
yield menu
|
128
|
+
self.menus << menu.build
|
129
|
+
end
|
130
|
+
|
131
|
+
def build
|
132
|
+
{ :name => [self.prefix, self.name].join("_").to_sym,
|
133
|
+
:text => [self.prefix, self.name].join("."),
|
134
|
+
:url => self.url,
|
135
|
+
:options => self.options,
|
136
|
+
:menus => self.menus }
|
137
|
+
end
|
138
|
+
|
139
|
+
class Menu
|
140
|
+
|
141
|
+
attr_accessor :name, :url, :options, :active_urls, :prefix
|
142
|
+
|
143
|
+
def initialize(name, params = {})
|
144
|
+
self.active_urls = []
|
145
|
+
self.name = name
|
146
|
+
self.url = params[:url]
|
147
|
+
self.options = params
|
148
|
+
self.prefix = params[:prefix]
|
149
|
+
end
|
150
|
+
|
151
|
+
def build
|
152
|
+
self.prefix << self.name
|
153
|
+
{ :name => self.prefix.join("_").to_sym,
|
154
|
+
:text => self.prefix.join("."),
|
155
|
+
:url => self.url,
|
156
|
+
:on => self.active_urls }
|
157
|
+
end
|
158
|
+
|
159
|
+
def connect(options = {})
|
160
|
+
options[:controller] = self.options[:url][:controller] unless options.has_key?(:controller)
|
161
|
+
self.active_urls << options
|
162
|
+
end
|
163
|
+
|
164
|
+
end #Menu
|
165
|
+
end # Tab
|
166
|
+
end # Navigation
|
167
|
+
end # Builder
|
168
|
+
end # Configuration
|
169
|
+
|
170
|
+
Builder = Configuration.new
|
171
|
+
|
172
|
+
end# EasyNavigation
|
metadata
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: innetra-easy_navigation
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ivan Torres
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-12-18 00:00:00 -08:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: Easy navigation for ruby on rails 2.2 (i18n)
|
17
|
+
email: mexpolk@gmail.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- README.rdoc
|
24
|
+
- lib/easy_navigation.rb
|
25
|
+
files:
|
26
|
+
- Manifest
|
27
|
+
- README.rdoc
|
28
|
+
- Rakefile
|
29
|
+
- init.rb
|
30
|
+
- lib/easy_navigation.rb
|
31
|
+
- easy_navigation.gemspec
|
32
|
+
has_rdoc: true
|
33
|
+
homepage: http://github.com/innetra/easy_navigation
|
34
|
+
post_install_message:
|
35
|
+
rdoc_options:
|
36
|
+
- --line-numbers
|
37
|
+
- --inline-source
|
38
|
+
- --title
|
39
|
+
- Easy_navigation
|
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: easy_navigation
|
59
|
+
rubygems_version: 1.2.0
|
60
|
+
signing_key:
|
61
|
+
specification_version: 2
|
62
|
+
summary: Easy navigation for ruby on rails 2.2 (i18n)
|
63
|
+
test_files: []
|
64
|
+
|