menu_helper 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.rdoc CHANGED
@@ -1,5 +1,10 @@
1
1
  == master
2
2
 
3
+ == 0.3.0 / 2009-04-18
4
+
5
+ * Add ui-state-active and level-specific menu css classes
6
+ * Change class css naming conventions to follow the new jQuery UI guidelines
7
+
3
8
  == 0.2.0 / 2008-12-14
4
9
 
5
10
  * Remove the PluginAWeek namespace
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2006-2008 Aaron Pfeifer
1
+ Copyright (c) 2006-2009 Aaron Pfeifer
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.rdoc CHANGED
@@ -62,18 +62,18 @@ _menu_bar.html.erb:
62
62
  %>
63
63
 
64
64
  Output (formatted for sanity):
65
- <ul class="menubar menubar-1">
66
- <li><a href="http://example.com/"><span>Home</span></a></li>
67
- <li><a href="http://example.com/products"><span>Products</span></a></li>
68
- <li><a href="http://example.com/services"><span>Services</span></a></li>
69
- <li class="menubar-selected"><a href="http://example.com/about_us"><span>About Us</span></a>
70
- <ul class="menubar menubar-2 menubar-selected">
71
- <li><a href="http://example.com/about_us"><span>Overview</span></a></li>
72
- <li class="menubar-selected"><a href="http://example.com/about_us/who_we_are"><span>Who We Are</span></a></li>
73
- <li class="menubar-last"><a href="http://example.com/about_us/contact"><span>Contact Us</span></a></li>
65
+ <ul class="ui-menubar ui-menubar-1">
66
+ <li class="ui-menubar-menu ui-menubar-menu-1"><a href="http://example.com/"><span>Home</span></a></li>
67
+ <li class="ui-menubar-menu ui-menubar-menu-1"><a href="http://example.com/products"><span>Products</span></a></li>
68
+ <li class="ui-menubar-menu ui-menubar-menu-1"><a href="http://example.com/services"><span>Services</span></a></li>
69
+ <li class="ui-menubar-menu ui-menubar-menu-1 ui-state-active ui-menubar-selected"><a href="http://example.com/about_us"><span>About Us</span></a>
70
+ <ul class="ui-menubar ui-menubar-2 ui-state-active ui-menubar-selected">
71
+ <li class="ui-menubar-menu ui-menubar-menu-2"><a href="http://example.com/about_us"><span>Overview</span></a></li>
72
+ <li class="ui-menubar-menu ui-menubar-menu-2 ui-state-active ui-menubar-selected"><a href="http://example.com/about_us/who_we_are"><span>Who We Are</span></a></li>
73
+ <li class="ui-menubar-menu ui-menubar-menu-2 ui-menubar-last"><a href="http://example.com/about_us/contact"><span>Contact Us</span></a></li>
74
74
  </ul>
75
75
  </li>
76
- <li class="ir menubar-last"><a href="http://www.google.com"><span>Search!</span></a></li>
76
+ <li class="ir ui-menubar-menu ui-menubar-menu-1 ui-menubar-last"><a href="http://www.google.com"><span>Search!</span></a></li>
77
77
  </ul>
78
78
 
79
79
  === Caveat Emptor
data/Rakefile CHANGED
@@ -5,7 +5,7 @@ require 'rake/contrib/sshpublisher'
5
5
 
6
6
  spec = Gem::Specification.new do |s|
7
7
  s.name = 'menu_helper'
8
- s.version = '0.2.0'
8
+ s.version = '0.3.0'
9
9
  s.platform = Gem::Platform::RUBY
10
10
  s.summary = 'Adds a helper method for generating a menubar'
11
11
 
data/lib/menu_helper.rb CHANGED
@@ -10,9 +10,13 @@ module MenuHelper
10
10
  # optional.
11
11
  #
12
12
  # Configuration options:
13
- # * +auto_set_ids+ - Whether or not to automatically add ids to each menu/menu bar. Default is true.
14
- # * +attach_active_submenus+ - Whether any active sub-menu bar should be rendered as part of its parent menu. Default is true.
15
- # * +content_for+ - The base block name to use when detaching active submenus. Default is "menu_bar". For example, this will render sub-menu bars to menu_bar_level_2
13
+ # * <tt>:auto_set_ids</tt> - Whether or not to automatically add ids to each
14
+ # menu/menu bar. Default is true.
15
+ # * <tt>:attach_active_submenus</tt> - Whether any active sub-menu bar should
16
+ # be rendered as part of its parent menu. Default is true.
17
+ # * <tt>:content_for</tt> - The base block name to use when detaching active
18
+ # submenus. Default is "menu_bar". For example, this will render
19
+ # sub-menu bars to menu_bar_level_2.
16
20
  #
17
21
  # == Examples
18
22
  #
@@ -28,13 +32,13 @@ module MenuHelper
28
32
  #
29
33
  # ...generates the following html if +about_us+ is selected...
30
34
  #
31
- # <ul id="nav" class="pretty menubar menubar-1">
32
- # <li id="nav-home"><a href="/"><span>Home</span></a></li>
33
- # <li id="nav-about_us" class="menubar-selected"><a href="/about_us"><span>About Us</span></a>
34
- # <ul class="menubar menubar-2" class="menubar-selected">
35
- # <li id="nav-about_us-who_we_are"><a href="/about_us/who_we_are"><span>Who We Are</span></a></li>
36
- # <li id="nav-about_us-what_we_do"><a href="/about_us/what_we_do"><span>What We Do</span></a></li>
37
- # <li id="nav-about_us-contact"><a href="mailto:contact@us.com"><span>Contact</span></a></li>
35
+ # <ul id="nav" class="pretty ui-menubar ui-menubar-1">
36
+ # <li id="nav-home" class="ui-menubar-menu ui-menubar-menu-1"><a href="/"><span>Home</span></a></li>
37
+ # <li id="nav-about_us" class="ui-menubar-menu ui-menubar-menu-1 ui-state-active ui-menubar-selected"><a href="/about_us"><span>About Us</span></a>
38
+ # <ul class="ui-menubar ui-menubar-2 ui-state-active ui-menubar-selected">
39
+ # <li id="nav-about_us-who_we_are" class="ui-menubar-menu ui-menubar-menu-2"><a href="/about_us/who_we_are"><span>Who We Are</span></a></li>
40
+ # <li id="nav-about_us-what_we_do" class="ui-menubar-menu ui-menubar-menu-2"><a href="/about_us/what_we_do"><span>What We Do</span></a></li>
41
+ # <li id="nav-about_us-contact" class="ui-menubar-menu ui-menubar-menu-2"><a href="mailto:contact@us.com"><span>Contact</span></a></li>
38
42
  # </ul>
39
43
  # </li>
40
44
  # </ul>
@@ -57,16 +61,16 @@ module MenuHelper
57
61
  #
58
62
  # ...generates the following html if +about_us+ is selected...
59
63
  #
60
- # <ul id="nav" class="menubar menubar-1">
61
- # <li id="nav-home"><a href="/"><span>Home</span></a></li>
62
- # <li id="nav-about_us" class="menubar-selected"><a href="/about_us"><span>About Us</span></a></li>
64
+ # <ul id="nav" class="ui-menubar ui-menubar-1">
65
+ # <li id="nav-home" class="ui-menubar-menu ui-menubar-menu-1"><a href="/"><span>Home</span></a></li>
66
+ # <li id="nav-about_us" class="ui-menubar-menu ui-menubar-menu-1 ui-state-active ui-menubar-selected"><a href="/about_us"><span>About Us</span></a></li>
63
67
  # </ul>
64
68
  #
65
69
  # <div id="subnav">
66
- # <ul class="menubar menubar-2 menubar-selected">
67
- # <li id="nav-about_us-who_we_are"><a href="/about_us/who_we_are"><span>Who We Are</span></a></li>
68
- # <li id="nav-about_us-what_we_do"><a href="/about_us/what_we_do"><span>What We Do</span></a></li>
69
- # <li id="nav-about_us-contact"><a href="mailto:contact@us.com"><span>Contact</span></a></li>
70
+ # <ul class="ui-menubar ui-menubar-2 ui-state-active ui-menubar-selected">
71
+ # <li id="nav-about_us-who_we_are" class="ui-menubar-menu ui-menubar-menu-2"><a href="/about_us/who_we_are"><span>Who We Are</span></a></li>
72
+ # <li id="nav-about_us-what_we_do" class="ui-menubar-menu ui-menubar-menu-2"><a href="/about_us/what_we_do"><span>What We Do</span></a></li>
73
+ # <li id="nav-about_us-contact" class="ui-menubar-menu ui-menubar-menu-2"><a href="mailto:contact@us.com"><span>Contact</span></a></li>
70
74
  # </ul>
71
75
  # </div>
72
76
  #
@@ -87,13 +91,13 @@ module MenuHelper
87
91
  # For example, if a sub-menu like +who_we_are+ is selected, the html
88
92
  # generated from the above full example would look like so:
89
93
  #
90
- # <ul id="nav" class="pretty menubar menubar-1">
91
- # <li id="nav-home"><a href="/"><span>Home</span></a></li>
92
- # <li id="nav-about_us" class="menubar-selected"><span>About Us</span>
94
+ # <ul id="nav" class="pretty ui-menubar ui-menubar-1">
95
+ # <li id="nav-home" class="ui-menubar-menu ui-menubar-menu-1"><a href="/"><span>Home</span></a></li>
96
+ # <li id="nav-about_us" class="ui-menubar-menu ui-menubar-menu-1 ui-state-active ui-menubar-selected"><span>About Us</span>
93
97
  # <ul class="menubar menubar-2 menubar-selected">
94
- # <li id="nav-about_us-who_we_are" class="menubar-selected"><a href="/about_us/who_we_are"><span>Who We Are</span></a></li>
95
- # <li id="nav-about_us-what_we_do"><a href="/about_us/what_we_do"><span>What We Do</span></a></li>
96
- # <li id="nav-about_us-contact"><a href="mailto:contact@us.com"><span>Contact</span></a></li>
98
+ # <li id="nav-about_us-who_we_are" class="ui-menubar-menu ui-menubar-menu-2 ui-state-active ui-menubar-selected"><a href="/about_us/who_we_are"><span>Who We Are</span></a></li>
99
+ # <li id="nav-about_us-what_we_do" class="ui-menubar-menu ui-menubar-menu-2"><a href="/about_us/what_we_do"><span>What We Do</span></a></li>
100
+ # <li id="nav-about_us-contact" class="ui-menubar-menu ui-menubar-menu-2"><a href="mailto:contact@us.com"><span>Contact</span></a></li>
97
101
  # </ul>
98
102
  # </li>
99
103
  # </ul>
@@ -17,9 +17,7 @@ module MenuHelper
17
17
  class HtmlElement
18
18
  include ActionView::Helpers::TagHelper
19
19
 
20
- delegate :[],
21
- :[]=,
22
- :to => '@html_options'
20
+ delegate :[], :[]=, :to => '@html_options'
23
21
 
24
22
  def initialize(html_options = {}) #:nodoc:
25
23
  @html_options = html_options.symbolize_keys
@@ -3,13 +3,17 @@ module MenuHelper
3
3
  class Menu < HtmlElement
4
4
  include ActionView::Helpers::UrlHelper
5
5
 
6
+ # The css class to apply for each menu
7
+ cattr_accessor :menu_class
8
+ @@menu_class = 'ui-menubar-menu'
9
+
6
10
  # The css class to apply when a menu is selected
7
11
  cattr_accessor :selected_class
8
- @@selected_class = 'menubar-selected'
12
+ @@selected_class = 'ui-state-active ui-menubar-selected'
9
13
 
10
14
  # The css class for the last menu in the menu bar
11
15
  cattr_accessor :last_class
12
- @@last_class = 'menubar-last'
16
+ @@last_class = 'ui-menubar-last'
13
17
 
14
18
  # The unique name assigned to this menu
15
19
  attr_reader :name
@@ -22,15 +26,12 @@ module MenuHelper
22
26
  attr_reader :parent_menu_bar
23
27
 
24
28
  # Add shortcuts to the menu bar configuration
25
- delegate :request_controller,
26
- :parent_menu,
27
- :auto_set_ids?,
29
+ delegate :request_controller, :parent_menu, :level, :auto_set_ids?,
28
30
  :attach_active_submenus?,
29
31
  :to => :parent_menu_bar
30
32
 
31
33
  # Add ability to add menus *after* creation
32
- delegate :menu,
33
- :to => '@menu_bar'
34
+ delegate :menu, :to => '@menu_bar'
34
35
 
35
36
  def initialize(parent_menu_bar, name, content = nil, url_options = {}, html_options = {}) #:nodoc
36
37
  # Allow the content parameter to be skipped
@@ -59,6 +60,7 @@ module MenuHelper
59
60
  # Set up default html options
60
61
  id_prefix = parent_menu_bar[:id] || parent_menu && parent_menu[:id]
61
62
  self[:id] ||= "#{id_prefix}-#{@name}" if auto_set_ids? && id_prefix
63
+ self[:class] = "#{self[:class]} #{menu_class} #{menu_class}-#{level}".strip
62
64
 
63
65
  # Create the menu bar for sub-menus in case any are generated. Use the
64
66
  # same configuration as the parent menu bar.
@@ -4,11 +4,11 @@ module MenuHelper
4
4
  class MenuBar < HtmlElement
5
5
  # The css class to apply for all menu bars
6
6
  cattr_accessor :menu_bar_class
7
- @@menu_bar_class = 'menubar'
7
+ @@menu_bar_class = 'ui-menubar'
8
8
 
9
9
  # The css class to apply when a sub-menu bar is selected
10
10
  cattr_accessor :selected_class
11
- @@selected_class = 'menubar-selected'
11
+ @@selected_class = 'ui-state-active ui-menubar-selected'
12
12
 
13
13
  # The request context in which this menu bar is being rendered
14
14
  attr_reader :request_controller
@@ -159,10 +159,10 @@ module MenuHelper
159
159
  # version of the menu's id. Examples of menus which customize the
160
160
  # content and/or html attributes are below:
161
161
  #
162
- # home.menu :contact # => <li id="contact"><a href="/contact">Contact</a></li>
163
- # home.menu :contact, 'Contact Us' # => <li id="contact"><a href="/contact">Contact Us</a></li>
164
- # home.menu :contact, {}, :class => 'pretty' # => <li id="contact" class="pretty"><a href="/contact">Contact</a></li>
165
- # home.menu :contact, 'Get in touch!', {}, :class => 'pretty' # => <li id="contact" class="pretty"><a href="/contact">Contact Us</a></li>
162
+ # home.menu :contact # => <li id="contact" class="ui-menubar-menu ui-menubar-menu-1"><a href="/contact">Contact</a></li>
163
+ # home.menu :contact, 'Contact Us' # => <li id="contact" class="ui-menubar-menu ui-menubar-menu-1"><a href="/contact">Contact Us</a></li>
164
+ # home.menu :contact, {}, :class => 'pretty' # => <li id="contact" class="pretty ui-menubar-menu ui-menubar-menu-1"><a href="/contact">Contact</a></li>
165
+ # home.menu :contact, 'Get in touch!', {}, :class => 'pretty' # => <li id="contact" class="pretty ui-menubar-menu ui-menubar-menu-1"><a href="/contact">Get in touch!</a></li>
166
166
  #
167
167
  # == Sub-menus
168
168
  #
@@ -14,15 +14,15 @@ class MenuHelperTest < ActionView::TestCase
14
14
  end
15
15
 
16
16
  expected = <<-eos
17
- <ul class="pretty menubar menubar-1">
18
- <li><a href="http://test.host/home"><span>Home</span></a>
19
- <ul class="menubar menubar-2">
20
- <li><a href="http://test.host/home/browse"><span>Browse</span></a></li>
21
- <li class="menubar-last"><a href="http://test.host/home/search"><span>Search</span></a></li>
17
+ <ul class="pretty ui-menubar ui-menubar-1">
18
+ <li class="ui-menubar-menu ui-menubar-menu-1"><a href="http://test.host/home"><span>Home</span></a>
19
+ <ul class="ui-menubar ui-menubar-2">
20
+ <li class="ui-menubar-menu ui-menubar-menu-2"><a href="http://test.host/home/browse"><span>Browse</span></a></li>
21
+ <li class="ui-menubar-menu ui-menubar-menu-2 ui-menubar-last"><a href="http://test.host/home/search"><span>Search</span></a></li>
22
22
  </ul>
23
23
  </li>
24
- <li class="menubar-selected"><a href="http://test.host/contact"><span>Contact Us</span></a></li>
25
- <li class="menubar-last"><a href="http://test.host/about_us"><span>About Us</span></a></li>
24
+ <li class="ui-menubar-menu ui-menubar-menu-1 ui-state-active ui-menubar-selected"><a href="http://test.host/contact"><span>Contact Us</span></a></li>
25
+ <li class="ui-menubar-menu ui-menubar-menu-1 ui-menubar-last"><a href="http://test.host/about_us"><span>About Us</span></a></li>
26
26
  </ul>
27
27
  eos
28
28
  assert_equal expected.gsub(/\n\s*/, ''), menu_bar_html
@@ -49,15 +49,15 @@ class MenuBarByDefaultTest < Test::Unit::TestCase
49
49
  end
50
50
 
51
51
  def test_should_set_css_classes
52
- assert_equal 'menubar menubar-1', @menu_bar[:class]
52
+ assert_equal 'ui-menubar ui-menubar-1', @menu_bar[:class]
53
53
  end
54
54
 
55
55
  def test_should_allow_css_classes_to_be_customized
56
56
  @original_menu_bar_class = MenuHelper::MenuBar.menu_bar_class
57
- MenuHelper::MenuBar.menu_bar_class = 'menus'
57
+ MenuHelper::MenuBar.menu_bar_class = 'ui-menus'
58
58
 
59
59
  menu_bar = MenuHelper::MenuBar.new(@controller)
60
- assert_equal 'menus menus-1', menu_bar[:class]
60
+ assert_equal 'ui-menus ui-menus-1', menu_bar[:class]
61
61
  ensure
62
62
  MenuHelper::MenuBar.menu_bar_class = @original_menu_bar_class
63
63
  end
@@ -89,7 +89,7 @@ class MenuBarTest < Test::Unit::TestCase
89
89
 
90
90
  def test_should_not_modify_html_options_after_building_hml
91
91
  @menu_bar.html
92
- assert_equal 'menubar menubar-1', @menu_bar[:class]
92
+ assert_equal 'ui-menubar ui-menubar-1', @menu_bar[:class]
93
93
  end
94
94
 
95
95
  def test_should_allow_menus_to_be_created
@@ -118,7 +118,7 @@ class MenuBarWithoutMenusTest < Test::Unit::TestCase
118
118
  end
119
119
 
120
120
  def test_should_not_render_menus
121
- assert_equal '<ul class="menubar menubar-1"></ul>', @menu_bar.html
121
+ assert_equal '<ul class="ui-menubar ui-menubar-1"></ul>', @menu_bar.html
122
122
  end
123
123
  end
124
124
 
@@ -130,7 +130,7 @@ class MenuBarWithCustomHtmlOptionsTest < Test::Unit::TestCase
130
130
  end
131
131
 
132
132
  def test_should_render_with_custom_options
133
- assert_equal '<ul class="pretty menubar menubar-1" id="menus"></ul>', @menu_bar.html
133
+ assert_equal '<ul class="pretty ui-menubar ui-menubar-1" id="menus"></ul>', @menu_bar.html
134
134
  end
135
135
  end
136
136
 
@@ -158,9 +158,9 @@ class MenuBarWithMenusTest < Test::Unit::TestCase
158
158
 
159
159
  def test_should_render_menus
160
160
  expected = <<-eos
161
- <ul class="menubar menubar-1" id="menus">
162
- <li id="menus-home"><a href="http://test.host/home"><span>Home</span></a></li>
163
- <li class="menubar-last" id="menus-about_us"><a href="http://test.host/about_us"><span>About</span></a></li>
161
+ <ul class="ui-menubar ui-menubar-1" id="menus">
162
+ <li class="ui-menubar-menu ui-menubar-menu-1" id="menus-home"><a href="http://test.host/home"><span>Home</span></a></li>
163
+ <li class="ui-menubar-menu ui-menubar-menu-1 ui-menubar-last" id="menus-about_us"><a href="http://test.host/about_us"><span>About</span></a></li>
164
164
  </ul>
165
165
  eos
166
166
  assert_equal expected.gsub(/\n\s*/, ''), @menu_bar.html
@@ -182,8 +182,8 @@ class MenuBarWithSelectedMenuTest < Test::Unit::TestCase
182
182
 
183
183
  def test_should_not_include_selected_css_class_in_html
184
184
  expected = <<-eos
185
- <ul class="menubar menubar-1">
186
- <li class="menubar-selected menubar-last"><a href="http://test.host/contact"><span>Contact</span></a></li>
185
+ <ul class="ui-menubar ui-menubar-1">
186
+ <li class="ui-menubar-menu ui-menubar-menu-1 ui-state-active ui-menubar-selected ui-menubar-last"><a href="http://test.host/contact"><span>Contact</span></a></li>
187
187
  </ul>
188
188
  eos
189
189
  assert_equal expected.gsub(/\n\s*/, ''), @menu_bar.html
@@ -201,8 +201,8 @@ class MenuBarWithoutAutoIdSettingTest < Test::Unit::TestCase
201
201
 
202
202
  def test_should_not_set_default_id_for_menus
203
203
  expected = <<-eos
204
- <ul class="menubar menubar-1" id="menus">
205
- <li class="menubar-last"><a href="http://test.host/home"><span>Home</span></a></li>
204
+ <ul class="ui-menubar ui-menubar-1" id="menus">
205
+ <li class="ui-menubar-menu ui-menubar-menu-1 ui-menubar-last"><a href="http://test.host/home"><span>Home</span></a></li>
206
206
  </ul>
207
207
  eos
208
208
  assert_equal expected.gsub(/\n\s*/, ''), @menu_bar.html
@@ -222,10 +222,10 @@ class MenuBarUnselectedWithDetachedActiveSubmenus < Test::Unit::TestCase
222
222
 
223
223
  def test_should_render_sub_menu_bars
224
224
  expected = <<-eos
225
- <ul class="menubar menubar-1">
226
- <li class="menubar-last"><a href="http://test.host/home"><span>Home</span></a>
227
- <ul class="menubar menubar-2">
228
- <li class="menubar-last"><a href="http://test.host/about_us"><span>About Us</span></a></li>
225
+ <ul class="ui-menubar ui-menubar-1">
226
+ <li class="ui-menubar-menu ui-menubar-menu-1 ui-menubar-last"><a href="http://test.host/home"><span>Home</span></a>
227
+ <ul class="ui-menubar ui-menubar-2">
228
+ <li class="ui-menubar-menu ui-menubar-menu-2 ui-menubar-last"><a href="http://test.host/about_us"><span>About Us</span></a></li>
229
229
  </ul>
230
230
  </li>
231
231
  </ul>
@@ -251,8 +251,8 @@ class MenuBarSelectedWithDetachedActiveSubmenus < Test::Unit::TestCase
251
251
 
252
252
  def test_should_not_render_sub_menu_bars
253
253
  expected = <<-eos
254
- <ul class="menubar menubar-1">
255
- <li class="menubar-selected menubar-last"><a href="http://test.host/contact"><span>Contact</span></a></li>
254
+ <ul class="ui-menubar ui-menubar-1">
255
+ <li class="ui-menubar-menu ui-menubar-menu-1 ui-state-active ui-menubar-selected ui-menubar-last"><a href="http://test.host/contact"><span>Contact</span></a></li>
256
256
  </ul>
257
257
  eos
258
258
  assert_equal expected.gsub(/\n\s*/, ''), @menu_bar.html
@@ -263,8 +263,8 @@ eos
263
263
  @menu_bar.html
264
264
 
265
265
  expected = <<-eos
266
- <ul class="menubar menubar-2">
267
- <li class="menubar-last"><a href="http://test.host/contact/investors"><span>Investors</span></a></li>
266
+ <ul class="ui-menubar ui-menubar-2">
267
+ <li class="ui-menubar-menu ui-menubar-menu-2 ui-menubar-last"><a href="http://test.host/contact/investors"><span>Investors</span></a></li>
268
268
  </ul>
269
269
  eos
270
270
  assert_equal expected.gsub(/\n\s*/, ''), @controller.instance_variable_get('@content_for_menu_bar_level_2')
@@ -306,8 +306,8 @@ class MenuBarWithParentMenuAndSelectedMenuTest < Test::Unit::TestCase
306
306
 
307
307
  def test_should_include_selected_css_class_in_html
308
308
  expected = <<-eos
309
- <ul class="menubar menubar-2 menubar-selected">
310
- <li class="menubar-selected menubar-last"><a href="http://test.host/contact"><span>Contact</span></a></li>
309
+ <ul class="ui-menubar ui-menubar-2 ui-state-active ui-menubar-selected">
310
+ <li class="ui-menubar-menu ui-menubar-menu-2 ui-state-active ui-menubar-selected ui-menubar-last"><a href="http://test.host/contact"><span>Contact</span></a></li>
311
311
  </ul>
312
312
  eos
313
313
  assert_equal expected.gsub(/\n\s*/, ''), @menu_bar.html
@@ -32,12 +32,16 @@ class MenuByDefaultTest < Test::Unit::TestCase
32
32
  assert @menu.attach_active_submenus?
33
33
  end
34
34
 
35
+ def test_should_not_be_selected
36
+ assert !@menu.selected?
37
+ end
38
+
35
39
  def test_should_not_add_an_html_id
36
40
  assert_nil @menu[:id]
37
41
  end
38
42
 
39
- def test_should_not_be_selected
40
- assert !@menu.selected?
43
+ def test_should_set_css_classes
44
+ assert_equal 'ui-menubar-menu ui-menubar-menu-1', @menu[:class]
41
45
  end
42
46
  end
43
47
 
@@ -58,27 +62,37 @@ class MenuTest < Test::Unit::TestCase
58
62
  assert in_block
59
63
  end
60
64
 
65
+ def test_should_allow_menu_class_to_be_customized
66
+ @original_menu_class = MenuHelper::Menu.menu_class
67
+ MenuHelper::Menu.menu_class = 'ui-menubar-item'
68
+
69
+ @menu = MenuHelper::Menu.new(@menu_bar, :home)
70
+ assert_equal '<li class="ui-menubar-item ui-menubar-item-1"><a href="http://test.host/home"><span>Home</span></a></li>', @menu.html
71
+ ensure
72
+ MenuHelper::Menu.menu_class = @original_menu_class
73
+ end
74
+
61
75
  def test_should_include_last_class_in_html_if_last_menu
62
- assert_equal '<li class="menubar-last"><a href="http://test.host/home"><span>Home</span></a></li>', @menu.html(true)
76
+ assert_equal '<li class="ui-menubar-menu ui-menubar-menu-1 ui-menubar-last"><a href="http://test.host/home"><span>Home</span></a></li>', @menu.html(true)
63
77
  end
64
78
 
65
79
  def test_should_append_last_class_if_class_attribute_already_exists
66
80
  @menu[:class] = 'pretty'
67
- assert_equal '<li class="pretty menubar-last"><a href="http://test.host/home"><span>Home</span></a></li>', @menu.html(true)
81
+ assert_equal '<li class="pretty ui-menubar-last"><a href="http://test.host/home"><span>Home</span></a></li>', @menu.html(true)
68
82
  end
69
83
 
70
84
  def test_should_allow_last_class_to_be_customized
71
85
  @original_last_class = MenuHelper::Menu.last_class
72
- MenuHelper::Menu.last_class = 'menubar-end'
86
+ MenuHelper::Menu.last_class = 'ui-menubar-end'
73
87
 
74
- assert_equal '<li class="menubar-end"><a href="http://test.host/home"><span>Home</span></a></li>', @menu.html(true)
88
+ assert_equal '<li class="ui-menubar-menu ui-menubar-menu-1 ui-menubar-end"><a href="http://test.host/home"><span>Home</span></a></li>', @menu.html(true)
75
89
  ensure
76
90
  MenuHelper::Menu.last_class = @original_last_class
77
91
  end
78
92
 
79
93
  def test_should_not_modify_html_options_after_building_html
80
94
  @menu.html(true)
81
- assert_nil @menu[:class]
95
+ assert_equal @menu[:class], 'ui-menubar-menu ui-menubar-menu-1'
82
96
  end
83
97
  end
84
98
 
@@ -189,7 +203,7 @@ class MenuWithoutContentTest < Test::Unit::TestCase
189
203
  end
190
204
 
191
205
  def test_should_use_titleized_version_of_name_as_content
192
- assert_equal '<li><a href="http://test.host/home"><span>Home</span></a></li>', @menu.html
206
+ assert_equal '<li class="ui-menubar-menu ui-menubar-menu-1"><a href="http://test.host/home"><span>Home</span></a></li>', @menu.html
193
207
  end
194
208
  end
195
209
 
@@ -202,7 +216,7 @@ class MenuWithCustomContentTest < Test::Unit::TestCase
202
216
  end
203
217
 
204
218
  def test_should_use_custom_content_as_content
205
- assert_equal '<li><a href="http://test.host/home"><span>My Home</span></a></li>', @menu.html
219
+ assert_equal '<li class="ui-menubar-menu ui-menubar-menu-1"><a href="http://test.host/home"><span>My Home</span></a></li>', @menu.html
206
220
  end
207
221
  end
208
222
 
@@ -215,7 +229,7 @@ class MenuWithoutLinkingTest < Test::Unit::TestCase
215
229
  end
216
230
 
217
231
  def test_should_not_linkify_html
218
- assert_equal '<li><span>Home</span></li>', @menu.html
232
+ assert_equal '<li class="ui-menubar-menu ui-menubar-menu-1"><span>Home</span></li>', @menu.html
219
233
  end
220
234
  end
221
235
 
@@ -245,7 +259,7 @@ class MenuWhenNotCurrentPageTest < Test::Unit::TestCase
245
259
  end
246
260
 
247
261
  def test_should_not_include_selected_css_class_in_html
248
- assert_equal '<li><a href="http://test.host/home"><span>Home</span></a></li>', @menu.html
262
+ assert_equal '<li class="ui-menubar-menu ui-menubar-menu-1"><a href="http://test.host/home"><span>Home</span></a></li>', @menu.html
249
263
  end
250
264
  end
251
265
 
@@ -262,18 +276,18 @@ class MenuWhenCurrentPageTest < Test::Unit::TestCase
262
276
  end
263
277
 
264
278
  def test_should_include_selected_css_class_in_html
265
- assert_equal '<li class="menubar-selected"><a href="http://test.host/contact"><span>Contact</span></a></li>', @menu.html
279
+ assert_equal '<li class="ui-menubar-menu ui-menubar-menu-1 ui-state-active ui-menubar-selected"><a href="http://test.host/contact"><span>Contact</span></a></li>', @menu.html
266
280
  end
267
281
 
268
282
  def test_should_append_selected_class_if_class_attribute_already_exists
269
283
  @menu[:class] = 'pretty'
270
- assert_equal '<li class="pretty menubar-selected"><a href="http://test.host/contact"><span>Contact</span></a></li>', @menu.html
284
+ assert_equal '<li class="pretty ui-state-active ui-menubar-selected"><a href="http://test.host/contact"><span>Contact</span></a></li>', @menu.html
271
285
  end
272
286
 
273
287
  def test_should_allow_selected_class_to_be_customized
274
288
  @original_selected_class = MenuHelper::Menu.selected_class
275
- MenuHelper::Menu.selected_class = 'menubar-active'
276
- assert_equal '<li class="menubar-active"><a href="http://test.host/contact"><span>Contact</span></a></li>', @menu.html
289
+ MenuHelper::Menu.selected_class = 'ui-menubar-active'
290
+ assert_equal '<li class="ui-menubar-menu ui-menubar-menu-1 ui-menubar-active"><a href="http://test.host/contact"><span>Contact</span></a></li>', @menu.html
277
291
  ensure
278
292
  MenuHelper::Menu.selected_class = @original_selected_class
279
293
  end
@@ -288,7 +302,7 @@ class MenuWithoutSubmenusTest < Test::Unit::TestCase
288
302
  end
289
303
 
290
304
  def test_should_not_render_a_menu_bar
291
- assert_equal '<li><a href="http://test.host/home"><span>Home</span></a></li>', @menu.html
305
+ assert_equal '<li class="ui-menubar-menu ui-menubar-menu-1"><a href="http://test.host/home"><span>Home</span></a></li>', @menu.html
292
306
  end
293
307
  end
294
308
 
@@ -306,11 +320,11 @@ class MenuWithSubmenusTest < Test::Unit::TestCase
306
320
 
307
321
  def test_should_render_a_menu_bar
308
322
  expected = <<-eos
309
- <li><a href="http://test.host/home"><span>Home</span></a>
310
- <ul class="menubar menubar-2">
311
- <li class="menubar-last"><a href="http://test.host/about_us"><span>About Us</span></a>
312
- <ul class="menubar menubar-3">
313
- <li class="menubar-last"><a href="http://test.host/about_us/who_we_are"><span>Who We Are</span></a></li>
323
+ <li class="ui-menubar-menu ui-menubar-menu-1"><a href="http://test.host/home"><span>Home</span></a>
324
+ <ul class="ui-menubar ui-menubar-2">
325
+ <li class="ui-menubar-menu ui-menubar-menu-2 ui-menubar-last"><a href="http://test.host/about_us"><span>About Us</span></a>
326
+ <ul class="ui-menubar ui-menubar-3">
327
+ <li class="ui-menubar-menu ui-menubar-menu-3 ui-menubar-last"><a href="http://test.host/about_us/who_we_are"><span>Who We Are</span></a></li>
314
328
  </ul>
315
329
  </li>
316
330
  </ul>
@@ -332,9 +346,9 @@ class MenuUnselectedWithDetachedActiveSubmenusTest < Test::Unit::TestCase
332
346
 
333
347
  def test_should_render_a_menu_bar
334
348
  expected = <<-eos
335
- <li><a href="http://test.host/home"><span>Home</span></a>
336
- <ul class="menubar menubar-2">
337
- <li class="menubar-last"><a href="http://test.host/about_us"><span>About Us</span></a></li>
349
+ <li class="ui-menubar-menu ui-menubar-menu-1"><a href="http://test.host/home"><span>Home</span></a>
350
+ <ul class="ui-menubar ui-menubar-2">
351
+ <li class="ui-menubar-menu ui-menubar-menu-2 ui-menubar-last"><a href="http://test.host/about_us"><span>About Us</span></a></li>
338
352
  </ul>
339
353
  </li>
340
354
  eos
@@ -357,7 +371,7 @@ class MenuSelectedWithDetachedActiveSubmenusTest < Test::Unit::TestCase
357
371
  end
358
372
 
359
373
  def test_should_not_render_a_menu_bar
360
- assert_equal '<li class="menubar-selected"><a href="http://test.host/contact"><span>Contact</span></a></li>', @menu.html
374
+ assert_equal '<li class="ui-menubar-menu ui-menubar-menu-1 ui-state-active ui-menubar-selected"><a href="http://test.host/contact"><span>Contact</span></a></li>', @menu.html
361
375
  end
362
376
 
363
377
  def test_should_store_a_menu_bar_in_content_variable
@@ -365,8 +379,8 @@ class MenuSelectedWithDetachedActiveSubmenusTest < Test::Unit::TestCase
365
379
  @menu.html
366
380
 
367
381
  expected = <<-eos
368
- <ul class="menubar menubar-2">
369
- <li class="menubar-last"><a href="http://test.host/contact/investors"><span>Investors</span></a></li>
382
+ <ul class="ui-menubar ui-menubar-2">
383
+ <li class="ui-menubar-menu ui-menubar-menu-2 ui-menubar-last"><a href="http://test.host/contact/investors"><span>Investors</span></a></li>
370
384
  </ul>
371
385
  eos
372
386
  assert_equal expected.gsub(/\n\s*/, ''), @controller.instance_variable_get('@content_for_menu_bar_level_2')
@@ -389,9 +403,9 @@ class MenuWithSubmenuAsCurrentPageTest < Test::Unit::TestCase
389
403
 
390
404
  def test_should_include_selected_css_class_in_html
391
405
  expected = <<-eos
392
- <li class="menubar-selected"><a href="http://test.host/about_us"><span>About Us</span></a>
393
- <ul class="menubar menubar-2 menubar-selected">
394
- <li class="menubar-selected menubar-last"><a href="http://test.host/contact"><span>Contact</span></a></li>
406
+ <li class="ui-menubar-menu ui-menubar-menu-1 ui-state-active ui-menubar-selected"><a href="http://test.host/about_us"><span>About Us</span></a>
407
+ <ul class="ui-menubar ui-menubar-2 ui-state-active ui-menubar-selected">
408
+ <li class="ui-menubar-menu ui-menubar-menu-2 ui-state-active ui-menubar-selected ui-menubar-last"><a href="http://test.host/contact"><span>Contact</span></a></li>
395
409
  </ul>
396
410
  </li>
397
411
  eos
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: menu_helper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aaron Pfeifer
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-12-14 00:00:00 -05:00
12
+ date: 2009-04-18 00:00:00 -04:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -69,7 +69,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
69
69
  requirements: []
70
70
 
71
71
  rubyforge_project: pluginaweek
72
- rubygems_version: 1.2.0
72
+ rubygems_version: 1.3.1
73
73
  signing_key:
74
74
  specification_version: 2
75
75
  summary: Adds a helper method for generating a menubar