titleist 0.1.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 +7 -0
- data/.codeclimate.yml +9 -0
- data/.gitignore +12 -0
- data/.rspec +2 -0
- data/.rubocop.yml +11 -0
- data/.ruby-version +1 -0
- data/.travis.yml +20 -0
- data/Gemfile +14 -0
- data/MIT-LICENSE +20 -0
- data/README.md +93 -0
- data/Rakefile +27 -0
- data/app/controllers/.keep +0 -0
- data/app/helpers/.keep +0 -0
- data/app/helpers/titleist_helper.rb +46 -0
- data/app/mailers/.keep +0 -0
- data/app/models/.keep +0 -0
- data/app/views/.keep +0 -0
- data/bin/rails +12 -0
- data/bin/rake +17 -0
- data/bin/rspec +17 -0
- data/lib/generators/titleist/USAGE +11 -0
- data/lib/generators/titleist/templates/locale.yml.erb +4 -0
- data/lib/generators/titleist/titleist_generator.rb +16 -0
- data/lib/tasks/titleist_tasks.rake +4 -0
- data/lib/titleist/engine.rb +8 -0
- data/lib/titleist/title.rb +138 -0
- data/lib/titleist/version.rb +3 -0
- data/lib/titleist.rb +29 -0
- data/titleist.gemspec +28 -0
- metadata +199 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 90873ada754915c66697e0e34345b70b6bbccc42
|
4
|
+
data.tar.gz: 1c6320f8d4f050b56c459f775118a94704748f8f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: dc54ebf325f9c2e4e617576bb2c3751594b6436c2ade7927c27bdaf9f14c67579d42c15cfe866b9cd129ed3567290c595b3932889f18b1bb2fe6d0e2eeb5051b
|
7
|
+
data.tar.gz: fd7b6fe3fc6892e8180cc83571a251d927dd3f357e78be11f78c822de4eabdbe844d4800ee73bf9b161019f766eba98b1378bc60cc68f2bc831d97df3c40fb44
|
data/.codeclimate.yml
ADDED
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.3.0
|
data/.travis.yml
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# set up the container
|
2
|
+
language: ruby
|
3
|
+
rvm:
|
4
|
+
- 2.3.1
|
5
|
+
cache: bundle
|
6
|
+
|
7
|
+
# test the build
|
8
|
+
script: bin/rake
|
9
|
+
|
10
|
+
# deploy tags to rubygems
|
11
|
+
deploy:
|
12
|
+
provider: rubygems
|
13
|
+
on:
|
14
|
+
tags: true
|
15
|
+
api_key:
|
16
|
+
secure: RtW6VGSMsO7Lz53VEL5moSiFPjdM7IP8tj0oSkg0AJcBzdI6AQdy4C3mFB84GXf7BJ7fVYdkWHNA3wEpD5XeAMRTMjNh8gsygdBepQ90r3NvPGiusrpyfrPEUD2Tm0RJh1AJTYLPi1snUktMemM75J0xhYvkeXEmtS5WrfbNtJOkNvPSJODSnPWQVf6++Q26JfT7IbVXzdXYmCbsZPDd/E9Q3Sxd3kgsIA3RMf4/jaoffGHpGbYL4+zhZyXZTgmOzw+6TuCMPVfHPWisRdoqQ75vcjVvXjePxZNBXB2Ap4biGXT78kTb2zOOM4ZxUAq8fFxF3sELMiKs/AhDGtUfhi8fRjJl6fes1NW6ONMvMbLkkk3puzu2i/fuwXpFLhr54d7OIhkDpjukadz7/vI+UescojA+kr5HwY1zKG6hbi7ayaMXaF1CNZk+ivB2yadvv0et7upoAmFSwEfAtN34mFlgLFAgn2U+MByl4OvZW87ndF4XvRthpNX4KgyGKhYenBHKgPZswvvsbsymOCxh217P0VFM7kuUv7lrF1WyraJbxPQPHgIS+JXDFhkgLFwTmZw9OccQx+E/czE1P6Ou2V5jcKk6tG/6YaEn/I0u5jeYdkstAsNEnaIO7fhjEE12BOrPn6myBps67KdjJdN9i0Q/cFtnc7A1EP5JbVZqqYE=
|
17
|
+
addons:
|
18
|
+
code_climate:
|
19
|
+
repo_token:
|
20
|
+
secure: ED+KEjC0xp89malnpkDPAMh9AyNK+1XE+wb8j8cXRheGHSMgLrDFw1cL6q+fyMuSGd56ITaqER86FuThHhH7YYEyd+x9ySf5j013u7CAKkXzkwqinT9Z3YK+LRC6OlELn88PDrvwN+Pc+2KhqusFDPcog9BizxcxiNXv0iOIIVqCnthZ5P+227K6TDwwwJO2NuL6V3IFl2YtlxC0Nze063/D/7H+U15Bnzt4XZJYkYmv7Q2G8dV0czymAhBGZ4okiht/pMrJiHlp3Qr8hO3U9A6sJXKMgkrhfn50VSsSLXqeLm0qnDshQArNrakeAAei5ZFCTgpUvJjrpQA1lPhA/IKtgFd57JRMUKqDuh8q497VgphEaOAbB0Z2hs3oFFCEq+lTD+cOQ5q5aQHXMOwKGVDCgnFRaR7ZYScJwCpMV4syse1HsjnEDOr5ELCwVIElw36xjFRTz3tfThn2eu2QFLskuatFhk+yhvHzrvwVopZFMpuj855kYjJeu5+Kkek9lzjKieXOry4ByiisclszLZ4Xll7QSWiTyeTCDVZ+igOb9nxOBsFgjYaFIBiFFWx2GOVPToPt/MYQEgmfq+VZbgncOvl2yeoCYSMZUlPDO7n3w/UTWmIMfh+vGwccsBm0siT3mhDcN+asqbkjiXF3B+afoaFyMNKVlR4Zpor/GqY=
|
data/Gemfile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
# Declare your gem's dependencies in titleist.gemspec.
|
4
|
+
# Bundler will treat runtime dependencies like base dependencies, and
|
5
|
+
# development dependencies will be added by default to the :development group.
|
6
|
+
gemspec
|
7
|
+
|
8
|
+
# Declare any dependencies that are still in development here instead of in
|
9
|
+
# your gemspec. These might include edge Rails or gems from your path or
|
10
|
+
# Git. Remember to move these dependencies to your gemspec before releasing
|
11
|
+
# your gem to rubygems.org.
|
12
|
+
|
13
|
+
# To use a debugger
|
14
|
+
# gem 'byebug', group: [:development, :test]
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2016 Tom Scott
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
# Titleist
|
2
|
+
|
3
|
+
[](https://travis-ci.org/tubbo/titleist)
|
4
|
+
[](https://codeclimate.com/github/tubbo/titleist)
|
5
|
+
[](https://codeclimate.com/github/tubbo/titleist/coverage)
|
6
|
+
[](https://codeclimate.com/github/tubbo/titleist)
|
7
|
+
[](https://codeclimate.com/github/tubbo/titleist)
|
8
|
+
|
9
|
+
A powerful title helper for [Rails][] apps that uses/abuses [i18n][] and allows
|
10
|
+
for maximum override potential.
|
11
|
+
|
12
|
+
## Usage
|
13
|
+
|
14
|
+
Run the generator to get an example locale file and titles appearing in
|
15
|
+
your `<title>` tag.
|
16
|
+
|
17
|
+
```bash
|
18
|
+
rails generate titleist
|
19
|
+
```
|
20
|
+
|
21
|
+
Edit your **config/locales/titleist.en.yml** file to add your own titles and format:
|
22
|
+
|
23
|
+
```yaml
|
24
|
+
en:
|
25
|
+
titles:
|
26
|
+
application: My Application
|
27
|
+
format: '%{page} | %{app}'
|
28
|
+
posts:
|
29
|
+
index: View All Posts
|
30
|
+
show: View Post
|
31
|
+
```
|
32
|
+
|
33
|
+
You can also use our fancy title helpers to generate your own titles.
|
34
|
+
|
35
|
+
For the full monty:
|
36
|
+
|
37
|
+
```erb
|
38
|
+
<title><%= title %></title>
|
39
|
+
```
|
40
|
+
|
41
|
+
Page titles only:
|
42
|
+
|
43
|
+
```erb
|
44
|
+
<h1><%= page_title %></h1>
|
45
|
+
```
|
46
|
+
|
47
|
+
Or the app title only:
|
48
|
+
|
49
|
+
```erb
|
50
|
+
<p>Copyright © 2015 <%= app_title %></p>
|
51
|
+
```
|
52
|
+
|
53
|
+
## Installation
|
54
|
+
|
55
|
+
Add this line to your application's Gemfile:
|
56
|
+
|
57
|
+
```ruby
|
58
|
+
gem 'titleist'
|
59
|
+
```
|
60
|
+
|
61
|
+
And then execute:
|
62
|
+
|
63
|
+
```bash
|
64
|
+
$ bundle
|
65
|
+
```
|
66
|
+
|
67
|
+
Or install it yourself as:
|
68
|
+
```bash
|
69
|
+
$ gem install titleist
|
70
|
+
```
|
71
|
+
|
72
|
+
## Contributing
|
73
|
+
|
74
|
+
Please include tests and submit changes in a pull request. Read our
|
75
|
+
[Code of Conduct][] to find more information on expected behavior and
|
76
|
+
how to resolve issues. All changes to the codebase are verified using
|
77
|
+
the [Travis CI][] build, and a failing build cannot be merged to
|
78
|
+
'master'. In addition, Travis is responsible for building and pushing
|
79
|
+
new gem versions to [RubyGems][] when a new tag is pushed to Github.
|
80
|
+
This library follows [Semantic Versioning][] to communicate the level of
|
81
|
+
change to end users.
|
82
|
+
|
83
|
+
## License
|
84
|
+
|
85
|
+
The gem is available as open source under the terms of the [MIT License][].
|
86
|
+
|
87
|
+
[Rails]: http://rubyonrails.org
|
88
|
+
[i18n]: http://guides.rubyonrails.org/i18n.html
|
89
|
+
[Code of Conduct]: CODE_OF_CONDUCT.md
|
90
|
+
[Travis CI]: http://travis-ci.org
|
91
|
+
[RubyGems]: http://rubygems.org
|
92
|
+
[Semantic Versioning]: http://semver.org
|
93
|
+
[MIT License]: MIT-LICENSE
|
data/Rakefile
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'bundler/setup'
|
2
|
+
require 'yard'
|
3
|
+
require 'rspec/core/rake_task'
|
4
|
+
require 'rubocop/rake_task'
|
5
|
+
require 'travis/release'
|
6
|
+
|
7
|
+
APP_RAKEFILE = File.expand_path('../spec/dummy/Rakefile', __FILE__)
|
8
|
+
|
9
|
+
load 'rails/tasks/engine.rake'
|
10
|
+
load 'rails/tasks/statistics.rake'
|
11
|
+
|
12
|
+
desc 'Generate documentation'
|
13
|
+
YARD::Rake::YardocTask.new :doc
|
14
|
+
|
15
|
+
desc 'Run all tests'
|
16
|
+
RSpec::Core::RakeTask.new :test
|
17
|
+
|
18
|
+
desc 'Run lint checks'
|
19
|
+
RuboCop::RakeTask.new :lint
|
20
|
+
|
21
|
+
# Release automatically with tag pushes to GitHub via Travis CI on
|
22
|
+
# to RubyGems.org
|
23
|
+
Travis::Release::Task.new
|
24
|
+
|
25
|
+
Bundler::GemHelper.install_tasks
|
26
|
+
|
27
|
+
task default: %i(test build)
|
File without changes
|
data/app/helpers/.keep
ADDED
File without changes
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# Helper methods included into +ActionView+ for rendering the current
|
2
|
+
# page and application title.
|
3
|
+
module TitleistHelper
|
4
|
+
# Full +<title>+ tag renderer that uses the current page title and
|
5
|
+
# wraps it in the proper HTML element.
|
6
|
+
#
|
7
|
+
# @return [ActiveSupport::SafeBuffer]
|
8
|
+
def title_tag(context = {})
|
9
|
+
content_tag :title, title(context).to_s.html_safe
|
10
|
+
end
|
11
|
+
|
12
|
+
# Generate the full page title for this request. When output into the
|
13
|
+
# view, the entire title is shown. You may also call +title.page+ or
|
14
|
+
# +title.app+ to view individual pieces of the title.
|
15
|
+
#
|
16
|
+
# @return [Titleist::Title]
|
17
|
+
def title(context = {})
|
18
|
+
@title ||= Titleist::Title.new(
|
19
|
+
controller: controller.controller_name,
|
20
|
+
action: controller.action_name,
|
21
|
+
context: context
|
22
|
+
)
|
23
|
+
end
|
24
|
+
|
25
|
+
# Override the current page title.
|
26
|
+
#
|
27
|
+
# @param [String] new_title
|
28
|
+
# @return [String]
|
29
|
+
def title=(new_title)
|
30
|
+
title.page = new_title
|
31
|
+
end
|
32
|
+
|
33
|
+
# Shorthand for calling +title.app+ in the view.
|
34
|
+
#
|
35
|
+
# @return [String] i18n-configured global application title.
|
36
|
+
def app_title
|
37
|
+
title.app
|
38
|
+
end
|
39
|
+
|
40
|
+
# Shorthand for calling +title.page+ in the view.
|
41
|
+
#
|
42
|
+
# @return [String] i18n-configured title for the current page.
|
43
|
+
def page_title
|
44
|
+
title.page
|
45
|
+
end
|
46
|
+
end
|
data/app/mailers/.keep
ADDED
File without changes
|
data/app/models/.keep
ADDED
File without changes
|
data/app/views/.keep
ADDED
File without changes
|
data/bin/rails
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# This command will automatically be run when you run "rails" with Rails 4 gems installed from the root of your application.
|
3
|
+
|
4
|
+
ENGINE_ROOT = File.expand_path('../..', __FILE__)
|
5
|
+
ENGINE_PATH = File.expand_path('../../lib/titleist/engine', __FILE__)
|
6
|
+
|
7
|
+
# Set up gems listed in the Gemfile.
|
8
|
+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
|
9
|
+
require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
|
10
|
+
|
11
|
+
require 'rails/all'
|
12
|
+
require 'rails/engine/commands'
|
data/bin/rake
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
#
|
4
|
+
# This file was generated by Bundler.
|
5
|
+
#
|
6
|
+
# The application 'rake' is installed as part of a gem, and
|
7
|
+
# this file is here to facilitate running it.
|
8
|
+
#
|
9
|
+
|
10
|
+
require 'pathname'
|
11
|
+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile',
|
12
|
+
Pathname.new(__FILE__).realpath)
|
13
|
+
|
14
|
+
require 'rubygems'
|
15
|
+
require 'bundler/setup'
|
16
|
+
|
17
|
+
load Gem.bin_path('rake', 'rake')
|
data/bin/rspec
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
#
|
4
|
+
# This file was generated by Bundler.
|
5
|
+
#
|
6
|
+
# The application 'rspec' is installed as part of a gem, and
|
7
|
+
# this file is here to facilitate running it.
|
8
|
+
#
|
9
|
+
|
10
|
+
require 'pathname'
|
11
|
+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile',
|
12
|
+
Pathname.new(__FILE__).realpath)
|
13
|
+
|
14
|
+
require 'rubygems'
|
15
|
+
require 'bundler/setup'
|
16
|
+
|
17
|
+
load Gem.bin_path('rspec-core', 'rspec')
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# Generate initial files for the gem to work.
|
2
|
+
class TitleistGenerator < Rails::Generators::Base
|
3
|
+
source_root File.expand_path('../templates', __FILE__)
|
4
|
+
|
5
|
+
def copy_locale
|
6
|
+
template 'locale.yml.erb', 'config/locales/titleist.en.yml'
|
7
|
+
end
|
8
|
+
|
9
|
+
def update_default_application_layout
|
10
|
+
gsub_file(
|
11
|
+
'app/views/layouts/application.html.erb',
|
12
|
+
%r{\s\s\s\s<title>(.*)</title>},
|
13
|
+
' <%= title_tag %>'
|
14
|
+
)
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,8 @@
|
|
1
|
+
module Titleist
|
2
|
+
# Extensions into the Rails framework, including the
|
3
|
+
# +Rails.configuration.titleist+ config which can optionally configure
|
4
|
+
# the global application title.
|
5
|
+
class Engine < Rails::Engine
|
6
|
+
config.titleist = ActiveSupport::OrderedOptions.new
|
7
|
+
end
|
8
|
+
end
|
@@ -0,0 +1,138 @@
|
|
1
|
+
module Titleist
|
2
|
+
# Object that turns passed-in scope details into a String of title
|
3
|
+
# text derived from the +I18n+ locale configuration.
|
4
|
+
class Title
|
5
|
+
# Top-level scope in the i18n locale for all title configuration.
|
6
|
+
ROOT_SCOPE = :titles
|
7
|
+
|
8
|
+
# @!attribute controller [r]
|
9
|
+
# @return [String] Controller name of the current request.
|
10
|
+
attr_reader :controller
|
11
|
+
|
12
|
+
# @!attribute action [r]
|
13
|
+
# @return [String] Action name of the current request.
|
14
|
+
attr_reader :action
|
15
|
+
|
16
|
+
# @!attribute context [r]
|
17
|
+
# @return [Hash] Passed-in context from the helper method.
|
18
|
+
attr_reader :context
|
19
|
+
|
20
|
+
# @param controller [String] Current request controller name.
|
21
|
+
# @param action [String] Current request action name.
|
22
|
+
# @param context [Hash] Optional params passed in from the helper.
|
23
|
+
def initialize(controller: '', action: '', context: {})
|
24
|
+
@controller = controller
|
25
|
+
@action = action
|
26
|
+
@context = context
|
27
|
+
end
|
28
|
+
|
29
|
+
# Global application title.
|
30
|
+
#
|
31
|
+
# @return [String]
|
32
|
+
def app
|
33
|
+
I18n.t :application, context.merge(
|
34
|
+
scope: ROOT_SCOPE,
|
35
|
+
default: default_app_title
|
36
|
+
)
|
37
|
+
end
|
38
|
+
|
39
|
+
# Page title from given scope.
|
40
|
+
#
|
41
|
+
# @return [String]
|
42
|
+
def page
|
43
|
+
@page ||= I18n.t action.to_sym, context.merge(
|
44
|
+
scope: scope,
|
45
|
+
default: default_page_title
|
46
|
+
)
|
47
|
+
end
|
48
|
+
|
49
|
+
# @!attribute page [w]
|
50
|
+
# Override the given scope and set a new page title.
|
51
|
+
# @return [String]
|
52
|
+
attr_writer :page
|
53
|
+
|
54
|
+
# Format this title as a +String+.
|
55
|
+
#
|
56
|
+
# @return [String]
|
57
|
+
def to_s
|
58
|
+
return app if root?
|
59
|
+
I18n.t :format, to_h
|
60
|
+
end
|
61
|
+
|
62
|
+
# Format this title as a +Hash+ of attributes.
|
63
|
+
#
|
64
|
+
# @return [Hash]
|
65
|
+
def to_h
|
66
|
+
{
|
67
|
+
scope: ROOT_SCOPE,
|
68
|
+
app: app,
|
69
|
+
page: page
|
70
|
+
}
|
71
|
+
end
|
72
|
+
|
73
|
+
# TODO: Necessary?
|
74
|
+
def root?
|
75
|
+
false
|
76
|
+
end
|
77
|
+
|
78
|
+
private
|
79
|
+
|
80
|
+
# Use the default configured app title in +Rails.configuration+ or
|
81
|
+
# the derived app title if one is not specified.
|
82
|
+
#
|
83
|
+
# @private
|
84
|
+
# @return [String] Default application title from module or config.
|
85
|
+
def default_app_title
|
86
|
+
Rails.configuration.titleist.app_title || derived_app_title
|
87
|
+
end
|
88
|
+
|
89
|
+
# Derive app title by titleizing the application module name if one
|
90
|
+
# is not configured.
|
91
|
+
#
|
92
|
+
# @private
|
93
|
+
# @return [String] Default app title guessed from module name.
|
94
|
+
def derived_app_title
|
95
|
+
Rails.application.class.name.deconstantize.titleize
|
96
|
+
end
|
97
|
+
|
98
|
+
# Default title of the current page, if one cannot be found.
|
99
|
+
#
|
100
|
+
# @private
|
101
|
+
# @return [String] Action title combined with resource title.
|
102
|
+
def default_page_title
|
103
|
+
return controller.titleize if action == 'index'
|
104
|
+
[action_title, resource_title].join(' ')
|
105
|
+
end
|
106
|
+
|
107
|
+
# Default title verb for the current action.
|
108
|
+
#
|
109
|
+
# @private
|
110
|
+
# @return [String] "View", "Delete", or the titleized +action+.
|
111
|
+
def action_title
|
112
|
+
case action
|
113
|
+
when 'show'
|
114
|
+
'View'
|
115
|
+
when 'destroy'
|
116
|
+
'Delete'
|
117
|
+
else
|
118
|
+
action.titleize
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
# Default title of the resource the controller is operating on.
|
123
|
+
#
|
124
|
+
# @private
|
125
|
+
# @return [String] Singularized controller name.
|
126
|
+
def resource_title
|
127
|
+
controller.singularize.titleize
|
128
|
+
end
|
129
|
+
|
130
|
+
# Scope for +I18n+ derived from the controller name and root.
|
131
|
+
#
|
132
|
+
# @private
|
133
|
+
# @return [Array] Derived i18n scope.
|
134
|
+
def scope
|
135
|
+
@scope ||= [ROOT_SCOPE, controller]
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
data/lib/titleist.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'active_support/all'
|
2
|
+
|
3
|
+
require 'titleist/version'
|
4
|
+
require 'titleist/engine'
|
5
|
+
|
6
|
+
# Serves standardized titles throughout your +Rails+ application,
|
7
|
+
# leveraging +I18n+ locale configuration and view helpers to make
|
8
|
+
# defining and presenting titles in any way you see fit as simple as
|
9
|
+
# possible.
|
10
|
+
#
|
11
|
+
# @example Setting a title
|
12
|
+
# en:
|
13
|
+
# titles:
|
14
|
+
# application: My App
|
15
|
+
# format: '%{app} | %{page}'
|
16
|
+
# pages:
|
17
|
+
# index: Home
|
18
|
+
# posts:
|
19
|
+
# index: All Posts
|
20
|
+
# show: "Post %{name}"
|
21
|
+
# new: New Post
|
22
|
+
#
|
23
|
+
# @example Rendering the current title
|
24
|
+
# = title_tag
|
25
|
+
module Titleist
|
26
|
+
extend ActiveSupport::Autoload
|
27
|
+
|
28
|
+
autoload :Title
|
29
|
+
end
|
data/titleist.gemspec
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
$LOAD_PATH.push File.expand_path('../lib', __FILE__)
|
2
|
+
|
3
|
+
# Maintain your gem's version:
|
4
|
+
require 'titleist/version'
|
5
|
+
|
6
|
+
# Describe your gem and declare its dependencies:
|
7
|
+
Gem::Specification.new do |s|
|
8
|
+
s.name = 'titleist'
|
9
|
+
s.version = Titleist::VERSION
|
10
|
+
s.authors = ['Tom Scott']
|
11
|
+
s.email = ['tscott@weblinc.com']
|
12
|
+
s.homepage = 'https://github.com/tubbo/titleist.git'
|
13
|
+
s.summary = 'Powerful, i18n-abusing title helper for Rails apps'
|
14
|
+
s.description = "#{s.description}. Improve your swing."
|
15
|
+
s.license = 'MIT'
|
16
|
+
s.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(spec)/}) }
|
17
|
+
|
18
|
+
s.add_dependency 'rails'
|
19
|
+
|
20
|
+
s.add_development_dependency 'pg'
|
21
|
+
s.add_development_dependency 'rspec-rails'
|
22
|
+
s.add_development_dependency 'capybara'
|
23
|
+
s.add_development_dependency 'rubocop'
|
24
|
+
s.add_development_dependency 'yard'
|
25
|
+
s.add_development_dependency 'codeclimate-test-reporter'
|
26
|
+
s.add_development_dependency 'generator_spec'
|
27
|
+
s.add_development_dependency 'travis-release'
|
28
|
+
end
|
metadata
ADDED
@@ -0,0 +1,199 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: titleist
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tom Scott
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-07-23 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: pg
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec-rails
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: capybara
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rubocop
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: yard
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: codeclimate-test-reporter
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: generator_spec
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: travis-release
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
description: ". Improve your swing."
|
140
|
+
email:
|
141
|
+
- tscott@weblinc.com
|
142
|
+
executables: []
|
143
|
+
extensions: []
|
144
|
+
extra_rdoc_files: []
|
145
|
+
files:
|
146
|
+
- ".codeclimate.yml"
|
147
|
+
- ".gitignore"
|
148
|
+
- ".rspec"
|
149
|
+
- ".rubocop.yml"
|
150
|
+
- ".ruby-version"
|
151
|
+
- ".travis.yml"
|
152
|
+
- Gemfile
|
153
|
+
- MIT-LICENSE
|
154
|
+
- README.md
|
155
|
+
- Rakefile
|
156
|
+
- app/controllers/.keep
|
157
|
+
- app/helpers/.keep
|
158
|
+
- app/helpers/titleist_helper.rb
|
159
|
+
- app/mailers/.keep
|
160
|
+
- app/models/.keep
|
161
|
+
- app/views/.keep
|
162
|
+
- bin/rails
|
163
|
+
- bin/rake
|
164
|
+
- bin/rspec
|
165
|
+
- lib/generators/titleist/USAGE
|
166
|
+
- lib/generators/titleist/templates/locale.yml.erb
|
167
|
+
- lib/generators/titleist/titleist_generator.rb
|
168
|
+
- lib/tasks/titleist_tasks.rake
|
169
|
+
- lib/titleist.rb
|
170
|
+
- lib/titleist/engine.rb
|
171
|
+
- lib/titleist/title.rb
|
172
|
+
- lib/titleist/version.rb
|
173
|
+
- titleist.gemspec
|
174
|
+
homepage: https://github.com/tubbo/titleist.git
|
175
|
+
licenses:
|
176
|
+
- MIT
|
177
|
+
metadata: {}
|
178
|
+
post_install_message:
|
179
|
+
rdoc_options: []
|
180
|
+
require_paths:
|
181
|
+
- lib
|
182
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
183
|
+
requirements:
|
184
|
+
- - ">="
|
185
|
+
- !ruby/object:Gem::Version
|
186
|
+
version: '0'
|
187
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
188
|
+
requirements:
|
189
|
+
- - ">="
|
190
|
+
- !ruby/object:Gem::Version
|
191
|
+
version: '0'
|
192
|
+
requirements: []
|
193
|
+
rubyforge_project:
|
194
|
+
rubygems_version: 2.5.1
|
195
|
+
signing_key:
|
196
|
+
specification_version: 4
|
197
|
+
summary: Powerful, i18n-abusing title helper for Rails apps
|
198
|
+
test_files: []
|
199
|
+
has_rdoc:
|