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 CHANGED
Binary file
data/README.rdoc CHANGED
@@ -76,7 +76,7 @@ this:
76
76
  end
77
77
 
78
78
  To render you newly created menu called :default, in your default layout
79
- (layout/application.erb):
79
+ (layout/application.html.erb):
80
80
 
81
81
  <%= simple_navigation :default %>
82
82
 
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"
@@ -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
- def render_menu(menu, options = {})
24
-
25
- # Set default html attributes
26
- html_attrs = { :id => menu[:id] }
27
- html_attrs[:class] = menu[:class] if menu.has_key?(:class)
28
-
29
- # Render submenus first so we can detect if current menu
30
- # is between child menu's
31
- menus = ''
32
- menus = content_tag(:ul,
33
- menu[:menus].map{ |child| render_menu(child, options) }) if menu.has_key?(:menus)
34
-
35
- # Is this menu is the current?
36
- if current_menu?(menu)
37
- html_attrs[:class] << ' current'
38
- self.current_menu_id = menu[:id]
39
- # Is the current menu under this menu?
40
- elsif self.current_menu_id
41
- html_attrs[:class] << ' current' if
42
- self.current_menu_id.to_s.match(/^#{menu[:id]}/)
43
- end
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
- # Render menu
46
- content_tag(:li,
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
- end # render_menu(menu)
54
+ end # render_menu(menu)
51
55
 
52
- def render_menu_title(menu)
53
- title = ''
54
- if menu[:options][:i18n]
55
- if menu.has_key?(:title)
56
- title = t(menu[:translation], :default => menu[:title])
57
- else
58
- title = t(menu[:translation], :default => menu[:name].to_s.titleize)
59
- end
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
- title = menu[:name].to_s.titleize
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
- end
67
- if menu.has_key?(:url)
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
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{simple_navigation}
5
- s.version = "1.4"
5
+ s.version = "1.4.1"
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"]
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: 7
4
+ hash: 5
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
8
  - 4
9
- version: "1.4"
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
- t0�K���8��'4�4��k>��Q��j�οl���Y�wz��&����^Lln��5w�;�%UB͈%�Aݯ$�A� qT��~�봶���"�i�U~��&.��0�Px<e�n��RX�h{�b��� ��(2�&Z����
1
+ ,��,�7F��P�o;�4�#Obfe��^��G���O s�ଶnm��sÅR�٭���]��\ߌ��*��w���HwO7.�j w�G�VG�A ���a��������V(w"���jf +���?�YΪA�`��>��1�_�;���Z���pv5 ��*��f�KV�~f�ɮB2�� =x�C-Ei*�0��!���ѲԠ