xebec 2.4.0 → 2.5.0

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.4.0
1
+ 2.5.0
@@ -93,7 +93,7 @@ module Xebec
93
93
  is_current = is_current_nav_item?(item, href)
94
94
  klass = item.name.to_s
95
95
  klass << " #{Xebec.currently_selected_nav_item_class}" if is_current
96
- helper.content_tag :li, :class => klass do
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
99
  else
@@ -102,6 +102,18 @@ module Xebec
102
102
  end
103
103
  end
104
104
 
105
+ # @param [Xebec::NavItem] item the navigation item
106
+ # @param [String] klass the HTML class attribute generated (including
107
+ # the "current" class if applicable)
108
+ # @param [String] text
109
+ # @param [String] href
110
+ # @param [true, false] is_current
111
+ # @return the first two arguments to a <tt>content_tag</tt> call --
112
+ # the name and HTML properties of the tag
113
+ def list_item_tag(item, klass, text, href, is_current)
114
+ return :li, :class => klass
115
+ end
116
+
105
117
  def text_for_nav_item(item)
106
118
  item_name = item.name
107
119
  I18n.t "navbar.#{bar.name}.#{item_name}", :default => item_name.to_s.titleize
@@ -0,0 +1,36 @@
1
+ require 'xebec/nav_bar_renderer'
2
+
3
+ module Xebec
4
+
5
+ # Replaces the default Xebec::NavBarRenderer with a version
6
+ # that supports separate "text" and "title" internationalization
7
+ # options for each navigation item. Instead of
8
+ # "navbar.#{bar.name}.#{item_name}" for the text, use
9
+ # "navbar.#{bar.name}.#{item_name}.text". Additionally,
10
+ # use "navbar.#{bar.name}.#{item_name}.title" for a separate
11
+ # title. The title will default to the text if not specified.
12
+ #
13
+ # @see Xebec::NavBarRenderer
14
+ class TitleEnhancedNavBarRenderer < ::Xebec::NavBarRenderer
15
+
16
+ protected
17
+
18
+ def list_item_tag(item, klass, text, href, is_current)
19
+ return :li, :class => klass, :title => title_for_nav_item(item, text)
20
+ end
21
+
22
+ def text_for_nav_item(item)
23
+ item_name = item.name
24
+ I18n.t "navbar.#{bar.name}.#{item_name}.text", :default => item_name.to_s.titleize
25
+ end
26
+
27
+ def title_for_nav_item(item, text)
28
+ item_name = item.name
29
+ I18n.t "navbar.#{bar.name}.#{item_name}.title", :default => text
30
+ end
31
+
32
+ end
33
+
34
+ end
35
+
36
+ Xebec::renderer_class = Xebec::TitleEnhancedNavBarRenderer
@@ -0,0 +1,85 @@
1
+ require File.join(File.dirname(__FILE__), 'test_helper')
2
+ require 'xebec'
3
+
4
+ class TitleEnhancedNavBarRendererTest < Test::Unit::TestCase
5
+
6
+ def setup
7
+ @old_renderer_class = Xebec::renderer_class
8
+ load 'xebec/title_enhanced_nav_bar_renderer.rb'
9
+ clear_translations!
10
+ @bar = Xebec::NavBar.new('elements')
11
+ @helper = new_nav_bar_helper
12
+ @renderer = Xebec::renderer_class.new(@bar, @helper)
13
+ @bar.nav_item :zn, '/elements/zn'
14
+ end
15
+
16
+ def teardown
17
+ Xebec::renderer_class = @old_renderer_class
18
+ end
19
+
20
+ context 'using the title-enhanced renderer' do
21
+
22
+ should 'replace the default renderer class automatically' do
23
+ assert_equal Xebec::TitleEnhancedNavBarRenderer, Xebec::renderer_class
24
+ end
25
+
26
+ context 'with neither text nor a title translation specified' do
27
+ should "use the nav item's name titleized for the link text" do
28
+ assert_select_from @renderer.to_s, 'ul li.zn' do
29
+ assert_select 'a', 'Zn'
30
+ end
31
+ end
32
+ should "use the nav item's name titleized for the <li>'s title" do
33
+ assert_select_from @renderer.to_s, 'ul li.zn[title="Zn"]'
34
+ end
35
+ end
36
+
37
+ context 'with a text but not a title translation specified' do
38
+ setup do
39
+ define_translation 'navbar.elements.zn.text', 'Zinc'
40
+ @bar.nav_item :zn, '/zn'
41
+ end
42
+ should "use the text translation for the link text" do
43
+ assert_select_from @renderer.to_s, 'ul li.zn' do
44
+ assert_select 'a', 'Zinc'
45
+ end
46
+ end
47
+ should "use the text translation for the <li>'s title" do
48
+ assert_select_from @renderer.to_s, 'ul li.zn[title="Zinc"]'
49
+ end
50
+ end
51
+
52
+ context 'with a title but no text translation specified' do
53
+ setup do
54
+ define_translation 'navbar.elements.zn.title', 'Zinc'
55
+ @bar.nav_item :zn, '/zn'
56
+ end
57
+ should "use the nav item's name titleized for the link text" do
58
+ assert_select_from @renderer.to_s, 'ul li.zn' do
59
+ assert_select 'a', 'Zn'
60
+ end
61
+ end
62
+ should "use the title translation for the <li>'s title" do
63
+ assert_select_from @renderer.to_s, 'ul li.zn[title="Zinc"]'
64
+ end
65
+ end
66
+
67
+ context 'with both a title and a text translation specified' do
68
+ setup do
69
+ define_translation 'navbar.elements.zn.text', 'Zinc'
70
+ define_translation 'navbar.elements.zn.title', '30: Zinc'
71
+ @bar.nav_item :zn, '/zn'
72
+ end
73
+ should "use the text translation for the link text" do
74
+ assert_select_from @renderer.to_s, 'ul li.zn' do
75
+ assert_select 'a', 'Zinc'
76
+ end
77
+ end
78
+ should "use the title translation for the <li>'s title" do
79
+ assert_select_from @renderer.to_s, 'ul li.zn[title="30: Zinc"]'
80
+ end
81
+ end
82
+
83
+ end
84
+
85
+ end
@@ -1,16 +1,21 @@
1
1
  require File.join(File.dirname(__FILE__), 'test_helper')
2
2
  require 'xebec'
3
- require 'xebec/web_app_theme_renderer'
4
3
 
5
4
  class WebAppThemeRendererTest < Test::Unit::TestCase
6
5
 
7
6
  def setup
7
+ @old_renderer_class = Xebec::renderer_class
8
+ load 'xebec/web_app_theme_renderer.rb'
8
9
  @bar = Xebec::NavBar.new('plants')
9
10
  @helper = new_nav_bar_helper
10
11
  @renderer = Xebec::renderer_class.new(@bar, @helper)
11
12
  @bar.nav_item :baz, '/baz'
12
13
  end
13
14
 
15
+ def teardown
16
+ Xebec::renderer_class = @old_renderer_class
17
+ end
18
+
14
19
  context 'using the Web-App-Theme support' do
15
20
  should 'replace the default renderer class automatically' do
16
21
  assert_equal Xebec::WebAppThemeRenderer, Xebec::renderer_class
data/xebec.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{xebec}
8
- s.version = "2.4.0"
8
+ s.version = "2.5.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["James A. Rosen"]
@@ -55,6 +55,7 @@ Gem::Specification.new do |s|
55
55
  "lib/xebec/nav_bar_renderer.rb",
56
56
  "lib/xebec/nav_item.rb",
57
57
  "lib/xebec/stylesheet_generator.rb",
58
+ "lib/xebec/title_enhanced_nav_bar_renderer.rb",
58
59
  "lib/xebec/web_app_theme_renderer.rb",
59
60
  "rails/init.rb",
60
61
  "tasks/README.md",
@@ -64,6 +65,7 @@ Gem::Specification.new do |s|
64
65
  "test/nav_bar_renderer_test.rb",
65
66
  "test/nav_bar_test.rb",
66
67
  "test/test_helper.rb",
68
+ "test/title_enhanced_nav_bar_renderer_test.rb",
67
69
  "test/web_app_theme_renderer_test.rb",
68
70
  "xebec.gemspec"
69
71
  ]
@@ -79,6 +81,7 @@ Gem::Specification.new do |s|
79
81
  "test/nav_bar_renderer_test.rb",
80
82
  "test/nav_bar_test.rb",
81
83
  "test/test_helper.rb",
84
+ "test/title_enhanced_nav_bar_renderer_test.rb",
82
85
  "test/web_app_theme_renderer_test.rb"
83
86
  ]
84
87
 
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 2
7
- - 4
7
+ - 5
8
8
  - 0
9
- version: 2.4.0
9
+ version: 2.5.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - James A. Rosen
@@ -107,6 +107,7 @@ files:
107
107
  - lib/xebec/nav_bar_renderer.rb
108
108
  - lib/xebec/nav_item.rb
109
109
  - lib/xebec/stylesheet_generator.rb
110
+ - lib/xebec/title_enhanced_nav_bar_renderer.rb
110
111
  - lib/xebec/web_app_theme_renderer.rb
111
112
  - rails/init.rb
112
113
  - tasks/README.md
@@ -116,6 +117,7 @@ files:
116
117
  - test/nav_bar_renderer_test.rb
117
118
  - test/nav_bar_test.rb
118
119
  - test/test_helper.rb
120
+ - test/title_enhanced_nav_bar_renderer_test.rb
119
121
  - test/web_app_theme_renderer_test.rb
120
122
  - xebec.gemspec
121
123
  has_rdoc: true
@@ -160,4 +162,5 @@ test_files:
160
162
  - test/nav_bar_renderer_test.rb
161
163
  - test/nav_bar_test.rb
162
164
  - test/test_helper.rb
165
+ - test/title_enhanced_nav_bar_renderer_test.rb
163
166
  - test/web_app_theme_renderer_test.rb