title 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 793a9fcdf8483dcc8fc6942fbdc454633ed341e9
4
- data.tar.gz: 5c6c254b59bee66021ded50e7e1a1235b13e809a
3
+ metadata.gz: 59409b794c1790c00f22f7b083e228c1fe8ad283
4
+ data.tar.gz: 8a6e321565ca1e3f3225c9627c518b4d9a4b7cc0
5
5
  SHA512:
6
- metadata.gz: 05af664351437e4ea4821e8949f97d216a8829aab148072fbb8be4c2a7a61a017d3172fe07ab4f5e397391af3f5533c25eb54405b6e2cc0370b7064fecaa5560
7
- data.tar.gz: baa821ed6c9bc0c9774079f1dd0ea02e99132e7a9bda4152b2118ea8bba901a487c0614f2fa19c0df4b394393f09a8ce18f0a22f12d0d67901d47f8e1c1ee511
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
- PageTitle.new(controller_path, action_name, controller.view_assigns.symbolize_keys).to_s
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
@@ -1,3 +1,3 @@
1
1
  module Title
2
- VERSION = '0.0.4'
2
+ VERSION = '0.0.5'
3
3
  end
@@ -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, :symbolize_keys).and_return({ name: 'Caleb' })
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, :symbolize_keys).and_return({})
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
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-02-13 00:00:00.000000000 Z
11
+ date: 2014-07-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler