innetra-easy_navigation 2.0.0 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +100 -23
- data/Rakefile +1 -1
- data/easy_navigation.gemspec +4 -4
- data/lib/easy_navigation.rb +59 -54
- metadata +3 -3
data/README.rdoc
CHANGED
@@ -10,55 +10,133 @@ This gem/plugin is intented to be used with Rails 2.2 as it uses i18n
|
|
10
10
|
|
11
11
|
Add the following line to your /config/environment.rb file:
|
12
12
|
|
13
|
-
config.gem "innetra-easy_navigation",
|
14
|
-
:lib => "easy_navigation",
|
13
|
+
config.gem "innetra-easy_navigation",
|
14
|
+
:lib => "easy_navigation",
|
15
15
|
:source => "http://gems.github.com"
|
16
16
|
|
17
17
|
And from the command line run:
|
18
18
|
|
19
19
|
rake gems:install
|
20
20
|
|
21
|
+
===Install as a Plugin
|
22
|
+
|
23
|
+
If your rather prefer to install it as a plugin, from your application
|
24
|
+
directory simply run:
|
25
|
+
|
26
|
+
script/plugin install git://github.com/innetra/easy_navigation.git
|
27
|
+
|
28
|
+
And you're done!
|
29
|
+
|
21
30
|
== Usage
|
22
31
|
|
23
|
-
Once installed simply create config/initializers/easy_navigation.rb file like
|
32
|
+
Once installed simply create config/initializers/easy_navigation.rb file like
|
24
33
|
this:
|
25
34
|
|
26
35
|
EasyNavigation::Builder.config do |map|
|
27
|
-
map.navigation :default
|
28
|
-
navigation.tab :home, :url => { :controller => "dashboard", :action => "index"
|
29
|
-
tab.menu :index, :url => { :controller => "dashboard", :action => "index" } do |menu|
|
30
|
-
menu.connect :
|
36
|
+
map.navigation :default do |navigation|
|
37
|
+
navigation.tab :home, :url => { :controller => "/dashboard", :action => "index"} do |tab|
|
38
|
+
tab.menu :index, :url => { :controller => "/dashboard", :action => "index" } do |menu|
|
39
|
+
menu.connect :controller => "dashboard"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
navigation.tab :contacts, :url => { :controller => "/contacts", :action => "index" } do |tab|
|
43
|
+
tab.menu :index, :url => { :controller => "/contacts", :action => "index" } do |menu|
|
44
|
+
menu.connect :controller => "/contacts"
|
45
|
+
menu.connect :controller => "/contacts/people", :except => "new"
|
46
|
+
menu.connect :controller => "/contacts/companies", :except => "new"
|
31
47
|
end
|
32
|
-
tab.menu :
|
48
|
+
tab.menu :new_person, :url => { :controller => "/contacts/people", :action => "new" } do |menu|
|
49
|
+
menu.connect :only => "new"
|
50
|
+
end
|
51
|
+
tab.menu :new_company, :url => { :controller => "/contacts/companies", :action => "new" } do |menu|
|
33
52
|
menu.connect :only => "new"
|
34
53
|
end
|
35
54
|
end
|
55
|
+
navigation.tab :admin, :url => { :controller => "/admin/users", :action => "index" } do |tab|
|
56
|
+
tab.menu :index, :url => { :controller => "/admin/users", :action => "index" } do |menu|
|
57
|
+
menu.connect :except => "new"
|
58
|
+
end
|
59
|
+
tab.menu :new, :url => { :controller => "/admin/users", :action => "new" } do |menu|
|
60
|
+
menu.connect :only => "new"
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
As an example, to render you newly created menu called :default in your
|
67
|
+
"layout/application.erb":
|
68
|
+
|
69
|
+
<%= easy_navigation :default, options = {} %>
|
70
|
+
|
71
|
+
==Internationalization (i18n)
|
72
|
+
|
73
|
+
If you want to use internationalization, set the option :i18n => true like this:
|
74
|
+
|
75
|
+
EasyNavigation::Builder.config do |map|
|
76
|
+
map.navigation :default, :i18n => true do |navigation|
|
77
|
+
...
|
36
78
|
end
|
37
79
|
end
|
38
80
|
|
39
|
-
For internationalization, edit your "en-US.easy_navigation.yml" file
|
81
|
+
For internationalization, edit your "en-US.easy_navigation.yml" file like this:
|
40
82
|
|
41
83
|
en-US:
|
42
|
-
|
43
|
-
default:
|
44
|
-
home:
|
45
|
-
title: "Home"
|
84
|
+
navigation:
|
85
|
+
default: # The name of your navigation menu
|
86
|
+
home: # The name of your tab
|
87
|
+
title: "Home" # The title of your tab
|
46
88
|
menus:
|
47
|
-
index: "Dashboard"
|
48
|
-
new: "New Page"
|
49
|
-
|
89
|
+
index: "Dashboard" # The title for index action menu
|
90
|
+
new: "New Page" # The title for new action menu
|
50
91
|
|
51
|
-
As an example, to render you newly created menu called :default in your
|
52
|
-
"layout/application.erb":
|
53
92
|
|
54
|
-
|
93
|
+
===Helper Options
|
94
|
+
|
95
|
+
:i18n => Set to "true" to use i18n internationalization.
|
96
|
+
:navigation_class => Sets the class name for navigation menus (default: navigation).
|
97
|
+
:tab_class => Sets the class name for tabs (default: tab).
|
98
|
+
:menu_class => Sets the class name for menus (default: menu).
|
99
|
+
:separator_class => Sets the class name for separators (default: sparator).
|
100
|
+
:separator => Place a separator after each menu (default: false)
|
101
|
+
|
102
|
+
===Render Customization
|
103
|
+
|
104
|
+
You may wan't to change the way that the navigation menu gets rendered, if so
|
105
|
+
simply override the following methods (from EasyNavigation::Helper):
|
106
|
+
|
107
|
+
====Navigation Menus
|
108
|
+
|
109
|
+
def render_navigation(id, tabs_html, class_name)
|
110
|
+
content_tag("ul", tabs_html, :id => id, :class => class_name)
|
111
|
+
end
|
112
|
+
|
113
|
+
====Tabs
|
114
|
+
|
115
|
+
def render_tab(id, text, url, menus_html, class_name)
|
116
|
+
content_tag("li",
|
117
|
+
"#{link_to(t(text), url)} #{content_tag("ul", menus_html)}",
|
118
|
+
:id => id, :class => class_name)
|
119
|
+
end
|
120
|
+
|
121
|
+
====Menus
|
122
|
+
|
123
|
+
def render_menu(id, text, url, class_name)
|
124
|
+
content_tag("li", link_to(t(text), url), :id => id, :class => class_name)
|
125
|
+
end
|
126
|
+
|
127
|
+
====Separators
|
128
|
+
|
129
|
+
def render_separator(class_name)
|
130
|
+
content_tag("li", "|", :class => class_name)
|
131
|
+
end
|
132
|
+
|
55
133
|
|
56
134
|
Pretty easy... right?
|
57
135
|
|
58
136
|
== License
|
59
137
|
|
60
138
|
Copyright (c) 2008 Innetra Consultancy Services, S.C.
|
61
|
-
|
139
|
+
|
62
140
|
Permission is hereby granted, free of charge, to any person obtaining
|
63
141
|
a copy of this software and associated documentation files (the
|
64
142
|
"Software"), to deal in the Software without restriction, including
|
@@ -66,10 +144,10 @@ without limitation the rights to use, copy, modify, merge, publish,
|
|
66
144
|
distribute, sublicense, and/or sell copies of the Software, and to
|
67
145
|
permit persons to whom the Software is furnished to do so, subject to
|
68
146
|
the following conditions:
|
69
|
-
|
147
|
+
|
70
148
|
The above copyright notice and this permission notice shall be
|
71
149
|
included in all copies or substantial portions of the Software.
|
72
|
-
|
150
|
+
|
73
151
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
74
152
|
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
75
153
|
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
@@ -77,4 +155,3 @@ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
77
155
|
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
78
156
|
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
79
157
|
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
80
|
-
|
data/Rakefile
CHANGED
@@ -2,7 +2,7 @@ require 'rubygems'
|
|
2
2
|
require 'rake'
|
3
3
|
require 'echoe'
|
4
4
|
|
5
|
-
Echoe.new('easy_navigation', '2.
|
5
|
+
Echoe.new('easy_navigation', '2.1.0') do |e|
|
6
6
|
e.description = "Easy navigation for Ruby on Rails 2.2 (i18n)"
|
7
7
|
e.url = "http://github.com/innetra/easy_navigation"
|
8
8
|
e.author = "Ivan Torres"
|
data/easy_navigation.gemspec
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{easy_navigation}
|
5
|
-
s.version = "2.
|
5
|
+
s.version = "2.1.0"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Ivan Torres"]
|
9
|
-
s.date = %q{
|
9
|
+
s.date = %q{2009-04-25}
|
10
10
|
s.description = %q{Easy navigation for Ruby on Rails 2.2 (i18n)}
|
11
11
|
s.email = %q{mexpolk@gmail.com}
|
12
12
|
s.extra_rdoc_files = ["README.rdoc", "lib/easy_navigation.rb"]
|
@@ -16,12 +16,12 @@ Gem::Specification.new do |s|
|
|
16
16
|
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Easy_navigation", "--main", "README.rdoc"]
|
17
17
|
s.require_paths = ["lib"]
|
18
18
|
s.rubyforge_project = %q{easy_navigation}
|
19
|
-
s.rubygems_version = %q{1.3.
|
19
|
+
s.rubygems_version = %q{1.3.2}
|
20
20
|
s.summary = %q{Easy navigation for Ruby on Rails 2.2 (i18n)}
|
21
21
|
|
22
22
|
if s.respond_to? :specification_version then
|
23
23
|
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
24
|
-
s.specification_version =
|
24
|
+
s.specification_version = 3
|
25
25
|
|
26
26
|
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
27
27
|
else
|
data/lib/easy_navigation.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module EasyNavigation
|
2
2
|
|
3
3
|
module Helper
|
4
|
-
|
4
|
+
|
5
5
|
def easy_navigation(name, options = {})
|
6
6
|
|
7
7
|
navigation_class_name = (options[:navigation_class] || "navigation").to_s
|
@@ -11,7 +11,7 @@ module EasyNavigation
|
|
11
11
|
separator = options[:separator] || false
|
12
12
|
|
13
13
|
tabs_html = ""
|
14
|
-
|
14
|
+
|
15
15
|
EasyNavigation::Builder.navigation[name][:tabs].each do |tab|
|
16
16
|
menus_html = ""
|
17
17
|
current_tab = false
|
@@ -19,45 +19,45 @@ module EasyNavigation
|
|
19
19
|
if current = current_menu?(menu)
|
20
20
|
current_tab = true
|
21
21
|
end
|
22
|
-
menus_html << self.render_menu(menu[:name], menu[:text],
|
23
|
-
menu[:url].merge!(:skip_relative_url_root => true),
|
22
|
+
menus_html << self.render_menu(menu[:name], menu[:text],
|
23
|
+
menu[:url].merge!(:skip_relative_url_root => true),
|
24
24
|
("#{menu_class_name} current" if current) || menu_class_name)
|
25
25
|
if separator
|
26
26
|
menus_html << self.render_separator(separator_class_name)
|
27
27
|
end
|
28
28
|
end
|
29
|
-
tabs_html << self.render_tab(tab[:name],
|
30
|
-
tab[:text],
|
31
|
-
tab[:url].merge!(:skip_relative_url_root => true),
|
29
|
+
tabs_html << self.render_tab(tab[:name],
|
30
|
+
tab[:text],
|
31
|
+
tab[:url].merge!(:skip_relative_url_root => true),
|
32
32
|
menus_html, ("#{tab_class_name} current" if current_tab) || tab_class_name)
|
33
33
|
end
|
34
34
|
self.render_navigation("navigation_" << name.to_s, tabs_html, navigation_class_name)
|
35
35
|
end
|
36
|
-
|
36
|
+
|
37
37
|
protected
|
38
|
-
|
38
|
+
|
39
39
|
def render_separator(class_name)
|
40
40
|
content_tag("li", "|", :class => class_name)
|
41
41
|
end
|
42
|
-
|
42
|
+
|
43
43
|
def render_menu(id, text, url, class_name)
|
44
|
-
content_tag("li", link_to(
|
44
|
+
content_tag("li", link_to(text, url), :id => id, :class => class_name)
|
45
45
|
end
|
46
|
-
|
46
|
+
|
47
47
|
def render_tab(id, text, url, menus_html, class_name)
|
48
48
|
content_tag("li",
|
49
|
-
"#{link_to(
|
49
|
+
"#{link_to(text, url)} #{content_tag("ul", menus_html)}",
|
50
50
|
:id => id, :class => class_name)
|
51
51
|
end
|
52
|
-
|
52
|
+
|
53
53
|
def render_navigation(id, tabs_html, class_name)
|
54
54
|
content_tag("ul", tabs_html, :id => id, :class => class_name)
|
55
55
|
end
|
56
|
-
|
56
|
+
|
57
57
|
def current_menu?(menu)
|
58
|
-
current = controller.params[:controller] == menu[:url][:controller].gsub(/^\//, "") &&
|
58
|
+
current = controller.params[:controller] == menu[:url][:controller].gsub(/^\//, "") &&
|
59
59
|
(controller.action_name == menu[:url][:action] || menu[:url][:action] == nil)
|
60
|
-
if menu.has_key?:on
|
60
|
+
if menu.has_key?:on
|
61
61
|
(menu[:on].is_a?(Array) ? menu[:on] : [menu[:on]]).each do |controllers|
|
62
62
|
(controllers.is_a?(Array) ? controllers : [controllers]).each do |c|
|
63
63
|
current |= controller.params[:controller] == c[:controller].gsub(/^\//, "")
|
@@ -68,7 +68,7 @@ module EasyNavigation
|
|
68
68
|
current &= !((c[:except].is_a?(Array) ? c[:except] : [c[:except]]).include?controller.action_name)
|
69
69
|
end
|
70
70
|
end
|
71
|
-
end
|
71
|
+
end
|
72
72
|
end
|
73
73
|
current
|
74
74
|
end
|
@@ -78,100 +78,105 @@ module EasyNavigation
|
|
78
78
|
class Configuration
|
79
79
|
|
80
80
|
attr_accessor :navigation
|
81
|
-
|
81
|
+
|
82
82
|
def initialize
|
83
83
|
self.navigation = {}
|
84
84
|
end
|
85
|
-
|
85
|
+
|
86
86
|
def config(&block)
|
87
87
|
builder = Builder.new
|
88
88
|
yield builder
|
89
|
-
builder.navigations.each { |tmp|
|
89
|
+
builder.navigations.each { |tmp|
|
90
90
|
self.navigation[tmp[:name]] = tmp
|
91
91
|
}
|
92
92
|
end
|
93
|
-
|
93
|
+
|
94
94
|
class Builder
|
95
|
-
|
95
|
+
|
96
96
|
attr_accessor :navigations
|
97
|
-
|
97
|
+
|
98
98
|
def initialize
|
99
99
|
self.navigations = []
|
100
100
|
end
|
101
|
-
|
101
|
+
|
102
102
|
def navigation(name, options = {}, &block)
|
103
103
|
navigation = Navigation.new(name, options.merge!(:prefix => "navigation"))
|
104
104
|
yield navigation
|
105
105
|
self.navigations << navigation.build
|
106
106
|
end
|
107
|
-
|
107
|
+
|
108
108
|
def build
|
109
109
|
{ :navigations => navigations }
|
110
110
|
end
|
111
|
-
|
111
|
+
|
112
112
|
class Navigation
|
113
|
-
|
113
|
+
|
114
114
|
attr_accessor :tabs, :name, :options
|
115
|
-
|
115
|
+
|
116
116
|
def initialize(name, options = {})
|
117
117
|
self.tabs = []
|
118
118
|
self.name = name
|
119
119
|
self.options = options
|
120
120
|
end
|
121
|
-
|
121
|
+
|
122
122
|
def tab(name, options = {}, &block)
|
123
|
+
options.merge!(self.options)
|
123
124
|
tab = Tab.new(name, options.merge!(:prefix => [self.options[:prefix], self.name]))
|
124
125
|
yield tab
|
125
126
|
self.tabs << tab.build
|
126
127
|
end
|
127
|
-
|
128
|
+
|
128
129
|
def build
|
129
130
|
self.options[:separator] = false unless self.options.has_key?(:separator)
|
130
131
|
{ :name => self.name.to_sym, :tabs => self.tabs, :options => self.options }
|
131
132
|
end
|
132
|
-
|
133
|
+
|
133
134
|
class Tab
|
134
|
-
|
135
|
-
attr_accessor :menus, :name, :options
|
136
|
-
|
135
|
+
|
136
|
+
attr_accessor :menus, :name, :options, :text
|
137
|
+
|
137
138
|
def initialize(name, options = {})
|
138
139
|
self.menus = []
|
139
140
|
self.name = name
|
140
141
|
self.options = options
|
142
|
+
self.text = name.to_s.gsub(/_/, " ").gsub(/\b('?[a-z])/) { $1.capitalize }
|
143
|
+
self.text = I18n.t([self.options[:prefix], self.name, "title"].join(".")) if self.options[:i18n] == true
|
141
144
|
end
|
142
|
-
|
145
|
+
|
143
146
|
def menu(name, options = {}, &block)
|
147
|
+
options.merge!(self.options)
|
144
148
|
menu = Menu.new(name, options.merge!(:prefix => [self.options[:prefix], self.name, "menus"]))
|
145
149
|
yield menu
|
146
150
|
self.menus << menu.build
|
147
151
|
end
|
148
|
-
|
152
|
+
|
149
153
|
def build
|
150
|
-
{ :name => [self.options[:prefix], self.name].join("_").to_sym,
|
151
|
-
:text =>
|
154
|
+
{ :name => [self.options[:prefix], self.name].join("_").to_sym,
|
155
|
+
:text => self.text,
|
152
156
|
:url => self.options[:url],
|
153
|
-
:options => self.options,
|
157
|
+
:options => self.options,
|
154
158
|
:menus => self.menus }
|
155
159
|
end
|
156
|
-
|
160
|
+
|
157
161
|
class Menu
|
158
|
-
|
159
|
-
attr_accessor :name, :options, :
|
160
|
-
|
161
|
-
def initialize(name,
|
162
|
+
|
163
|
+
attr_accessor :active_urls, :name, :options, :text
|
164
|
+
|
165
|
+
def initialize(name, options = {})
|
162
166
|
self.active_urls = []
|
163
167
|
self.name = name
|
164
|
-
self.options =
|
168
|
+
self.options = options
|
169
|
+
self.text = self.name.to_s.gsub(/_/, " ").gsub(/\b('?[a-z])/) { $1.capitalize }
|
170
|
+
self.text = I18n.t([self.options[:prefix], self.name, "title"].join(".")) if self.options[:i18n] == true
|
165
171
|
end
|
166
|
-
|
172
|
+
|
167
173
|
def build
|
168
|
-
self.options[:prefix]
|
169
|
-
|
170
|
-
:
|
171
|
-
:url => self.options[:url],
|
174
|
+
{ :name => self.options[:prefix].join("_").to_sym,
|
175
|
+
:text => text,
|
176
|
+
:url => self.options[:url],
|
172
177
|
:on => self.active_urls }
|
173
178
|
end
|
174
|
-
|
179
|
+
|
175
180
|
def connect(options = {})
|
176
181
|
options[:controller] = self.options[:url][:controller] unless options.has_key?(:controller)
|
177
182
|
self.active_urls << options
|
@@ -182,9 +187,9 @@ module EasyNavigation
|
|
182
187
|
end # Navigation
|
183
188
|
end # Builder
|
184
189
|
end # Configuration
|
185
|
-
|
190
|
+
|
186
191
|
Builder = Configuration.new
|
187
|
-
|
192
|
+
|
188
193
|
end # EasyNavigation
|
189
194
|
|
190
195
|
ActionView::Base.send :include, EasyNavigation::Helper
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: innetra-easy_navigation
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ivan Torres
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date:
|
12
|
+
date: 2009-04-25 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -58,7 +58,7 @@ requirements: []
|
|
58
58
|
rubyforge_project: easy_navigation
|
59
59
|
rubygems_version: 1.2.0
|
60
60
|
signing_key:
|
61
|
-
specification_version:
|
61
|
+
specification_version: 3
|
62
62
|
summary: Easy navigation for Ruby on Rails 2.2 (i18n)
|
63
63
|
test_files: []
|
64
64
|
|