lolita-menu 0.0.8 → 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- data/History.rdoc +8 -0
- data/VERSION +1 -1
- data/app/models/menu.rb +1 -0
- data/app/models/menu_item.rb +33 -1
- data/lolita-menu.gemspec +3 -3
- data/public/javascripts/lolita/menu-items.js +1 -1
- data/spec/models/menu_item_spec.rb +30 -0
- metadata +84 -89
data/History.rdoc
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.9
|
data/app/models/menu.rb
CHANGED
data/app/models/menu_item.rb
CHANGED
@@ -6,7 +6,7 @@ class MenuItem < ActiveRecord::Base
|
|
6
6
|
belongs_to :menu, :class_name => "Menu"
|
7
7
|
|
8
8
|
validates :name,:presence => true
|
9
|
-
validates :url, :format => {:with =>
|
9
|
+
validates :url, :format => {:with => /^(\/)|(http).*/}, :unless=>:root?
|
10
10
|
|
11
11
|
before_create :set_default_positions
|
12
12
|
after_create :put_in_place
|
@@ -29,6 +29,31 @@ class MenuItem < ActiveRecord::Base
|
|
29
29
|
end
|
30
30
|
# instance methods
|
31
31
|
|
32
|
+
def active?(request,options={})
|
33
|
+
active_item = self_and_all_children.detect{|item|
|
34
|
+
item.url_match?(request,options[:fullpath])
|
35
|
+
}
|
36
|
+
|
37
|
+
!!active_item
|
38
|
+
endg
|
39
|
+
|
40
|
+
def url_match?(request,fullpath=false)
|
41
|
+
|
42
|
+
if self.url.match(/^http/)
|
43
|
+
self.url==request.url
|
44
|
+
else
|
45
|
+
only_path = (fullpath ? request.fullpath : request.path).gsub(/\?.*/,"")
|
46
|
+
self.real_url(request.params) == only_path
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def real_url(params)
|
51
|
+
self.url.gsub(/(:\w+)\/?/) do |m|
|
52
|
+
params_key = $1.gsub(":","").to_sym
|
53
|
+
params.has_key?(params_key) ? "#{params[params_key]}#{m[m.size-1]=="/" ? "/" : ""}" : ""
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
32
57
|
def visible?
|
33
58
|
self.is_visible
|
34
59
|
end
|
@@ -53,6 +78,13 @@ class MenuItem < ActiveRecord::Base
|
|
53
78
|
@children
|
54
79
|
end
|
55
80
|
|
81
|
+
def self_and_all_children
|
82
|
+
@self_and_all_children||=self.class.where("lft>=:left AND rgt<=:right AND menu_id=:menu",{
|
83
|
+
:left => self.lft,:right => self.rgt, :menu=>self.menu_id
|
84
|
+
}).order("lft asc")
|
85
|
+
@self_and_all_children
|
86
|
+
end
|
87
|
+
|
56
88
|
def root
|
57
89
|
if self.parent_id.nil?
|
58
90
|
self
|
data/lolita-menu.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{lolita-menu}
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.9"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["ITHouse", "Arturs Meisters"]
|
12
|
-
s.date = %q{2011-06-
|
12
|
+
s.date = %q{2011-06-10}
|
13
13
|
s.description = %q{Manage public menus for each project inside Lolita.}
|
14
14
|
s.email = %q{support@ithouse.lv}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -64,7 +64,7 @@ Gem::Specification.new do |s|
|
|
64
64
|
s.homepage = %q{http://github.com/ithouse/lolita-menu}
|
65
65
|
s.licenses = ["MIT"]
|
66
66
|
s.require_paths = ["lib"]
|
67
|
-
s.rubygems_version = %q{1.6.
|
67
|
+
s.rubygems_version = %q{1.6.2}
|
68
68
|
s.summary = %q{Menu managing plugin for Lolita.}
|
69
69
|
s.test_files = [
|
70
70
|
"spec/controllers/menu_items_controller_spec.rb",
|
@@ -6,6 +6,36 @@ describe MenuItem do
|
|
6
6
|
MenuItem.create!(:name=>"item",:url=>"/")
|
7
7
|
end
|
8
8
|
|
9
|
+
describe "recognize active item" do
|
10
|
+
|
11
|
+
let(:menu){Menu.create!(:name=>"new menu")}
|
12
|
+
|
13
|
+
let(:request){
|
14
|
+
mock_obj = mock(Object)
|
15
|
+
mock_obj.stub!(:params).and_return({})
|
16
|
+
mock_obj
|
17
|
+
}
|
18
|
+
|
19
|
+
it "should recognize full paths" do
|
20
|
+
item = menu.append(MenuItem.create!(:name => "Name", :url => "http://google.lv"))
|
21
|
+
request.stub!(:url).and_return("http://google.lv")
|
22
|
+
item.active?(request).should be_true
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should recognize relative paths" do
|
26
|
+
item = menu.append(MenuItem.create!(:name => "Name", :url => "/posts"))
|
27
|
+
request.stub!(:path).and_return("/posts?page=1")
|
28
|
+
item.active?(request).should be_true
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should recognize relative paths with arguments" do
|
32
|
+
item = menu.append(MenuItem.create!(:name => "Name", :url => "/:whoes/posts"))
|
33
|
+
request.stub!(:path).and_return("/my/posts?page=1")
|
34
|
+
request.stub!(:params).and_return({:whoes => "my"})
|
35
|
+
item.active?(request).should be_true
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
9
39
|
describe "positioning items" do
|
10
40
|
|
11
41
|
let(:menu){Menu.create!(:name=>"new menu")}
|
metadata
CHANGED
@@ -1,139 +1,136 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: lolita-menu
|
3
|
-
version: !ruby/object:Gem::Version
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.9
|
4
5
|
prerelease:
|
5
|
-
version: 0.0.8
|
6
6
|
platform: ruby
|
7
|
-
authors:
|
7
|
+
authors:
|
8
8
|
- ITHouse
|
9
9
|
- Arturs Meisters
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
|
14
|
-
date: 2011-06-09 00:00:00 +03:00
|
13
|
+
date: 2011-06-10 00:00:00.000000000 +03:00
|
15
14
|
default_executable:
|
16
|
-
dependencies:
|
17
|
-
- !ruby/object:Gem::Dependency
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
18
17
|
name: lolita
|
19
|
-
requirement: &
|
18
|
+
requirement: &70928720 !ruby/object:Gem::Requirement
|
20
19
|
none: false
|
21
|
-
requirements:
|
20
|
+
requirements:
|
22
21
|
- - ~>
|
23
|
-
- !ruby/object:Gem::Version
|
22
|
+
- !ruby/object:Gem::Version
|
24
23
|
version: 3.1.6
|
25
24
|
type: :runtime
|
26
25
|
prerelease: false
|
27
|
-
version_requirements: *
|
28
|
-
- !ruby/object:Gem::Dependency
|
26
|
+
version_requirements: *70928720
|
27
|
+
- !ruby/object:Gem::Dependency
|
29
28
|
name: haml
|
30
|
-
requirement: &
|
29
|
+
requirement: &70928030 !ruby/object:Gem::Requirement
|
31
30
|
none: false
|
32
|
-
requirements:
|
33
|
-
- -
|
34
|
-
- !ruby/object:Gem::Version
|
35
|
-
version:
|
31
|
+
requirements:
|
32
|
+
- - ! '>='
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
36
35
|
type: :runtime
|
37
36
|
prerelease: false
|
38
|
-
version_requirements: *
|
39
|
-
- !ruby/object:Gem::Dependency
|
37
|
+
version_requirements: *70928030
|
38
|
+
- !ruby/object:Gem::Dependency
|
40
39
|
name: rspec
|
41
|
-
requirement: &
|
40
|
+
requirement: &70927320 !ruby/object:Gem::Requirement
|
42
41
|
none: false
|
43
|
-
requirements:
|
42
|
+
requirements:
|
44
43
|
- - ~>
|
45
|
-
- !ruby/object:Gem::Version
|
44
|
+
- !ruby/object:Gem::Version
|
46
45
|
version: 2.6.0
|
47
46
|
type: :development
|
48
47
|
prerelease: false
|
49
|
-
version_requirements: *
|
50
|
-
- !ruby/object:Gem::Dependency
|
48
|
+
version_requirements: *70927320
|
49
|
+
- !ruby/object:Gem::Dependency
|
51
50
|
name: sqlite3
|
52
|
-
requirement: &
|
51
|
+
requirement: &70926540 !ruby/object:Gem::Requirement
|
53
52
|
none: false
|
54
|
-
requirements:
|
55
|
-
- -
|
56
|
-
- !ruby/object:Gem::Version
|
57
|
-
version:
|
53
|
+
requirements:
|
54
|
+
- - ! '>='
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '0'
|
58
57
|
type: :development
|
59
58
|
prerelease: false
|
60
|
-
version_requirements: *
|
61
|
-
- !ruby/object:Gem::Dependency
|
59
|
+
version_requirements: *70926540
|
60
|
+
- !ruby/object:Gem::Dependency
|
62
61
|
name: rspec-rails
|
63
|
-
requirement: &
|
62
|
+
requirement: &70925910 !ruby/object:Gem::Requirement
|
64
63
|
none: false
|
65
|
-
requirements:
|
64
|
+
requirements:
|
66
65
|
- - ~>
|
67
|
-
- !ruby/object:Gem::Version
|
66
|
+
- !ruby/object:Gem::Version
|
68
67
|
version: 2.6.0
|
69
68
|
type: :development
|
70
69
|
prerelease: false
|
71
|
-
version_requirements: *
|
72
|
-
- !ruby/object:Gem::Dependency
|
70
|
+
version_requirements: *70925910
|
71
|
+
- !ruby/object:Gem::Dependency
|
73
72
|
name: haml-rails
|
74
|
-
requirement: &
|
73
|
+
requirement: &70925310 !ruby/object:Gem::Requirement
|
75
74
|
none: false
|
76
|
-
requirements:
|
77
|
-
- -
|
78
|
-
- !ruby/object:Gem::Version
|
79
|
-
version:
|
75
|
+
requirements:
|
76
|
+
- - ! '>='
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '0'
|
80
79
|
type: :development
|
81
80
|
prerelease: false
|
82
|
-
version_requirements: *
|
83
|
-
- !ruby/object:Gem::Dependency
|
81
|
+
version_requirements: *70925310
|
82
|
+
- !ruby/object:Gem::Dependency
|
84
83
|
name: shoulda
|
85
|
-
requirement: &
|
84
|
+
requirement: &70924540 !ruby/object:Gem::Requirement
|
86
85
|
none: false
|
87
|
-
requirements:
|
88
|
-
- -
|
89
|
-
- !ruby/object:Gem::Version
|
90
|
-
version:
|
86
|
+
requirements:
|
87
|
+
- - ! '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
91
90
|
type: :development
|
92
91
|
prerelease: false
|
93
|
-
version_requirements: *
|
94
|
-
- !ruby/object:Gem::Dependency
|
92
|
+
version_requirements: *70924540
|
93
|
+
- !ruby/object:Gem::Dependency
|
95
94
|
name: bundler
|
96
|
-
requirement: &
|
95
|
+
requirement: &70923830 !ruby/object:Gem::Requirement
|
97
96
|
none: false
|
98
|
-
requirements:
|
97
|
+
requirements:
|
99
98
|
- - ~>
|
100
|
-
- !ruby/object:Gem::Version
|
99
|
+
- !ruby/object:Gem::Version
|
101
100
|
version: 1.0.0
|
102
101
|
type: :development
|
103
102
|
prerelease: false
|
104
|
-
version_requirements: *
|
105
|
-
- !ruby/object:Gem::Dependency
|
103
|
+
version_requirements: *70923830
|
104
|
+
- !ruby/object:Gem::Dependency
|
106
105
|
name: jeweler
|
107
|
-
requirement: &
|
106
|
+
requirement: &70922920 !ruby/object:Gem::Requirement
|
108
107
|
none: false
|
109
|
-
requirements:
|
108
|
+
requirements:
|
110
109
|
- - ~>
|
111
|
-
- !ruby/object:Gem::Version
|
110
|
+
- !ruby/object:Gem::Version
|
112
111
|
version: 1.5.2
|
113
112
|
type: :development
|
114
113
|
prerelease: false
|
115
|
-
version_requirements: *
|
116
|
-
- !ruby/object:Gem::Dependency
|
114
|
+
version_requirements: *70922920
|
115
|
+
- !ruby/object:Gem::Dependency
|
117
116
|
name: rcov
|
118
|
-
requirement: &
|
117
|
+
requirement: &70916600 !ruby/object:Gem::Requirement
|
119
118
|
none: false
|
120
|
-
requirements:
|
121
|
-
- -
|
122
|
-
- !ruby/object:Gem::Version
|
123
|
-
version:
|
119
|
+
requirements:
|
120
|
+
- - ! '>='
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: '0'
|
124
123
|
type: :development
|
125
124
|
prerelease: false
|
126
|
-
version_requirements: *
|
125
|
+
version_requirements: *70916600
|
127
126
|
description: Manage public menus for each project inside Lolita.
|
128
127
|
email: support@ithouse.lv
|
129
128
|
executables: []
|
130
|
-
|
131
129
|
extensions: []
|
132
|
-
|
133
|
-
extra_rdoc_files:
|
130
|
+
extra_rdoc_files:
|
134
131
|
- LICENSE.txt
|
135
132
|
- README.rdoc
|
136
|
-
files:
|
133
|
+
files:
|
137
134
|
- .document
|
138
135
|
- Gemfile
|
139
136
|
- History.rdoc
|
@@ -179,36 +176,34 @@ files:
|
|
179
176
|
- test_orm/rails/config/enviroment.rb
|
180
177
|
has_rdoc: true
|
181
178
|
homepage: http://github.com/ithouse/lolita-menu
|
182
|
-
licenses:
|
179
|
+
licenses:
|
183
180
|
- MIT
|
184
181
|
post_install_message:
|
185
182
|
rdoc_options: []
|
186
|
-
|
187
|
-
require_paths:
|
183
|
+
require_paths:
|
188
184
|
- lib
|
189
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
185
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
190
186
|
none: false
|
191
|
-
requirements:
|
192
|
-
- -
|
193
|
-
- !ruby/object:Gem::Version
|
194
|
-
|
195
|
-
segments:
|
187
|
+
requirements:
|
188
|
+
- - ! '>='
|
189
|
+
- !ruby/object:Gem::Version
|
190
|
+
version: '0'
|
191
|
+
segments:
|
196
192
|
- 0
|
197
|
-
|
198
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
193
|
+
hash: 276747599
|
194
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
199
195
|
none: false
|
200
|
-
requirements:
|
201
|
-
- -
|
202
|
-
- !ruby/object:Gem::Version
|
203
|
-
version:
|
196
|
+
requirements:
|
197
|
+
- - ! '>='
|
198
|
+
- !ruby/object:Gem::Version
|
199
|
+
version: '0'
|
204
200
|
requirements: []
|
205
|
-
|
206
201
|
rubyforge_project:
|
207
|
-
rubygems_version: 1.6.
|
202
|
+
rubygems_version: 1.6.2
|
208
203
|
signing_key:
|
209
204
|
specification_version: 3
|
210
205
|
summary: Menu managing plugin for Lolita.
|
211
|
-
test_files:
|
206
|
+
test_files:
|
212
207
|
- spec/controllers/menu_items_controller_spec.rb
|
213
208
|
- spec/models/menu_item_spec.rb
|
214
209
|
- spec/models/menu_spec.rb
|