menumatic 0.1.4 → 0.1.5
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/Gemfile +1 -1
- data/Gemfile.lock +33 -4
- data/README.md +3 -6
- data/lib/menumatic/helpers/navigation_helper.rb +1 -1
- data/lib/menumatic/navigation/item/renderers.rb +7 -8
- data/lib/menumatic/navigation.rb +2 -0
- data/lib/menumatic/version.rb +1 -1
- data/lib/menumatic.rb +1 -0
- data/spec/factories.rb +0 -6
- data/spec/group_spec.rb +22 -0
- data/spec/link_spec.rb +20 -16
- data/spec/navigation_helper_spec.rb +20 -0
- data/spec/navigation_spec.rb +30 -0
- data/spec/renderer_spec.rb +50 -0
- data/spec/spec_helper.rb +6 -1
- metadata +12 -4
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,21 @@
|
|
1
|
+
GIT
|
2
|
+
remote: https://github.com/jnicklas/capybara.git
|
3
|
+
revision: 47dbcdfdf0ae5896586f0131250a64b2553115a0
|
4
|
+
specs:
|
5
|
+
capybara (0.4.1.1)
|
6
|
+
celerity (>= 0.7.9)
|
7
|
+
culerity (>= 0.2.4)
|
8
|
+
mime-types (>= 1.16)
|
9
|
+
nokogiri (>= 1.3.3)
|
10
|
+
rack (>= 1.0.0)
|
11
|
+
rack-test (>= 0.5.4)
|
12
|
+
selenium-webdriver (>= 0.0.27)
|
13
|
+
xpath (~> 0.1.3)
|
14
|
+
|
1
15
|
PATH
|
2
16
|
remote: .
|
3
17
|
specs:
|
4
|
-
menumatic (0.
|
18
|
+
menumatic (0.1.4)
|
5
19
|
|
6
20
|
GEM
|
7
21
|
remote: http://rubygems.org/
|
@@ -39,17 +53,24 @@ GEM
|
|
39
53
|
ZenTest (>= 4.4.1)
|
40
54
|
autotest-growl (0.2.9)
|
41
55
|
builder (2.1.2)
|
56
|
+
celerity (0.8.8)
|
57
|
+
childprocess (0.1.7)
|
58
|
+
ffi (~> 0.6.3)
|
59
|
+
culerity (0.2.15)
|
42
60
|
diff-lcs (1.1.2)
|
43
61
|
erubis (2.6.6)
|
44
62
|
abstract (>= 1.0.0)
|
45
|
-
|
63
|
+
ffi (0.6.3)
|
64
|
+
rake (>= 0.8.7)
|
46
65
|
i18n (0.5.0)
|
66
|
+
json_pure (1.5.1)
|
47
67
|
mail (2.2.15)
|
48
68
|
activesupport (>= 2.3.6)
|
49
69
|
i18n (>= 0.4.0)
|
50
70
|
mime-types (~> 1.16)
|
51
71
|
treetop (~> 1.4.8)
|
52
72
|
mime-types (1.16)
|
73
|
+
nokogiri (1.4.4)
|
53
74
|
polyglot (0.3.1)
|
54
75
|
rack (1.2.1)
|
55
76
|
rack-mount (0.6.13)
|
@@ -78,10 +99,18 @@ GEM
|
|
78
99
|
rspec-expectations (2.5.0)
|
79
100
|
diff-lcs (~> 1.1.2)
|
80
101
|
rspec-mocks (2.5.0)
|
102
|
+
rubyzip (0.9.4)
|
103
|
+
selenium-webdriver (0.1.3)
|
104
|
+
childprocess (~> 0.1.5)
|
105
|
+
ffi (~> 0.6.3)
|
106
|
+
json_pure
|
107
|
+
rubyzip
|
81
108
|
thor (0.14.6)
|
82
109
|
treetop (1.4.9)
|
83
110
|
polyglot (>= 0.3.1)
|
84
111
|
tzinfo (0.3.24)
|
112
|
+
xpath (0.1.3)
|
113
|
+
nokogiri (~> 1.3)
|
85
114
|
|
86
115
|
PLATFORMS
|
87
116
|
ruby
|
@@ -89,7 +118,7 @@ PLATFORMS
|
|
89
118
|
DEPENDENCIES
|
90
119
|
autotest
|
91
120
|
autotest-growl
|
92
|
-
|
121
|
+
capybara!
|
93
122
|
menumatic!
|
94
|
-
rails (
|
123
|
+
rails (= 3.0.5)
|
95
124
|
rspec
|
data/README.md
CHANGED
@@ -55,7 +55,7 @@ Inside your navigation file, you can then define the structure of your
|
|
55
55
|
navigation, here is an example taken from the [Menumatic example
|
56
56
|
application](http://github.com/thetron/menumatic-sample-application):
|
57
57
|
|
58
|
-
navigate_to "Home", home_path, :active_on => [
|
58
|
+
navigate_to "Home", home_path, :active_on => [home_path, root_path]
|
59
59
|
navigate_to "About", about_path
|
60
60
|
navigate_to "Store", store_on_special_path do |store|
|
61
61
|
store.navigate_to "On special", store_on_special_path
|
@@ -135,11 +135,8 @@ some feedback!
|
|
135
135
|
|
136
136
|
This is what I have planned for some future releases:
|
137
137
|
|
138
|
-
*
|
139
|
-
|
140
|
-
big priority for Menumatic.
|
141
|
-
|
142
|
-
* __More configuration options__
|
138
|
+
* Better test coverage
|
139
|
+
* More configuration options
|
143
140
|
|
144
141
|
|
145
142
|
# Credits
|
@@ -16,7 +16,7 @@ module Menumatic
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def sitemap(document, navigation_id = "application", options = {})
|
19
|
-
navigation = load_navigation(navigation_id)
|
19
|
+
navigation = Menumatic::Navigation::Base.load_navigation(navigation_id)
|
20
20
|
navigation.root.render_sitemap(document, request, options)
|
21
21
|
end
|
22
22
|
end
|
@@ -39,9 +39,8 @@ module Menumatic
|
|
39
39
|
# render link
|
40
40
|
link = ""
|
41
41
|
link = link_to(self.label, self.destination, self.html_options).html_safe if self.is_link? && !options[:group]
|
42
|
-
|
43
42
|
if on_valid_level?(options[:levels], options[:current_level])
|
44
|
-
if options[:current_level] == 1 || (self.is_group? && options[:group] == self.group_id)
|
43
|
+
if (options[:current_level] == 1 && self.is_group?) || (self.is_group? && options[:group] == self.group_id)
|
45
44
|
list.html_safe
|
46
45
|
elsif options[:show] == :all || self.is_active?(request)
|
47
46
|
content_tag(options[:item_tag], link.to_s + list.to_s, html_options.merge_with_join(self.wrapper_options)).to_s.html_safe
|
@@ -95,26 +94,26 @@ module Menumatic
|
|
95
94
|
end
|
96
95
|
|
97
96
|
def depth_count(request, options = {})
|
98
|
-
return options[:levels].count
|
97
|
+
return options[:levels].count if options[:levels] && !options[:levels].empty?
|
99
98
|
count_active_descendants(request)
|
100
99
|
end
|
101
100
|
|
102
101
|
def paths_match?(request)
|
103
102
|
if self.is_link?
|
104
103
|
self.active_paths.each do |path|
|
105
|
-
return true if path.is_a?(Regexp) && (request.fullpath =~ path || request.url =~ path)
|
106
|
-
return true if path.is_a?(String) && (request.fullpath == path || request.url == path)
|
104
|
+
return true if path.is_a?(Regexp) && (request.fullpath.split('?').first =~ path || request.url.split('?').first =~ path)
|
105
|
+
return true if path.is_a?(String) && (request.fullpath.split('?').first == path || request.url.split('?').first == path)
|
107
106
|
end
|
108
|
-
return request.fullpath == self.destination || request.url == self.destination if self.active_paths.empty?
|
107
|
+
return request.fullpath.split('?').first == self.destination || request.url.split('?').first == self.destination if self.active_paths.empty?
|
109
108
|
end
|
110
109
|
end
|
111
110
|
|
112
111
|
def on_valid_level?(levels, current_level)
|
113
|
-
levels_to_i(levels).include?(current_level-1)
|
112
|
+
levels.nil? || levels.empty? || levels_to_i(levels).include?(current_level-1)
|
114
113
|
end
|
115
114
|
|
116
115
|
def levels_to_i(levels_in_words)
|
117
|
-
levels_in_words.map{ |word| word.is_a?(Symbol) ? @@level_options.index(word.to_sym) + 1 : word }
|
116
|
+
levels_in_words.map{ |word| word.is_a?(Symbol) ? @@level_options.index(word.to_sym) + 1 : word } if levels_in_words
|
118
117
|
end
|
119
118
|
end
|
120
119
|
end
|
data/lib/menumatic/navigation.rb
CHANGED
@@ -6,6 +6,8 @@ module Menumatic
|
|
6
6
|
attr_accessor :id, :root
|
7
7
|
|
8
8
|
class << self
|
9
|
+
include Rails.application.routes.url_helpers if Rails && Rails.application
|
10
|
+
|
9
11
|
def navigate_to(label, destination, options = {})
|
10
12
|
if block_given?
|
11
13
|
item = self.get_instance.root.navigate_to(label, destination, options, &Proc.new)
|
data/lib/menumatic/version.rb
CHANGED
data/lib/menumatic.rb
CHANGED
data/spec/factories.rb
CHANGED
data/spec/group_spec.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Menumatic::Navigation::Item::Group do
|
4
|
+
before :each do
|
5
|
+
@group = Menumatic::Navigation::Item::Group.new(:test_group, {})
|
6
|
+
@group.navigate_to("Home", "/home")
|
7
|
+
@group.navigate_to("About", "/about")
|
8
|
+
@group.navigate_to("Contact us", "/contact_us")
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should have a group ID" do
|
12
|
+
@group.respond_to?(:group_id).should == true
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should render a list containing its child items" do
|
16
|
+
html = Capybara.string @group.render(@request)
|
17
|
+
html.should have_selector('ul.level_1')
|
18
|
+
html.should have_selector('ul.level_1 > li > a[href="/home"]')
|
19
|
+
html.should have_selector('ul.level_1 > li > a[href="/about"]')
|
20
|
+
html.should have_selector('ul.level_1 > li > a[href="/contact_us"]')
|
21
|
+
end
|
22
|
+
end
|
data/spec/link_spec.rb
CHANGED
@@ -1,17 +1,12 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
-
require 'active_resource/http_mock'
|
3
2
|
|
4
3
|
describe Menumatic::Navigation::Item::Link do
|
5
4
|
|
6
5
|
before :each do
|
7
6
|
@label = "Search"
|
8
|
-
@destination =
|
7
|
+
@destination = @request.fullpath
|
9
8
|
@options = {}
|
10
9
|
@link = Menumatic::Navigation::Item::Link.new(@label, @destination, @options)
|
11
|
-
|
12
|
-
ActiveResource::HttpMock.respond_to do |mock|
|
13
|
-
mock.get '/search', {}, ''
|
14
|
-
end
|
15
10
|
end
|
16
11
|
|
17
12
|
it "should have a label" do
|
@@ -33,20 +28,29 @@ describe Menumatic::Navigation::Item::Link do
|
|
33
28
|
end
|
34
29
|
|
35
30
|
it "should be active when destination is the same as the request path" do
|
36
|
-
|
37
|
-
|
31
|
+
@link.is_active?(@request).should == true
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should be active when destination is the same as the request path and the request path includes a get param" do
|
35
|
+
@request.stub!(:fullpath).and_return("/search?text=a%20search&page=1")
|
36
|
+
@link.is_active?(@request).should == true
|
38
37
|
end
|
39
38
|
|
40
39
|
it "should not be active when destination is not the same as the request path" do
|
41
|
-
@link.
|
40
|
+
@link.destination = "/home"
|
41
|
+
@link.is_active?(@request).should == false
|
42
42
|
end
|
43
43
|
|
44
|
-
it "should be able to parent links"
|
45
|
-
|
44
|
+
it "should be able to parent links" do
|
45
|
+
@link.navigate_to("Contact us", "/contact_us")
|
46
|
+
@link.items.first.is_link?.should == true
|
47
|
+
@link.items.first.label.should == "Contact us"
|
48
|
+
@link.items.first.destination.should == "/contact_us"
|
49
|
+
end
|
46
50
|
|
47
|
-
it "should
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
51
|
+
it "should be able to parent groups" do
|
52
|
+
@link.group(:sidebar)
|
53
|
+
@link.items.first.is_group?.should == true
|
54
|
+
@link.items.first.group_id.should == :sidebar
|
55
|
+
end
|
52
56
|
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Menumatic::Navigation::Item::Group do
|
4
|
+
before :each do
|
5
|
+
# build a reasonably complex navigation and ensure that it's
|
6
|
+
# properly stored for retreival
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should be reloadable from it's ID"
|
10
|
+
it "should reload between renders"
|
11
|
+
it "should have a depth of 1 if no items are active"
|
12
|
+
it "should have a depth of 1 if a first-level child is active"
|
13
|
+
it "should have a depth of 2 if a second-level child is active"
|
14
|
+
it "should have a depth of 3 if a third-level child is active"
|
15
|
+
it "should have each level labelled in sequence starting at 1"
|
16
|
+
it "should be able to display all links"
|
17
|
+
it "should be able to render a different list tag"
|
18
|
+
it "should be able to render a different item tag"
|
19
|
+
it "should render different "
|
20
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Menumatic::Navigation::Item::Base do
|
4
|
+
before :each do
|
5
|
+
@item = Menumatic::Navigation::Item::Base.new()
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should have items" do
|
9
|
+
@item.respond_to?(:items).should == true
|
10
|
+
@item.items.is_a?(Array).should == true
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should have html options" do
|
14
|
+
@item.respond_to?(:html_options).should == true
|
15
|
+
@item.html_options.is_a?(Hash).should == true
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should have wrapper options" do
|
19
|
+
@item.respond_to?(:wrapper_options).should == true
|
20
|
+
@item.wrapper_options.is_a?(Hash).should == true
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should test if it is a link" do
|
24
|
+
@item.respond_to?(:is_link?).should == true
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should test if it is a group" do
|
28
|
+
@item.respond_to?(:is_group?).should == true
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Menumatic::Navigation::Item::Renderers do
|
4
|
+
before :each do
|
5
|
+
@label = "Search"
|
6
|
+
@destination = @request.fullpath
|
7
|
+
@options = {}
|
8
|
+
@link = Menumatic::Navigation::Item::Link.new(@label, @destination, @options)
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should render a list item containing only a link when it has no children" do
|
12
|
+
html = Capybara.string @link.render(@request)
|
13
|
+
html.should have_selector('li a')
|
14
|
+
html.should_not have_selector('li ul')
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should render a list item containing only a link when it has no active descendants" do
|
18
|
+
@link.navigate_to("Child link", "/page/something_unrelated")
|
19
|
+
@link.destination = "/page"
|
20
|
+
html = Capybara.string @link.render(@request)
|
21
|
+
html.should have_selector('li a')
|
22
|
+
html.should_not have_selector('li ul')
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should render a list item containing an active link when active" do
|
26
|
+
html = Capybara.string @link.render(@request)
|
27
|
+
html.should have_selector('li.active a')
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should render a list item containing a list of its children when active" do
|
31
|
+
@link.navigate_to("Child link 1", "/page/child_1")
|
32
|
+
@link.navigate_to("Child link 2", "/page/child_2")
|
33
|
+
html = Capybara.string @link.render(@request)
|
34
|
+
html.should have_selector('li ul li a[href="/page/child_1"]')
|
35
|
+
html.should have_selector('li ul li a[href="/page/child_2"]')
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should render a list item containing an active link and a list of its children when it has an active descendant" do
|
39
|
+
@link.destination = "/home"
|
40
|
+
|
41
|
+
@link.navigate_to "Child link 1", "/page/child_1" do |child|
|
42
|
+
child.navigate_to "Search", @request.fullpath
|
43
|
+
end
|
44
|
+
@link.navigate_to "Child link 2", "/page/child_2"
|
45
|
+
|
46
|
+
html = Capybara.string @link.render(@request)
|
47
|
+
html.should have_selector('li > ul.active')
|
48
|
+
html.should have_selector("li > ul.active > li.active > ul.active > li.active > a[href='#{@request.fullpath}']")
|
49
|
+
end
|
50
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,9 +1,14 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'bundler/setup'
|
3
3
|
|
4
|
+
require 'capybara'
|
4
5
|
require 'action_controller'
|
5
6
|
require 'menumatic'
|
6
7
|
|
7
8
|
RSpec.configure do |config|
|
8
|
-
|
9
|
+
config.before :each do
|
10
|
+
@request = mock(:request)
|
11
|
+
@request.stub!(:fullpath).and_return("/search")
|
12
|
+
@request.stub!(:url).and_return("http://test.menumatic.com/search")
|
13
|
+
end
|
9
14
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: menumatic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 17
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 5
|
10
|
+
version: 0.1.5
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Nicholas Bruning
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-03-
|
18
|
+
date: 2011-03-13 00:00:00 +11:00
|
19
19
|
default_executable:
|
20
20
|
dependencies: []
|
21
21
|
|
@@ -63,7 +63,11 @@ files:
|
|
63
63
|
- lib/menumatic/version.rb
|
64
64
|
- menumatic.gemspec
|
65
65
|
- spec/factories.rb
|
66
|
+
- spec/group_spec.rb
|
66
67
|
- spec/link_spec.rb
|
68
|
+
- spec/navigation_helper_spec.rb
|
69
|
+
- spec/navigation_spec.rb
|
70
|
+
- spec/renderer_spec.rb
|
67
71
|
- spec/spec_helper.rb
|
68
72
|
has_rdoc: true
|
69
73
|
homepage: http://github.com/thetron/menumatic
|
@@ -101,5 +105,9 @@ specification_version: 3
|
|
101
105
|
summary: Menumatic is a Rails 3 gem which aims to simplify building complex website navigation
|
102
106
|
test_files:
|
103
107
|
- spec/factories.rb
|
108
|
+
- spec/group_spec.rb
|
104
109
|
- spec/link_spec.rb
|
110
|
+
- spec/navigation_helper_spec.rb
|
111
|
+
- spec/navigation_spec.rb
|
112
|
+
- spec/renderer_spec.rb
|
105
113
|
- spec/spec_helper.rb
|