simple_navigation 1.4.3 → 1.4.4

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/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.3') do |e|
5
+ Echoe.new('simple_navigation', '1.4.4') 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"
@@ -14,11 +14,27 @@ module SimpleNavigation
14
14
  # Reset current menu
15
15
  self.current_menu_id = nil
16
16
 
17
- html_attrs = { :id => navigation[:id], :class => 'simple_navigation' }
18
- html_attrs[:class] << " #{navigation[:class]}" if navigation.has_key?(:class)
17
+ options = {
18
+ :id => navigation[:id],
19
+ :class => 'simple_navigation'
20
+ }
21
+
22
+ # Set CSS class that user may added
23
+ if navigation.has_key?(:options) && navigation[:options].has_key?(:class)
24
+ options[:class] << " #{navigation[:options][:class]}"
25
+ end
19
26
 
20
27
  # Render root menus
21
- content_tag(:ul, navigation[:menus].map{ |menu| render_menu(menu) }, html_attrs)
28
+ if navigation.has_key?(:menus) && !navigation[:menus].empty?
29
+ menus = navigation[:menus].enum_with_index.collect do |item, index|
30
+ item_options = { :class => item[:options][:class].clone || '' }
31
+ item_options[:class] << ' first' if index == 0
32
+ item_options[:class] << ' last' if index == navigation[:menus].size - 1
33
+ render_menu(item, item_options)
34
+ end
35
+ end
36
+
37
+ content_tag(:ul, menus || '', options)
22
38
 
23
39
  end # simple_navigation(name)
24
40
 
@@ -28,28 +44,36 @@ module SimpleNavigation
28
44
  def render_menu(menu, options = {})
29
45
 
30
46
  # Set default html attributes
31
- html_attrs = { :id => menu[:id] }
32
- html_attrs[:class] = menu[:class] || ""
47
+ options[:id] = menu[:id]
33
48
 
34
- # Render submenus first so we can detect if current menu
49
+ # FIXME: Make the following code block DRY, by including it
50
+ # on render_menu method
51
+
52
+ # Render sub-menus first so we can detect if current menu
35
53
  # is between child menu's
36
54
  menus = ''
37
- menus = content_tag(:ul,
38
- menu[:menus].map{ |child| render_menu(child, options) }) if menu.has_key?(:menus)
55
+ if menu.has_key?(:menus) && !menu[:menus].empty?
56
+ menus = menu[:menus].enum_with_index.collect do |item, index|
57
+ item_options = { :class => item[:options][:class].clone || '' }
58
+ item_options[:class] << ' first' if index == 0
59
+ item_options[:class] << ' last' if index == menu[:menus].size - 1
60
+ render_menu(item, item_options)
61
+ end
62
+ menus = content_tag(:ul, menus)
63
+ end
39
64
 
40
65
  # Is this menu is the current?
41
66
  if current_menu?(menu)
42
- html_attrs[:class] << ' current'
67
+ options[:class] << ' current'
43
68
  self.current_menu_id = menu[:id]
44
69
  # If any of the children menus is the current
45
70
  # mark parent menu as current too
46
71
  elsif self.current_menu_id
47
- html_attrs[:class] << ' current' if
48
- self.current_menu_id.to_s.match(/^#{menu[:id]}/)
72
+ options[:class] << ' current' if self.current_menu_id.to_s.match(/^#{menu[:id]}/)
49
73
  end
50
74
 
51
75
  # Render menu
52
- content_tag(:li, render_menu_title(menu) + menus, html_attrs)
76
+ content_tag(:li, render_menu_title(menu) + menus, options)
53
77
 
54
78
  end # render_menu(menu)
55
79
 
@@ -68,7 +92,7 @@ module SimpleNavigation
68
92
  menu[:name].to_s.titleize
69
93
  end
70
94
  end
71
- link_to(title, (menu.has_key?(:url) ? url_for(menu[:url]) : "#" ))
95
+ link_to(content_tag(:span, title), (menu.has_key?(:url) ? url_for(menu[:url]) : "#" ))
72
96
  end # render_menu_title(menu)
73
97
 
74
98
  # Detects if the menu being rendered is the current
@@ -79,13 +103,13 @@ module SimpleNavigation
79
103
  (controller.params[:action] == menu[:url][:action])
80
104
  if menu.has_key?(:urls)
81
105
  (menu[:urls].is_a?(Array) ? menu[:urls] : [menu[:urls]]).each do |controllers|
82
- (controllers.is_a?(Array) ? controllers : [controllers]).each do |c|
83
- current |= controller.params[:controller] == c[:controller].gsub(/^\//, "")
84
- if c.has_key?(:only)
85
- current &= (c[:only].is_a?(Array) ? c[:only] : [c[:only]]).include?(controller.params[:action])
106
+ (controllers.is_a?(Array) ? controllers : [controllers]).each do |item|
107
+ current |= controller.params[:controller] == item[:controller].gsub(/^\//, "")
108
+ if item.has_key?(:only)
109
+ current &= (item[:only].is_a?(Array) ? item[:only] : [item[:only]]).include?(controller.params[:action])
86
110
  end
87
- if c.has_key?(:except)
88
- current &= !((c[:except].is_a?(Array) ? c[:except] : [c[:except]]).include?(controller.params[:action]))
111
+ if item.has_key?(:except)
112
+ current &= !((item[:except].is_a?(Array) ? item[:except] : [item[:except]]).include?(controller.params[:action]))
89
113
  end
90
114
  end
91
115
  end
@@ -153,6 +177,7 @@ module SimpleNavigation
153
177
  options.merge!(:i18n => self.options[:i18n])
154
178
  options.merge!(:translation => [self.translation, 'menus'].join('.'))
155
179
  options.merge!(:prefix => self.id)
180
+ options.merge!(:class => "") unless options.has_key?(:class)
156
181
  menu = Menu.new(name, title, options)
157
182
  yield menu if block
158
183
  self.menus << menu.build
@@ -191,6 +216,7 @@ module SimpleNavigation
191
216
  options.merge!(:i18n => self.options[:i18n])
192
217
  options.merge!(:translation => [self.translation, 'menus'].join('.'))
193
218
  options.merge!(:prefix => self.id)
219
+ options.merge!(:class => "") unless options.has_key?(:class)
194
220
  menu = Menu.new(name, title, options)
195
221
  yield menu if block
196
222
  self.menus << menu.build
@@ -2,12 +2,12 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{simple_navigation}
5
- s.version = "1.4.3"
5
+ s.version = "1.4.4"
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
9
  s.cert_chain = ["/Users/ivan/.ssh/gem-public_cert.pem"]
10
- s.date = %q{2010-09-23}
10
+ s.date = %q{2010-09-24}
11
11
  s.description = %q{Simple navigation menu gem for Ruby on Rails}
12
12
  s.email = %q{mexpolk@gmail.com}
13
13
  s.extra_rdoc_files = ["README.rdoc", "lib/simple_navigation.rb"]
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_navigation
3
3
  version: !ruby/object:Gem::Version
4
- hash: 1
4
+ hash: 15
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
8
  - 4
9
- - 3
10
- version: 1.4.3
9
+ - 4
10
+ version: 1.4.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Ivan Torres
@@ -36,7 +36,7 @@ cert_chain:
36
36
  MKLC1g==
37
37
  -----END CERTIFICATE-----
38
38
 
39
- date: 2010-09-23 00:00:00 -05:00
39
+ date: 2010-09-24 00:00:00 -05:00
40
40
  default_executable:
41
41
  dependencies: []
42
42
 
metadata.gz.sig CHANGED
Binary file