page_title_helper 1.0.0 → 1.0.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/VERSION.yml +1 -1
- data/lib/page_title_helper.rb +14 -5
- data/test/multiple_formats_test.rb +2 -2
- data/test/page_title_helper_test.rb +5 -5
- data/test/test_helper.rb +8 -1
- metadata +2 -2
data/VERSION.yml
CHANGED
data/lib/page_title_helper.rb
CHANGED
@@ -9,6 +9,8 @@
|
|
9
9
|
|
10
10
|
# PageTitleHelper
|
11
11
|
module PageTitleHelper
|
12
|
+
|
13
|
+
# http://github.com/thoughtbot/paperclip/blob/master/lib/paperclip/interpolations.rb
|
12
14
|
module Interpolations
|
13
15
|
# Represents the environment which is passed into each interpolation call.
|
14
16
|
class TitleEnv < ::Struct.new(:options, :view, :controller, :title); end
|
@@ -86,10 +88,17 @@ module PageTitleHelper
|
|
86
88
|
|
87
89
|
protected
|
88
90
|
|
89
|
-
# Find current title key based on currently rendering template
|
90
|
-
#
|
91
|
-
#
|
92
|
-
|
93
|
-
|
91
|
+
# Find current title key based on currently rendering template.
|
92
|
+
#
|
93
|
+
# Access +ActionView+s internal <tt>@_first_render</tt> variable, to access
|
94
|
+
# template first rendered, this is to help create the DRY-I18n-titles magic,
|
95
|
+
# and also kind of a hack, because this really seems to be some sort if
|
96
|
+
# internal variable, that's why it's "abstracted" away as well.
|
97
|
+
#
|
98
|
+
# Also ensure that the extensions (like <tt>.html.erb</tt> or
|
99
|
+
# <tt>.html.haml</tt>) have been stripped of and translated in the sense
|
100
|
+
# of converting <tt>/</tt> to <tt>.</tt>.
|
101
|
+
def i18n_template_key(suffix = nil)
|
102
|
+
@_first_render.template_path.gsub(/\.[^\/]*\Z/, '').tr('/', '.') + (suffix.present? ? ".#{suffix}" : "")
|
94
103
|
end
|
95
104
|
end
|
@@ -61,12 +61,12 @@ class MultipleFormatsTest < ActiveSupport::TestCase
|
|
61
61
|
end
|
62
62
|
|
63
63
|
should "allow to overide format through YAML" do
|
64
|
-
|
64
|
+
@view.template = 'pages/features.html.haml'
|
65
65
|
assert_equal 'Wohaapp > Feature comparison', @view.page_title
|
66
66
|
end
|
67
67
|
|
68
68
|
should "handle raw string formats from YAML as well" do
|
69
|
-
|
69
|
+
@view.template = 'pages/signup.html.haml'
|
70
70
|
assert_equal 'Sign up for Wohaapp now!', @view.page_title
|
71
71
|
end
|
72
72
|
end
|
@@ -9,7 +9,7 @@ class PageTitleHelperTest < ActiveSupport::TestCase
|
|
9
9
|
I18n.reload!
|
10
10
|
|
11
11
|
@view = ActionView::Base.new
|
12
|
-
@view.
|
12
|
+
@view.template_path = "contacts/list.html.erb"
|
13
13
|
end
|
14
14
|
|
15
15
|
context "::Interpolations" do
|
@@ -90,17 +90,17 @@ class PageTitleHelperTest < ActiveSupport::TestCase
|
|
90
90
|
end
|
91
91
|
|
92
92
|
should "render translated :'app.tagline' if no title is available" do
|
93
|
-
|
93
|
+
@view.template_path = 'view/does/not_exist.html.erb'
|
94
94
|
assert_equal "Default - Page title helper", @view.page_title
|
95
95
|
end
|
96
96
|
|
97
97
|
should "render custom 'default' string, if title is not available" do
|
98
|
-
|
98
|
+
@view.template_path = 'view/does/not_exist.html.erb'
|
99
99
|
assert_equal 'Some default - Page title helper', @view.page_title(:default => 'Some default')
|
100
100
|
end
|
101
101
|
|
102
102
|
should "render custom default translation, if title is not available" do
|
103
|
-
|
103
|
+
@view.template_path = 'view/does/not_exist.html.erb'
|
104
104
|
assert_equal 'Other default - Page title helper', @view.page_title(:default => :'app.other_tagline')
|
105
105
|
end
|
106
106
|
|
@@ -109,7 +109,7 @@ class PageTitleHelperTest < ActiveSupport::TestCase
|
|
109
109
|
end
|
110
110
|
|
111
111
|
should "work with other template engines, like HAML" do
|
112
|
-
|
112
|
+
@view.template_path = 'contacts/myhaml.html.haml'
|
113
113
|
assert_equal 'this is haml! - Page title helper', @view.page_title
|
114
114
|
end
|
115
115
|
end
|
data/test/test_helper.rb
CHANGED
@@ -13,4 +13,11 @@ end
|
|
13
13
|
|
14
14
|
ROOT = File.expand_path File.dirname(File.dirname(__FILE__))
|
15
15
|
RAILS_ROOT = '/this/is/just/for/testing/page_title_helper'
|
16
|
-
RAILS_ENV = 'test'
|
16
|
+
RAILS_ENV = 'test'
|
17
|
+
|
18
|
+
class ActionView::Base
|
19
|
+
def template=(template)
|
20
|
+
@_first_render = template.respond_to?(:template_path) ? template : ActionView::Template.new(template)
|
21
|
+
end
|
22
|
+
alias_method :template_path=, :template=
|
23
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: page_title_helper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lukas Westermann
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-11-
|
12
|
+
date: 2009-11-26 00:00:00 +01:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|