jonuts-merb-menus 0.0.6 → 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/merb-menus/menu.rb +1 -1
- data/lib/merb-menus/merb_controller.rb +2 -2
- data/lib/merb-menus/version.rb +1 -1
- data/spec/merb-menus/item_spec.rb +37 -0
- data/spec/merb-menus/menu_spec.rb +30 -0
- data/spec/merb-menus/rule.rb +23 -0
- data/spec/merb-menus/submenu_spec.rb +28 -0
- data/spec/merb-menus_spec.rb +137 -0
- data/spec/spec_helper.rb +16 -0
- metadata +24 -15
data/lib/merb-menus/menu.rb
CHANGED
@@ -2,8 +2,8 @@ class Merb::Controller
|
|
2
2
|
before do
|
3
3
|
Merb::Menus.reset
|
4
4
|
|
5
|
-
controller = params[
|
6
|
-
action = params[
|
5
|
+
controller = params['controller']
|
6
|
+
action = params['action']
|
7
7
|
|
8
8
|
if top = Merb::Menus.current_menu = Merb::Menus.default
|
9
9
|
if menu = top.current_submenu = get_submenu(top,controller)
|
data/lib/merb-menus/version.rb
CHANGED
@@ -0,0 +1,37 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
describe Merb::Menus::Item do
|
4
|
+
before do
|
5
|
+
@menu = Merb::Menus::Menu.new(:foo)
|
6
|
+
@menu.display_style(:split) {|thing| thing.to_s.split("_").join(" ")}
|
7
|
+
|
8
|
+
@submenu = Merb::Menus::Submenu.new(:cakes, @menu)
|
9
|
+
@submenu.use_display_style(:split)
|
10
|
+
|
11
|
+
@cheesecake = Merb::Menus::Item.new(:name => :cheese_cake, :submenu => @submenu)
|
12
|
+
@spongecake = Merb::Menus::Item.new(:name => :sponge, :submenu => @submenu, :anchor => "sPOnge cAkE")
|
13
|
+
@poundcake = Merb::Menus::Item.new(:name => :pound, :submenu => @submenu, :href => "http://bettercakesite")
|
14
|
+
end
|
15
|
+
|
16
|
+
it "has a unique key"
|
17
|
+
it "has a submenu" do
|
18
|
+
@cheesecake.submenu.should == @submenu
|
19
|
+
end
|
20
|
+
|
21
|
+
it "sets the anchor based on display rule in submenu" do
|
22
|
+
@cheesecake.anchor.should == "cheese cake"
|
23
|
+
end
|
24
|
+
|
25
|
+
it "overrides default display style if given in opts" do
|
26
|
+
@spongecake.anchor.should == "sPOnge cAkE"
|
27
|
+
end
|
28
|
+
|
29
|
+
it "generates a url" do
|
30
|
+
@cheesecake.href.should == "/cakes/cheese_cake"
|
31
|
+
@spongecake.href.should == "/cakes/sponge"
|
32
|
+
@poundcake.href.should == "http://bettercakesite"
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
describe Merb::Menus::Menu do
|
4
|
+
before do
|
5
|
+
@menu = Merb::Menus::Menu.new(:foo)
|
6
|
+
@menu.submenu(:wutup){}
|
7
|
+
@menu.submenu(:dog){}
|
8
|
+
end
|
9
|
+
|
10
|
+
it "tracks submenus" do
|
11
|
+
@menu.submenus.should have(2).things
|
12
|
+
end
|
13
|
+
|
14
|
+
it "stores different display rules"
|
15
|
+
it "defines a url generator"
|
16
|
+
it "has a default url generation method"
|
17
|
+
end
|
18
|
+
|
19
|
+
describe Merb::Menus::Menu, "#submenu" do
|
20
|
+
before do
|
21
|
+
@menu = Merb::Menus::Menu.new(:hellothar)
|
22
|
+
end
|
23
|
+
|
24
|
+
it "creates a submenu without taking a block" do
|
25
|
+
lambda{@menu.submenu(:foo)}.should_not raise_error(ArgumentError)
|
26
|
+
@menu.submenus.should have(1).item
|
27
|
+
@menu.submenus.first.name.should == :foo
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
describe Merb::Menus::DisplayStyle do
|
4
|
+
before do
|
5
|
+
@menu = Merb::Menus::Menu.new(:foo)
|
6
|
+
@split_rule = Merb::Menus::DisplayStyle.new(:split,@menu){|thing| thing.to_s.split("_").join(" ")}
|
7
|
+
@splitncap = Merb::Menus::DisplayStyle.new(:split,@menu){|thing| thing.to_s.split("_").join(" ")}
|
8
|
+
@dollarfy = Merb::Menus::DisplayStyle.new(:dollar,@menu){|thing| "$#{thing.to_s.gsub(/_/,',')}"}
|
9
|
+
end
|
10
|
+
|
11
|
+
it "has a unique key" do
|
12
|
+
@split_rule.key.should == :split
|
13
|
+
@splitncap.key.should == :split
|
14
|
+
|
15
|
+
@split_rule.rule.call("hello_thar").should == "hello thar"
|
16
|
+
@splitncap.rule.call("wut_the_deal").should == "wut the deal"
|
17
|
+
end
|
18
|
+
|
19
|
+
it "has a styling rule" do
|
20
|
+
Merb::Menus::DisplayStyle.add_rule(:feh).should be_nil
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
describe Merb::Menus::Submenu do
|
4
|
+
before do
|
5
|
+
Merb::Menus::Menu.new :foo
|
6
|
+
@submenu = Merb::Menus::Submenu.new(:berries, Merb::Menus::Menu[:foo])
|
7
|
+
@submenu.item(:straw)
|
8
|
+
@submenu.item(:rasp)
|
9
|
+
@submenu.item(:black, :anchor => "HELLOTHAR", :url => "eek")
|
10
|
+
end
|
11
|
+
|
12
|
+
it "has a unique key" do
|
13
|
+
@submenu.name.should == :berries
|
14
|
+
end
|
15
|
+
|
16
|
+
it "has a collection of items" do
|
17
|
+
@submenu.items.should have(3).things
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'sets item properly' do
|
21
|
+
item = @submenu.items.first
|
22
|
+
item.name.should == :straw
|
23
|
+
item.submenu.should == @submenu
|
24
|
+
item.anchor.should == "straw"
|
25
|
+
item.href.should == "/berries/straw"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
@@ -0,0 +1,137 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
class Application < Merb::Controller
|
4
|
+
create_menu :main do
|
5
|
+
submenu :cakes, :href => "/cakes" do
|
6
|
+
item :cheese
|
7
|
+
item :chocolate
|
8
|
+
item :devils_food, :anchor => "Devil's Food"
|
9
|
+
end
|
10
|
+
|
11
|
+
submenu :beers, :href => "/beers" do
|
12
|
+
item :budweiser
|
13
|
+
item :rolling_rock
|
14
|
+
item :fosters, :anchor => "Foster's"
|
15
|
+
item :fat_tire
|
16
|
+
end
|
17
|
+
|
18
|
+
submenu :drinks, :href => "/drinks" do
|
19
|
+
item :soda
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
class Cakes < Application
|
26
|
+
use_menu :main
|
27
|
+
|
28
|
+
# this should be associated with item :cheese
|
29
|
+
def cheese
|
30
|
+
'hello'
|
31
|
+
end
|
32
|
+
|
33
|
+
def chocolate
|
34
|
+
menu_item :beers, :budweiser
|
35
|
+
|
36
|
+
'word up'
|
37
|
+
end
|
38
|
+
|
39
|
+
def not_devils_food
|
40
|
+
# associate this action with item :devils_food
|
41
|
+
menu_item :devils_food
|
42
|
+
|
43
|
+
':)'
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
class Beers < Application
|
48
|
+
def fat_tire
|
49
|
+
'yoink'
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
class Snack < Application
|
54
|
+
use_menu :main, :cakes
|
55
|
+
|
56
|
+
def cheese_cake
|
57
|
+
menu_item :cheese
|
58
|
+
|
59
|
+
[current_menu, current_submenu, current_item].join(" ")
|
60
|
+
end
|
61
|
+
|
62
|
+
def pistachios
|
63
|
+
[current_menu, current_submenu, current_item].join(" ")
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
class Drinks < Application
|
68
|
+
def soda
|
69
|
+
"#{current_menu}/#{current_submenu}/#{current_item}"
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
describe "menu generator", "Merb::Controller" do
|
74
|
+
before do
|
75
|
+
@menu = Merb::Menus[:main]
|
76
|
+
end
|
77
|
+
|
78
|
+
it "should create the menu" do
|
79
|
+
@menu.name.should == :main
|
80
|
+
end
|
81
|
+
|
82
|
+
it "should create all the submenus" do
|
83
|
+
@menu.submenus.should have(3).things
|
84
|
+
@menu.submenus.first.name.should == :cakes
|
85
|
+
end
|
86
|
+
|
87
|
+
it "should create the submenu items" do
|
88
|
+
@menu.submenus.first.items.should have(3).things
|
89
|
+
@menu.submenus.first.items.map{|e| e.name}.should == [:cheese, :chocolate, :devils_food]
|
90
|
+
|
91
|
+
@menu.submenus[1].items.should have(4).things
|
92
|
+
@menu.submenus[1].items.map{|e| e.name}.should == [:budweiser, :rolling_rock, :fosters, :fat_tire]
|
93
|
+
end
|
94
|
+
|
95
|
+
it "is accessible from child controllers"
|
96
|
+
|
97
|
+
it "sets the current menu properly" do
|
98
|
+
request('/cakes/cheese')
|
99
|
+
top = Merb::Menus[:main]
|
100
|
+
top.current_submenu.name.should == :cakes
|
101
|
+
top.current_submenu.current_item.name.should == :cheese
|
102
|
+
end
|
103
|
+
|
104
|
+
it "overrides actions default menu item" do
|
105
|
+
request('/cakes/chocolate')
|
106
|
+
top = Merb::Menus[:main]
|
107
|
+
top.current_submenu.name.should == :beers
|
108
|
+
top.current_submenu.current_item.name.should == :budweiser
|
109
|
+
end
|
110
|
+
|
111
|
+
it "finds the correct controller/action combo automagically" do
|
112
|
+
request '/beers/fat_tire'
|
113
|
+
Merb::Menus.current_menu.name.should == :main
|
114
|
+
Merb::Menus.current_menu.current_submenu.name.should == :beers
|
115
|
+
Merb::Menus.current_menu.current_submenu.current_item.name.should == :fat_tire
|
116
|
+
end
|
117
|
+
|
118
|
+
it "has helpers to access current menu data" do
|
119
|
+
req = request '/drinks/soda'
|
120
|
+
|
121
|
+
req.body.to_s.should == "main/drinks/soda"
|
122
|
+
end
|
123
|
+
|
124
|
+
it do
|
125
|
+
req = request '/snack/cheese_cake'
|
126
|
+
req.body.to_s.should == "main cakes cheese"
|
127
|
+
end
|
128
|
+
|
129
|
+
it "resets all current menus before each request" do
|
130
|
+
req = request '/snack/pistachios'
|
131
|
+
req.body.to_s.should_not == "main cakes cheese" #this would happen w/o the reset
|
132
|
+
req.body.to_s.should == "main cakes "
|
133
|
+
end
|
134
|
+
|
135
|
+
|
136
|
+
end
|
137
|
+
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
$:.push File.join(File.dirname(__FILE__), '..', 'lib')
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'spec'
|
5
|
+
require 'merb-core'
|
6
|
+
require 'merb-core/test'
|
7
|
+
require 'merb-menus'
|
8
|
+
|
9
|
+
Merb::Router.prepare {default_routes}
|
10
|
+
|
11
|
+
Merb.start :environment => "test", :adapter => "runner"
|
12
|
+
|
13
|
+
Spec::Runner.configure {|config|
|
14
|
+
config.include(Merb::Test::RouteHelper)
|
15
|
+
}
|
16
|
+
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jonuts-merb-menus
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- jonah honeyman
|
@@ -13,16 +13,22 @@ date: 2009-05-06 00:00:00 -07:00
|
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
16
|
-
description: Merb plugin that provides dot dot dot uh menus
|
16
|
+
description: Merb plugin that provides dot dot dot uh menus
|
17
17
|
email: jonah@honeyman.org
|
18
18
|
executables: []
|
19
19
|
|
20
20
|
extensions: []
|
21
21
|
|
22
|
-
extra_rdoc_files:
|
23
|
-
|
22
|
+
extra_rdoc_files:
|
23
|
+
- README
|
24
|
+
- LICENSE
|
25
|
+
- TODO
|
24
26
|
files:
|
25
|
-
-
|
27
|
+
- LICENSE
|
28
|
+
- README
|
29
|
+
- Rakefile
|
30
|
+
- TODO
|
31
|
+
- lib/merb-menus
|
26
32
|
- lib/merb-menus/item.rb
|
27
33
|
- lib/merb-menus/menu.rb
|
28
34
|
- lib/merb-menus/merb_controller.rb
|
@@ -30,19 +36,22 @@ files:
|
|
30
36
|
- lib/merb-menus/rule.rb
|
31
37
|
- lib/merb-menus/submenu.rb
|
32
38
|
- lib/merb-menus/version.rb
|
33
|
-
-
|
34
|
-
-
|
35
|
-
-
|
36
|
-
-
|
39
|
+
- lib/merb-menus.rb
|
40
|
+
- spec/merb-menus
|
41
|
+
- spec/merb-menus/item_spec.rb
|
42
|
+
- spec/merb-menus/menu_spec.rb
|
43
|
+
- spec/merb-menus/rule.rb
|
44
|
+
- spec/merb-menus/submenu_spec.rb
|
45
|
+
- spec/merb-menus_spec.rb
|
46
|
+
- spec/spec_helper.rb
|
37
47
|
has_rdoc: true
|
38
48
|
homepage: http://github.com/jonuts/merb-menus
|
49
|
+
licenses:
|
39
50
|
post_install_message:
|
40
|
-
rdoc_options:
|
41
|
-
|
42
|
-
- --charset=UTF-8
|
51
|
+
rdoc_options: []
|
52
|
+
|
43
53
|
require_paths:
|
44
54
|
- lib
|
45
|
-
- lib/merb-menus
|
46
55
|
required_ruby_version: !ruby/object:Gem::Requirement
|
47
56
|
requirements:
|
48
57
|
- - ">="
|
@@ -58,9 +67,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
58
67
|
requirements: []
|
59
68
|
|
60
69
|
rubyforge_project:
|
61
|
-
rubygems_version: 1.
|
70
|
+
rubygems_version: 1.3.5
|
62
71
|
signing_key:
|
63
72
|
specification_version: 2
|
64
|
-
summary: Merb plugin that provides dot dot dot uh menus
|
73
|
+
summary: Merb plugin that provides dot dot dot uh menus
|
65
74
|
test_files: []
|
66
75
|
|