page_title_helper 3.0.0 → 6.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +71 -53
- data/CODE_OF_CONDUCT.md +3 -3
- data/Gemfile +2 -0
- data/README.md +146 -124
- data/Rakefile +2 -0
- data/lib/page_title_helper/version.rb +3 -1
- data/lib/page_title_helper.rb +32 -10
- data/page_title_helper.gemspec +11 -10
- data/test/multiple_formats_test.rb +5 -2
- data/test/page_title_helper_test.rb +5 -1
- data/test/test_helper.rb +2 -0
- metadata +50 -23
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 5526377f52ae74a93d1dd45729c0278258db52f32e5e38e37ec9baed06a33a6d
|
4
|
+
data.tar.gz: bd18c28d5e3f5bfe0b0d2138d305d4af987293088dd7ac3c362db127ef903cbf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d1fe1095a08095559012b02daceda00de0152bf1f4dd531a719acbdabac958f5a0e2722950119bf0091783c2592a0c90720dbfaaf9f2f98d26e07012b400f347
|
7
|
+
data.tar.gz: 18c030e2df24abbe72cbfbecb39b3ee373b7a4723aeb1b03c3ab2d55a7a27bcec56bc3c4d5618ebc862e202f56369e672ec106af9fbf6039fbec4d26104f1b4a
|
data/CHANGELOG.md
CHANGED
@@ -1,73 +1,91 @@
|
|
1
1
|
# Page title helper change log
|
2
2
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
4
|
-
This project adheres to [Semantic Versioning](
|
4
|
+
This project adheres to [Semantic Versioning](https://semver.org/).
|
5
5
|
|
6
|
-
Read more at [Keep a CHANGELOG](
|
6
|
+
Read more at [Keep a CHANGELOG](https://keepachangelog.com/en/0.3.0/)
|
7
7
|
about why a change log is important.
|
8
8
|
|
9
|
-
|
10
|
-
## 3.0.0 [unreleased]
|
9
|
+
## x.y.z
|
11
10
|
|
12
11
|
### Added
|
13
|
-
- Add Ruby 2.4.0 to the build matrix
|
14
|
-
([#68](https://github.com/lwe/page_title_helper/pull/68))
|
15
|
-
- Add a CHANGELOG.md
|
16
|
-
([#59](https://github.com/lwe/page_title_helper/pull/59))
|
17
|
-
- Add RuboCop checking to the CI
|
18
|
-
([#52](https://github.com/lwe/page_title_helper/pull/52))
|
19
|
-
- Add a CODE_OF_CONDUCT.md
|
20
|
-
([#51](https://github.com/lwe/page_title_helper/pull/51))
|
21
|
-
- Update Ruby to 2.3.3 and 2.2.6 on Travis
|
22
|
-
([#38](https://github.com/lwe/page_title_helper/pull/38))
|
23
|
-
- Add Ruby 2.3.0 to the build matrix
|
24
|
-
- Re-add Ruby 2.0.0 to the build matrix
|
25
|
-
([#29](https://github.com/lwe/page_title_helper/pull/29))
|
26
|
-
- Test against Ruby 2.2
|
27
|
-
- Use Appraisal for building with different Rails versions
|
28
|
-
([#19](https://github.com/lwe/page_title_helper/pull/19))
|
29
|
-
|
30
12
|
|
31
13
|
### Changed
|
32
|
-
- Replaced Appraisals with specific Gemfiles
|
33
|
-
([#41](https://github.com/lwe/page_title_helper/pull/41))
|
34
|
-
- Delete obsolete init.rb file
|
35
|
-
([#61](https://github.com/lwe/page_title_helper/pull/61))
|
36
|
-
- Add Rails 5.0 to the build matrix
|
37
|
-
([#42](https://github.com/lwe/page_title_helper/pull/42))
|
38
|
-
- Raise RVM and Gem minimum versions
|
39
|
-
([#3](https://github.com/lwe/page_title_helper/pull/3))
|
40
|
-
|
41
14
|
|
42
15
|
### Deprecated
|
43
16
|
|
17
|
+
### Removed
|
18
|
+
|
19
|
+
### Fixed
|
20
|
+
|
21
|
+
### Security
|
22
|
+
|
23
|
+
## 6.0.0
|
24
|
+
|
25
|
+
### Added
|
26
|
+
- Add support for Rails 7.0 (#131)
|
27
|
+
- Add support for Ruby 3.1 (#143)
|
44
28
|
|
45
29
|
### Removed
|
46
|
-
- Drop support for
|
47
|
-
|
48
|
-
|
49
|
-
|
30
|
+
- Drop support for Ruby 2.5 and 2.6 (#127, #145)
|
31
|
+
|
32
|
+
### Fixed
|
33
|
+
- Avoid modifying a frozen array in Ruby 3 (#135)
|
34
|
+
|
35
|
+
## 5.0.0
|
36
|
+
|
37
|
+
### Added
|
38
|
+
- Add support for Ruby 3 (#120)
|
39
|
+
- Add automatic gem release (#122)
|
40
|
+
- Add support for Rails 6.1 (#113, #114)
|
41
|
+
- Officially support Ruby 2.7 (#103)
|
50
42
|
|
43
|
+
### Removed
|
44
|
+
- Drop support for Ruby 2.4 (#109)
|
45
|
+
- Drop support for Rails < 5.2 (#104)
|
51
46
|
|
52
47
|
### Fixed
|
53
|
-
-
|
54
|
-
|
55
|
-
- Fix the Travis build on Ruby 2.3.3
|
56
|
-
([#63](https://github.com/lwe/page_title_helper/pull/63))
|
57
|
-
- Do do not shell-out to `git` in Gemfile
|
58
|
-
([#49](https://github.com/lwe/page_title_helper/pull/49))
|
59
|
-
- Get the tests to run in Rails 4.2 and 5.0
|
60
|
-
([#40](https://github.com/lwe/page_title_helper/pull/40))
|
61
|
-
- Stop requiring version from the main class
|
62
|
-
([#47](https://github.com/lwe/page_title_helper/pull/47))
|
63
|
-
- Allow the Rails 3.2 build to fail only with Ruby 2.2
|
64
|
-
([#30](https://github.com/lwe/page_title_helper/pull/30))
|
65
|
-
- Allow Rails 3.2 builds to fail
|
66
|
-
([#26](https://github.com/lwe/page_title_helper/pull/26))
|
67
|
-
- Configure Travis for better performance
|
68
|
-
([#10](https://github.com/lwe/page_title_helper/pull/10))
|
69
|
-
- Remove Gemfile.lock
|
70
|
-
([#1](https://github.com/lwe/page_title_helper/pull/1))
|
48
|
+
- Use a better-maintained Ruby setup for the CI (#121)
|
49
|
+
- Fix warnings in the `.travis.yml` (#106)
|
71
50
|
|
51
|
+
## 4.0.0
|
72
52
|
|
73
|
-
###
|
53
|
+
### Added
|
54
|
+
- Add support for Rails 6.0 (#94)
|
55
|
+
|
56
|
+
### Removed
|
57
|
+
- Drop support for Ruby < 2.4 (#93)
|
58
|
+
|
59
|
+
## 3.0.0
|
60
|
+
|
61
|
+
### Added
|
62
|
+
- Add Ruby 2.4.0 to the build matrix (#68)
|
63
|
+
- Add a CHANGELOG.md (#59)
|
64
|
+
- Add RuboCop checking to the CI (#52)
|
65
|
+
- Add a CODE_OF_CONDUCT.md (#51)
|
66
|
+
- Update Ruby to 2.3.3 and 2.2.6 on Travis (#38)
|
67
|
+
- Add Ruby 2.3.0 to the build matrix
|
68
|
+
- Re-add Ruby 2.0.0 to the build matrix (#29)
|
69
|
+
- Test against Ruby 2.2
|
70
|
+
- Use Appraisal for building with different Rails versions (#19)
|
71
|
+
|
72
|
+
### Changed
|
73
|
+
- Replaced Appraisals with specific Gemfiles (#41)
|
74
|
+
- Delete obsolete init.rb file (#61)
|
75
|
+
- Add Rails 5.0 to the build matrix (#42)
|
76
|
+
- Raise RVM and Gem minimum versions (#3)
|
77
|
+
|
78
|
+
### Removed
|
79
|
+
- Drop support for Rails 3.2 and 4.0 (#39)
|
80
|
+
- Drop support for Ruby 1.9.x (#24)
|
81
|
+
|
82
|
+
### Fixed
|
83
|
+
- Fix @_page_title uninitialized warning (#62)
|
84
|
+
- Fix the Travis build on Ruby 2.3.3 (#63)
|
85
|
+
- Do do not shell-out to `git` in Gemfile (#49)
|
86
|
+
- Get the tests to run in Rails 4.2 and 5.0 (#40)
|
87
|
+
- Stop requiring version from the main class (#47)
|
88
|
+
- Allow the Rails 3.2 build to fail only with Ruby 2.2 (#30)
|
89
|
+
- Allow Rails 3.2 builds to fail (#26)
|
90
|
+
- Configure Travis for better performance (#10)
|
91
|
+
- Remove Gemfile.lock (#1)
|
data/CODE_OF_CONDUCT.md
CHANGED
@@ -71,7 +71,7 @@ members of the project's leadership.
|
|
71
71
|
|
72
72
|
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
73
73
|
version 1.4, available at
|
74
|
-
[
|
74
|
+
[https://contributor-covenant.org/version/1/4/][version].
|
75
75
|
|
76
|
-
[homepage]:
|
77
|
-
[version]:
|
76
|
+
[homepage]: https://contributor-covenant.org
|
77
|
+
[version]: https://contributor-covenant.org/version/1/4/
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,202 +1,224 @@
|
|
1
1
|
# Page title helper
|
2
2
|
|
3
|
-
[![
|
4
|
-
[![Gem Version](https://badge.fury.io/rb/page_title_helper.svg)](
|
5
|
-
|
6
|
-
This project adheres to [Semantic Versioning](http://semver.org/).
|
3
|
+
[![GitHub CI Status](https://github.com/lwe/page_title_helper/workflows/CI/badge.svg?branch=main)](https://github.com/lwe/page_title_helper/actions)
|
4
|
+
[![Gem Version](https://badge.fury.io/rb/page_title_helper.svg)](https://badge.fury.io/rb/page_title_helper)
|
7
5
|
|
6
|
+
This project adheres to [Semantic Versioning](https://semver.org/).
|
8
7
|
|
9
8
|
## What does this gem do?
|
10
9
|
|
11
|
-
Ever wondered if there was an easier and DRY-way to set your page titles
|
12
|
-
introducing _page title helper_, a small view helper for
|
13
|
-
to inflect titles from controllers and actions.
|
10
|
+
Ever wondered if there was an easier and DRY-way to set your page titles
|
11
|
+
(and/or headings), introducing _page title helper_, a small view helper for
|
12
|
+
Rails to inflect titles from controllers and actions.
|
14
13
|
|
15
14
|
In your layout, add this to your `<head>`-section:
|
16
15
|
|
17
|
-
|
18
|
-
|
19
|
-
|
16
|
+
```html
|
17
|
+
<title><%= page_title %></title>
|
18
|
+
```
|
20
19
|
|
21
20
|
That's it. Now just add translations, in e.g. `config/locales/en.yml`:
|
22
21
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
22
|
+
```yaml
|
23
|
+
en:
|
24
|
+
contacts:
|
25
|
+
index:
|
26
|
+
title: "Contacts"
|
27
|
+
```
|
27
28
|
|
28
29
|
When `/contacts/` is requested, the key `:en, :contacts, :index, :title`
|
29
|
-
is looked up and printed, together with the applications basename, like:
|
30
|
+
is looked up and printed, together with the applications basename, like:
|
31
|
+
`Contacts - My cool App`.
|
30
32
|
The format etc. is of course configurable, just head down to the options.
|
31
33
|
|
32
34
|
## Installation
|
33
35
|
|
34
36
|
As gem (from rubygems.org):
|
35
37
|
|
36
|
-
|
37
|
-
|
38
|
+
```ruby
|
39
|
+
# then add the following line to Gemfile
|
40
|
+
gem 'page_title_helper'
|
38
41
|
|
39
|
-
|
40
|
-
|
42
|
+
# living on the bleeding edge?
|
43
|
+
gem 'page_title_helper', git: 'git://github.com/lwe/page_title_helper.git'
|
44
|
+
```
|
41
45
|
|
42
46
|
## Translated titles
|
43
47
|
|
44
|
-
All translated titles are inflected from the current controller and action,
|
45
|
-
easily explain all lookups, here an example with the corresponding
|
48
|
+
All translated titles are inflected from the current controller and action,
|
49
|
+
so to easily explain all lookups, here an example with the corresponding
|
50
|
+
lookups:
|
46
51
|
|
47
|
-
|
48
|
-
|
49
|
-
|
52
|
+
```
|
53
|
+
Admin::AccountController#index => :'admin.account.index.title'
|
54
|
+
:'admin.account.title'
|
55
|
+
options[:default]
|
56
|
+
```
|
50
57
|
|
51
|
-
For `create` and `update` a further fallback to `new.title` and `edit.title`
|
52
|
-
been added, because they certainly are duplicates.
|
58
|
+
For `create` and `update` a further fallback to `new.title` and `edit.title`
|
59
|
+
have been added, because they certainly are duplicates.
|
53
60
|
|
54
61
|
## Customize titles
|
55
62
|
|
56
|
-
Need a custom title, or need to fill in some placeholders? Just use the _bang_
|
57
|
-
`contacts/show.html.erb` the requirement is to
|
58
|
-
`<title>-tag`as well as in the heading?
|
63
|
+
Need a custom title, or need to fill in some placeholders? Just use the _bang_
|
64
|
+
method (`page_title!`), in e.g. `contacts/show.html.erb` the requirement is to
|
65
|
+
display the contacts name in the `<title>-tag`as well as in the heading?
|
66
|
+
|
67
|
+
```html
|
68
|
+
<h1><%= page_title!(@contact.name) %></h1>
|
69
|
+
```
|
59
70
|
|
60
|
-
|
71
|
+
A call to `page_title` will now return the contacts name, neat :) if for
|
72
|
+
example the `<h1>` does not match the `<title>`, then well, just do something
|
73
|
+
like:
|
61
74
|
|
62
|
-
|
63
|
-
|
75
|
+
```html
|
76
|
+
<% page_title!(@contact.name + " (" + @contact.company.name + ")") %>
|
77
|
+
<h1><%= @contact.name %></h1>
|
78
|
+
```
|
64
79
|
|
65
|
-
|
66
|
-
|
80
|
+
Guess, that's it. Of course it's also possible to use `translate` within
|
81
|
+
`page_title!`, to translate custom titles, like:
|
67
82
|
|
68
|
-
|
69
|
-
translate custom titles, like:
|
83
|
+
In `config/locales/en.yml`:
|
70
84
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
85
|
+
```yaml
|
86
|
+
en:
|
87
|
+
dashboard:
|
88
|
+
index:
|
89
|
+
title: "Welcome back, {{name}}"
|
90
|
+
```
|
76
91
|
|
77
|
-
|
78
|
-
|
92
|
+
In `app/views/dashboard/index.html.erb`:
|
93
|
+
```html
|
94
|
+
<h1><%= page_title!(t('.title', name: @user.first_name)) %></h1>
|
95
|
+
```
|
79
96
|
|
80
|
-
## More fun with <
|
97
|
+
## More fun with <code>:format</code>
|
81
98
|
|
82
|
-
The `:format` option is used to specify how a title is formatted, i.e. if the
|
83
|
-
prepended or appended or if it contains the account name etc.
|
84
|
-
paperclip's path interpolations:
|
99
|
+
The `:format` option is used to specify how a title is formatted, i.e. if the
|
100
|
+
app name is prepended or appended or if it contains the account name etc.
|
101
|
+
It uses a similar approach as paperclip's path interpolations:
|
85
102
|
|
86
|
-
|
103
|
+
```ruby
|
104
|
+
page_title format: ':title / :app' # => "Contacts / My cool app"
|
105
|
+
```
|
87
106
|
|
88
|
-
Adding custom interpolations is as easy as defining a block, for example to
|
89
|
-
controller:
|
107
|
+
Adding custom interpolations is as easy as defining a block, for example to
|
108
|
+
access the current controller:
|
90
109
|
|
91
|
-
|
92
|
-
|
93
|
-
|
110
|
+
```ruby
|
111
|
+
PageTitleHelper.interpolates :controller do |env|
|
112
|
+
env[:view].controller.controller_name.humanize
|
113
|
+
end
|
94
114
|
|
95
|
-
|
115
|
+
page_title format: ':title / :controller / :app' # => "Welcome back / Dashboard / My cool app"
|
116
|
+
```
|
96
117
|
|
97
|
-
To access just the title, without any magic app stuff interpolated or appended,
|
118
|
+
To access just the title, without any magic app stuff interpolated or appended,
|
119
|
+
use:
|
98
120
|
|
99
|
-
|
100
|
-
|
121
|
+
```ruby
|
122
|
+
page_title! "untitled"
|
123
|
+
page_title format: false # => "untitled"
|
124
|
+
```
|
101
125
|
|
102
126
|
Need a custom format for a single title? Just return an array:
|
103
127
|
|
104
|
-
|
105
|
-
|
128
|
+
In the view:
|
129
|
+
|
130
|
+
```html
|
131
|
+
<h1><%= page_title!(@contact.name, ":title from :company - :app") %></h1> # => <h1>Franz Meyer</h1>
|
132
|
+
```
|
133
|
+
|
134
|
+
In the `<head>`:
|
135
|
+
|
136
|
+
```html
|
137
|
+
<title><%= page_title %></title> # => this time it will use custom title like "Franz Meyer from ABC Corp. - My cool app"
|
138
|
+
```
|
139
|
+
|
140
|
+
To streamline that feature a bit and simplify reuse of often used formats,
|
141
|
+
it's possible to define format aliases like:
|
106
142
|
|
107
|
-
|
108
|
-
<title><%= page_title %></title> # => this time it will use custom title like "Franz Meyer from ABC Corp. - My cool app"
|
143
|
+
In an initializer, e.g., `config/initializers/page_title_helper.rb`:
|
109
144
|
|
110
|
-
|
145
|
+
```ruby
|
146
|
+
PageTitleHelper.formats[:with_company] = ":title from :company - :app"
|
147
|
+
# show app first for promo pages :)
|
148
|
+
PageTitleHelper.formats[:promo] = ":app - :title"
|
149
|
+
```
|
111
150
|
|
112
|
-
|
113
|
-
PageTitleHelper.formats[:with_company] = ":title from :company - :app"
|
114
|
-
PageTitleHelper.formats[:promo] = ":app - :title" # show app first for promo pages :)
|
151
|
+
Then in the view to display a contact:
|
115
152
|
|
116
|
-
|
117
|
-
|
153
|
+
```ruby
|
154
|
+
page_title! @contact.name, :with_company
|
155
|
+
```
|
118
156
|
|
119
|
-
|
120
|
-
en:
|
121
|
-
pages:
|
122
|
-
features:
|
123
|
-
title:
|
124
|
-
- "Features comparison"
|
125
|
-
- !ruby/sym promo
|
157
|
+
Or for the promo page via `config/locales/en.yml` (!):
|
126
158
|
|
127
|
-
|
128
|
-
|
159
|
+
```yaml
|
160
|
+
en:
|
161
|
+
pages:
|
162
|
+
features:
|
163
|
+
title:
|
164
|
+
- "Features comparison"
|
165
|
+
- !ruby/sym promo
|
166
|
+
```
|
167
|
+
|
168
|
+
Pretty, cool, ain't it? The special `format: :app` works also via the `formats`
|
169
|
+
hash. Then there is also a `:default` format, which can be used to override the
|
170
|
+
default format.
|
129
171
|
|
130
172
|
## All options - explained
|
131
173
|
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
<td>Inflected from <tt>Rails.root</tt></td>
|
141
|
-
<td>string</td>
|
142
|
-
</tr>
|
143
|
-
<tr>
|
144
|
-
<td><tt>:default</tt></td>
|
145
|
-
<td>String which is displayed when no translation exists and no custom title
|
146
|
-
has been specified. Can also be set to a symbol or array to take advantage of
|
147
|
-
<tt>I18n.translate</tt>s <tt>:default</tt> option.</td>
|
148
|
-
<td><tt>:'app.tagline'</tt></td>
|
149
|
-
<td>string, symbol or array of those</td>
|
150
|
-
</tr>
|
151
|
-
<tr>
|
152
|
-
<td><tt>:format</tt></td>
|
153
|
-
<td>Defines the output format, accepts a string containing multiple interpolations, or
|
154
|
-
a symbol to a format alias, see <i>More fun with <tt>:format</tt></i>. If set to
|
155
|
-
+false+, just the current title is returned.</td>
|
156
|
-
<td><tt>:default</tt></td>
|
157
|
-
<td>string, symbol</td>
|
158
|
-
</tr>
|
159
|
-
</table>
|
160
|
-
</p>
|
161
|
-
|
162
|
-
Options can be set globally via `PageTitleHelper.options`. Note, currently it only
|
163
|
-
makes sense to set `:default` globally.
|
174
|
+
| Option | Description | Default | Values |
|
175
|
+
|----------|-------------|---------|--------|
|
176
|
+
|`:app` | Specify the applications name, however it's recommended to define it via translation key `:'app.name'`. | Inflected from `Rails.root`| string |
|
177
|
+
|`:default`| String which is displayed when no translation exists and no custom title has been specified. Can also be set to a symbol or array to take advantage of `I18n.translate`'s `:default` option. | `'app.tagline'` | string, symbol or array of those |
|
178
|
+
|`:format` | Defines the output format, accepts a string containing multiple interpolations, or a symbol to a format alias, see _More fun with `:format`_. If set to `false`, just the current title is returned. | `:default`| string, symbol |
|
179
|
+
|
180
|
+
Options can be set globally via `PageTitleHelper.options`. Note, currently it
|
181
|
+
only makes sense to set `:default` globally.
|
164
182
|
|
165
183
|
To add or change formats use:
|
166
184
|
|
167
|
-
|
168
|
-
|
185
|
+
```ruby
|
186
|
+
# change the default format used (if no format is specified):
|
187
|
+
PageTitleHelper.formats[:default] = ":title // :app"
|
169
188
|
|
170
|
-
|
171
|
-
|
189
|
+
# add a custom format alias (which can be used with page_title(format: :promo))
|
190
|
+
PageTitleHelper.formats[:promo] = ":app // :title"
|
191
|
+
```
|
172
192
|
|
173
|
-
_Note:_
|
193
|
+
_Note:_ It's recommended to add this kind of stuff to an initializer, like e.g.
|
174
194
|
`config/initializers/page_title_helper.rb`.
|
175
195
|
|
176
196
|
## A (maybe useful) interpolation
|
177
197
|
|
178
|
-
The internationalized controller name, with fallback to just display the
|
179
|
-
|
180
|
-
PageTitleHelper.interpolates :controller do |env|
|
181
|
-
c = env[:view].controller
|
182
|
-
I18n.t(c.controller_path.tr('/', '.') + '.controller', default: c.controller_name.humanize)
|
183
|
-
end
|
198
|
+
The internationalized controller name, with fallback to just display the
|
199
|
+
humanized name:
|
184
200
|
|
185
|
-
|
201
|
+
```ruby
|
202
|
+
PageTitleHelper.interpolates :controller do |env|
|
203
|
+
c = env[:view].controller
|
204
|
+
I18n.t(c.controller_path.tr('/', '.') + '.controller', default: c.controller_name.humanize)
|
205
|
+
end
|
206
|
+
```
|
186
207
|
|
208
|
+
_Note:_ Put this kind of stuff into an initializer, like
|
209
|
+
`config/initializers/page_title_helper.rb` or something like that.
|
187
210
|
|
188
211
|
## Contributing
|
189
212
|
|
190
213
|
Pull request are more than welcome. Please adhere to our
|
191
|
-
[
|
214
|
+
[code of conduct](CODE_OF_CONDUCT.md) in discussions and contributions.
|
192
215
|
Thanks!
|
193
216
|
|
194
|
-
|
195
217
|
## Maintainers
|
196
218
|
|
197
219
|
* [@lwe - Lukas Westermann](https://github.com/lwe)
|
198
220
|
* [@oliverklee - Oliver Klee](https://github.com/oliverklee)
|
199
221
|
|
200
|
-
|
201
222
|
## Licence and copyright
|
202
|
-
Copyright (c) 2009 Lukas Westermann (Zurich, Switzerland), released under the
|
223
|
+
Copyright (c) 2009 Lukas Westermann (Zurich, Switzerland), released under the
|
224
|
+
MIT license
|
data/Rakefile
CHANGED
data/lib/page_title_helper.rb
CHANGED
@@ -1,16 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# PageTitleHelper provides an +ActionView+ helper method to simplify adding
|
2
4
|
# custom titles to pages.
|
3
5
|
#
|
4
6
|
# Author:: Lukas Westermann
|
5
7
|
# Copyright:: Copyright (c) 2009 Lukas Westermann (Zurich, Switzerland)
|
6
|
-
# Licence:: MIT-Licence (
|
8
|
+
# Licence:: MIT-Licence (https://www.opensource.org/licenses/mit-license.php)
|
7
9
|
#
|
8
|
-
# See documentation for +page_title+ for usage examples and more
|
10
|
+
# See documentation for +page_title+ for usage examples and more information.
|
9
11
|
require 'active_support'
|
10
12
|
|
11
13
|
# PageTitleHelper
|
12
14
|
module PageTitleHelper
|
13
|
-
#
|
15
|
+
# https://github.com/thoughtbot/paperclip/blob/master/lib/paperclip/interpolations.rb
|
14
16
|
module Interpolations
|
15
17
|
extend self
|
16
18
|
|
@@ -23,7 +25,7 @@ module PageTitleHelper
|
|
23
25
|
end
|
24
26
|
|
25
27
|
def app(env)
|
26
|
-
env[:app] || I18n.
|
28
|
+
env[:app] || I18n.t('app.name', default: File.basename(Rails.root).humanize)
|
27
29
|
end
|
28
30
|
|
29
31
|
def title(env)
|
@@ -67,16 +69,13 @@ module PageTitleHelper
|
|
67
69
|
options[:format] ||= :title # handles :format => false
|
68
70
|
options.assert_valid_keys(:app, :default, :format)
|
69
71
|
|
70
|
-
|
71
|
-
title = @_page_title ||= page_title_from_translation(options[:default])
|
72
|
-
title, options[:format] = *(title << options[:format]) if title.is_a?(Array)
|
72
|
+
format, real_title = build_title_and_format(options)
|
73
73
|
|
74
74
|
# handle format aliases
|
75
|
-
format = options.delete(:format)
|
76
75
|
format = PageTitleHelper.formats[format] if PageTitleHelper.formats.include?(format)
|
77
76
|
|
78
77
|
# construct basic env to pass around
|
79
|
-
env = { title:
|
78
|
+
env = { title: real_title, app: options[:app], options: options, view: self }
|
80
79
|
|
81
80
|
# interpolate format
|
82
81
|
Interpolations.interpolate(format, env)
|
@@ -96,7 +95,30 @@ module PageTitleHelper
|
|
96
95
|
keys << :"#{base}.title"
|
97
96
|
keys << default
|
98
97
|
|
99
|
-
I18n.
|
98
|
+
I18n.t(keys.shift, default: keys)
|
99
|
+
end
|
100
|
+
|
101
|
+
private
|
102
|
+
|
103
|
+
##
|
104
|
+
# Read the page title and splits it into 'real' title and the customized
|
105
|
+
# format.
|
106
|
+
#
|
107
|
+
# @param {Hash} options
|
108
|
+
#
|
109
|
+
# @return {Array}
|
110
|
+
#
|
111
|
+
def build_title_and_format(options)
|
112
|
+
raw_title = @_page_title ||= page_title_from_translation(options[:default])
|
113
|
+
if raw_title.is_a?(Array)
|
114
|
+
title_and_format = raw_title + [options[:format]]
|
115
|
+
real_title, format = *title_and_format
|
116
|
+
else
|
117
|
+
real_title = raw_title
|
118
|
+
format = options[:format]
|
119
|
+
end
|
120
|
+
|
121
|
+
[format, real_title]
|
100
122
|
end
|
101
123
|
end
|
102
124
|
|
data/page_title_helper.gemspec
CHANGED
@@ -1,5 +1,4 @@
|
|
1
|
-
|
2
|
-
$:.push File.expand_path('../lib', __FILE__)
|
1
|
+
$LOAD_PATH.push File.expand_path('lib', __dir__)
|
3
2
|
require 'page_title_helper/version'
|
4
3
|
|
5
4
|
Gem::Specification.new do |s|
|
@@ -9,22 +8,24 @@ Gem::Specification.new do |s|
|
|
9
8
|
s.summary = 'Simple, internationalized and DRY page titles and headings for Rails.'
|
10
9
|
s.description = 'Simple, internationalized and DRY page titles and headings for Rails.'
|
11
10
|
|
12
|
-
s.required_ruby_version
|
13
|
-
s.required_rubygems_version = '>= 1.3.6'
|
11
|
+
s.required_ruby_version = '>= 2.7.0'
|
14
12
|
|
15
13
|
s.authors = ['Lukas Westermann']
|
16
14
|
s.email = ['lukas.westermann@gmail.com']
|
17
|
-
s.homepage = '
|
15
|
+
s.homepage = 'https://github.com/lwe/page_title_helper'
|
18
16
|
|
19
|
-
s.files = %w
|
17
|
+
s.files = %w[Gemfile LICENSE README.md CODE_OF_CONDUCT.md CHANGELOG.md Rakefile
|
18
|
+
page_title_helper.gemspec] + Dir['**/*.{rb,yml}']
|
20
19
|
s.test_files = s.files.grep(%r{^(test|spec)/})
|
21
20
|
s.require_path = 'lib'
|
22
21
|
|
23
22
|
s.license = 'MIT'
|
24
23
|
|
25
|
-
s.add_dependency 'rails', '>=
|
24
|
+
s.add_dependency 'rails', '>= 5.2.0', '< 7.1'
|
26
25
|
|
27
|
-
s.add_development_dependency 'rake', '
|
28
|
-
s.add_development_dependency '
|
29
|
-
s.add_development_dependency 'rubocop', '~>
|
26
|
+
s.add_development_dependency 'rake', '~> 13.0.6'
|
27
|
+
s.add_development_dependency 'rubocop', '~> 1.26.1'
|
28
|
+
s.add_development_dependency 'rubocop-rails', '~> 2.14.2'
|
29
|
+
s.add_development_dependency 'rubocop-rake', '~> 0.6.0'
|
30
|
+
s.add_development_dependency 'shoulda', '~> 4.0.0'
|
30
31
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'minitest/autorun'
|
2
4
|
require 'test_helper'
|
3
5
|
|
@@ -45,7 +47,8 @@ class MultipleFormatsTest < ActiveSupport::TestCase
|
|
45
47
|
|
46
48
|
should 'override locally supplied :format arguments' do
|
47
49
|
assert_equal('Something', @view.page_title { ['Something', '* * * :title * * *'] })
|
48
|
-
|
50
|
+
# yeah, using x-tra ugly titles :)
|
51
|
+
assert_equal '* * * Something * * *', @view.page_title(format: '-= :title =-')
|
49
52
|
end
|
50
53
|
end
|
51
54
|
end
|
@@ -58,7 +61,7 @@ class MultipleFormatsTest < ActiveSupport::TestCase
|
|
58
61
|
@view = TestView.new
|
59
62
|
end
|
60
63
|
|
61
|
-
should 'allow to
|
64
|
+
should 'allow to override format through YAML' do
|
62
65
|
@view.controller! 'pages', 'features'
|
63
66
|
assert_equal 'Wohaapp > Feature comparison', @view.page_title
|
64
67
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'minitest/autorun'
|
2
4
|
require 'test_helper'
|
3
5
|
|
@@ -30,7 +32,9 @@ class PageTitleHelperTest < ActiveSupport::TestCase
|
|
30
32
|
PageTitleHelper.interpolates(:foobar_test) { |_env| 'foobar_test' }
|
31
33
|
PageTitleHelper.interpolates(:title_foobar) { |_env| 'title_foobar' }
|
32
34
|
|
33
|
-
assert_equal 'title_foobar / foobar_test / foobar / foobar_x',
|
35
|
+
assert_equal 'title_foobar / foobar_test / foobar / foobar_x',
|
36
|
+
PageTitleHelper::Interpolations.interpolate(':title_foobar / :foobar_test / :foobar / :foobar_x',
|
37
|
+
{})
|
34
38
|
end
|
35
39
|
end
|
36
40
|
|
data/test/test_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: page_title_helper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 6.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lukas Westermann
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-04-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -16,62 +16,90 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 5.2.0
|
20
20
|
- - "<"
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version: '
|
22
|
+
version: '7.1'
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
26
26
|
requirements:
|
27
27
|
- - ">="
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version:
|
29
|
+
version: 5.2.0
|
30
30
|
- - "<"
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version: '
|
32
|
+
version: '7.1'
|
33
33
|
- !ruby/object:Gem::Dependency
|
34
34
|
name: rake
|
35
35
|
requirement: !ruby/object:Gem::Requirement
|
36
36
|
requirements:
|
37
|
-
- - "
|
37
|
+
- - "~>"
|
38
38
|
- !ruby/object:Gem::Version
|
39
|
-
version:
|
39
|
+
version: 13.0.6
|
40
40
|
type: :development
|
41
41
|
prerelease: false
|
42
42
|
version_requirements: !ruby/object:Gem::Requirement
|
43
43
|
requirements:
|
44
|
-
- - "
|
44
|
+
- - "~>"
|
45
45
|
- !ruby/object:Gem::Version
|
46
|
-
version:
|
46
|
+
version: 13.0.6
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
|
-
name:
|
48
|
+
name: rubocop
|
49
49
|
requirement: !ruby/object:Gem::Requirement
|
50
50
|
requirements:
|
51
|
-
- - "
|
51
|
+
- - "~>"
|
52
52
|
- !ruby/object:Gem::Version
|
53
|
-
version:
|
53
|
+
version: 1.26.1
|
54
54
|
type: :development
|
55
55
|
prerelease: false
|
56
56
|
version_requirements: !ruby/object:Gem::Requirement
|
57
57
|
requirements:
|
58
|
-
- - "
|
58
|
+
- - "~>"
|
59
59
|
- !ruby/object:Gem::Version
|
60
|
-
version:
|
60
|
+
version: 1.26.1
|
61
61
|
- !ruby/object:Gem::Dependency
|
62
|
-
name: rubocop
|
62
|
+
name: rubocop-rails
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - "~>"
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: 2.14.2
|
68
|
+
type: :development
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - "~>"
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: 2.14.2
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: rubocop-rake
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - "~>"
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: 0.6.0
|
82
|
+
type: :development
|
83
|
+
prerelease: false
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - "~>"
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: 0.6.0
|
89
|
+
- !ruby/object:Gem::Dependency
|
90
|
+
name: shoulda
|
63
91
|
requirement: !ruby/object:Gem::Requirement
|
64
92
|
requirements:
|
65
93
|
- - "~>"
|
66
94
|
- !ruby/object:Gem::Version
|
67
|
-
version: 0.
|
95
|
+
version: 4.0.0
|
68
96
|
type: :development
|
69
97
|
prerelease: false
|
70
98
|
version_requirements: !ruby/object:Gem::Requirement
|
71
99
|
requirements:
|
72
100
|
- - "~>"
|
73
101
|
- !ruby/object:Gem::Version
|
74
|
-
version: 0.
|
102
|
+
version: 4.0.0
|
75
103
|
description: Simple, internationalized and DRY page titles and headings for Rails.
|
76
104
|
email:
|
77
105
|
- lukas.westermann@gmail.com
|
@@ -93,7 +121,7 @@ files:
|
|
93
121
|
- test/multiple_formats_test.rb
|
94
122
|
- test/page_title_helper_test.rb
|
95
123
|
- test/test_helper.rb
|
96
|
-
homepage:
|
124
|
+
homepage: https://github.com/lwe/page_title_helper
|
97
125
|
licenses:
|
98
126
|
- MIT
|
99
127
|
metadata: {}
|
@@ -105,15 +133,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
105
133
|
requirements:
|
106
134
|
- - ">="
|
107
135
|
- !ruby/object:Gem::Version
|
108
|
-
version: 2.
|
136
|
+
version: 2.7.0
|
109
137
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
110
138
|
requirements:
|
111
139
|
- - ">="
|
112
140
|
- !ruby/object:Gem::Version
|
113
|
-
version:
|
141
|
+
version: '0'
|
114
142
|
requirements: []
|
115
|
-
|
116
|
-
rubygems_version: 2.6.13
|
143
|
+
rubygems_version: 3.2.32
|
117
144
|
signing_key:
|
118
145
|
specification_version: 4
|
119
146
|
summary: Simple, internationalized and DRY page titles and headings for Rails.
|