title 0.0.4 → 0.0.5
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.
- checksums.yaml +4 -4
- data/README.md +13 -0
- data/app/helpers/title/title_helper.rb +3 -2
- data/lib/title/version.rb +1 -1
- data/spec/helpers/title_helper_spec.rb +11 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 59409b794c1790c00f22f7b083e228c1fe8ad283
|
4
|
+
data.tar.gz: 8a6e321565ca1e3f3225c9627c518b4d9a4b7cc0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0d2421d70c9b2c352dacf75987ab432f3b8b10efc7cf8cb0628ba861d0a4edf460de4e4ae3a592ffab21baaa09f48fee3d4907b9e7679c4de0d2ba048e13c5ba
|
7
|
+
data.tar.gz: 7d2ab4a3ac91991c2a711300dac74de5436961520784204cfa76548c7e699f5684f93a3e6fb3324b73a5b13babe48a02efebc367b2c99329ce1383f96faa9638
|
data/README.md
CHANGED
@@ -35,6 +35,19 @@ def to_s
|
|
35
35
|
end
|
36
36
|
```
|
37
37
|
|
38
|
+
You can pass additional values to the `#title` helper, which can be referenced
|
39
|
+
in your translations:
|
40
|
+
|
41
|
+
```erb
|
42
|
+
<title><%= title(user_name: current_user.name) %></title>
|
43
|
+
```
|
44
|
+
|
45
|
+
```yaml
|
46
|
+
en:
|
47
|
+
titles:
|
48
|
+
application: '%{user_name} - AppName'
|
49
|
+
```
|
50
|
+
|
38
51
|
## Acknowledgement
|
39
52
|
|
40
53
|
Though the idea of translating titles was arrived at seperately, [Brandon
|
@@ -1,7 +1,8 @@
|
|
1
1
|
module Title
|
2
2
|
module TitleHelper
|
3
|
-
def title
|
4
|
-
|
3
|
+
def title(additional_context = {})
|
4
|
+
context = controller.view_assigns.merge(additional_context).symbolize_keys
|
5
|
+
PageTitle.new(controller_path, action_name, context).to_s
|
5
6
|
end
|
6
7
|
|
7
8
|
class PageTitle
|
data/lib/title/version.rb
CHANGED
@@ -37,15 +37,24 @@ describe Title::TitleHelper do
|
|
37
37
|
stub_rails
|
38
38
|
stub_controller_and_action(:users, :show)
|
39
39
|
load_translations(users: { show: '%{name}' })
|
40
|
-
helper.stub_chain(:controller, :view_assigns
|
40
|
+
helper.stub_chain(:controller, :view_assigns).and_return('name' => 'Caleb')
|
41
41
|
|
42
42
|
expect(helper.title).to eq('Caleb')
|
43
43
|
end
|
44
44
|
|
45
|
+
it 'can accept a hash of extra context in addition to the view assigns' do
|
46
|
+
stub_rails
|
47
|
+
stub_controller_and_action(:users, :show)
|
48
|
+
load_translations(users: { show: '%{greeting} %{name}' })
|
49
|
+
helper.stub_chain(:controller, :view_assigns).and_return('name' => 'Caleb')
|
50
|
+
|
51
|
+
expect(helper.title(greeting: 'Hello')).to eq('Hello Caleb')
|
52
|
+
end
|
53
|
+
|
45
54
|
def stub_rails
|
46
55
|
helper.stub(:controller_path).and_return('dashboards')
|
47
56
|
helper.stub(:action_name)
|
48
|
-
helper.stub_chain(:controller, :view_assigns
|
57
|
+
helper.stub_chain(:controller, :view_assigns).and_return({})
|
49
58
|
Rails.stub_chain(:application, :class).and_return('Dummy::Application')
|
50
59
|
end
|
51
60
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: title
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Caleb Thompson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-07-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|