titler 1.2.0 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.circleci/config.yml +25 -0
- data/.gitignore +1 -0
- data/.ruby-version +1 -1
- data/Gemfile +1 -1
- data/README.md +27 -1
- data/Rakefile +2 -1
- data/app/helpers/titler/titler_helper.rb +23 -19
- data/config/initializers/titler.rb +3 -3
- data/lib/generators/titler/install/install_generator.rb +4 -4
- data/lib/generators/titler/locales/locales_generator.rb +3 -3
- data/lib/titler/configuration.rb +8 -8
- data/lib/titler/version.rb +1 -1
- data/lib/titler.rb +6 -6
- data/titler.gemspec +27 -30
- metadata +38 -44
- data/spec/configure_spec.rb +0 -46
- data/spec/helpers/titler_helper_spec.rb +0 -193
- data/spec/spec_helper.rb +0 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 245b3b8af826c022cdd490b57b881fb3ca5ce99ca1287514a75dff672e4a32cd
|
4
|
+
data.tar.gz: '089dba315f02229fc4f242fbc248273d90fe10f600254793b59627e438bf352b'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 023dc916006d558135e6930894285f571c4c0cb1b905c5329f86e6b3b970708d2f5b70a8092c236d920f3a157d84bc1c526fcd4d725580d075aac228f7761012
|
7
|
+
data.tar.gz: 0604f2f44666dd2edd3ab858a6e41b67c3a94b0c47c16e0dea70df34da304dd81217c9b3a46869bf700965056db074bb287460d797e882824693ab5c1707ad3b
|
@@ -0,0 +1,25 @@
|
|
1
|
+
version: 2.1
|
2
|
+
orbs:
|
3
|
+
ruby: circleci/ruby@0.1.2
|
4
|
+
|
5
|
+
jobs:
|
6
|
+
test:
|
7
|
+
parameters:
|
8
|
+
ruby-version:
|
9
|
+
type: string
|
10
|
+
docker:
|
11
|
+
- image: << parameters.ruby-version >>
|
12
|
+
steps:
|
13
|
+
- checkout
|
14
|
+
- ruby/bundle-install
|
15
|
+
- run:
|
16
|
+
name: Run tests
|
17
|
+
command: bundle exec rake
|
18
|
+
|
19
|
+
workflows:
|
20
|
+
all-tests:
|
21
|
+
jobs:
|
22
|
+
- test:
|
23
|
+
matrix:
|
24
|
+
parameters:
|
25
|
+
ruby-version: ["ruby:3.0.1", "ruby:2.7.3", "ruby:2.6.7"]
|
data/.gitignore
CHANGED
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
ruby-2.
|
1
|
+
ruby-2.6.5
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -3,6 +3,7 @@
|
|
3
3
|
[![Build Status](https://travis-ci.org/roberttravispierce/titler.svg?branch=master)](https://travis-ci.org/roberttravispierce/titler)
|
4
4
|
[![Code Climate](https://codeclimate.com/github/roberttravispierce/titler/badges/gpa.svg)](https://codeclimate.com/github/roberttravispierce/titler)
|
5
5
|
[![Coverage Status](https://coveralls.io/repos/github/roberttravispierce/titler/badge.svg?branch=master)](https://coveralls.io/github/roberttravispierce/titler?branch=master)
|
6
|
+
[![Ruby Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://github.com/testdouble/standard)
|
6
7
|
[![Gem Version](https://badge.fury.io/rb/titler.svg)](https://badge.fury.io/rb/titler)
|
7
8
|
|
8
9
|
1. [What is it?](#overview)
|
@@ -131,6 +132,31 @@ Titler.configure do |config|
|
|
131
132
|
end
|
132
133
|
```
|
133
134
|
|
135
|
+
### Configuration options
|
136
|
+
|
137
|
+
- **use_env_prefix** (Default = 'true')
|
138
|
+
|
139
|
+
Toggle use of the env_prefix. Note the prefix will never be use in a production environment no matter what the setting.
|
140
|
+
|
141
|
+
- **delimiter** (Default = ' - ')
|
142
|
+
|
143
|
+
Change the character delimiter between elements. Be sure to include any spaces you desire.
|
144
|
+
|
145
|
+
- **app_name_position** (Default = 'append')
|
146
|
+
|
147
|
+
Adjust how the app name is used. Options are 'append', 'prepend', or 'none'
|
148
|
+
|
149
|
+
- **use_app_tagline** (Default = 'true')
|
150
|
+
|
151
|
+
Toggle use of marketing tagline. Position is right before an appended app_name or right after a prepended app_name.
|
152
|
+
|
153
|
+
- **admin_name** (Default = 'Admin')
|
154
|
+
|
155
|
+
Change the text to add to the title if an admin controller is being used
|
156
|
+
|
157
|
+
- **admin_controller** (Default = 'AdminController')
|
158
|
+
|
159
|
+
Class name of controller to trigger addition of 'admin_name' in title
|
134
160
|
|
135
161
|
## <a name="why"></a>So why the fuss about titles anyway?
|
136
162
|
|
@@ -144,7 +170,7 @@ Here are some resources to learn more about the importance of thoughtful, well-c
|
|
144
170
|
|
145
171
|
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.
|
146
172
|
|
147
|
-
Invaluable guidance and
|
173
|
+
Invaluable guidance and encouragement was provided along the way by Jonathan Allured ([jonallured](https://github.com/jonallured)). Thank you Jon, for agreeing to be a mentor and give back to the community.
|
148
174
|
|
149
175
|
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.
|
150
176
|
|
data/Rakefile
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module Titler
|
2
2
|
module TitlerHelper
|
3
3
|
def page_title(page_title)
|
4
|
-
content_for(:page_title) {page_title}
|
4
|
+
content_for(:page_title) { page_title }
|
5
5
|
end
|
6
6
|
|
7
7
|
def titler(custom_vars = {})
|
@@ -24,7 +24,7 @@ module Titler
|
|
24
24
|
end
|
25
25
|
|
26
26
|
def to_s
|
27
|
-
th =
|
27
|
+
th = {}
|
28
28
|
th[:env_prefix] = env_prefix
|
29
29
|
th[:admin_namespace] = admin_namespace
|
30
30
|
th[:title_body] = title_body
|
@@ -37,14 +37,14 @@ module Titler
|
|
37
37
|
|
38
38
|
def env_prefix
|
39
39
|
if @configuration.use_env_prefix
|
40
|
-
Rails.env.production? ?
|
40
|
+
Rails.env.production? ? "" : "(#{Rails.env[0, 1].upcase}) "
|
41
41
|
else
|
42
|
-
|
42
|
+
""
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
46
46
|
def admin_namespace
|
47
|
-
admin_namespace? ? admin_default_name + delimiter :
|
47
|
+
admin_namespace? ? admin_default_name + delimiter : ""
|
48
48
|
end
|
49
49
|
|
50
50
|
def admin_namespace?
|
@@ -56,38 +56,42 @@ module Titler
|
|
56
56
|
end
|
57
57
|
|
58
58
|
def delimiter
|
59
|
-
if @i18n.exists?(
|
60
|
-
@i18n.t(
|
59
|
+
if @i18n.exists?("titler.delimiter") && @i18n.t("titler.delimiter").present?
|
60
|
+
@i18n.t("titler.delimiter")
|
61
61
|
else
|
62
62
|
@configuration.delimiter
|
63
63
|
end
|
64
64
|
end
|
65
65
|
|
66
66
|
def app_name
|
67
|
-
if @i18n.exists?(
|
68
|
-
@i18n.t(
|
67
|
+
if @i18n.exists?("titler.app_name") && @i18n.t("titler.app_name").present?
|
68
|
+
@i18n.t("titler.app_name")
|
69
69
|
else
|
70
70
|
Rails.application.class.to_s.split("::").first
|
71
71
|
end
|
72
72
|
end
|
73
73
|
|
74
74
|
def app_tagline
|
75
|
-
|
75
|
+
@i18n.exists?("titler.app_tagline") ? @i18n.t("titler.app_tagline") : ""
|
76
76
|
end
|
77
77
|
|
78
78
|
def title_body
|
79
79
|
if @title_as_set.present?
|
80
80
|
@title_as_set
|
81
81
|
else
|
82
|
-
|
82
|
+
begin
|
83
|
+
@controller.controller_name.titleize + " " + @controller.action_name.titleize
|
84
|
+
rescue
|
85
|
+
""
|
86
|
+
end
|
83
87
|
end
|
84
88
|
end
|
85
89
|
|
86
90
|
def build_title_str(th)
|
87
91
|
case @configuration.app_name_position
|
88
|
-
when
|
92
|
+
when "append"
|
89
93
|
th[:env_prefix] + th[:admin_namespace] + th[:title_body] + app_tagline_str(th) + app_name_str(th)
|
90
|
-
when
|
94
|
+
when "prepend"
|
91
95
|
th[:env_prefix] + app_name_str(th) + app_tagline_str(th) + th[:admin_namespace] + th[:title_body]
|
92
96
|
else
|
93
97
|
th[:env_prefix] + th[:admin_namespace] + th[:title_body] + app_tagline_str(th)
|
@@ -99,12 +103,12 @@ module Titler
|
|
99
103
|
th[:app_name]
|
100
104
|
else
|
101
105
|
case @configuration.app_name_position
|
102
|
-
when
|
106
|
+
when "append"
|
103
107
|
delimiter + th[:app_name]
|
104
|
-
when
|
108
|
+
when "prepend"
|
105
109
|
th[:app_name] + delimiter
|
106
110
|
else
|
107
|
-
|
111
|
+
""
|
108
112
|
end
|
109
113
|
end
|
110
114
|
end
|
@@ -112,12 +116,12 @@ module Titler
|
|
112
116
|
def app_tagline_str(th)
|
113
117
|
tagline = th[:app_tagline]
|
114
118
|
if tagline.blank? || !@configuration.use_app_tagline
|
115
|
-
|
119
|
+
""
|
116
120
|
else
|
117
121
|
case @configuration.app_name_position
|
118
|
-
when
|
122
|
+
when "append"
|
119
123
|
delimiter + tagline
|
120
|
-
when
|
124
|
+
when "prepend"
|
121
125
|
tagline + delimiter
|
122
126
|
end
|
123
127
|
end
|
@@ -1,8 +1,8 @@
|
|
1
1
|
Titler.configure do |config|
|
2
2
|
config.use_env_prefix = true
|
3
|
-
config.delimiter =
|
4
|
-
config.app_name_position =
|
3
|
+
config.delimiter = " - "
|
4
|
+
config.app_name_position = "append" # append, prepend, none
|
5
5
|
config.use_app_tagline = true
|
6
|
-
config.admin_name =
|
6
|
+
config.admin_name = "Admin"
|
7
7
|
config.admin_controller = AdminController
|
8
8
|
end
|
@@ -1,18 +1,18 @@
|
|
1
|
-
require
|
1
|
+
require "rails/generators/base"
|
2
2
|
|
3
3
|
module Titler
|
4
4
|
module Generators
|
5
5
|
class InstallGenerator < Rails::Generators::Base
|
6
|
-
source_root File.expand_path(
|
6
|
+
source_root File.expand_path("../templates", __FILE__)
|
7
7
|
desc "Creates Titler initializer and i18n for your application"
|
8
8
|
|
9
9
|
def copy_initializer
|
10
|
-
template
|
10
|
+
template "titler.rb", "config/initializers/titler.rb"
|
11
11
|
puts "Initializer install complete."
|
12
12
|
end
|
13
13
|
|
14
14
|
def copy_i18n
|
15
|
-
template
|
15
|
+
template "titler.en.yml", "config/locales/titler.en.yml"
|
16
16
|
puts "Localization install complete."
|
17
17
|
end
|
18
18
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require "rails/generators/base"
|
2
2
|
|
3
3
|
module Titler
|
4
4
|
module Generators
|
@@ -14,14 +14,14 @@ module Titler
|
|
14
14
|
private
|
15
15
|
|
16
16
|
def locales
|
17
|
-
files_within_root(
|
17
|
+
files_within_root(".", "config/locales/**/*.*")
|
18
18
|
end
|
19
19
|
|
20
20
|
def files_within_root(prefix, glob)
|
21
21
|
root = "#{self.class.source_root}/#{prefix}"
|
22
22
|
|
23
23
|
Dir["#{root}/#{glob}"].sort.map do |full_path|
|
24
|
-
full_path.sub(root,
|
24
|
+
full_path.sub(root, ".").gsub("/./", "/")
|
25
25
|
end
|
26
26
|
end
|
27
27
|
end
|
data/lib/titler/configuration.rb
CHANGED
@@ -3,19 +3,19 @@ class AdminController; end
|
|
3
3
|
module Titler
|
4
4
|
class Configuration
|
5
5
|
attr_accessor :admin_name,
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
6
|
+
:admin_controller,
|
7
|
+
:app_name_position,
|
8
|
+
:use_env_prefix,
|
9
|
+
:use_app_tagline,
|
10
|
+
:delimiter
|
11
11
|
|
12
12
|
def initialize
|
13
|
-
@admin_name =
|
13
|
+
@admin_name = "Admin"
|
14
14
|
@admin_controller = AdminController
|
15
|
-
@app_name_position =
|
15
|
+
@app_name_position = "append" # append, prepend, none
|
16
16
|
@use_env_prefix = true
|
17
17
|
@use_app_tagline = true
|
18
|
-
@delimiter =
|
18
|
+
@delimiter = " - " # Note: (Eventually) a 'titler.delimiter' i18n value will override this
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
data/lib/titler/version.rb
CHANGED
data/lib/titler.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
app = File.expand_path(
|
1
|
+
app = File.expand_path("../../app", __FILE__)
|
2
2
|
$LOAD_PATH.unshift(app) unless $LOAD_PATH.include?(app)
|
3
3
|
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require
|
8
|
-
require
|
4
|
+
require "titler/version"
|
5
|
+
require "rails/engine"
|
6
|
+
require "titler/engine"
|
7
|
+
require "titler/configuration"
|
8
|
+
require "helpers/titler/titler_helper"
|
data/titler.gemspec
CHANGED
@@ -1,23 +1,24 @@
|
|
1
|
-
|
2
|
-
lib = File.expand_path('../lib', __FILE__)
|
1
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
2
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require
|
3
|
+
require "titler/version"
|
5
4
|
|
6
5
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name
|
8
|
-
spec.version
|
9
|
-
spec.authors
|
10
|
-
spec.email
|
11
|
-
|
12
|
-
spec.summary
|
13
|
-
spec.description
|
14
|
-
spec.homepage
|
15
|
-
spec.license
|
16
|
-
spec.files
|
17
|
-
|
6
|
+
spec.name = "titler"
|
7
|
+
spec.version = Titler::VERSION
|
8
|
+
spec.authors = ["Robert Travis Pierce", "Jonathan Allured"]
|
9
|
+
spec.email = ["robert@roberttravispierce.com"]
|
10
|
+
|
11
|
+
spec.summary = "Titler is a ruby gem that automaticaly gives you useful and consistent page titles for your Rails application."
|
12
|
+
spec.description = "Titler is a ruby gem that automaticaly gives you useful and consistent page titles for your Rails application. You can set specific page titles in the controller or view with fallbacks and useful defaults for all situations."
|
13
|
+
spec.homepage = "https://github.com/roberttravispierce/titler"
|
14
|
+
spec.license = "MIT"
|
15
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
16
|
+
f.match(%r{^(test|spec|features)/})
|
17
|
+
end
|
18
|
+
spec.test_files = spec.files.grep(/\Aspec\//)
|
18
19
|
spec.require_path = "lib"
|
19
20
|
|
20
|
-
spec.required_ruby_version = "
|
21
|
+
spec.required_ruby_version = ">= 2"
|
21
22
|
|
22
23
|
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
23
24
|
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
@@ -28,28 +29,24 @@ Gem::Specification.new do |spec|
|
|
28
29
|
# "public gem pushes."
|
29
30
|
# end
|
30
31
|
|
31
|
-
spec.
|
32
|
-
|
33
|
-
end
|
34
|
-
spec.bindir = "exe"
|
35
|
-
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
32
|
+
spec.bindir = "exe"
|
33
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
36
34
|
spec.require_paths = ["lib"]
|
37
35
|
|
38
|
-
spec.add_development_dependency
|
39
|
-
spec.add_development_dependency "
|
40
|
-
spec.add_development_dependency "
|
41
|
-
spec.add_development_dependency "rspec", "~> 3.0"
|
36
|
+
spec.add_development_dependency "bundler"
|
37
|
+
spec.add_development_dependency "rake"
|
38
|
+
spec.add_development_dependency "rspec"
|
42
39
|
spec.add_development_dependency "rspec-nc"
|
43
40
|
spec.add_development_dependency "guard"
|
44
41
|
spec.add_development_dependency "guard-rspec"
|
45
42
|
spec.add_development_dependency "pry"
|
46
43
|
spec.add_development_dependency "pry-remote"
|
47
44
|
spec.add_development_dependency "pry-nav"
|
48
|
-
spec.add_development_dependency
|
49
|
-
spec.add_development_dependency
|
50
|
-
spec.add_development_dependency
|
51
|
-
|
52
|
-
spec.add_dependency 'rails', '>= 3.1'
|
53
|
-
spec.add_dependency 'i18n'
|
45
|
+
spec.add_development_dependency "rb-readline"
|
46
|
+
spec.add_development_dependency "rspec-rails"
|
47
|
+
spec.add_development_dependency "coveralls"
|
48
|
+
spec.add_development_dependency "standard"
|
54
49
|
|
50
|
+
spec.add_dependency "rails", ">= 5.2"
|
51
|
+
spec.add_dependency "i18n"
|
55
52
|
end
|
metadata
CHANGED
@@ -1,72 +1,58 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: titler
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Robert Travis Pierce
|
8
8
|
- Jonathan Allured
|
9
|
-
autorequire:
|
9
|
+
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2022-09-07 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
|
-
- !ruby/object:Gem::Dependency
|
15
|
-
name: rails
|
16
|
-
requirement: !ruby/object:Gem::Requirement
|
17
|
-
requirements:
|
18
|
-
- - "~>"
|
19
|
-
- !ruby/object:Gem::Version
|
20
|
-
version: 5.0.3
|
21
|
-
type: :development
|
22
|
-
prerelease: false
|
23
|
-
version_requirements: !ruby/object:Gem::Requirement
|
24
|
-
requirements:
|
25
|
-
- - "~>"
|
26
|
-
- !ruby/object:Gem::Version
|
27
|
-
version: 5.0.3
|
28
14
|
- !ruby/object:Gem::Dependency
|
29
15
|
name: bundler
|
30
16
|
requirement: !ruby/object:Gem::Requirement
|
31
17
|
requirements:
|
32
|
-
- - "
|
18
|
+
- - ">="
|
33
19
|
- !ruby/object:Gem::Version
|
34
|
-
version: '
|
20
|
+
version: '0'
|
35
21
|
type: :development
|
36
22
|
prerelease: false
|
37
23
|
version_requirements: !ruby/object:Gem::Requirement
|
38
24
|
requirements:
|
39
|
-
- - "
|
25
|
+
- - ">="
|
40
26
|
- !ruby/object:Gem::Version
|
41
|
-
version: '
|
27
|
+
version: '0'
|
42
28
|
- !ruby/object:Gem::Dependency
|
43
29
|
name: rake
|
44
30
|
requirement: !ruby/object:Gem::Requirement
|
45
31
|
requirements:
|
46
|
-
- - "
|
32
|
+
- - ">="
|
47
33
|
- !ruby/object:Gem::Version
|
48
|
-
version: '
|
34
|
+
version: '0'
|
49
35
|
type: :development
|
50
36
|
prerelease: false
|
51
37
|
version_requirements: !ruby/object:Gem::Requirement
|
52
38
|
requirements:
|
53
|
-
- - "
|
39
|
+
- - ">="
|
54
40
|
- !ruby/object:Gem::Version
|
55
|
-
version: '
|
41
|
+
version: '0'
|
56
42
|
- !ruby/object:Gem::Dependency
|
57
43
|
name: rspec
|
58
44
|
requirement: !ruby/object:Gem::Requirement
|
59
45
|
requirements:
|
60
|
-
- - "
|
46
|
+
- - ">="
|
61
47
|
- !ruby/object:Gem::Version
|
62
|
-
version: '
|
48
|
+
version: '0'
|
63
49
|
type: :development
|
64
50
|
prerelease: false
|
65
51
|
version_requirements: !ruby/object:Gem::Requirement
|
66
52
|
requirements:
|
67
|
-
- - "
|
53
|
+
- - ">="
|
68
54
|
- !ruby/object:Gem::Version
|
69
|
-
version: '
|
55
|
+
version: '0'
|
70
56
|
- !ruby/object:Gem::Dependency
|
71
57
|
name: rspec-nc
|
72
58
|
requirement: !ruby/object:Gem::Requirement
|
@@ -193,20 +179,34 @@ dependencies:
|
|
193
179
|
- - ">="
|
194
180
|
- !ruby/object:Gem::Version
|
195
181
|
version: '0'
|
182
|
+
- !ruby/object:Gem::Dependency
|
183
|
+
name: standard
|
184
|
+
requirement: !ruby/object:Gem::Requirement
|
185
|
+
requirements:
|
186
|
+
- - ">="
|
187
|
+
- !ruby/object:Gem::Version
|
188
|
+
version: '0'
|
189
|
+
type: :development
|
190
|
+
prerelease: false
|
191
|
+
version_requirements: !ruby/object:Gem::Requirement
|
192
|
+
requirements:
|
193
|
+
- - ">="
|
194
|
+
- !ruby/object:Gem::Version
|
195
|
+
version: '0'
|
196
196
|
- !ruby/object:Gem::Dependency
|
197
197
|
name: rails
|
198
198
|
requirement: !ruby/object:Gem::Requirement
|
199
199
|
requirements:
|
200
200
|
- - ">="
|
201
201
|
- !ruby/object:Gem::Version
|
202
|
-
version: '
|
202
|
+
version: '5.2'
|
203
203
|
type: :runtime
|
204
204
|
prerelease: false
|
205
205
|
version_requirements: !ruby/object:Gem::Requirement
|
206
206
|
requirements:
|
207
207
|
- - ">="
|
208
208
|
- !ruby/object:Gem::Version
|
209
|
-
version: '
|
209
|
+
version: '5.2'
|
210
210
|
- !ruby/object:Gem::Dependency
|
211
211
|
name: i18n
|
212
212
|
requirement: !ruby/object:Gem::Requirement
|
@@ -230,6 +230,7 @@ executables: []
|
|
230
230
|
extensions: []
|
231
231
|
extra_rdoc_files: []
|
232
232
|
files:
|
233
|
+
- ".circleci/config.yml"
|
233
234
|
- ".coveralls.yml"
|
234
235
|
- ".gitignore"
|
235
236
|
- ".rspec"
|
@@ -253,36 +254,29 @@ files:
|
|
253
254
|
- lib/titler/configuration.rb
|
254
255
|
- lib/titler/engine.rb
|
255
256
|
- lib/titler/version.rb
|
256
|
-
- spec/configure_spec.rb
|
257
|
-
- spec/helpers/titler_helper_spec.rb
|
258
|
-
- spec/spec_helper.rb
|
259
257
|
- titler.gemspec
|
260
258
|
homepage: https://github.com/roberttravispierce/titler
|
261
259
|
licenses:
|
262
260
|
- MIT
|
263
261
|
metadata: {}
|
264
|
-
post_install_message:
|
262
|
+
post_install_message:
|
265
263
|
rdoc_options: []
|
266
264
|
require_paths:
|
267
265
|
- lib
|
268
266
|
required_ruby_version: !ruby/object:Gem::Requirement
|
269
267
|
requirements:
|
270
|
-
- - "
|
268
|
+
- - ">="
|
271
269
|
- !ruby/object:Gem::Version
|
272
|
-
version: '2
|
270
|
+
version: '2'
|
273
271
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
274
272
|
requirements:
|
275
273
|
- - ">="
|
276
274
|
- !ruby/object:Gem::Version
|
277
275
|
version: '0'
|
278
276
|
requirements: []
|
279
|
-
|
280
|
-
|
281
|
-
signing_key:
|
277
|
+
rubygems_version: 3.1.2
|
278
|
+
signing_key:
|
282
279
|
specification_version: 4
|
283
280
|
summary: Titler is a ruby gem that automaticaly gives you useful and consistent page
|
284
281
|
titles for your Rails application.
|
285
|
-
test_files:
|
286
|
-
- spec/configure_spec.rb
|
287
|
-
- spec/helpers/titler_helper_spec.rb
|
288
|
-
- spec/spec_helper.rb
|
282
|
+
test_files: []
|
data/spec/configure_spec.rb
DELETED
@@ -1,46 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'titler'
|
3
|
-
|
4
|
-
class ManagerController; end
|
5
|
-
|
6
|
-
module Titler
|
7
|
-
describe Configuration do
|
8
|
-
|
9
|
-
context 'with configuration block' do
|
10
|
-
it 'uses the options in the configuration block instead of defaults' do
|
11
|
-
Titler.configure do |config|
|
12
|
-
config.admin_controller = ManagerController
|
13
|
-
config.admin_name = 'Manager'
|
14
|
-
config.app_name_position = 'prepend'
|
15
|
-
config.delimiter = ' | '
|
16
|
-
config.use_app_tagline = false
|
17
|
-
config.use_env_prefix = false
|
18
|
-
end
|
19
|
-
|
20
|
-
expect(Titler.configuration.admin_controller).to eq ManagerController
|
21
|
-
expect(Titler.configuration.admin_name).to eq 'Manager'
|
22
|
-
expect(Titler.configuration.app_name_position).to eq 'prepend'
|
23
|
-
expect(Titler.configuration.delimiter).to eq ' | '
|
24
|
-
expect(Titler.configuration.use_app_tagline).to eq false
|
25
|
-
expect(Titler.configuration.use_env_prefix).to eq false
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
describe "#configure" do
|
30
|
-
it "sets use_env_prefix to true" do
|
31
|
-
config = Configuration.new
|
32
|
-
expect(config.use_env_prefix).to be true
|
33
|
-
end
|
34
|
-
|
35
|
-
it "can set use_env_prefix to false" do
|
36
|
-
config = Configuration.new
|
37
|
-
allow(config).to receive(:use_env_prefix).and_return(false)
|
38
|
-
expect(config.use_env_prefix).to be false
|
39
|
-
end
|
40
|
-
|
41
|
-
after :each do
|
42
|
-
Titler.reset
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
@@ -1,193 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'titler'
|
3
|
-
|
4
|
-
describe Titler::TitlerHelper do
|
5
|
-
|
6
|
-
# Defaults Only Context ----------------------------------------------------
|
7
|
-
context 'when no title info is set' do
|
8
|
-
it '(1) uses defaults' do
|
9
|
-
controller = MockController.new
|
10
|
-
stub_rails(controller, 'production', nil)
|
11
|
-
load_translations({})
|
12
|
-
|
13
|
-
expected_title = "#{env_prefix}#{controller.controller_name.titleize} #{controller.action_name.titleize} - #{app_name}"
|
14
|
-
expect(titler_helper.titler).to eq(expected_title)
|
15
|
-
end
|
16
|
-
|
17
|
-
it '(2) prefixes defaults in development' do
|
18
|
-
controller = MockController.new
|
19
|
-
stub_rails(controller, 'development', nil)
|
20
|
-
load_translations({})
|
21
|
-
|
22
|
-
expected_title = "#{env_prefix}#{controller.controller_name.titleize} #{controller.action_name.titleize} - #{app_name}"
|
23
|
-
expect(titler_helper.titler).to eq(expected_title)
|
24
|
-
end
|
25
|
-
|
26
|
-
it '(3) adds admin namespace to defaults' do
|
27
|
-
controller = MockAdminController.new
|
28
|
-
stub_rails(controller, 'production', nil)
|
29
|
-
load_translations({})
|
30
|
-
|
31
|
-
expected_title = "#{env_prefix}Admin - #{controller.controller_name.titleize} #{controller.action_name.titleize} - #{app_name}"
|
32
|
-
expect(titler_helper.titler).to eq(expected_title)
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
# i18n Values Context ----------------------------------------------------
|
37
|
-
context 'when titler i18n values exist' do
|
38
|
-
it '(1) adds delimiter to defaults' do
|
39
|
-
controller = MockController.new
|
40
|
-
stub_rails(controller, 'production', nil)
|
41
|
-
load_translations({ delimiter: ' | ' })
|
42
|
-
|
43
|
-
expected_title = "#{env_prefix}#{controller.controller_name.titleize} #{controller.action_name.titleize} | #{app_name}"
|
44
|
-
expect(titler_helper.titler).to eq(expected_title)
|
45
|
-
end
|
46
|
-
|
47
|
-
it '(2) used config delimiter if i18n.t is blank' do
|
48
|
-
controller = MockController.new
|
49
|
-
stub_rails(controller, 'production', nil)
|
50
|
-
load_translations({ delimiter: '' })
|
51
|
-
|
52
|
-
expected_title = "#{env_prefix}#{controller.controller_name.titleize} #{controller.action_name.titleize} - #{app_name}"
|
53
|
-
expect(titler_helper.titler).to eq(expected_title)
|
54
|
-
end
|
55
|
-
|
56
|
-
it '(3) adds app name to defaults' do
|
57
|
-
controller = MockController.new
|
58
|
-
stub_rails(controller, 'production', nil)
|
59
|
-
load_translations({ app_name: 'Test App' })
|
60
|
-
|
61
|
-
expected_title = "#{env_prefix}#{controller.controller_name.titleize} #{controller.action_name.titleize} - Test App"
|
62
|
-
expect(titler_helper.titler).to eq(expected_title)
|
63
|
-
end
|
64
|
-
|
65
|
-
it '(4) uses default app name if i18n.t is blank' do
|
66
|
-
controller = MockController.new
|
67
|
-
stub_rails(controller, 'production', nil)
|
68
|
-
load_translations({ app_name: '' })
|
69
|
-
|
70
|
-
expected_title = "#{env_prefix}#{controller.controller_name.titleize} #{controller.action_name.titleize} - #{app_name}"
|
71
|
-
expect(titler_helper.titler).to eq(expected_title)
|
72
|
-
end
|
73
|
-
|
74
|
-
it '(5) adds tagline to defaults' do
|
75
|
-
controller = MockController.new
|
76
|
-
stub_rails(controller, 'production', nil)
|
77
|
-
load_translations({ app_tagline: 'All the News' })
|
78
|
-
|
79
|
-
expected_title = "#{env_prefix}#{controller.controller_name.titleize} #{controller.action_name.titleize} - All the News - #{app_name}"
|
80
|
-
expect(titler_helper.titler).to eq(expected_title)
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
# Specific Page Title Context ----------------------------------------------------
|
85
|
-
context 'when specific page title exists' do
|
86
|
-
it '(1) uses page_title var when present' do
|
87
|
-
controller = MockController.new
|
88
|
-
stub_rails(controller, 'production', nil)
|
89
|
-
load_translations({})
|
90
|
-
titler_helper.instance_variable_set(:@page_title, 'Var Test Page')
|
91
|
-
expected_title = "#{env_prefix}Var Test Page - #{app_name}"
|
92
|
-
expect(titler_helper.titler).to eq(expected_title)
|
93
|
-
end
|
94
|
-
|
95
|
-
# it '(1) uses content_for when present' do
|
96
|
-
# controller = MockController.new
|
97
|
-
# stub_rails(controller, 'production', nil)
|
98
|
-
# #TODO setting the content_for is not working for some reason
|
99
|
-
# titler_helper.content_for(:page_title, 'Test Page')
|
100
|
-
# expected_title = "#{env_prefix}Test Page - #{app_name}"
|
101
|
-
# expect(titler_helper.titler).to eq(expected_title)
|
102
|
-
# end
|
103
|
-
end
|
104
|
-
|
105
|
-
# Configuration Values Context ----------------------------------------------------
|
106
|
-
context 'when titler configuration values exist' do
|
107
|
-
it 'uses the options in the configuration block instead of defaults' do
|
108
|
-
controller = MockController.new
|
109
|
-
stub_rails(controller, 'production', nil)
|
110
|
-
load_translations({})
|
111
|
-
|
112
|
-
Titler.configure do |config|
|
113
|
-
config.delimiter = ' | '
|
114
|
-
end
|
115
|
-
|
116
|
-
expect(titler_helper.titler).to include('|')
|
117
|
-
|
118
|
-
Titler.reset
|
119
|
-
end
|
120
|
-
end
|
121
|
-
|
122
|
-
def stub_rails(controller, env_str, content_for)
|
123
|
-
allow(Rails).to receive_message_chain(:application, :class).and_return('TitlerTest::Application')
|
124
|
-
allow(Rails).to receive(:env).and_return(ActiveSupport::StringInquirer.new(env_str))
|
125
|
-
allow(Rails).to receive(:controller).and_return(controller)
|
126
|
-
|
127
|
-
allow(titler_helper).to receive_message_chain(:content_for).and_return(content_for)
|
128
|
-
allow(titler_helper).to receive_message_chain(:controller, :view_assigns).and_return({})
|
129
|
-
allow(titler_helper).to receive_message_chain(:controller).and_return(controller)
|
130
|
-
end
|
131
|
-
|
132
|
-
def app_name
|
133
|
-
Rails.application.class.to_s.split("::").first
|
134
|
-
end
|
135
|
-
|
136
|
-
def load_translations(titles)
|
137
|
-
I18n.backend.reload!
|
138
|
-
I18n.backend.store_translations(:en, { titler: titles })
|
139
|
-
end
|
140
|
-
|
141
|
-
def env_prefix
|
142
|
-
Rails.env.production? ? '' : "(#{Rails.env[0,1].upcase}) "
|
143
|
-
end
|
144
|
-
|
145
|
-
# TODO: I think there's a way to do away with this stub style and use something like:
|
146
|
-
# allow(helper).to receive(:controller).and_return('MockController') but I'm not sure.
|
147
|
-
class MockController
|
148
|
-
def controller_name
|
149
|
-
"mock"
|
150
|
-
end
|
151
|
-
|
152
|
-
def action_name
|
153
|
-
"action"
|
154
|
-
end
|
155
|
-
|
156
|
-
def view_assigns
|
157
|
-
{}
|
158
|
-
end
|
159
|
-
end
|
160
|
-
|
161
|
-
class AdminController; end
|
162
|
-
class MockAdminController < AdminController
|
163
|
-
def controller_name
|
164
|
-
"mock_admin"
|
165
|
-
end
|
166
|
-
|
167
|
-
def action_name
|
168
|
-
"action"
|
169
|
-
end
|
170
|
-
|
171
|
-
def view_assigns
|
172
|
-
{}
|
173
|
-
end
|
174
|
-
end
|
175
|
-
|
176
|
-
class MyAdminController < AdminController
|
177
|
-
def controller_name
|
178
|
-
"my_admin"
|
179
|
-
end
|
180
|
-
|
181
|
-
def action_name
|
182
|
-
"action"
|
183
|
-
end
|
184
|
-
|
185
|
-
def view_assigns
|
186
|
-
{}
|
187
|
-
end
|
188
|
-
end
|
189
|
-
|
190
|
-
def titler_helper
|
191
|
-
@titler_helper ||= Class.new { include Titler::TitlerHelper }.new
|
192
|
-
end
|
193
|
-
end
|
data/spec/spec_helper.rb
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
require 'coveralls'
|
2
|
-
Coveralls.wear!
|
3
|
-
|
4
|
-
require "bundler/setup"
|
5
|
-
require 'pry'
|
6
|
-
require "titler"
|
7
|
-
require 'rails'
|
8
|
-
|
9
|
-
RSpec.configure do |config|
|
10
|
-
# Enable flags like --only-failures and --next-failure
|
11
|
-
config.example_status_persistence_file_path = ".rspec_status"
|
12
|
-
|
13
|
-
config.after(:each) { I18n.locale = :en }
|
14
|
-
|
15
|
-
config.expect_with :rspec do |c|
|
16
|
-
c.syntax = :expect
|
17
|
-
end
|
18
|
-
end
|