title 0.0.1 → 0.0.2

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: 25b8d4302b48003bbbfc0dd7e2ae61cbfb9a9004
4
- data.tar.gz: 9a2ec345e1a7afd798b99fb7d58bf7bbd6239607
3
+ metadata.gz: 6c795ba3f15ebae717a82a25f1972ab853e73419
4
+ data.tar.gz: 2f62923f88cd8dc69abb7859de3c006e8f605876
5
5
  SHA512:
6
- metadata.gz: c0efc92301205ff80a47cc07862b870af60af7eecd804dc1235b1518e613e3420bf369d6abfcad340185e5a4f1be3cb80d4d299d20e16e58ef8e02d43d4801f2
7
- data.tar.gz: 124a5e5da330f6aa8a977943bd17b1169e2da6bba2cd6e751f46b69818621ee32352a239c3290fe16246fc56a8f32dd31b6fc170cdd4a4049f114f4902bdec8f
6
+ metadata.gz: b6a8492f732db46220af427baeb074b136bde549699e860e17f3ec544195dcc260af77141638c63a79602a5082280def5c7c09d29b1d4f490de2d56506450211
7
+ data.tar.gz: 39b3e5a49237c4e5f8d07c4fef6f734b010cb56d74aecbb9ed153e945f23fc66e5ed1c0c1d9960e95891b82ef7049eb7a7f5b2fd69f38649c03a1927c3a1583e
data/README.md CHANGED
@@ -1,29 +1,32 @@
1
1
  # Title
2
2
 
3
- TODO: Write a gem description
3
+ Translations for \<title\>s!
4
4
 
5
- ## Installation
6
-
7
- Add this line to your application's Gemfile:
8
-
9
- gem 'title'
10
-
11
- And then execute:
12
-
13
- $ bundle
5
+ ## Usage
14
6
 
15
- Or install it yourself as:
7
+ Add to your translations:
16
8
 
17
- $ gem install title
9
+ ```yaml
10
+ en:
11
+ titles:
12
+ application: AppName
13
+ dashboards:
14
+ show: Dashboard
15
+ users:
16
+ show: '%{user}'
17
+ new: Registration
18
+ ```
18
19
 
19
- ## Usage
20
+ And to your HTML:
20
21
 
21
- TODO: Write usage instructions here
22
+ ```erb
23
+ <title><%= title %></title>
24
+ ```
22
25
 
23
- ## Contributing
26
+ And to your `User` model:
24
27
 
25
- 1. Fork it
26
- 2. Create your feature branch (`git checkout -b my-new-feature`)
27
- 3. Commit your changes (`git commit -am 'Add some feature'`)
28
- 4. Push to the branch (`git push origin my-new-feature`)
29
- 5. Create new Pull Request
28
+ ```ruby
29
+ def to_s
30
+ name
31
+ end
32
+ ```
data/Rakefile CHANGED
@@ -1 +1 @@
1
- require "bundler/gem_tasks"
1
+ require 'bundler/gem_tasks'
@@ -0,0 +1,38 @@
1
+ module Title
2
+ module TitleHelper
3
+ def title
4
+ PageTitle.new(controller_path, action_name, controller.view_assigns.symbolize_keys).to_s
5
+ end
6
+
7
+ class PageTitle
8
+ def initialize(controller_path, action_name, context)
9
+ @controller_path = controller_path
10
+ @action_name = action_name
11
+ @context = context
12
+ end
13
+
14
+ def to_s
15
+ I18n.t(
16
+ [:titles, controller_name, action_name].join('.'),
17
+ context.merge(default: [application_title, guess_title])
18
+ )
19
+ end
20
+
21
+ private
22
+
23
+ attr_reader :controller_path, :action_name, :context
24
+
25
+ def application_title
26
+ :'titles.application'
27
+ end
28
+
29
+ def guess_title
30
+ Rails.application.class.to_s.split('::').first
31
+ end
32
+
33
+ def controller_name
34
+ controller_path.gsub('/', '.')
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,3 @@
1
+ module Title
2
+ class Engine < Rails::Engine; end
3
+ end
data/lib/title/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Title
2
- VERSION = "0.0.1"
2
+ VERSION = '0.0.2'
3
3
  end
data/lib/title.rb CHANGED
@@ -1,4 +1,7 @@
1
- require "title/version"
1
+ require 'title/version'
2
+ require 'rails/engine'
3
+ require 'title/engine'
4
+ require 'title/helpers/title_helper'
2
5
 
3
6
  module Title
4
7
  # Your code goes here...
@@ -0,0 +1,54 @@
1
+ require 'rubygems'
2
+ require 'pry'
3
+ require 'title'
4
+
5
+ describe Title::TitleHelper do
6
+ it 'is the app name when no translation is present' do
7
+ stub_rails
8
+
9
+ expect(helper.title).to eq('Dummy')
10
+ end
11
+
12
+ it 'uses the application title by default' do
13
+ stub_rails
14
+ load_translations(application: 'Not Dummy')
15
+
16
+ expect(helper.title).to eq('Not Dummy')
17
+ end
18
+
19
+ it 'matches controller/action to translation and uses that title' do
20
+ stub_rails
21
+ stub_controller_and_action(:dashboards, :show)
22
+ load_translations(dashboards: { show: 'Dashboard' })
23
+
24
+ expect(helper.title).to eq('Dashboard')
25
+ end
26
+
27
+ it 'can use view assigns' do
28
+ stub_rails
29
+ stub_controller_and_action(:users, :show)
30
+ load_translations(users: { show: '%{name}' })
31
+ helper.stub_chain(:controller, :view_assigns, :symbolize_keys).and_return({ name: 'Caleb' })
32
+
33
+ expect(helper.title).to eq('Caleb')
34
+ end
35
+
36
+ def stub_rails
37
+ helper.stub(:controller_path).and_return('dashboards')
38
+ helper.stub(:action_name)
39
+ helper.stub_chain(:controller, :view_assigns, :symbolize_keys).and_return({})
40
+ Rails.stub_chain(:application, :class).and_return('Dummy::Application')
41
+ end
42
+
43
+ def stub_controller_and_action(controller, action)
44
+ helper.stub(controller_path: controller.to_s, action_name: action.to_s)
45
+ end
46
+
47
+ def helper
48
+ @helper ||= Class.new { include Title::TitleHelper }.new
49
+ end
50
+
51
+ def load_translations(titles)
52
+ I18n.backend.store_translations(:en, { titles: titles })
53
+ end
54
+ end
data/title.gemspec CHANGED
@@ -1,23 +1,27 @@
1
1
  # coding: utf-8
2
2
  lib = File.expand_path('../lib', __FILE__)
3
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
4
5
  require 'title/version'
5
6
 
6
7
  Gem::Specification.new do |spec|
7
- spec.name = "title"
8
+ spec.name = 'title'
8
9
  spec.version = Title::VERSION
9
- spec.authors = ["Caleb Thompson"]
10
- spec.email = ["caleb@calebthompson.io"]
11
- spec.description = %q{: Write a gem description}
12
- spec.summary = %q{: Write a gem summary}
13
- spec.homepage = ""
14
- spec.license = "MIT"
10
+ spec.authors = ['Caleb Thompson']
11
+ spec.email = ['caleb@calebthompson.io']
12
+ spec.summary = 'I18n your <title>s'
13
+ spec.description = 'Abuses I18n to set HTML <title>s'
14
+ spec.homepage = 'https://github.com/calebthompson/title'
15
+ spec.license = 'MIT'
15
16
 
16
17
  spec.files = `git ls-files`.split($/)
17
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
- spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
- spec.require_paths = ["lib"]
18
+ spec.test_files = spec.files.grep(%r{^spec/})
19
+ spec.require_paths = ['lib', 'app']
20
+
21
+ spec.add_development_dependency 'bundler', '~> 1.3'
22
+ spec.add_development_dependency 'rake'
23
+ spec.add_development_dependency 'rspec'
20
24
 
21
- spec.add_development_dependency "bundler", "~> 1.3"
22
- spec.add_development_dependency "rake"
25
+ spec.add_dependency 'rails', '>= 3.1'
26
+ spec.add_dependency 'I18n'
23
27
  end
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.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Caleb Thompson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-07-10 00:00:00.000000000 Z
11
+ date: 2013-07-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -38,7 +38,49 @@ dependencies:
38
38
  - - '>='
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
- description: ': Write a gem description'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rails
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '3.1'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '3.1'
69
+ - !ruby/object:Gem::Dependency
70
+ name: I18n
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Abuses I18n to set HTML <title>s
42
84
  email:
43
85
  - caleb@calebthompson.io
44
86
  executables: []
@@ -50,10 +92,13 @@ files:
50
92
  - LICENSE.txt
51
93
  - README.md
52
94
  - Rakefile
95
+ - app/title/helpers/title_helper.rb
53
96
  - lib/title.rb
97
+ - lib/title/engine.rb
54
98
  - lib/title/version.rb
99
+ - spec/helpers/title_helper_spec.rb
55
100
  - title.gemspec
56
- homepage: ''
101
+ homepage: https://github.com/calebthompson/title
57
102
  licenses:
58
103
  - MIT
59
104
  metadata: {}
@@ -61,6 +106,7 @@ post_install_message:
61
106
  rdoc_options: []
62
107
  require_paths:
63
108
  - lib
109
+ - app
64
110
  required_ruby_version: !ruby/object:Gem::Requirement
65
111
  requirements:
66
112
  - - '>='
@@ -76,6 +122,6 @@ rubyforge_project:
76
122
  rubygems_version: 2.0.3
77
123
  signing_key:
78
124
  specification_version: 4
79
- summary: ': Write a gem summary'
80
- test_files: []
81
- has_rdoc:
125
+ summary: I18n your <title>s
126
+ test_files:
127
+ - spec/helpers/title_helper_spec.rb