titler 0.4.1 → 0.4.2
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/.coveralls.yml +2 -0
- data/README.md +67 -56
- data/config/locales/titler.en.yml +2 -2
- data/lib/titler/version.rb +1 -1
- data/spec/helpers/titler_helper_spec.rb +9 -8
- data/spec/spec_helper.rb +3 -0
- data/titler.gemspec +3 -1
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 243be14d9f33906b9429d81e2dc09bcaf1787f69
|
4
|
+
data.tar.gz: 7663cf50018d91b19a79d289098db27585a3b1d0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 70c9195c1e3b2f5c5711c736d35062d23efb890202b7ce2324be402c47158ab36ed9fae7f3b8901a56002605505656f256374864d5823686e0917285e1f7323f
|
7
|
+
data.tar.gz: 284f2771bbe1c0e4cf61198ae4b85011ec52b0ef203fe21cca4dd906033816fd60e7cb88874103b648355a2d624621db54c753555bb143c16c127b94953a0f5a
|
data/.coveralls.yml
ADDED
data/README.md
CHANGED
@@ -3,17 +3,17 @@
|
|
3
3
|
[](https://travis-ci.org/roberttravispierce/titler)
|
4
4
|
[](https://codeclimate.com/github/roberttravispierce/titler)
|
5
5
|
[](https://coveralls.io/github/roberttravispierce/titler?branch=master)
|
6
|
+
[](https://badge.fury.io/rb/titler)
|
6
7
|
|
7
|
-
|
8
|
+
1. [What is it?](#overview)
|
9
|
+
2. [How do I get up and running?](#starting)
|
10
|
+
3. [How do I use it?](#details)
|
11
|
+
4. [How do I customize it?](#customize)
|
12
|
+
4. [So why the fuss about titles anyway?](#why)
|
13
|
+
5. [Who built this?](#attribution)
|
14
|
+
6. [How can I help improve it?](#contributing)
|
8
15
|
|
9
|
-
|
10
|
-
2. [How do I get up and running?](#how-do-i-get-up-and-running?)
|
11
|
-
3. [How do I use it?](#how-do-i-use-it?)
|
12
|
-
4. [So why the fuss about titles anyway?](#so-why-the-fuss-about-titles-anyway?)
|
13
|
-
5. [Who built this?](#who-built-this?)
|
14
|
-
6. [How can I help improve it?](#how-can-i-help-improve-it?)
|
15
|
-
|
16
|
-
## What is it?
|
16
|
+
## <a name="overview"></a>What is it?
|
17
17
|
|
18
18
|
Titler is a ruby gem that automaticaly gives you useful and consistent page titles for your Rails application.
|
19
19
|
|
@@ -21,7 +21,7 @@ Titler is a ruby gem that automaticaly gives you useful and consistent page titl
|
|
21
21
|
|
22
22
|
There are lots of options and configurations available, all with sensible fallbacks and defaults, including reading from your i18n files. See the [How do I use it?](#how-do-i-use-it?) section for more information.
|
23
23
|
|
24
|
-
## How do I get up and running?
|
24
|
+
## <a name="starting"></a>How do I get up and running?
|
25
25
|
|
26
26
|
1. Install the titler gem to your Gemfile and install it:
|
27
27
|
```ruby
|
@@ -31,35 +31,14 @@ gem 'titler'
|
|
31
31
|
$ bundle install
|
32
32
|
```
|
33
33
|
|
34
|
-
2.
|
35
|
-
```console
|
36
|
-
$ rails generate titler:install
|
37
|
-
```
|
38
|
-
|
39
|
-
3. Add the page_title and set_page_title helper methods to your application helper:
|
40
|
-
|
41
|
-
*app/helpers/application_helper.rb*
|
42
|
-
```ruby
|
43
|
-
module ApplicationHelper
|
44
|
-
|
45
|
-
def page_title(page_title)
|
46
|
-
content_for(:page_title) {page_title}
|
47
|
-
end
|
48
|
-
|
49
|
-
def set_page_title
|
50
|
-
Titler::Title.new(controller: self, i18n: I18n, title_as_set: content_for(:page_title) || @page_title).title
|
51
|
-
end
|
52
|
-
...
|
53
|
-
```
|
54
|
-
|
55
|
-
4. Change your application layout title tag to:
|
34
|
+
2. Change the title tag in your application layout(s) to:
|
56
35
|
|
57
36
|
*app/views/layouts/application.html.erb*
|
58
37
|
```html
|
59
|
-
<title><%=
|
38
|
+
<title><%= titler %></title>
|
60
39
|
```
|
61
40
|
|
62
|
-
|
41
|
+
3. Set specific page titles as desired in your controllers or views:
|
63
42
|
```ruby
|
64
43
|
# Example of setting the title in a controller method:
|
65
44
|
helpers.page_title "Legal and Privacy Notices"
|
@@ -71,40 +50,32 @@ helpers.page_title "Legal and Privacy Notices"
|
|
71
50
|
|
72
51
|
This will get you basic, consistent page titles. You can further customize universal and specific page title behavior. See the [How do I use it?](#usage) section.
|
73
52
|
|
74
|
-
## How do I use it?
|
53
|
+
## <a name="details"></a>How do I use it?
|
75
54
|
|
76
55
|

|
77
56
|
|
78
57
|
With Titler, a page title consists of the following elements:
|
79
58
|
|
80
|
-
### Environment Prefix
|
81
|
-
(env_prefix)
|
59
|
+
### Environment Prefix (env_prefix)
|
82
60
|
- A one letter prefix in parentheses showing the rails environment. Example "(D) Title here..." for Development environment, or "(S) Title here..." for Staging environment. **This aids in quickly scanning and locating browser tabs during development and testing**. It is omitted for production environments.
|
83
61
|
|
84
|
-
### Admin Namespace
|
85
|
-
(admin_namespace)
|
62
|
+
### Admin Namespace (admin_namespace)
|
86
63
|
- The title will be prefixed with "Admin" (admin_namespace i18n value) if the page controller is within an Admin namespace.
|
87
64
|
|
88
|
-
### Element Delimiter
|
89
|
-
(delimiter)
|
65
|
+
### Element Delimiter (delimiter)
|
90
66
|
- Elements within the built title string will be delimited by this string. Developer can set it in the i18n file. The default is " - "
|
91
67
|
|
92
|
-
### Title Body
|
93
|
-
(title_body)
|
94
|
-
|
68
|
+
### Title Body (title_body)
|
95
69
|
This is the core of the individual page title, which is set by the developer throughout their app. In order of preference:
|
96
70
|
|
97
71
|
- content_for :page_title if found
|
98
72
|
- @page_title instance variable if found
|
99
73
|
- The Controller and Action (method) name is used if none of the above are found
|
100
74
|
|
101
|
-
### App Tagline
|
102
|
-
(app_tagline)
|
103
|
-
|
75
|
+
### App Tagline (app_tagline)
|
104
76
|
This allows for an additional marketing tagline to be in every title. Set in the "app_tagline" i18n value and ignored if not found.
|
105
77
|
|
106
|
-
### App Name
|
107
|
-
(app_name)
|
78
|
+
### App Name (app_name)
|
108
79
|
|
109
80
|
- The built title string is appended with the name of the application. This is set in the "app_name" i18n value. Default fallback is the Rails.application.class name.
|
110
81
|
|
@@ -117,22 +88,53 @@ This allows for an additional marketing tagline to be in every title. Set in the
|
|
117
88
|
- Mom App | Posts Index
|
118
89
|
|
119
90
|
|
120
|
-
###
|
91
|
+
### _Demonstration App with Live Versions_
|
121
92
|
|
122
|
-
|
93
|
+

|
123
94
|
|
124
95
|
There is a [titler_demo](https://github.com/roberttravispierce/titler_demo) demonstration app that shows how the titler gem works in a Rails app in many of the different combinations & situations. You can view live versions of it here:
|
125
96
|
|
126
97
|
- In a Staging Environment: https://titler-demo-staging.herokuapp.com/
|
127
98
|
- In a Production Environment: https://titler-demo-production.herokuapp.com/
|
128
99
|
|
129
|
-
##
|
100
|
+
## <a name="customize"></a>How do I customize it?
|
130
101
|
|
131
|
-
|
102
|
+
I'm working on a generator to add a config initializer and i18n locale file. In the meantime you can add a i18n locale file to change defaults (see the [titler_demo](https://github.com/roberttravispierce/titler_demo) demonstration app for an example):
|
132
103
|
|
133
|
-
|
104
|
+
*app/config/locales/titler.en.yml*
|
105
|
+
```yaml
|
106
|
+
---
|
107
|
+
en:
|
108
|
+
titler:
|
109
|
+
app_name: 'App Name'
|
110
|
+
app_tagline: 'Your tagline'
|
111
|
+
delimiter: ' | '
|
112
|
+
```
|
134
113
|
|
135
|
-
|
114
|
+

|
115
|
+
|
116
|
+
*app/config/initializers/titler.rb*
|
117
|
+
```ruby
|
118
|
+
Titler.configure do |config|
|
119
|
+
config.use_env_prefix = true
|
120
|
+
config.delimiter = ' - '
|
121
|
+
config.app_name_position = 'append' # append, prepend, none
|
122
|
+
config.use_app_tagline = true
|
123
|
+
config.admin_name = 'Admin'
|
124
|
+
config.admin_controller = AdminController
|
125
|
+
end
|
126
|
+
```
|
127
|
+
|
128
|
+
|
129
|
+
## <a name="why"></a>So why the fuss about titles anyway?
|
130
|
+
|
131
|
+
Here are some resources to learn more about the importance of thoughtful, well-crafted page titles:
|
132
|
+
|
133
|
+
- [Title Tags Guide \| Good & Bad Examples \| Search Engine Watch](https://searchenginewatch.com/2016/05/16/how-to-write-meta-title-tags-for-seo-with-good-and-bad-examples/#checklist)
|
134
|
+
- [9 Best Practices Title Tag Search Engine Optimization \- SEO](http://searchengineland.com/nine-best-practices-for-optimized-title-tags-111979)
|
135
|
+
- [Writing HTML Title Tags For Humans, Google & Bing](http://searchengineland.com/writing-html-title-tags-humans-google-bing-59384)
|
136
|
+
|
137
|
+
## <a name="attribution"></a>Who built this?
|
136
138
|
|
137
139
|
Titler was conceived and developed by Robert Travis Pierce ([roberttravispierce](https://github.com/roberttravispierce)), to scratch his own itch and further his education in Ruby and Rails.
|
138
140
|
|
@@ -140,7 +142,9 @@ Invaluable guidance and encouragment was provided along the way by Jonathan Allu
|
|
140
142
|
|
141
143
|
In addition, the [title gem](https://github.com/calebthompson/title) by [calebthompson](https://github.com/calebthompson), helped greatly with figuring out how to structure the gem as a rails engine, and served as a guide for several improvements.
|
142
144
|
|
143
|
-
## How can I help improve it?
|
145
|
+
## <a name="contributing"></a>How can I help improve it?
|
146
|
+
|
147
|
+
Please feel free to contribute any suggestions, improvements or refactors. This is an exercise in ruby education for me and an attempt to add something of value to the community.
|
144
148
|
|
145
149
|
Bug reports and pull requests are welcome on GitHub at https://github.com/roberttravispierce/titler.
|
146
150
|
|
@@ -155,6 +159,13 @@ Here's the most direct way to get your work merged into the project.
|
|
155
159
|
- Push the branch up to your fork
|
156
160
|
- Send a pull request for your branch
|
157
161
|
|
162
|
+
### Future Improvements
|
163
|
+
|
164
|
+
- Implement configuration and generator. The components are mostly there already. Just need to hook it all up correctly.
|
165
|
+
- Have i18n template installed locally by a generator.
|
166
|
+
- Improve test coverage and scheme
|
167
|
+
- Implement the more robust controller/action fallback ideas from the [title gem](https://github.com/calebthompson/title)
|
168
|
+
|
158
169
|
### Developing locally
|
159
170
|
|
160
171
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
data/lib/titler/version.rb
CHANGED
@@ -65,6 +65,15 @@ describe Titler::TitlerHelper do
|
|
65
65
|
|
66
66
|
# Specific Page Title Context ----------------------------------------------------
|
67
67
|
context 'when specific page title exists' do
|
68
|
+
it '(1) uses page_title var when present' do
|
69
|
+
controller = MockController.new
|
70
|
+
stub_rails(controller, 'production', nil)
|
71
|
+
load_translations({})
|
72
|
+
titler_helper.instance_variable_set(:@page_title, 'Var Test Page')
|
73
|
+
expected_title = "#{env_prefix}Var Test Page - #{app_name}"
|
74
|
+
expect(titler_helper.titler).to eq(expected_title)
|
75
|
+
end
|
76
|
+
|
68
77
|
# it '(1) uses content_for when present' do
|
69
78
|
# controller = MockController.new
|
70
79
|
# stub_rails(controller, 'production', nil)
|
@@ -73,14 +82,6 @@ describe Titler::TitlerHelper do
|
|
73
82
|
# expected_title = "#{env_prefix}Test Page - #{app_name}"
|
74
83
|
# expect(titler_helper.titler).to eq(expected_title)
|
75
84
|
# end
|
76
|
-
|
77
|
-
it '(2) uses page_title var when present' do
|
78
|
-
controller = MockController.new
|
79
|
-
stub_rails(controller, 'production', nil)
|
80
|
-
titler_helper.instance_variable_set(:@page_title, 'Var Test Page')
|
81
|
-
expected_title = "#{env_prefix}Var Test Page - #{app_name}"
|
82
|
-
expect(titler_helper.titler).to eq(expected_title)
|
83
|
-
end
|
84
85
|
end
|
85
86
|
|
86
87
|
# Configuration Values Context ----------------------------------------------------
|
data/spec/spec_helper.rb
CHANGED
data/titler.gemspec
CHANGED
@@ -6,7 +6,7 @@ require 'titler/version'
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = "titler"
|
8
8
|
spec.version = Titler::VERSION
|
9
|
-
spec.authors = ["Robert Travis Pierce"
|
9
|
+
spec.authors = ["Robert Travis Pierce"]
|
10
10
|
spec.email = ["robert@roberttravispierce.com"]
|
11
11
|
|
12
12
|
spec.summary = %q{A gem that make titling your Rails app pages dead simple but still allows you flexibility and control.}
|
@@ -47,7 +47,9 @@ Gem::Specification.new do |spec|
|
|
47
47
|
spec.add_development_dependency "pry-nav"
|
48
48
|
spec.add_development_dependency 'rb-readline'
|
49
49
|
spec.add_development_dependency 'rspec-rails'
|
50
|
+
spec.add_development_dependency 'coveralls'
|
50
51
|
|
51
52
|
spec.add_dependency 'rails', '>= 3.1'
|
52
53
|
spec.add_dependency 'i18n'
|
54
|
+
|
53
55
|
end
|
metadata
CHANGED
@@ -1,11 +1,10 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: titler
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Robert Travis Pierce
|
8
|
-
- Jonathan Allured
|
9
8
|
autorequire:
|
10
9
|
bindir: exe
|
11
10
|
cert_chain: []
|
@@ -179,6 +178,20 @@ dependencies:
|
|
179
178
|
- - ">="
|
180
179
|
- !ruby/object:Gem::Version
|
181
180
|
version: '0'
|
181
|
+
- !ruby/object:Gem::Dependency
|
182
|
+
name: coveralls
|
183
|
+
requirement: !ruby/object:Gem::Requirement
|
184
|
+
requirements:
|
185
|
+
- - ">="
|
186
|
+
- !ruby/object:Gem::Version
|
187
|
+
version: '0'
|
188
|
+
type: :development
|
189
|
+
prerelease: false
|
190
|
+
version_requirements: !ruby/object:Gem::Requirement
|
191
|
+
requirements:
|
192
|
+
- - ">="
|
193
|
+
- !ruby/object:Gem::Version
|
194
|
+
version: '0'
|
182
195
|
- !ruby/object:Gem::Dependency
|
183
196
|
name: rails
|
184
197
|
requirement: !ruby/object:Gem::Requirement
|
@@ -217,6 +230,7 @@ executables: []
|
|
217
230
|
extensions: []
|
218
231
|
extra_rdoc_files: []
|
219
232
|
files:
|
233
|
+
- ".coveralls.yml"
|
220
234
|
- ".gitignore"
|
221
235
|
- ".rspec"
|
222
236
|
- ".ruby-gemset"
|