titleist 0.1.1 → 1.0.0
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/.github/workflows/tests.yml +19 -0
- data/.gitignore +1 -2
- data/.rubocop.yml +26 -1
- data/.ruby-version +1 -1
- data/Gemfile +13 -2
- data/README.md +95 -25
- data/Rakefile +17 -6
- data/docs/index.md +7 -0
- data/lib/generators/titleist/titleist_generator.rb +3 -0
- data/lib/titleist.rb +14 -9
- data/lib/titleist/controller.rb +36 -0
- data/lib/titleist/engine.rb +10 -4
- data/lib/titleist/helper.rb +23 -0
- data/lib/titleist/title.rb +52 -89
- data/lib/titleist/version.rb +5 -1
- data/rbi/sord.rbi +117 -0
- data/sorbet/config +2 -0
- data/sorbet/rbi/gems/actioncable.rbi +318 -0
- data/sorbet/rbi/gems/actionmailbox.rbi +56 -0
- data/sorbet/rbi/gems/actionmailer.rbi +446 -0
- data/sorbet/rbi/gems/actionpack.rbi +3411 -0
- data/sorbet/rbi/gems/actiontext.rbi +79 -0
- data/sorbet/rbi/gems/actionview.rbi +1185 -0
- data/sorbet/rbi/gems/activejob.rbi +362 -0
- data/sorbet/rbi/gems/activemodel.rbi +749 -0
- data/sorbet/rbi/gems/activerecord.rbi +5713 -0
- data/sorbet/rbi/gems/activestorage.rbi +221 -0
- data/sorbet/rbi/gems/activesupport.rbi +2437 -0
- data/sorbet/rbi/gems/addressable.rbi +146 -0
- data/sorbet/rbi/gems/ast.rbi +47 -0
- data/sorbet/rbi/gems/capybara.rbi +1787 -0
- data/sorbet/rbi/gems/childprocess.rbi +106 -0
- data/sorbet/rbi/gems/codeclimate-test-reporter.rbi +125 -0
- data/sorbet/rbi/gems/concurrent-ruby.rbi +1587 -0
- data/sorbet/rbi/gems/crass.rbi +92 -0
- data/sorbet/rbi/gems/docile.rbi +29 -0
- data/sorbet/rbi/gems/erubi.rbi +26 -0
- data/sorbet/rbi/gems/globalid.rbi +98 -0
- data/sorbet/rbi/gems/i18n.rbi +191 -0
- data/sorbet/rbi/gems/jaro_winkler.rbi +14 -0
- data/sorbet/rbi/gems/loofah.rbi +129 -0
- data/sorbet/rbi/gems/mail.rbi +1582 -0
- data/sorbet/rbi/gems/marcel.rbi +12 -0
- data/sorbet/rbi/gems/method_source.rbi +63 -0
- data/sorbet/rbi/gems/mini_mime.rbi +51 -0
- data/sorbet/rbi/gems/minitest.rbi +419 -0
- data/sorbet/rbi/gems/mocha.rbi +794 -0
- data/sorbet/rbi/gems/nio4r.rbi +67 -0
- data/sorbet/rbi/gems/nokogiri.rbi +1010 -0
- data/sorbet/rbi/gems/parallel.rbi +81 -0
- data/sorbet/rbi/gems/parser.rbi +920 -0
- data/sorbet/rbi/gems/public_suffix.rbi +103 -0
- data/sorbet/rbi/gems/puma.rbi +586 -0
- data/sorbet/rbi/gems/rack-test.rbi +161 -0
- data/sorbet/rbi/gems/rack.rbi +634 -0
- data/sorbet/rbi/gems/rails-dom-testing.rbi +67 -0
- data/sorbet/rbi/gems/rails-html-sanitizer.rbi +91 -0
- data/sorbet/rbi/gems/railties.rbi +834 -0
- data/sorbet/rbi/gems/rainbow.rbi +117 -0
- data/sorbet/rbi/gems/rake.rbi +269 -0
- data/sorbet/rbi/gems/regexp_parser.rbi +912 -0
- data/sorbet/rbi/gems/rubocop.rbi +7232 -0
- data/sorbet/rbi/gems/ruby-progressbar.rbi +304 -0
- data/sorbet/rbi/gems/rubyzip.rbi +546 -0
- data/sorbet/rbi/gems/selenium-webdriver.rbi +1450 -0
- data/sorbet/rbi/gems/simplecov-html.rbi +30 -0
- data/sorbet/rbi/gems/simplecov.rbi +189 -0
- data/sorbet/rbi/gems/site_ruby.rbi +265 -0
- data/sorbet/rbi/gems/sprockets-rails.rbi +105 -0
- data/sorbet/rbi/gems/sprockets.rbi +753 -0
- data/sorbet/rbi/gems/sqlite3.rbi +353 -0
- data/sorbet/rbi/gems/thor.rbi +579 -0
- data/sorbet/rbi/gems/thread_safe.rbi +81 -0
- data/sorbet/rbi/gems/tzinfo.rbi +405 -0
- data/sorbet/rbi/gems/unicode-display_width.rbi +16 -0
- data/sorbet/rbi/gems/webdrivers.rbi +155 -0
- data/sorbet/rbi/gems/xpath.rbi +158 -0
- data/sorbet/rbi/gems/yard.rbi +1159 -0
- data/sorbet/rbi/hidden-definitions/errors.txt +14957 -0
- data/sorbet/rbi/hidden-definitions/hidden.rbi +24898 -0
- data/sorbet/rbi/sorbet-typed/lib/actionmailer/all/actionmailer.rbi +13 -0
- data/sorbet/rbi/sorbet-typed/lib/actionpack/all/actionpack.rbi +938 -0
- data/sorbet/rbi/sorbet-typed/lib/actionview/all/actionview.rbi +314 -0
- data/sorbet/rbi/sorbet-typed/lib/activemodel/all/activemodel.rbi +425 -0
- data/sorbet/rbi/sorbet-typed/lib/activerecord/>=5.2/activerecord.rbi +17 -0
- data/sorbet/rbi/sorbet-typed/lib/activerecord/all/activerecord.rbi +1425 -0
- data/sorbet/rbi/sorbet-typed/lib/activerecord/~>6.0.0/activerecord.rbi +475 -0
- data/sorbet/rbi/sorbet-typed/lib/activestorage/>=6.0.0/activestorage.rbi +19 -0
- data/sorbet/rbi/sorbet-typed/lib/activestorage/all/activestorage.rbi +173 -0
- data/sorbet/rbi/sorbet-typed/lib/activesupport/>=6.0.0.rc1/activesupport.rbi +23 -0
- data/sorbet/rbi/sorbet-typed/lib/activesupport/all/activesupport.rbi +858 -0
- data/sorbet/rbi/sorbet-typed/lib/bundler/all/bundler.rbi +8684 -0
- data/sorbet/rbi/sorbet-typed/lib/minitest/all/minitest.rbi +108 -0
- data/sorbet/rbi/sorbet-typed/lib/railties/all/railties.rbi +25 -0
- data/sorbet/rbi/sorbet-typed/lib/rainbow/all/rainbow.rbi +254 -0
- data/sorbet/rbi/sorbet-typed/lib/ruby/all/gem.rbi +4222 -0
- data/sorbet/rbi/sorbet-typed/lib/ruby/all/open3.rbi +111 -0
- data/sorbet/rbi/sorbet-typed/lib/ruby/all/resolv.rbi +543 -0
- data/sorbet/rbi/todo.rbi +20 -0
- data/titleist.gemspec +3 -14
- metadata +96 -155
- data/.travis.yml +0 -45
- data/app/controllers/.keep +0 -0
- data/app/helpers/.keep +0 -0
- data/app/helpers/titleist_helper.rb +0 -47
- data/app/mailers/.keep +0 -0
- data/app/models/.keep +0 -0
- data/app/views/.keep +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 78c5ab14076bcd7fcfaff5793bcd1337d77256ef5c96ab0e42bb207f0ad737d4
|
4
|
+
data.tar.gz: 7cb45dd51d98dfe9af8ffd38c185705c18e50bac5f7f1070cff15a49df5e344e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '09c43fafdcd01c5cafe0d0c9bb66edb80223e3c911558edf061ade5033205007ab389a5c2a3157abb76d9906f05f868d56d866dc190e7888bfdaa846bc1d618d'
|
7
|
+
data.tar.gz: 5ed29f28e9d91b4637040fa2746151995e7d608f8d3ae45fc4dfd7c9f13f41a41ca4be7d4a5820f8855930a858441a2000bae9f1a7242139bd8447947594d916
|
@@ -0,0 +1,19 @@
|
|
1
|
+
name: Tests
|
2
|
+
on: [push]
|
3
|
+
jobs:
|
4
|
+
test:
|
5
|
+
name: Automated Tests
|
6
|
+
runs-on: ubuntu-latest
|
7
|
+
steps:
|
8
|
+
- name: Checkout Latest Source Code
|
9
|
+
uses: actions/checkout@v1
|
10
|
+
- name: Install Ruby
|
11
|
+
uses: actions/setup-ruby@v1
|
12
|
+
with:
|
13
|
+
ruby-version: 2.6.x
|
14
|
+
- name: Install SQLite
|
15
|
+
run: sudo apt-get install -yy libsqlite3-dev
|
16
|
+
- name: Install bundled dependencies
|
17
|
+
run: bundle install
|
18
|
+
- name: Build the gem and run automated tests
|
19
|
+
run: bundle exec rake
|
data/.gitignore
CHANGED
data/.rubocop.yml
CHANGED
@@ -9,8 +9,33 @@ Style/StringLiterals:
|
|
9
9
|
Style/FrozenStringLiteralComment:
|
10
10
|
Enabled: false
|
11
11
|
|
12
|
-
|
12
|
+
Layout/LineLength:
|
13
13
|
Exclude:
|
14
14
|
- titleist.gemspec
|
15
15
|
- test/test_helper.rb
|
16
16
|
- bin/rails
|
17
|
+
|
18
|
+
Style/FormatStringToken:
|
19
|
+
Exclude:
|
20
|
+
- lib/titleist/title.rb
|
21
|
+
|
22
|
+
Layout/EmptyLinesAroundAttributeAccessor:
|
23
|
+
Enabled: true
|
24
|
+
Layout/SpaceAroundMethodCallOperator:
|
25
|
+
Enabled: true
|
26
|
+
Lint/DeprecatedOpenSSLConstant:
|
27
|
+
Enabled: true
|
28
|
+
Lint/RaiseException:
|
29
|
+
Enabled: true
|
30
|
+
Lint/StructNewOverride:
|
31
|
+
Enabled: true
|
32
|
+
Style/ExponentialNotation:
|
33
|
+
Enabled: true
|
34
|
+
Style/HashEachMethods:
|
35
|
+
Enabled: true
|
36
|
+
Style/HashTransformKeys:
|
37
|
+
Enabled: true
|
38
|
+
Style/HashTransformValues:
|
39
|
+
Enabled: true
|
40
|
+
Style/SlicingWithRange:
|
41
|
+
Enabled: true
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.6.
|
1
|
+
2.6.5
|
data/Gemfile
CHANGED
@@ -9,6 +9,17 @@ gemspec
|
|
9
9
|
# your gemspec. These might include edge Rails or gems from your path or
|
10
10
|
# Git. Remember to move these dependencies to your gemspec before releasing
|
11
11
|
# your gem to rubygems.org.
|
12
|
+
gem 'capybara', '~> 3'
|
13
|
+
gem 'codeclimate-test-reporter'
|
14
|
+
gem 'minitest', '~> 5'
|
15
|
+
gem 'mocha', '~> 1'
|
16
|
+
gem 'puma', '~> 4'
|
17
|
+
gem 'rails', '~> 6.0.0'
|
18
|
+
gem 'rubocop', '~> 0'
|
19
|
+
gem 'selenium-webdriver', '~> 3'
|
20
|
+
gem 'sqlite3', '~> 1.4'
|
21
|
+
gem 'webdrivers', '~> 4'
|
22
|
+
gem 'yard', '~> 0.9'
|
12
23
|
|
13
|
-
|
14
|
-
|
24
|
+
gem 'sorbet', '~> 0'
|
25
|
+
gem 'sord', '~> 2'
|
data/README.md
CHANGED
@@ -1,13 +1,32 @@
|
|
1
1
|
# Titleist
|
2
2
|
|
3
|
-
|
4
|
-
|
3
|
+

|
4
|
+
|
5
|
+
[](https://github.com/tubbo/titleist/actions)
|
6
|
+
[](https://codeclimate.com/github/tubbo/titleist)
|
5
7
|
[](https://codeclimate.com/github/tubbo/titleist/coverage)
|
6
|
-
[](https://codeclimate.com/github/tubbo/titleist)
|
7
|
-
[](https://codeclimate.com/github/tubbo/titleist)
|
8
8
|
|
9
|
-
A powerful title helper for [Rails][] apps
|
10
|
-
|
9
|
+
A powerful title helper for [Rails][] apps using [i18n][], with the
|
10
|
+
ability to override practically everything.
|
11
|
+
|
12
|
+
## Installation
|
13
|
+
|
14
|
+
Add this line to your application's Gemfile:
|
15
|
+
|
16
|
+
```ruby
|
17
|
+
gem 'titleist'
|
18
|
+
```
|
19
|
+
|
20
|
+
And then run:
|
21
|
+
|
22
|
+
```bash
|
23
|
+
$ bundle
|
24
|
+
```
|
25
|
+
|
26
|
+
Or install it yourself as:
|
27
|
+
```bash
|
28
|
+
$ gem install titleist
|
29
|
+
```
|
11
30
|
|
12
31
|
## Usage
|
13
32
|
|
@@ -18,24 +37,34 @@ your `
|
|
18
37
|
rails generate titleist
|
19
38
|
```
|
20
39
|
|
40
|
+
### Configuration
|
41
|
+
|
21
42
|
Edit your **config/locales/titleist.en.yml** file to add your own titles and format:
|
22
43
|
|
23
44
|
```yaml
|
24
45
|
en:
|
25
|
-
|
26
|
-
application: My Application
|
46
|
+
titleist:
|
27
47
|
format: '%{page} | %{app}'
|
28
|
-
|
29
|
-
|
30
|
-
|
48
|
+
layouts:
|
49
|
+
application:
|
50
|
+
title: My Application
|
51
|
+
posts:
|
52
|
+
index:
|
53
|
+
title: View All Posts
|
54
|
+
show:
|
55
|
+
title: View Post
|
31
56
|
```
|
32
57
|
|
58
|
+
### Helpers
|
59
|
+
|
33
60
|
You can also use our fancy title helpers to generate your own titles.
|
34
61
|
|
35
62
|
For the full monty:
|
36
63
|
|
37
64
|
```erb
|
38
65
|
<title><%= title %></title>
|
66
|
+
<!-- or... %>
|
67
|
+
<%= title_tag %>
|
39
68
|
```
|
40
69
|
|
41
70
|
Page titles only:
|
@@ -50,34 +79,76 @@ Or the app title only:
|
|
50
79
|
<p>Copyright © 2015 <%= app_title %></p>
|
51
80
|
```
|
52
81
|
|
53
|
-
|
82
|
+
These methods are also available in the controller layer.
|
54
83
|
|
55
|
-
|
84
|
+
### Context
|
85
|
+
|
86
|
+
You can provide title context in your controllers for displaying things
|
87
|
+
like model data in the title.
|
56
88
|
|
57
89
|
```ruby
|
58
|
-
|
90
|
+
class PostsController < ApplicationController
|
91
|
+
def show
|
92
|
+
@post = Post.find params[:id]
|
93
|
+
title[:post] = @post.title
|
94
|
+
end
|
95
|
+
end
|
59
96
|
```
|
60
97
|
|
61
|
-
|
98
|
+
By default, all `params` are added to this context, and they can be read
|
99
|
+
by their keys in your i18n translations:
|
62
100
|
|
63
|
-
```
|
64
|
-
|
101
|
+
```yaml
|
102
|
+
en:
|
103
|
+
posts:
|
104
|
+
show:
|
105
|
+
title: '%{post} (ID: %{post_id})'
|
65
106
|
```
|
66
107
|
|
67
|
-
|
68
|
-
|
69
|
-
|
108
|
+
### Overriding
|
109
|
+
|
110
|
+
The entire page title can be overridden if you wish:
|
111
|
+
|
112
|
+
```ruby
|
113
|
+
class PostsController < ApplicationController
|
114
|
+
def show
|
115
|
+
@post = Post.find params[:id]
|
116
|
+
title.page = @post.title
|
117
|
+
end
|
118
|
+
end
|
119
|
+
```
|
120
|
+
|
121
|
+
Or the app title:
|
122
|
+
|
123
|
+
```ruby
|
124
|
+
class PostsController < ApplicationController
|
125
|
+
def show
|
126
|
+
@post = Post.find params[:id]
|
127
|
+
title.page = @post.title
|
128
|
+
title.app = current_site.name
|
129
|
+
end
|
130
|
+
end
|
70
131
|
```
|
71
132
|
|
133
|
+
### Defaults
|
134
|
+
|
135
|
+
Titelist attempts to derive default values if you do not configure them
|
136
|
+
in locales. For example, if the `.posts.new.title` translation can't be
|
137
|
+
found, the default title would be `"New Post"`, based on the name of the
|
138
|
+
controller and action.
|
139
|
+
|
140
|
+
The default title of your app is the name of the application module,
|
141
|
+
which is also what Rails considers to be the "app name".
|
142
|
+
|
72
143
|
## Contributing
|
73
144
|
|
74
145
|
Please include tests and submit changes in a pull request. Read our
|
75
146
|
[Code of Conduct][] to find more information on expected behavior and
|
76
147
|
how to resolve issues. All changes to the codebase are verified using
|
77
|
-
the
|
78
|
-
|
79
|
-
|
80
|
-
|
148
|
+
the CI build, and a failing build cannot be merged to 'master'. In
|
149
|
+
addition, Travis is responsible for building and pushing new gem
|
150
|
+
versions to [RubyGems][] when a new tag is pushed to Github. This
|
151
|
+
library follows [Semantic Versioning][] to communicate the level of
|
81
152
|
change to end users.
|
82
153
|
|
83
154
|
## License
|
@@ -87,7 +158,6 @@ The gem is available as open source under the terms of the [MIT License][].
|
|
87
158
|
[Rails]: http://rubyonrails.org
|
88
159
|
[i18n]: http://guides.rubyonrails.org/i18n.html
|
89
160
|
[Code of Conduct]: CODE_OF_CONDUCT.md
|
90
|
-
[Travis CI]: http://travis-ci.org
|
91
161
|
[RubyGems]: http://rubygems.org
|
92
162
|
[Semantic Versioning]: http://semver.org
|
93
163
|
[MIT License]: MIT-LICENSE
|
data/Rakefile
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'bundler/setup'
|
2
|
+
require 'bundler/gem_tasks'
|
2
3
|
require 'yard'
|
3
4
|
require 'rubocop/rake_task'
|
4
|
-
require 'travis/release'
|
5
5
|
require 'rake/testtask'
|
6
6
|
|
7
7
|
APP_RAKEFILE = File.expand_path('test/dummy/Rakefile', __dir__)
|
@@ -10,13 +10,24 @@ load 'rails/tasks/engine.rake'
|
|
10
10
|
load 'rails/tasks/statistics.rake'
|
11
11
|
|
12
12
|
desc 'Generate documentation'
|
13
|
-
|
13
|
+
task :doc do
|
14
|
+
sh 'bundle exec sord rbi/sord.rbi'
|
15
|
+
end
|
14
16
|
|
15
17
|
desc 'Run lint checks'
|
16
18
|
RuboCop::RakeTask.new :lint
|
17
19
|
|
18
|
-
|
19
|
-
|
20
|
-
|
20
|
+
Rake::TestTask.new(:test) do |t|
|
21
|
+
t.libs << "test"
|
22
|
+
t.libs << "lib"
|
23
|
+
t.test_files = FileList["test/**/*_test.rb"]
|
24
|
+
t.verbose = false
|
25
|
+
t.warning = false
|
26
|
+
end
|
21
27
|
|
22
|
-
|
28
|
+
desc 'Run type checks'
|
29
|
+
task :check do
|
30
|
+
sh 'bundle exec srb tc'
|
31
|
+
end
|
32
|
+
|
33
|
+
task default: %i[doc lint test build]
|
data/docs/index.md
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
# Titleist
|
2
|
+
|
3
|
+

|
4
|
+
|
5
|
+
## A powerful `<title>` helper for [Ruby on Rails](https://rubyonrails.org) applications.
|
6
|
+
|
7
|
+
### Check out the [README](https://github.com/tubbo/titleist#readme) for more information.
|
@@ -1,11 +1,14 @@
|
|
1
|
+
# typed: strict
|
1
2
|
# Generate initial files for the gem to work.
|
2
3
|
class TitleistGenerator < Rails::Generators::Base
|
3
4
|
source_root File.expand_path('templates', __dir__)
|
4
5
|
|
6
|
+
# @return [nil]
|
5
7
|
def copy_locale
|
6
8
|
template 'locale.yml.erb', 'config/locales/titleist.en.yml'
|
7
9
|
end
|
8
10
|
|
11
|
+
# @return [nil]
|
9
12
|
def update_default_application_layout
|
10
13
|
gsub_file(
|
11
14
|
'app/views/layouts/application.html.erb',
|
data/lib/titleist.rb
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
+
# typed: strict
|
1
2
|
require 'active_support/all'
|
3
|
+
require 'sorbet-runtime'
|
2
4
|
|
3
5
|
require 'titleist/version'
|
4
6
|
require 'titleist/engine'
|
@@ -10,15 +12,16 @@ require 'titleist/engine'
|
|
10
12
|
#
|
11
13
|
# @example Setting a title
|
12
14
|
# en:
|
13
|
-
#
|
14
|
-
#
|
15
|
-
#
|
16
|
-
#
|
17
|
-
#
|
18
|
-
#
|
19
|
-
#
|
20
|
-
#
|
21
|
-
#
|
15
|
+
# titleist:
|
16
|
+
# format: '%{app} | %{page}' # this is the default
|
17
|
+
# application:
|
18
|
+
# title: My App
|
19
|
+
# pages:
|
20
|
+
# index:
|
21
|
+
# title: Home
|
22
|
+
# posts:
|
23
|
+
# show:
|
24
|
+
# title: "Post %{name}"
|
22
25
|
#
|
23
26
|
# @example Rendering the current title
|
24
27
|
# = title_tag
|
@@ -26,4 +29,6 @@ module Titleist
|
|
26
29
|
extend ActiveSupport::Autoload
|
27
30
|
|
28
31
|
autoload :Title
|
32
|
+
autoload :Controller
|
33
|
+
autoload :Helper
|
29
34
|
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# typed: false
|
2
|
+
|
3
|
+
module Titleist
|
4
|
+
# Controller mixins for reading titles without ActionView
|
5
|
+
module Controller
|
6
|
+
extend ActiveSupport::Concern
|
7
|
+
extend T::Sig
|
8
|
+
|
9
|
+
included do
|
10
|
+
helper_method :title, :app_title, :page_title
|
11
|
+
end
|
12
|
+
|
13
|
+
# Generate the full page title for this request. When output into the
|
14
|
+
# view, the entire title is shown. You may also call +title.page+ or
|
15
|
+
# +title.app+ to view individual pieces of the title.
|
16
|
+
#
|
17
|
+
# @return [Titleist::Title]
|
18
|
+
def title
|
19
|
+
@title ||= Title.new(**params.to_unsafe_h.deep_symbolize_keys)
|
20
|
+
end
|
21
|
+
|
22
|
+
# Shorthand for calling +title.app+ in the view.
|
23
|
+
#
|
24
|
+
# @return [String] i18n-configured global application title.
|
25
|
+
def app_title
|
26
|
+
title.app
|
27
|
+
end
|
28
|
+
|
29
|
+
# Shorthand for calling +title.page+ in the view.
|
30
|
+
#
|
31
|
+
# @return [String] i18n-configured title for the current page.
|
32
|
+
def page_title
|
33
|
+
title.page
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/lib/titleist/engine.rb
CHANGED
@@ -1,8 +1,14 @@
|
|
1
|
+
# typed: strong
|
1
2
|
module Titleist
|
2
|
-
# Extensions into the Rails framework
|
3
|
-
#
|
4
|
-
# the global application title.
|
3
|
+
# Extensions into the Rails framework that mixin the controller and
|
4
|
+
# helper modules when ActionController and ActionView are loaded.
|
5
5
|
class Engine < Rails::Engine
|
6
|
-
|
6
|
+
ActiveSupport.on_load :action_controller_base do
|
7
|
+
include Titleist::Controller
|
8
|
+
end
|
9
|
+
|
10
|
+
ActiveSupport.on_load :action_view do
|
11
|
+
include Titleist::Helper
|
12
|
+
end
|
7
13
|
end
|
8
14
|
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# typed: false
|
2
|
+
|
3
|
+
module Titleist
|
4
|
+
# Helper methods in ActionView for rendering the title.
|
5
|
+
module Helper
|
6
|
+
extend T::Sig
|
7
|
+
|
8
|
+
# Render the full title as a `<title>` tag.
|
9
|
+
#
|
10
|
+
# @return [String]
|
11
|
+
def title_tag
|
12
|
+
content_tag :title, title_text.to_s
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
# @private
|
18
|
+
# @return [String]
|
19
|
+
def title_text
|
20
|
+
current_page?(root_path) ? title.app : title
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|