menumatic 0.1.5 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +1 -1
- data/Gemfile.lock +3 -2
- data/README.md +1 -1
- data/lib/menumatic.rb +1 -3
- data/lib/menumatic/exceptions.rb +22 -0
- data/lib/menumatic/navigation.rb +8 -4
- data/lib/menumatic/navigation/item/renderers.rb +18 -1
- data/lib/menumatic/rails/rendering.rb +1 -1
- data/lib/menumatic/version.rb +1 -1
- data/menumatic.gemspec +7 -2
- data/spec/navigation_helper_spec.rb +72 -16
- metadata +55 -9
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -15,7 +15,8 @@ GIT
|
|
15
15
|
PATH
|
16
16
|
remote: .
|
17
17
|
specs:
|
18
|
-
menumatic (0.
|
18
|
+
menumatic (0.2.0)
|
19
|
+
rails (>= 3.0.4)
|
19
20
|
|
20
21
|
GEM
|
21
22
|
remote: http://rubygems.org/
|
@@ -120,5 +121,5 @@ DEPENDENCIES
|
|
120
121
|
autotest-growl
|
121
122
|
capybara!
|
122
123
|
menumatic!
|
123
|
-
rails (
|
124
|
+
rails (>= 3.0.4)
|
124
125
|
rspec
|
data/README.md
CHANGED
data/lib/menumatic.rb
CHANGED
@@ -13,9 +13,6 @@ module Menumatic
|
|
13
13
|
end
|
14
14
|
autoload :Base, 'menumatic/navigation'
|
15
15
|
end
|
16
|
-
|
17
|
-
#autoload :Mapper, 'menumatic/action_dispatch/routing/mapper'
|
18
|
-
#autoload :SitemapController, '../app/controllers/menumatic
|
19
16
|
end
|
20
17
|
|
21
18
|
require 'rails'
|
@@ -23,3 +20,4 @@ require 'menumatic/rails/routes'
|
|
23
20
|
require 'menumatic/rails/rendering'
|
24
21
|
require 'menumatic/engine'
|
25
22
|
require 'menumatic/hash'
|
23
|
+
require 'menumatic/exceptions'
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Menumatic
|
2
|
+
# A general Menumatic Exception
|
3
|
+
class Error < StandardError; end
|
4
|
+
|
5
|
+
# Raised when a navigation cannot be found, usually from load_navigation
|
6
|
+
class NavigationNotFound < Error
|
7
|
+
|
8
|
+
|
9
|
+
def initialize(navigation = nil)
|
10
|
+
@navigation = navigation
|
11
|
+
@default_message = "No navigation not specified in call to render()."
|
12
|
+
end
|
13
|
+
|
14
|
+
def to_s
|
15
|
+
if @navigation
|
16
|
+
"Navigation file not found: #{@navigation}"
|
17
|
+
else
|
18
|
+
@default_message
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/lib/menumatic/navigation.rb
CHANGED
@@ -42,10 +42,14 @@ module Menumatic
|
|
42
42
|
end
|
43
43
|
|
44
44
|
def load_navigation(navigation_id)
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
45
|
+
if File.exists?("app/navigation/#{navigation_id}_navigation.rb")
|
46
|
+
# Eager load the requested navgation (allows for use of normal if/unless statements)
|
47
|
+
Menumatic::Navigation::Base.destroy_all
|
48
|
+
load "app/navigation/#{navigation_id}_navigation.rb"
|
49
|
+
Menumatic::Navigation::Base.get(navigation_id)
|
50
|
+
else
|
51
|
+
raise Menumatic::NavigationNotFound, "app/navigation/#{navigation_id}_navigation.rb"
|
52
|
+
end
|
49
53
|
end
|
50
54
|
end
|
51
55
|
|
@@ -20,6 +20,9 @@ module Menumatic
|
|
20
20
|
options[:wrapper_tag] ||= :ul
|
21
21
|
options[:item_tag] ||= :li
|
22
22
|
|
23
|
+
# 1.0 roadmap - rendering should be divided into these two methods
|
24
|
+
render_as_link(request, options) || render_as_group(request, options)
|
25
|
+
|
23
26
|
# render list
|
24
27
|
list = self.items.map { |item| item.render(request, options) }.join("")
|
25
28
|
html_options[:class] ||= ""
|
@@ -95,7 +98,8 @@ module Menumatic
|
|
95
98
|
|
96
99
|
def depth_count(request, options = {})
|
97
100
|
return options[:levels].count if options[:levels] && !options[:levels].empty?
|
98
|
-
count_active_descendants(request)
|
101
|
+
depth = count_active_descendants(request)
|
102
|
+
(depth > 0) ? depth : 1
|
99
103
|
end
|
100
104
|
|
101
105
|
def paths_match?(request)
|
@@ -115,6 +119,19 @@ module Menumatic
|
|
115
119
|
def levels_to_i(levels_in_words)
|
116
120
|
levels_in_words.map{ |word| word.is_a?(Symbol) ? @@level_options.index(word.to_sym) + 1 : word } if levels_in_words
|
117
121
|
end
|
122
|
+
|
123
|
+
private
|
124
|
+
def render_as_link(request, options = {})
|
125
|
+
if self.is_link?
|
126
|
+
#... todo
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
def render_as_group(request, options = {})
|
131
|
+
if self.is_group?
|
132
|
+
#... todo
|
133
|
+
end
|
134
|
+
end
|
118
135
|
end
|
119
136
|
end
|
120
137
|
end
|
@@ -5,7 +5,7 @@ module ActionView
|
|
5
5
|
# for :navigation, which will render the selected navigation from the
|
6
6
|
# `app/navigation` directory.
|
7
7
|
def render_with_navigation_option(options = {}, locals = {}, &block)
|
8
|
-
if options.has_key? :navigation
|
8
|
+
if options.respond_to?(:has_key?) && options.has_key?(:navigation)
|
9
9
|
navigation_id = options[:navigation]
|
10
10
|
options.delete(:navigation)
|
11
11
|
menumatic(navigation_id, options)
|
data/lib/menumatic/version.rb
CHANGED
data/menumatic.gemspec
CHANGED
@@ -9,11 +9,16 @@ Gem::Specification.new do |s|
|
|
9
9
|
s.authors = ["Nicholas Bruning"]
|
10
10
|
s.email = ["nicholas@bruning.com.au"]
|
11
11
|
s.homepage = "http://github.com/thetron/menumatic"
|
12
|
-
s.summary = %q{Menumatic is a Rails 3 gem which
|
13
|
-
s.description = %q{Menumatic is a Rails 3
|
12
|
+
s.summary = %q{Menumatic is a Rails 3 gem which simplifies building complex website navigation}
|
13
|
+
s.description = %q{Menumatic is a Rails 3 gem which simplifies the development of complex website navigation, producing semantic, usable navigation menus.}
|
14
14
|
|
15
15
|
s.rubyforge_project = "menumatic"
|
16
16
|
|
17
|
+
s.add_dependency 'rails', '>= 3.0.4'
|
18
|
+
|
19
|
+
s.add_development_dependency 'rspec'
|
20
|
+
s.add_development_dependency 'rails', '>= 3.0.4'
|
21
|
+
|
17
22
|
s.files = `git ls-files`.split("\n")
|
18
23
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
24
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
@@ -1,20 +1,76 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe Menumatic::
|
3
|
+
describe Menumatic::Helpers::NavigationHelper do
|
4
4
|
before :each do
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
it "should
|
18
|
-
|
19
|
-
|
5
|
+
@navigation = Menumatic::Navigation::Base::new(:application).root
|
6
|
+
@navigation.navigate_to "Home", "/home"
|
7
|
+
@navigation.navigate_to "Store", "/store" do |store|
|
8
|
+
store.navigate_to "Categories", "/store/categories" do |categories|
|
9
|
+
categories.navigate_to "Blue things", "/store/categories/blue"
|
10
|
+
categories.navigate_to "Red things", "/store/categories/red"
|
11
|
+
end
|
12
|
+
store.navigate_to "Specials", "/store/specials"
|
13
|
+
end
|
14
|
+
@navigation.navigate_to "Contact us", "/contact_us"
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should have a depth of 1 if no items are active" do
|
18
|
+
@navigation.depth_count(@request).should == 1
|
19
|
+
end
|
20
|
+
|
21
|
+
|
22
|
+
it "should have a depth of 1 if a first-level child is active" do
|
23
|
+
@request.stub!(:fullpath).and_return("/contact_us")
|
24
|
+
@request.stub!(:url).and_return("http://test.menumatic.com/contact_us")
|
25
|
+
@navigation.depth_count(@request).should == 1
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should have a depth of 2 if a second-level child is active" do
|
29
|
+
@request.stub!(:fullpath).and_return("/store/specials")
|
30
|
+
@request.stub!(:url).and_return("http://test.menumatic.com/store/specials")
|
31
|
+
@navigation.depth_count(@request).should == 2
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should have a depth of 3 if a third-level child is active" do
|
35
|
+
@request.stub!(:fullpath).and_return("/store/categories/red")
|
36
|
+
@request.stub!(:url).and_return("http://test.menumatic.com/store/categories/red")
|
37
|
+
@navigation.depth_count(@request).should == 3
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should have each level labelled in sequence starting at 1" do
|
41
|
+
@request.stub!(:fullpath).and_return("/store/categories/red")
|
42
|
+
@request.stub!(:url).and_return("http://test.menumatic.com/store/categories/red")
|
43
|
+
Capybara::string(@navigation.render(@request)).should have_selector("ul.level_1 > li > ul.level_2 > li ul.level_3")
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should be able to display all links" do
|
47
|
+
html = Capybara::string(@navigation.render(@request, :show => :all))
|
48
|
+
html.should have_selector('a[href="/home"]')
|
49
|
+
html.should have_selector('a[href="/store"]')
|
50
|
+
html.should have_selector('a[href="/store/categories"]')
|
51
|
+
html.should have_selector('a[href="/store/categories/blue"]')
|
52
|
+
html.should have_selector('a[href="/store/categories/red"]')
|
53
|
+
html.should have_selector('a[href="/store/specials"]')
|
54
|
+
html.should have_selector('a[href="/contact_us"]')
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should be able to render a different list tag" do
|
58
|
+
html = Capybara::string(@navigation.render(@request, :wrapper_tag => :nav))
|
59
|
+
html.should have_selector('nav.level_1')
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should be able to render a different item tag" do
|
63
|
+
html = Capybara::string(@navigation.render(@request, :item_tag => :span))
|
64
|
+
html.should have_selector('ul.level_1 > span > a[href="/home"]')
|
65
|
+
end
|
66
|
+
|
67
|
+
it "should accept a custom HTML class" do
|
68
|
+
html = Capybara::string(@navigation.render(@request, :class => "additional_test_class"))
|
69
|
+
html.should have_selector('ul.additional_test_class')
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should accept a custom HTML ID" do
|
73
|
+
html = Capybara::string(@navigation.render(@request, :id => "navigation_test_id"))
|
74
|
+
html.should have_selector('ul#navigation_test_id')
|
75
|
+
end
|
20
76
|
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: 23
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
8
|
+
- 2
|
9
|
+
- 0
|
10
|
+
version: 0.2.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Nicholas Bruning
|
@@ -15,11 +15,56 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-03-
|
18
|
+
date: 2011-03-15 00:00:00 +11:00
|
19
19
|
default_executable:
|
20
|
-
dependencies:
|
21
|
-
|
22
|
-
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: rails
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 15
|
30
|
+
segments:
|
31
|
+
- 3
|
32
|
+
- 0
|
33
|
+
- 4
|
34
|
+
version: 3.0.4
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: *id001
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: rspec
|
39
|
+
prerelease: false
|
40
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
hash: 3
|
46
|
+
segments:
|
47
|
+
- 0
|
48
|
+
version: "0"
|
49
|
+
type: :development
|
50
|
+
version_requirements: *id002
|
51
|
+
- !ruby/object:Gem::Dependency
|
52
|
+
name: rails
|
53
|
+
prerelease: false
|
54
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
55
|
+
none: false
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
hash: 15
|
60
|
+
segments:
|
61
|
+
- 3
|
62
|
+
- 0
|
63
|
+
- 4
|
64
|
+
version: 3.0.4
|
65
|
+
type: :development
|
66
|
+
version_requirements: *id003
|
67
|
+
description: Menumatic is a Rails 3 gem which simplifies the development of complex website navigation, producing semantic, usable navigation menus.
|
23
68
|
email:
|
24
69
|
- nicholas@bruning.com.au
|
25
70
|
executables: []
|
@@ -49,6 +94,7 @@ files:
|
|
49
94
|
- lib/menumatic.rb
|
50
95
|
- lib/menumatic/.DS_Store
|
51
96
|
- lib/menumatic/engine.rb
|
97
|
+
- lib/menumatic/exceptions.rb
|
52
98
|
- lib/menumatic/hash.rb
|
53
99
|
- lib/menumatic/helpers/navigation_helper.rb
|
54
100
|
- lib/menumatic/navigation.rb
|
@@ -102,7 +148,7 @@ rubyforge_project: menumatic
|
|
102
148
|
rubygems_version: 1.3.7
|
103
149
|
signing_key:
|
104
150
|
specification_version: 3
|
105
|
-
summary: Menumatic is a Rails 3 gem which
|
151
|
+
summary: Menumatic is a Rails 3 gem which simplifies building complex website navigation
|
106
152
|
test_files:
|
107
153
|
- spec/factories.rb
|
108
154
|
- spec/group_spec.rb
|