nav 0.6.0 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/nav/builder.rb +7 -12
- data/lib/nav/version.rb +2 -2
- data/lib/nav.rb +1 -1
- data/test/nav_test.rb +1 -16
- data/test/test_helper.rb +2 -2
- metadata +6 -6
data/lib/nav/builder.rb
CHANGED
@@ -3,7 +3,7 @@ module Nav
|
|
3
3
|
def initialize( template, options = {} )
|
4
4
|
@template, @options = template, options
|
5
5
|
@actions = []
|
6
|
-
|
6
|
+
|
7
7
|
yield self if block_given?
|
8
8
|
end
|
9
9
|
|
@@ -26,11 +26,8 @@ module Nav
|
|
26
26
|
wrapper_options = {
|
27
27
|
:current => html_options.delete(:current),
|
28
28
|
:disabled => html_options.delete(:disabled),
|
29
|
-
:force_current => html_options.delete(:force_current),
|
30
|
-
:prepend => html_options.delete(:prepend),
|
31
|
-
:append => html_options.delete(:append)
|
32
29
|
}
|
33
|
-
|
30
|
+
|
34
31
|
[ link_to(name, options, html_options), wrapper_options, options ]
|
35
32
|
end
|
36
33
|
end
|
@@ -53,29 +50,27 @@ module Nav
|
|
53
50
|
def action_wrapper( contents, options = {}, url_for_options = {} )
|
54
51
|
present = [contents, options, url_for_options] # the one we're dealing with
|
55
52
|
present_index = @actions.index( present )
|
56
|
-
|
53
|
+
|
57
54
|
before_present = @actions.at( present_index - 1 ) if present_index > 0
|
58
55
|
after_present = @actions.at( present_index + 1 ) if present_index < @actions.size
|
59
56
|
|
60
57
|
classes = []
|
58
|
+
classes << options[:class] if options.key?(:class)
|
61
59
|
classes << "first" if present == @actions.first
|
62
60
|
classes << "after_first" if present_index == 1
|
63
61
|
classes << "before_last" if present == @actions[-2]
|
64
62
|
classes << "last" if present == @actions.last
|
65
63
|
classes << "current" if current?( *present )
|
66
|
-
classes << "disabled" if options
|
64
|
+
classes << "disabled" if options[:disabled]
|
67
65
|
classes << "before_current" if after_present && current?( *after_present )
|
68
66
|
classes << "after_current" if before_present && current?( *before_present )
|
69
|
-
# classes << classes.join("_") if classes.any?
|
70
|
-
|
71
|
-
contents = options[:prepend].to_s + contents + options[:append].to_s
|
72
67
|
|
73
68
|
content_tag :li, contents.html_safe, :class => classes.join(" ")
|
74
69
|
end
|
75
70
|
|
76
71
|
def current?( contents, options = {}, url_for_options = {} )
|
77
72
|
current = options[:current]
|
78
|
-
|
73
|
+
|
79
74
|
is_current = case current
|
80
75
|
when TrueClass then true
|
81
76
|
when Regexp then request_uri.match(current).nil? ? false : true
|
@@ -83,7 +78,7 @@ module Nav
|
|
83
78
|
else false
|
84
79
|
end
|
85
80
|
|
86
|
-
return true if is_current && !options[:disabled]
|
81
|
+
return true if is_current && !options[:disabled]
|
87
82
|
return true if is_current || !url_for_options.is_a?(Symbol) && @template.current_page?(url_for_options) && url_for_options != {} && !options[:disabled]
|
88
83
|
|
89
84
|
false
|
data/lib/nav/version.rb
CHANGED
data/lib/nav.rb
CHANGED
data/test/nav_test.rb
CHANGED
@@ -1,13 +1,7 @@
|
|
1
1
|
require_relative 'test_helper'
|
2
|
-
puts 'awesome'
|
3
2
|
|
4
3
|
describe Nav do
|
5
4
|
|
6
|
-
# <ul id="nav">
|
7
|
-
# <li class="">before <a href="/">test</a></li>
|
8
|
-
# <li class="">before <a href="#" onclick="new Ajax.Request('/', {asynchronous:true, evalScripts:true, parameters:'authenticity_token=' + encodeURIComponent('7016ef6fd7413d836cd720a6071e22e4f14e0212')}); return false;">test</a></li>
|
9
|
-
# </ul>
|
10
|
-
|
11
5
|
before do
|
12
6
|
@view = ActionView::Base.new
|
13
7
|
@view.output_buffer = ''
|
@@ -30,14 +24,5 @@ describe Nav do
|
|
30
24
|
assert_match(/<a.*href=\"\/link\">my-link<\/a>/, m)
|
31
25
|
end
|
32
26
|
|
33
|
-
|
34
|
-
m = @view.nav { |m| m.action('my-link', '/link', :prepend => 'something before') }
|
35
|
-
assert_match(/<li.*>something before<a/, m)
|
36
|
-
end
|
37
|
-
|
38
|
-
it "should display :append options after the link" do
|
39
|
-
m = @view.nav { |m| m.action('my-link', '/link', :append => 'something after') }
|
40
|
-
assert_match(/<\/a>something after<\/li>/, m)
|
41
|
-
end
|
42
|
-
|
27
|
+
# TODO: Add test cases for actions with blocks
|
43
28
|
end
|
data/test/test_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nav
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-02-
|
12
|
+
date: 2012-02-29 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: actionpack
|
16
|
-
requirement: &
|
16
|
+
requirement: &70286083358500 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '3'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70286083358500
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rr
|
27
|
-
requirement: &
|
27
|
+
requirement: &70286083357760 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,7 +32,7 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70286083357760
|
36
36
|
description: Simple nagivation builder
|
37
37
|
email:
|
38
38
|
executables: []
|