simple_navigation 1.4 → 1.4.1
Sign up to get free protection for your applications and to get access to all the features.
- data.tar.gz.sig +0 -0
- data/README.rdoc +1 -1
- data/Rakefile +1 -1
- data/lib/simple_navigation.rb +51 -48
- data/simple_navigation.gemspec +1 -1
- metadata +3 -2
- metadata.gz.sig +1 -1
data.tar.gz.sig
CHANGED
Binary file
|
data/README.rdoc
CHANGED
data/Rakefile
CHANGED
@@ -2,7 +2,7 @@ require 'rubygems'
|
|
2
2
|
require 'rake'
|
3
3
|
require 'echoe'
|
4
4
|
|
5
|
-
Echoe.new('simple_navigation', '1.4') do |e|
|
5
|
+
Echoe.new('simple_navigation', '1.4.1') do |e|
|
6
6
|
e.description = "Simple navigation menu gem for Ruby on Rails"
|
7
7
|
e.url = "http://github.com/mexpolk/simple_navigation"
|
8
8
|
e.author = "Ivan Torres"
|
data/lib/simple_navigation.rb
CHANGED
@@ -1,9 +1,11 @@
|
|
1
1
|
module SimpleNavigation
|
2
2
|
|
3
|
+
# Simple Navigation helper methods module
|
3
4
|
module Helper
|
4
5
|
|
5
6
|
attr_accessor :current_menu_id
|
6
7
|
|
8
|
+
# Renders simple navigation menu by key name
|
7
9
|
def simple_navigation(name)
|
8
10
|
|
9
11
|
# Load navigation hash
|
@@ -20,60 +22,57 @@ module SimpleNavigation
|
|
20
22
|
|
21
23
|
end # simple_navigation(name)
|
22
24
|
|
23
|
-
|
24
|
-
|
25
|
-
#
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
25
|
+
protected
|
26
|
+
|
27
|
+
# Render menu element
|
28
|
+
def render_menu(menu, options = {})
|
29
|
+
|
30
|
+
# Set default html attributes
|
31
|
+
html_attrs = { :id => menu[:id] }
|
32
|
+
html_attrs[:class] = menu[:class] if menu.has_key?(:class)
|
33
|
+
|
34
|
+
# Render submenus first so we can detect if current menu
|
35
|
+
# is between child menu's
|
36
|
+
menus = ''
|
37
|
+
menus = content_tag(:ul,
|
38
|
+
menu[:menus].map{ |child| render_menu(child, options) }) if menu.has_key?(:menus)
|
39
|
+
|
40
|
+
# Is this menu is the current?
|
41
|
+
if current_menu?(menu)
|
42
|
+
html_attrs[:class] << ' current'
|
43
|
+
self.current_menu_id = menu[:id]
|
44
|
+
# If any of the children menus is the current
|
45
|
+
# mark parent menu as current too
|
46
|
+
elsif self.current_menu_id
|
47
|
+
html_attrs[:class] << ' current' if
|
48
|
+
self.current_menu_id.to_s.match(/^#{menu[:id]}/)
|
49
|
+
end
|
44
50
|
|
45
|
-
|
46
|
-
|
47
|
-
render_menu_title(menu) + menus,
|
48
|
-
html_attrs)
|
51
|
+
# Render menu
|
52
|
+
content_tag(:li, render_menu_title(menu) + menus, html_attrs)
|
49
53
|
|
50
|
-
|
54
|
+
end # render_menu(menu)
|
51
55
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
else
|
61
|
-
if menu.has_key?(:title)
|
62
|
-
title = menu[:title]
|
56
|
+
# Renders the menu title
|
57
|
+
#
|
58
|
+
# * If menu hash has the title key it is used as the title for the menu being rendered
|
59
|
+
# * If menu hash +:title+ key is not present then it formats +:name+ key as titleized string
|
60
|
+
# * If menu hash +:title+ key is not present and i18n is turned on, then it will use +:name+ key as translation key
|
61
|
+
def render_menu_title(menu)
|
62
|
+
title = if menu.has_key?(:title)
|
63
|
+
menu[:title]
|
63
64
|
else
|
64
|
-
|
65
|
+
if menu[:options][:i18n]
|
66
|
+
t(menu[:translation], :default => menu[:name].to_s.titleize)
|
67
|
+
else
|
68
|
+
menu[:name].to_s.titleize
|
69
|
+
end
|
65
70
|
end
|
66
|
-
|
67
|
-
|
68
|
-
title = link_to(title, url_for(menu[:url]))
|
69
|
-
else
|
70
|
-
title = content_tag(:span, title)
|
71
|
-
end
|
72
|
-
title
|
73
|
-
end # render_menu_title(menu)
|
74
|
-
|
75
|
-
protected
|
71
|
+
link_to(title, (menu.has_key?(:url) ? url_for(menu[:url]) : "#" ))
|
72
|
+
end # render_menu_title(menu)
|
76
73
|
|
74
|
+
# Detects if the menu being rendered is the current
|
75
|
+
# (it also marks parent menus as current).
|
77
76
|
def current_menu?(menu)
|
78
77
|
return false unless menu.has_key?(:url)
|
79
78
|
current = (controller.params[:controller] == menu[:url][:controller].gsub(/^\//, "")) &&
|
@@ -96,6 +95,7 @@ module SimpleNavigation
|
|
96
95
|
|
97
96
|
end # Helper
|
98
97
|
|
98
|
+
# Simple Navigation configuration class
|
99
99
|
class Configuration
|
100
100
|
|
101
101
|
attr_accessor :navigation
|
@@ -110,6 +110,7 @@ module SimpleNavigation
|
|
110
110
|
builder.navigations.each { |tmp| self.navigation[tmp[:name]] = tmp }
|
111
111
|
end
|
112
112
|
|
113
|
+
# Simple Navigation configuration builder
|
113
114
|
class Builder
|
114
115
|
|
115
116
|
attr_accessor :navigations, :prefix
|
@@ -131,6 +132,7 @@ module SimpleNavigation
|
|
131
132
|
{ :navigations => navigations }
|
132
133
|
end
|
133
134
|
|
135
|
+
# Hash structure containing simple navigation menu configuration
|
134
136
|
class Navigation
|
135
137
|
|
136
138
|
attr_accessor :id, :menus, :name, :options, :translation
|
@@ -164,6 +166,7 @@ module SimpleNavigation
|
|
164
166
|
:options => self.options }
|
165
167
|
end
|
166
168
|
|
169
|
+
# Menu builder
|
167
170
|
class Menu
|
168
171
|
|
169
172
|
attr_accessor :id, :menus, :name, :options, :title, :translation, :url, :urls
|
data/simple_navigation.gemspec
CHANGED
metadata
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple_navigation
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 5
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 4
|
9
|
-
|
9
|
+
- 1
|
10
|
+
version: 1.4.1
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
13
|
- Ivan Torres
|
metadata.gz.sig
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
,��,�7F��P�o;�4�#Obfe��^��G���O �s�ଶnm��sÅR�٭���]��\ߌ��*��w���H�wO7.�jw�G�VG�A ���a��������V(w"���jf +���?�YΪA�`��>��1�_�;���Z���pv�5��*��f�KV�~f�ɮB2��=x�C-Ei*�0��!���ѲԠ
|