xebec 2.6.0 → 2.6.1
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/.gitignore +1 -0
- data/developer_tasks/doc.rake +3 -3
- data/developer_tasks/test.rake +1 -1
- data/doc/example_app/app/controllers/application_controller.rb +4 -4
- data/doc/example_app/app/controllers/pages_controller.rb +1 -1
- data/doc/example_app/app/controllers/projects_controller.rb +9 -9
- data/doc/example_app/app/views/layouts/_site_nav_bar.html.erb +1 -1
- data/generators/xebec_stylesheet/templates/xebec.css.erb +3 -3
- data/lib/xebec.rb +6 -6
- data/lib/xebec/controller_support.rb +11 -11
- data/lib/xebec/has_nav_bars.rb +7 -7
- data/lib/xebec/html5.rb +8 -8
- data/lib/xebec/nav_bar.rb +10 -10
- data/lib/xebec/nav_bar_helper.rb +11 -11
- data/lib/xebec/nav_bar_renderer.rb +22 -22
- data/lib/xebec/nav_item.rb +5 -5
- data/lib/xebec/stylesheet_generator.rb +8 -8
- data/lib/xebec/title_enhanced_nav_bar_renderer.rb +6 -6
- data/lib/xebec/web_app_theme_renderer.rb +5 -5
- data/test/controller_support_test.rb +11 -12
- data/test/html5_test.rb +14 -14
- data/test/nav_bar_helper_test.rb +17 -17
- data/test/nav_bar_renderer_test.rb +33 -22
- data/test/nav_bar_test.rb +10 -10
- data/test/test_helper.rb +14 -16
- data/test/title_enhanced_nav_bar_renderer_test.rb +10 -10
- data/test/web_app_theme_renderer_test.rb +5 -5
- data/xebec.gemspec +5 -7
- metadata +13 -11
- data/VERSION +0 -1
- data/developer_tasks/gem.rake +0 -34
@@ -2,13 +2,13 @@ require 'xebec/nav_bar'
|
|
2
2
|
require 'xebec/html5'
|
3
3
|
|
4
4
|
module Xebec
|
5
|
-
|
5
|
+
|
6
6
|
# A renderer for a Xebec::NavBar that knows how to turn the NavBar
|
7
7
|
# into an HTML list using ActionView helper methods.
|
8
8
|
class NavBarRenderer
|
9
|
-
|
9
|
+
|
10
10
|
# Create a new NavBar renderer object. The renderer will pass all
|
11
|
-
# methods on to the NavBar except for +to_s+, which will
|
11
|
+
# methods on to the NavBar except for +to_s+, which will
|
12
12
|
# render the NavBar as an HTML list.
|
13
13
|
#
|
14
14
|
# @param [Xebec::NavBar] bar the navigation bar to renderer
|
@@ -19,7 +19,7 @@ module Xebec
|
|
19
19
|
helper.respond_to?(:content_tag) && helper.respond_to?(:link_to_unless_current)
|
20
20
|
@bar, @helper = bar, helper
|
21
21
|
end
|
22
|
-
|
22
|
+
|
23
23
|
# @return [String] the proxied navigation bar as an HTML list.
|
24
24
|
#
|
25
25
|
# The HREF for each navigation item is generated as follows:
|
@@ -43,32 +43,32 @@ module Xebec
|
|
43
43
|
else
|
44
44
|
helper.content_tag(root_element, options) do
|
45
45
|
helper.content_tag(*list_tag) do
|
46
|
-
bar.items.
|
47
|
-
render_nav_item
|
48
|
-
end
|
46
|
+
bar.items.inject(''.html_safe) do |content, item|
|
47
|
+
content << render_nav_item(item)
|
48
|
+
end
|
49
49
|
end
|
50
50
|
end
|
51
51
|
end
|
52
52
|
end
|
53
|
-
|
53
|
+
|
54
54
|
def inspect
|
55
55
|
to_s
|
56
56
|
end
|
57
|
-
|
57
|
+
|
58
58
|
def respond_to?(sym)
|
59
59
|
return true if bar.respond_to?(sym)
|
60
60
|
super
|
61
61
|
end
|
62
|
-
|
62
|
+
|
63
63
|
def method_missing(sym, *args, &block)
|
64
64
|
return bar.send(sym, *args, &block) if bar.respond_to?(sym)
|
65
65
|
super
|
66
66
|
end
|
67
|
-
|
67
|
+
|
68
68
|
protected
|
69
|
-
|
69
|
+
|
70
70
|
attr_reader :bar, :helper
|
71
|
-
|
71
|
+
|
72
72
|
def root_navbar_tag
|
73
73
|
html_attributes = bar.html_attributes
|
74
74
|
html_attributes[:class] ||= ''
|
@@ -80,13 +80,13 @@ module Xebec
|
|
80
80
|
return :div, html_attributes
|
81
81
|
end
|
82
82
|
end
|
83
|
-
|
83
|
+
|
84
84
|
# @return the first two arguments to a <tt>content_tag</tt> call --
|
85
85
|
# the name and HTML properties of the tag
|
86
86
|
def list_tag
|
87
87
|
return :ul, {}
|
88
88
|
end
|
89
|
-
|
89
|
+
|
90
90
|
def render_nav_item(item)
|
91
91
|
text = text_for_nav_item item
|
92
92
|
href = href_for_nav_item item
|
@@ -96,12 +96,12 @@ module Xebec
|
|
96
96
|
helper.content_tag(*list_item_tag(item, klass, text, href, is_current)) do
|
97
97
|
if is_current
|
98
98
|
helper.content_tag :span, text
|
99
|
-
else
|
99
|
+
else
|
100
100
|
helper.link_to text, href
|
101
101
|
end
|
102
102
|
end
|
103
103
|
end
|
104
|
-
|
104
|
+
|
105
105
|
# @param [Xebec::NavItem] item the navigation item
|
106
106
|
# @param [String] klass the HTML class attribute generated (including
|
107
107
|
# the "current" class if applicable)
|
@@ -113,21 +113,21 @@ module Xebec
|
|
113
113
|
def list_item_tag(item, klass, text, href, is_current)
|
114
114
|
return :li, :class => klass
|
115
115
|
end
|
116
|
-
|
116
|
+
|
117
117
|
def text_for_nav_item(item)
|
118
118
|
item_name = item.name
|
119
119
|
I18n.t "navbar.#{bar.name}.#{item_name}", :default => item_name.to_s.titleize
|
120
120
|
end
|
121
|
-
|
121
|
+
|
122
122
|
def href_for_nav_item(item)
|
123
123
|
item.href or helper.send("#{item.name}_path")
|
124
124
|
end
|
125
|
-
|
125
|
+
|
126
126
|
def is_current_nav_item?(item, href)
|
127
127
|
current = bar.current.to_s
|
128
128
|
current == item.name.to_s || current.blank? && helper.current_page?(href)
|
129
129
|
end
|
130
|
-
|
130
|
+
|
131
131
|
end
|
132
|
-
|
132
|
+
|
133
133
|
end
|
data/lib/xebec/nav_item.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
module Xebec
|
2
|
-
|
2
|
+
|
3
3
|
class NavItem
|
4
|
-
|
4
|
+
|
5
5
|
attr_reader :name, :href
|
6
|
-
|
6
|
+
|
7
7
|
# Create a new navigation item.
|
8
8
|
#
|
9
9
|
# @param [String, Symbol] name the name of the item
|
@@ -15,7 +15,7 @@ module Xebec
|
|
15
15
|
raise ArgumentError.new("#{name || '<nil>'} is not a valid name for a navigation item") if name.blank?
|
16
16
|
@name, @href = name, href
|
17
17
|
end
|
18
|
-
|
18
|
+
|
19
19
|
end
|
20
|
-
|
20
|
+
|
21
21
|
end
|
@@ -1,18 +1,18 @@
|
|
1
1
|
module Xebec
|
2
|
-
|
2
|
+
|
3
3
|
# The `nav_bar` helper method will add the "current" class to the
|
4
4
|
# currently-selected item of each navigation bar. Highlighting the
|
5
5
|
# item requires just some basic CSS:
|
6
|
-
#
|
6
|
+
#
|
7
7
|
# nav { color: green; }
|
8
8
|
# nav .current { color: purple; }
|
9
|
-
#
|
9
|
+
#
|
10
10
|
# Each rendered navigation bar will include its name as a CSS class
|
11
11
|
# if you want to style them differently:
|
12
|
-
#
|
12
|
+
#
|
13
13
|
# nav.site { color: green; }
|
14
14
|
# nav.area { color: white; background-color: green; }
|
15
|
-
#
|
15
|
+
#
|
16
16
|
# (In case you were wondering about those `nav` elements, they're
|
17
17
|
# part of [the HTML5 specification](http://dev.w3.org/html5/spec/Overview.html#the-nav-element).
|
18
18
|
#
|
@@ -27,7 +27,7 @@ module Xebec
|
|
27
27
|
end
|
28
28
|
|
29
29
|
protected
|
30
|
-
|
30
|
+
|
31
31
|
def after_generate
|
32
32
|
puts "Generated a stylesheet with navigation bars #{navigation_bars.to_sentence}"
|
33
33
|
end
|
@@ -39,7 +39,7 @@ module Xebec
|
|
39
39
|
def banner
|
40
40
|
%{Usage: #{$0} #{spec.name} [nav_bar_name [nav_bar_name ...]]\nGenerates navigation bar stylesheets in public/stylesheets/}
|
41
41
|
end
|
42
|
-
|
42
|
+
|
43
43
|
end
|
44
|
-
|
44
|
+
|
45
45
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'xebec/nav_bar_renderer'
|
2
2
|
|
3
3
|
module Xebec
|
4
|
-
|
4
|
+
|
5
5
|
# Replaces the default Xebec::NavBarRenderer with a version
|
6
6
|
# that supports separate "text" and "title" internationalization
|
7
7
|
# options for each navigation item. Instead of
|
@@ -12,9 +12,9 @@ module Xebec
|
|
12
12
|
#
|
13
13
|
# @see Xebec::NavBarRenderer
|
14
14
|
class TitleEnhancedNavBarRenderer < ::Xebec::NavBarRenderer
|
15
|
-
|
15
|
+
|
16
16
|
protected
|
17
|
-
|
17
|
+
|
18
18
|
def list_item_tag(item, klass, text, href, is_current)
|
19
19
|
return :li, :class => klass, :title => title_for_nav_item(item, text)
|
20
20
|
end
|
@@ -23,14 +23,14 @@ module Xebec
|
|
23
23
|
item_name = item.name
|
24
24
|
I18n.t "navbar.#{bar.name}.#{item_name}.text", :default => item_name.to_s.titleize
|
25
25
|
end
|
26
|
-
|
26
|
+
|
27
27
|
def title_for_nav_item(item, text)
|
28
28
|
item_name = item.name
|
29
29
|
I18n.t "navbar.#{bar.name}.#{item_name}.title", :default => text
|
30
30
|
end
|
31
|
-
|
31
|
+
|
32
32
|
end
|
33
|
-
|
33
|
+
|
34
34
|
end
|
35
35
|
|
36
36
|
Xebec::renderer_class = Xebec::TitleEnhancedNavBarRenderer
|
@@ -1,22 +1,22 @@
|
|
1
1
|
require 'xebec/nav_bar_renderer'
|
2
2
|
|
3
3
|
module Xebec
|
4
|
-
|
4
|
+
|
5
5
|
# Replaces the default Xebec::NavBarRenderer with a version
|
6
6
|
# that includes the CSS classes used by WebAppThemes.
|
7
7
|
#
|
8
8
|
# @see Xebec::NavBarRenderer
|
9
9
|
# @see http://github.com/pilu/web-app-theme
|
10
10
|
class WebAppThemeRenderer < ::Xebec::NavBarRenderer
|
11
|
-
|
11
|
+
|
12
12
|
protected
|
13
|
-
|
13
|
+
|
14
14
|
def list_tag
|
15
15
|
return :ul, :class => 'wat-cf'
|
16
16
|
end
|
17
|
-
|
17
|
+
|
18
18
|
end
|
19
|
-
|
19
|
+
|
20
20
|
end
|
21
21
|
|
22
22
|
Xebec::renderer_class = Xebec::WebAppThemeRenderer
|
@@ -2,10 +2,11 @@ require File.join(File.dirname(__FILE__), 'test_helper')
|
|
2
2
|
require 'xebec'
|
3
3
|
|
4
4
|
class ControllerSupportTest < Test::Unit::TestCase
|
5
|
-
|
5
|
+
|
6
6
|
def setup
|
7
7
|
@controller_class = Class.new(ActionController::Base).tap do |c|
|
8
8
|
c.instance_eval do
|
9
|
+
include ActionController::Testing
|
9
10
|
include Xebec::ControllerSupport
|
10
11
|
def public_nav_bar(*args, &block)
|
11
12
|
nav_bar(*args, &block)
|
@@ -14,41 +15,39 @@ class ControllerSupportTest < Test::Unit::TestCase
|
|
14
15
|
end
|
15
16
|
@controller = @controller_class.new
|
16
17
|
end
|
17
|
-
|
18
|
+
|
18
19
|
def call_before_filters
|
19
|
-
@
|
20
|
-
filter.call(@controller)
|
21
|
-
end
|
20
|
+
@controller.run_callbacks(:process_action)
|
22
21
|
end
|
23
|
-
|
22
|
+
|
24
23
|
context 'ControllerSupport::ClassMethods#nav_bar' do
|
25
|
-
|
24
|
+
|
26
25
|
should 'append a before_filter that looks up the named navigation bar' do
|
27
26
|
@controller_class.public_nav_bar :turtles
|
28
27
|
@controller.expects(:nav_bar).with(:turtles)
|
29
28
|
call_before_filters
|
30
29
|
end
|
31
|
-
|
30
|
+
|
32
31
|
should 'append a before_filter with the given options' do
|
33
32
|
options = { :only => :show }
|
34
33
|
@controller_class.expects(:append_before_filter).with(options)
|
35
34
|
@controller_class.public_nav_bar :foo, options
|
36
35
|
end
|
37
|
-
|
36
|
+
|
38
37
|
should 'append a before_filter that passes the given block to the named nav bar instance' do
|
39
38
|
@controller_class.public_nav_bar(:baz) { |nb| nb.nav_item :help }
|
40
39
|
bar = @controller.nav_bar :baz
|
41
40
|
bar.expects(:nav_item).with(:help)
|
42
41
|
call_before_filters
|
43
42
|
end
|
44
|
-
|
43
|
+
|
45
44
|
end
|
46
|
-
|
45
|
+
|
47
46
|
context 'ControllerSupport::InstanceMethods#nav_bar' do
|
48
47
|
should 'treat Symbol names and String names equivalently' do
|
49
48
|
left = @controller.nav_bar(:left)
|
50
49
|
assert_equal left, @controller.nav_bar('left')
|
51
50
|
end
|
52
51
|
end
|
53
|
-
|
52
|
+
|
54
53
|
end
|
data/test/html5_test.rb
CHANGED
@@ -3,55 +3,55 @@ require 'xebec'
|
|
3
3
|
require 'xebec/html5'
|
4
4
|
|
5
5
|
class HTML5Test < Test::Unit::TestCase
|
6
|
-
|
6
|
+
|
7
7
|
def setup
|
8
8
|
@helper = new_nav_bar_helper
|
9
9
|
end
|
10
|
-
|
10
|
+
|
11
11
|
def internet_explorer_8
|
12
12
|
'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; MDDC)'
|
13
13
|
end
|
14
|
-
|
14
|
+
|
15
15
|
def internet_explorer_7
|
16
16
|
'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; InfoPath.1; MS-RTC LM 8)'
|
17
17
|
end
|
18
|
-
|
18
|
+
|
19
19
|
def firefox
|
20
20
|
'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.2pre) Gecko/20100225 Ubuntu/9.10 (karmic) Namoroka/3.6.2pre'
|
21
21
|
end
|
22
|
-
|
22
|
+
|
23
23
|
def safari
|
24
24
|
'Mozilla/5.0 (iPod; U; CPU iPhone OS 2_2_1 like Mac OS X; en-us) AppleWebKit/525.18.1 (KHTML, like Gecko) Version/3.1.1 Mobile/5H11a Safari/525.20'
|
25
25
|
end
|
26
|
-
|
26
|
+
|
27
27
|
context 'HTML5#user_agent_supports_html5?' do
|
28
28
|
setup { Xebec::HTML5.force = false }
|
29
|
-
|
29
|
+
|
30
30
|
context 'when Xebec::HTML5.force is false' do
|
31
31
|
should 'return false for Internet Explorer 8' do
|
32
32
|
@helper.request.user_agent = internet_explorer_8
|
33
33
|
assert !@helper.user_agent_supports_html5?
|
34
34
|
end
|
35
|
-
|
35
|
+
|
36
36
|
should 'return false for Internet Explorer 7' do
|
37
37
|
@helper.request.user_agent = internet_explorer_7
|
38
38
|
assert !@helper.user_agent_supports_html5?
|
39
39
|
end
|
40
|
-
|
40
|
+
|
41
41
|
should 'return true for Firefox' do
|
42
42
|
@helper.request.user_agent = firefox
|
43
43
|
assert @helper.user_agent_supports_html5?
|
44
44
|
end
|
45
|
-
|
45
|
+
|
46
46
|
should 'return true for Safari' do
|
47
47
|
@helper.request.user_agent = safari
|
48
48
|
assert @helper.user_agent_supports_html5?
|
49
49
|
end
|
50
50
|
end
|
51
|
-
|
51
|
+
|
52
52
|
context 'when Xebec::HTML5.force is true' do
|
53
53
|
setup { Xebec::HTML5.force = true }
|
54
|
-
|
54
|
+
|
55
55
|
should 'return false for Internet Explorer 8' do
|
56
56
|
@helper.request.user_agent = internet_explorer_8
|
57
57
|
assert @helper.user_agent_supports_html5?
|
@@ -72,7 +72,7 @@ class HTML5Test < Test::Unit::TestCase
|
|
72
72
|
assert @helper.user_agent_supports_html5?
|
73
73
|
end
|
74
74
|
end
|
75
|
-
|
75
|
+
|
76
76
|
end
|
77
|
-
|
77
|
+
|
78
78
|
end
|
data/test/nav_bar_helper_test.rb
CHANGED
@@ -2,17 +2,17 @@ require File.join(File.dirname(__FILE__), 'test_helper')
|
|
2
2
|
require 'xebec'
|
3
3
|
|
4
4
|
class NavBarHelperTest < Test::Unit::TestCase
|
5
|
-
|
5
|
+
|
6
6
|
context 'NavBarHelper#nav_bar' do
|
7
|
-
|
7
|
+
|
8
8
|
setup do
|
9
9
|
@helper = new_nav_bar_helper
|
10
10
|
end
|
11
|
-
|
11
|
+
|
12
12
|
should 'return a NavBar renderer' do
|
13
13
|
assert @helper.nav_bar.kind_of?(Xebec::NavBarRenderer)
|
14
14
|
end
|
15
|
-
|
15
|
+
|
16
16
|
should 'use a custom renderer class if one is set' do
|
17
17
|
begin
|
18
18
|
@old_renderer_class = Xebec::renderer_class
|
@@ -36,34 +36,34 @@ class NavBarHelperTest < Test::Unit::TestCase
|
|
36
36
|
ensure
|
37
37
|
Xebec::renderer_class = @old_renderer_class
|
38
38
|
end
|
39
|
-
end
|
40
|
-
|
39
|
+
end
|
40
|
+
|
41
41
|
should 'return a NavBar with the given name' do
|
42
42
|
assert_equal :snacks, @helper.nav_bar(:snacks).name
|
43
43
|
end
|
44
|
-
|
44
|
+
|
45
45
|
should 'return the same NavBar for repeated calls with the same name' do
|
46
46
|
snacks = @helper.nav_bar(:snacks)
|
47
47
|
assert_equal snacks, @helper.nav_bar(:snacks)
|
48
48
|
end
|
49
|
-
|
49
|
+
|
50
50
|
should 'treat Symbol names and String names equivalently' do
|
51
51
|
desserts = @helper.nav_bar(:desserts)
|
52
52
|
assert_equal desserts, @helper.nav_bar('desserts')
|
53
53
|
end
|
54
|
-
|
54
|
+
|
55
55
|
should 'allow additional HTML attributes' do
|
56
56
|
salads = @helper.nav_bar(:salads, :id => 'salads-nav')
|
57
57
|
assert_equal 'salads-nav', @helper.nav_bar(:salads).html_attributes[:id]
|
58
58
|
end
|
59
|
-
|
59
|
+
|
60
60
|
should "evaluate a block in the helper's scope" do
|
61
61
|
@helper.expects(:zoink!)
|
62
|
-
@helper.nav_bar do
|
62
|
+
@helper.nav_bar do |bar|
|
63
63
|
zoink!
|
64
64
|
end
|
65
65
|
end
|
66
|
-
|
66
|
+
|
67
67
|
should "yield the NavBar renderer to the given block" do
|
68
68
|
bar = @helper.nav_bar
|
69
69
|
bar.expects :zoink!
|
@@ -71,21 +71,21 @@ class NavBarHelperTest < Test::Unit::TestCase
|
|
71
71
|
nb.zoink!
|
72
72
|
end
|
73
73
|
end
|
74
|
-
|
74
|
+
|
75
75
|
end
|
76
|
-
|
76
|
+
|
77
77
|
context 'NavBarHelper#nav_bar_unless_empty' do
|
78
78
|
setup do
|
79
79
|
@helper = new_nav_bar_helper
|
80
80
|
@bar = @helper.nav_bar(:pets)
|
81
81
|
end
|
82
|
-
|
82
|
+
|
83
83
|
context 'with an empty navigation bar' do
|
84
84
|
should 'return an empty String' do
|
85
85
|
assert @helper.nav_bar_unless_empty(:pets).blank?
|
86
86
|
end
|
87
87
|
end
|
88
|
-
|
88
|
+
|
89
89
|
context 'with a non-empty navigation bar' do
|
90
90
|
setup { @bar.nav_item :cats, '/cats' }
|
91
91
|
should 'return a navigation bar' do
|
@@ -93,5 +93,5 @@ class NavBarHelperTest < Test::Unit::TestCase
|
|
93
93
|
end
|
94
94
|
end
|
95
95
|
end
|
96
|
-
|
96
|
+
|
97
97
|
end
|