page_title_helper 1.0.1 → 5.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 83ca84d323ad19f09e49b6ee6333f2cd3c06f0e2e3f8748b8081a204fdebc4ac
4
+ data.tar.gz: 4c9affff4ee6f51d0dfccb906ec4406e5a50032da651fcc92be19603368741e0
5
+ SHA512:
6
+ metadata.gz: 19879f1e33647398e8d15ee0b3adbaacd29a6645fd89b33838fddf11f469a577abf2467a368f6b352e61ad4db8fc71f0ac4f5e918112b16c59ab84751bfca0a2
7
+ data.tar.gz: c28883f1bd9cefd68c8f121b4caced4bd946ffec08d5e10f4e33f8a6008ed825132886362b97afa36a642ce05e02b22182899743daeb56515962e24ac9e51fdd
data/CHANGELOG.md ADDED
@@ -0,0 +1,79 @@
1
+ # Page title helper change log
2
+
3
+ All notable changes to this project will be documented in this file.
4
+ This project adheres to [Semantic Versioning](https://semver.org/).
5
+
6
+ Read more at [Keep a CHANGELOG](https://keepachangelog.com/en/0.3.0/)
7
+ about why a change log is important.
8
+
9
+ ## x.y.z
10
+
11
+ ### Added
12
+
13
+ ### Changed
14
+
15
+ ### Deprecated
16
+
17
+ ### Removed
18
+
19
+ ### Fixed
20
+
21
+ ### Security
22
+
23
+ ## 5.0.0
24
+
25
+ ### Added
26
+ - Add support for Ruby 3 (#120)
27
+ - Add automatic gem release (#122)
28
+ - Add support for Rails 6.1 (#113, #114)
29
+ - Officially support Ruby 2.7 (#103)
30
+
31
+ ### Removed
32
+ - Drop support for Ruby 2.4 (#109)
33
+ - Drop support for Rails < 5.2 (#104)
34
+
35
+ ### Fixed
36
+ - Use a better-maintained Ruby setup for the CI (#121)
37
+ - Fix warnings in the `.travis.yml` (#106)
38
+
39
+ ## 4.0.0
40
+
41
+ ### Added
42
+ - Add support for Rails 6.0 (#94)
43
+
44
+ ### Removed
45
+ - Drop support for Ruby < 2.4 (#93)
46
+
47
+ ## 3.0.0
48
+
49
+ ### Added
50
+ - Add Ruby 2.4.0 to the build matrix (#68)
51
+ - Add a CHANGELOG.md (#59)
52
+ - Add RuboCop checking to the CI (#52)
53
+ - Add a CODE_OF_CONDUCT.md (#51)
54
+ - Update Ruby to 2.3.3 and 2.2.6 on Travis (#38)
55
+ - Add Ruby 2.3.0 to the build matrix
56
+ - Re-add Ruby 2.0.0 to the build matrix (#29)
57
+ - Test against Ruby 2.2
58
+ - Use Appraisal for building with different Rails versions (#19)
59
+
60
+ ### Changed
61
+ - Replaced Appraisals with specific Gemfiles (#41)
62
+ - Delete obsolete init.rb file (#61)
63
+ - Add Rails 5.0 to the build matrix (#42)
64
+ - Raise RVM and Gem minimum versions (#3)
65
+
66
+ ### Removed
67
+ - Drop support for Rails 3.2 and 4.0 (#39)
68
+ - Drop support for Ruby 1.9.x (#24)
69
+
70
+ ### Fixed
71
+ - Fix @_page_title uninitialized warning (#62)
72
+ - Fix the Travis build on Ruby 2.3.3 (#63)
73
+ - Do do not shell-out to `git` in Gemfile (#49)
74
+ - Get the tests to run in Rails 4.2 and 5.0 (#40)
75
+ - Stop requiring version from the main class (#47)
76
+ - Allow the Rails 3.2 build to fail only with Ruby 2.2 (#30)
77
+ - Allow Rails 3.2 builds to fail (#26)
78
+ - Configure Travis for better performance (#10)
79
+ - Remove Gemfile.lock (#1)
@@ -0,0 +1,77 @@
1
+ # Contributor Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age,
8
+ body size, disability, ethnicity, gender identity and expression, level of
9
+ experience, nationality, personal appearance, race, religion, or sexual
10
+ identity and orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+
35
+ ## Our Responsibilities
36
+
37
+ Project maintainers are responsible for clarifying the standards of acceptable
38
+ behavior and are expected to take appropriate and fair corrective action in
39
+ response to any instances of unacceptable behavior.
40
+
41
+ Project maintainers have the right and responsibility to remove, edit, or
42
+ reject comments, commits, code, wiki edits, issues, and other contributions
43
+ that are not aligned to this Code of Conduct, or to ban temporarily or
44
+ permanently any contributor for other behaviors that they deem inappropriate,
45
+ threatening, offensive, or harmful.
46
+
47
+ ## Scope
48
+
49
+ This Code of Conduct applies both within project spaces and in public spaces
50
+ when an individual is representing the project or its community. Examples of
51
+ representing a project or community include using an official project e-mail
52
+ address, posting via an official social media account, or acting as an
53
+ appointed representative at an online or offline event. Representation of a
54
+ project may be further defined and clarified by project maintainers.
55
+
56
+ ## Enforcement
57
+
58
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
59
+ reported by contacting the project team at (lukas dot westermann at gmail dot com).
60
+ All complaints will be reviewed and investigated and will result in a response
61
+ that is deemed necessary and appropriate to the circumstances. The project team
62
+ is obligated to maintain confidentiality with regard to the reporter of an
63
+ incident. Further details of specific enforcement policies may be posted
64
+ separately.
65
+
66
+ Project maintainers who do not follow or enforce the Code of Conduct in good
67
+ faith may face temporary or permanent repercussions as determined by other
68
+ members of the project's leadership.
69
+
70
+ ## Attribution
71
+
72
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
73
+ version 1.4, available at
74
+ [https://contributor-covenant.org/version/1/4/][version].
75
+
76
+ [homepage]: https://contributor-covenant.org
77
+ [version]: https://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ gemspec
data/README.md CHANGED
@@ -1,178 +1,224 @@
1
1
  # Page title helper
2
2
 
3
- Ever wondered if there was an easier and DRY-way to set your page titles (and/or headings). Backed
4
- by Rails (only tested on 2.3.x) and it's new `I18n`-class the solution is a simple helper method.
5
-
6
- In your layout add this to your `<head>-section`:
7
-
8
- ...
9
- <title><%=h page_title %></title>
10
- ...
11
-
12
- That's it. Now just add your translations, to the locales, in e.g. `config/locales/en.yml`:
13
-
14
- en:
15
- contacts:
16
- index:
17
- title: "Contacts"
18
-
19
- When `contacs/index.html.erb` is rendered, the key `:en, :contacts, :index, :title`
20
- is looked up and printed, together with the applications basename, like: `My cool app - Contacts`.
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)
5
+
6
+ This project adheres to [Semantic Versioning](https://semver.org/).
7
+
8
+ ## What does this gem do?
9
+
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.
13
+
14
+ In your layout, add this to your `<head>`-section:
15
+
16
+ ```html
17
+ <title><%= page_title %></title>
18
+ ```
19
+
20
+ That's it. Now just add translations, in e.g. `config/locales/en.yml`:
21
+
22
+ ```yaml
23
+ en:
24
+ contacts:
25
+ index:
26
+ title: "Contacts"
27
+ ```
28
+
29
+ When `/contacts/` is requested, the key `:en, :contacts, :index, :title`
30
+ is looked up and printed, together with the applications basename, like:
31
+ `Contacts - My cool App`.
21
32
  The format etc. is of course configurable, just head down to the options.
22
33
 
23
34
  ## Installation
24
35
 
25
- As gem (from gemcutter.org, as of version 0.7.0):
36
+ As gem (from rubygems.org):
37
+
38
+ ```ruby
39
+ # then add the following line to Gemfile
40
+ gem 'page_title_helper'
41
+
42
+ # living on the bleeding edge?
43
+ gem 'page_title_helper', git: 'git://github.com/lwe/page_title_helper.git'
44
+ ```
26
45
 
27
- sudo gem install page_title_helper [-s http://gemcutter.org]
28
-
29
- # then add the following line to config/environment.rb
30
- config.gem 'page_title_helper', :source => 'http://gemcutter.org'
31
-
32
- or as plain old Rails plugin:
46
+ ## Translated titles
33
47
 
34
- ./script/plugin install git://github.com/lwe/page_title_helper.git
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:
51
+
52
+ ```
53
+ Admin::AccountController#index => :'admin.account.index.title'
54
+ :'admin.account.title'
55
+ options[:default]
56
+ ```
57
+
58
+ For `create` and `update` a further fallback to `new.title` and `edit.title`
59
+ have been added, because they certainly are duplicates.
35
60
 
36
61
  ## Customize titles
37
62
 
38
- Need a custom title, or need to fill in some placeholders? Just use the _bang_ method (`page_title!`), in e.g.
39
- `contacts/show.html.erb` the requirement is to display the contacts name in the
40
- `<title>-tag`as well as in the heading?
41
-
42
- <h1><%=h page_title!(@contact.name) %></h1>
43
-
44
- A call to `page_title` will now return the contacts name, neat :) if for example the
45
- `<h1>` does not match the `<title>`, then well, just do something like:
46
-
47
- <% page_title!(@contact.name + " (" + @contact.company.name + ")") %>
48
- <h1><%=h @contact.name %></h1>
49
-
50
- Guess, that's it. Of course it's also possible to use `translate` with `page_title!`, to
51
- translate customzied titles, like:
52
-
53
- # in config/locales/en.yml:
54
- en:
55
- dashboard:
56
- index:
57
- title: "Welcome back, {{name}}"
58
-
59
- # in app/views/dashboard/index.html.erb:
60
- <h1><%=h page_title!(t('.title', :name => @user.first_name)) %></h1>
61
-
62
- ## More fun with <tt>:format</tt>
63
-
64
- The `:format` option is used to specify how a title is formatted, i.e. if the app name is
65
- prependor appended, or if it contains the account name etc. It uses a similar approach as
66
- paperclip's path interpolations:
67
-
68
- page_title :format => ':title / :app' # => "Contacts / My cool app"
69
-
70
- Adding custom interpolations is as easy as defining a block, for example to access the current
71
- controller:
72
-
73
- PageTitleHelper.interpolates :controller do |env|
74
- env.controller.controller_name.humanize
75
- end
76
-
77
- page_title :format => ':title / :controller / :app' # => "Welcome back / Dashboard / My cool app"
78
-
79
- To access just the title, without any magic app stuff interpolated or appended, use:
80
-
81
- page_title! "untitled"
82
- page_title :format => false # => "untitled"
83
-
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
+ ```
70
+
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:
74
+
75
+ ```html
76
+ <% page_title!(@contact.name + " (" + @contact.company.name + ")") %>
77
+ <h1><%= @contact.name %></h1>
78
+ ```
79
+
80
+ Guess, that's it. Of course it's also possible to use `translate` within
81
+ `page_title!`, to translate custom titles, like:
82
+
83
+ In `config/locales/en.yml`:
84
+
85
+ ```yaml
86
+ en:
87
+ dashboard:
88
+ index:
89
+ title: "Welcome back, {{name}}"
90
+ ```
91
+
92
+ In `app/views/dashboard/index.html.erb`:
93
+ ```html
94
+ <h1><%= page_title!(t('.title', name: @user.first_name)) %></h1>
95
+ ```
96
+
97
+ ## More fun with <code>:format</code>
98
+
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:
102
+
103
+ ```ruby
104
+ page_title format: ':title / :app' # => "Contacts / My cool app"
105
+ ```
106
+
107
+ Adding custom interpolations is as easy as defining a block, for example to
108
+ access the current controller:
109
+
110
+ ```ruby
111
+ PageTitleHelper.interpolates :controller do |env|
112
+ env[:view].controller.controller_name.humanize
113
+ end
114
+
115
+ page_title format: ':title / :controller / :app' # => "Welcome back / Dashboard / My cool app"
116
+ ```
117
+
118
+ To access just the title, without any magic app stuff interpolated or appended,
119
+ use:
120
+
121
+ ```ruby
122
+ page_title! "untitled"
123
+ page_title format: false # => "untitled"
124
+ ```
125
+
84
126
  Need a custom format for a single title? Just return an array:
85
127
 
86
- # in the view:
87
- <h1><%=h page_title!(@contact.name, ":title from :company - :app") %></h1> # => <h1>Franz Meyer</h1>
88
-
89
- # in the <head>
90
- <title><%=h(page_title) %></title> # => this time it will use custom title like "Franz Meyer from ABC Corp. - MyCoolApp"
91
-
92
- To streamline that feature a bit and simplify reuse of often used formats, it's now possible to define format aliases like:
93
-
94
- # in an initializer:
95
- PageTitleHelper.formats[:with_company] = ":title from :company - :app"
96
- PageTitleHelper.formats[:promo] = ":app - :title" # show app first for promo pages :)
97
-
98
- # then in the view to display a contact...
99
- page_title! @contact.name, :with_company
100
-
101
- # ...or for the promo page via config/locales/en.yml (!)
102
- en:
103
- pages:
104
- features:
105
- title:
106
- - "Features comparison"
107
- - !ruby/sym promo
108
-
109
- Pretty, cool, aint it? The special `:format => :app` works also with the `formats` hash. Then there is also a
110
- `:default` format, which should be used to override the default format.
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:
142
+
143
+ In an initializer, e.g., `config/initializers/page_title_helper.rb`:
144
+
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
+ ```
150
+
151
+ Then in the view to display a contact:
152
+
153
+ ```ruby
154
+ page_title! @contact.name, :with_company
155
+ ```
156
+
157
+ Or for the promo page via `config/locales/en.yml` (!):
158
+
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.
111
171
 
112
172
  ## All options - explained
113
173
 
114
- <table>
115
- <tr>
116
- <th>Option</th><th>Description</th><th>Default</th><th>Values</th>
117
- </tr>
118
- <tr>
119
- <td><tt>:app</tt></td>
120
- <td>Specify the applications name, however it's
121
- recommended to define the translation key <tt>:'app.name'</tt>.</td>
122
- <td>Inflected from <tt>RAILS_ROOT</tt></td>
123
- <td>string</td>
124
- </tr>
125
- <tr>
126
- <td><tt>:default</tt></td>
127
- <td>String which is displayed when no translation exists and no custom title
128
- has been specified. Can also be set to a symbol or array to take advantage of
129
- <tt>I18n.translate</tt>s <tt>:default</tt> option.</td>
130
- <td><tt>:'app.tagline'</tt></td>
131
- <td>string, symbol or array of those</td>
132
- </tr>
133
- <tr>
134
- <td><tt>:format</tt></td>
135
- <td>Defines the output format, accepts a string containing multiple interpolations, or
136
- a symbol to a format alias, see <i>More fun with <tt>:format</tt></i>. If set to
137
- +false+, just the current title is returned.</td>
138
- <td><tt>:default</tt></td>
139
- <td>string, symbol</td>
140
- </tr>
141
- <tr>
142
- <td><tt>:suffix</tt></td>
143
- <td>Not happy with the fact that the translations must be named like
144
- <tt>en -> contacts -> index -> title</tt>, but prefer e.g. them to be suffixed with
145
- <tt>page_title</tt>? Then just set <tt>:suffix => :page_title</tt>.</td>
146
- <td><tt>:title</tt></td>
147
- <td>symbol or string</td>
148
- </tr>
149
- </table>
150
- </p>
151
-
152
- If an option should be set globally it's possible to change the default options hash as follows:
153
-
154
- PageTitleHelper.options[:suffix] = :page_title
155
-
156
- Note, currently it only makes sense to set `:default` and/or `:page_title` 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.
182
+
157
183
  To add or change formats use:
158
184
 
159
- # change the default format used (if no format is specified):
160
- PageTitleHelper.formats[:default] = ":title // :app"
161
-
162
- # add a custom format alias (which can be used with page_title(:format => :promo))
163
- PageTitleHelper.formats[:promo] = ":app // :title"
164
-
165
- _Note:_ it's recommended to add this kind of stuff to an initializer.
185
+ ```ruby
186
+ # change the default format used (if no format is specified):
187
+ PageTitleHelper.formats[:default] = ":title // :app"
188
+
189
+ # add a custom format alias (which can be used with page_title(format: :promo))
190
+ PageTitleHelper.formats[:promo] = ":app // :title"
191
+ ```
192
+
193
+ _Note:_ It's recommended to add this kind of stuff to an initializer, like e.g.
194
+ `config/initializers/page_title_helper.rb`.
166
195
 
167
196
  ## A (maybe useful) interpolation
168
197
 
169
- The internationalized controller name, with fallback to just display the humanized name:
198
+ The internationalized controller name, with fallback to just display the
199
+ humanized name:
200
+
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
+ ```
207
+
208
+ _Note:_ Put this kind of stuff into an initializer, like
209
+ `config/initializers/page_title_helper.rb` or something like that.
210
+
211
+ ## Contributing
212
+
213
+ Pull request are more than welcome. Please adhere to our
214
+ [code of conduct](CODE_OF_CONDUCT.md) in discussions and contributions.
215
+ Thanks!
216
+
217
+ ## Maintainers
218
+
219
+ * [@lwe - Lukas Westermann](https://github.com/lwe)
220
+ * [@oliverklee - Oliver Klee](https://github.com/oliverklee)
170
221
 
171
- PageTitleHelper.interpolates :controller do |env|
172
- I18n.t env.controller.controller_path.tr('/','.') + '.controller', :default => env.controller.controller_name.humanize
173
- end
174
-
175
- _Note:_ Put this kind of stuff into an initilizer, like `config/initializers/page_title.rb` or someting like that.
176
-
177
222
  ## Licence and copyright
178
- Copyright (c) 2009 Lukas Westermann (Zurich, Switzerland), released under the MIT license
223
+ Copyright (c) 2009 Lukas Westermann (Zurich, Switzerland), released under the
224
+ MIT license