page_title 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.rspec +2 -0
- data/.travis.yml +3 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +77 -0
- data/Rakefile +6 -0
- data/lib/page_title.rb +48 -0
- data/lib/page_title/engine.rb +8 -0
- data/lib/page_title/helpers.rb +8 -0
- data/lib/page_title/version.rb +3 -0
- data/page_title.gemspec +25 -0
- data/spec/controllers/application_controller_spec.rb +85 -0
- data/spec/dummy/README.rdoc +28 -0
- data/spec/dummy/Rakefile +6 -0
- data/spec/dummy/app/assets/images/.keep +0 -0
- data/spec/dummy/app/assets/javascripts/application.js +13 -0
- data/spec/dummy/app/assets/stylesheets/application.css +13 -0
- data/spec/dummy/app/controllers/application_controller.rb +5 -0
- data/spec/dummy/app/controllers/concerns/.keep +0 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/mailers/.keep +0 -0
- data/spec/dummy/app/models/.keep +0 -0
- data/spec/dummy/app/models/concerns/.keep +0 -0
- data/spec/dummy/app/views/application/index.html.erb +0 -0
- data/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/bin/bundle +3 -0
- data/spec/dummy/bin/rails +4 -0
- data/spec/dummy/bin/rake +4 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/config/application.rb +13 -0
- data/spec/dummy/config/boot.rb +5 -0
- data/spec/dummy/config/database.yml +25 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +29 -0
- data/spec/dummy/config/environments/production.rb +80 -0
- data/spec/dummy/config/environments/test.rb +31 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/dummy/config/initializers/inflections.rb +16 -0
- data/spec/dummy/config/initializers/mime_types.rb +5 -0
- data/spec/dummy/config/initializers/secret_token.rb +12 -0
- data/spec/dummy/config/initializers/session_store.rb +3 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +23 -0
- data/spec/dummy/config/routes.rb +56 -0
- data/spec/dummy/lib/assets/.keep +0 -0
- data/spec/dummy/log/.keep +0 -0
- data/spec/dummy/log/test.log +81 -0
- data/spec/dummy/public/404.html +58 -0
- data/spec/dummy/public/422.html +58 -0
- data/spec/dummy/public/500.html +57 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/page_title_spec.rb +32 -0
- data/spec/spec_helper.rb +16 -0
- data/spec/support/helpers.rb +35 -0
- metadata +228 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 1b31f68b4a317190bae0c5ddd9f12d6952bbcfdf
|
4
|
+
data.tar.gz: 6abe236198afc5ec21516fe2aaed2b146e956d78
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 607f015ff61a8f3bae0fa9b77b8e022728de7fdd5fa2e4cf39e47eea277df3b00d5c909dc899bb2e28cb61860152e0d6e1e70e0c2b086075c0d27fc0d8934ec8
|
7
|
+
data.tar.gz: 0d85dc430bd5016a616cbcfd0a9d90288e6561da9a08154f8006f497d286e1195ded1ef54dc2040bc90bb631d6e73bbee95b1c4152bbe4b611375186a299a92b
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Nando Vieira
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
# page_title
|
2
|
+
|
3
|
+
Set the page title on Rails apps.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem "page_title"
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install page_title
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
You can use this on your layout file to display the page title:
|
22
|
+
|
23
|
+
```erb
|
24
|
+
<%= page_title %>
|
25
|
+
```
|
26
|
+
|
27
|
+
The page title will be inferred from the controller and action names. For an action `SiteController#index` you'll the following translate scope:
|
28
|
+
|
29
|
+
```yaml
|
30
|
+
en:
|
31
|
+
titles:
|
32
|
+
base: "%{title} • MyCompany"
|
33
|
+
site:
|
34
|
+
index: "Welcome to our site"
|
35
|
+
```
|
36
|
+
|
37
|
+
The `titles.base` scope is required and will be used to set a general title information, like your company's name.
|
38
|
+
|
39
|
+
You can also set the page title for namespaced controllers. For an action `Admin::Site#index` you'll need the following translate scope:
|
40
|
+
|
41
|
+
```yaml
|
42
|
+
en:
|
43
|
+
titles:
|
44
|
+
base: "%{title} • MyCompany"
|
45
|
+
admin:
|
46
|
+
site:
|
47
|
+
index: "Welcome to our site"
|
48
|
+
```
|
49
|
+
|
50
|
+
Sometimes you need to render some dynamic value. In this case, you can use the I18n placeholders.
|
51
|
+
|
52
|
+
```yaml
|
53
|
+
en:
|
54
|
+
titles:
|
55
|
+
base: "%{title} • MyCompany"
|
56
|
+
workshops:
|
57
|
+
show: "%{name}"
|
58
|
+
```
|
59
|
+
|
60
|
+
You can set dynamic values using the `PageSite::Base#[]=`.
|
61
|
+
|
62
|
+
```ruby
|
63
|
+
class WorkshopsController < ApplicationController
|
64
|
+
def show
|
65
|
+
@workshop = Workshop.find_by_permalink!(params[:permalink])
|
66
|
+
page_title[:name] = @workshop.name
|
67
|
+
end
|
68
|
+
end
|
69
|
+
```
|
70
|
+
|
71
|
+
## Contributing
|
72
|
+
|
73
|
+
1. Fork it
|
74
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
75
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
76
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
77
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/lib/page_title.rb
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
require "i18n"
|
2
|
+
require "forwardable"
|
3
|
+
require "page_title/engine"
|
4
|
+
require "page_title/helpers"
|
5
|
+
require "page_title/version"
|
6
|
+
|
7
|
+
module PageTitle
|
8
|
+
class Base
|
9
|
+
# Set the controller instance. It must implement
|
10
|
+
# the methods controller_name and action_name.
|
11
|
+
attr_reader :controller
|
12
|
+
|
13
|
+
# Set the main translation options.
|
14
|
+
attr_reader :options
|
15
|
+
|
16
|
+
extend Forwardable
|
17
|
+
def_delegators :options, :[], :[]=, :merge!
|
18
|
+
|
19
|
+
def initialize(controller)
|
20
|
+
@controller = controller
|
21
|
+
@options = {}
|
22
|
+
end
|
23
|
+
|
24
|
+
def to_s
|
25
|
+
base_translation
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
def title_translation
|
30
|
+
I18n.t(
|
31
|
+
title_scope,
|
32
|
+
options.merge(scope: "titles")
|
33
|
+
)
|
34
|
+
end
|
35
|
+
|
36
|
+
def base_translation
|
37
|
+
I18n.t("titles.base", title: title_translation)
|
38
|
+
end
|
39
|
+
|
40
|
+
def normalized_controller_name
|
41
|
+
controller.controller_name.gsub(%r[/], ".")
|
42
|
+
end
|
43
|
+
|
44
|
+
def title_scope
|
45
|
+
[normalized_controller_name, controller.action_name].join(".")
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
data/page_title.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require "./lib/page_title/version"
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = "page_title"
|
5
|
+
spec.version = PageTitle::VERSION
|
6
|
+
spec.authors = ["Nando Vieira"]
|
7
|
+
spec.email = ["fnando.vieira@gmail.com"]
|
8
|
+
spec.description = "Set the page title on Rails apps"
|
9
|
+
spec.summary = spec.description
|
10
|
+
spec.homepage = "http://github.com/fnando/page_title"
|
11
|
+
spec.license = "MIT"
|
12
|
+
|
13
|
+
spec.files = `git ls-files`.split($/)
|
14
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
15
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
16
|
+
spec.require_paths = ["lib"]
|
17
|
+
|
18
|
+
spec.add_dependency "rails"
|
19
|
+
|
20
|
+
spec.add_development_dependency "bundler"
|
21
|
+
spec.add_development_dependency "rake"
|
22
|
+
spec.add_development_dependency "rspec"
|
23
|
+
spec.add_development_dependency "rspec-rails"
|
24
|
+
spec.add_development_dependency "pry-meta"
|
25
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe ApplicationController do
|
4
|
+
context "simple controller name" do
|
5
|
+
set_translations "titles.base" => "%{title} - SITE",
|
6
|
+
"titles.site.index" => "TITLE"
|
7
|
+
|
8
|
+
controller do
|
9
|
+
def controller_name
|
10
|
+
"site"
|
11
|
+
end
|
12
|
+
|
13
|
+
def index
|
14
|
+
render text: page_title
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
it do
|
19
|
+
get :index
|
20
|
+
expect(response.body).to eql("TITLE - SITE")
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
context "namespaced controller name" do
|
25
|
+
set_translations "titles.base" => "%{title} - SITE",
|
26
|
+
"titles.admin.site.index" => "TITLE"
|
27
|
+
|
28
|
+
controller do
|
29
|
+
def controller_name
|
30
|
+
"admin/site"
|
31
|
+
end
|
32
|
+
|
33
|
+
def index
|
34
|
+
render text: page_title
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
it do
|
39
|
+
get :index
|
40
|
+
expect(response.body).to eql("TITLE - SITE")
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
context "using placeholders" do
|
45
|
+
set_translations "titles.base" => "%{title} - SITE",
|
46
|
+
"titles.site.index" => "%{name}"
|
47
|
+
|
48
|
+
controller do
|
49
|
+
def controller_name
|
50
|
+
"site"
|
51
|
+
end
|
52
|
+
|
53
|
+
def index
|
54
|
+
page_title[:name] = "NAME"
|
55
|
+
render text: page_title
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
it do
|
60
|
+
get :index
|
61
|
+
expect(response.body).to eql("NAME - SITE")
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
context "rendering template" do
|
66
|
+
render_views
|
67
|
+
|
68
|
+
set_translations "titles.base" => "%{title} - SITE",
|
69
|
+
"titles.site.index" => "TITLE"
|
70
|
+
|
71
|
+
controller do
|
72
|
+
def controller_name
|
73
|
+
"site"
|
74
|
+
end
|
75
|
+
|
76
|
+
def index
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
it do
|
81
|
+
get :index
|
82
|
+
expect(response.body).to match(%r[<title>TITLE - SITE</title>])
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
== README
|
2
|
+
|
3
|
+
This README would normally document whatever steps are necessary to get the
|
4
|
+
application up and running.
|
5
|
+
|
6
|
+
Things you may want to cover:
|
7
|
+
|
8
|
+
* Ruby version
|
9
|
+
|
10
|
+
* System dependencies
|
11
|
+
|
12
|
+
* Configuration
|
13
|
+
|
14
|
+
* Database creation
|
15
|
+
|
16
|
+
* Database initialization
|
17
|
+
|
18
|
+
* How to run the test suite
|
19
|
+
|
20
|
+
* Services (job queues, cache servers, search engines, etc.)
|
21
|
+
|
22
|
+
* Deployment instructions
|
23
|
+
|
24
|
+
* ...
|
25
|
+
|
26
|
+
|
27
|
+
Please feel free to use a different markup language if you do not plan to run
|
28
|
+
<tt>rake doc:app</tt>.
|
data/spec/dummy/Rakefile
ADDED
File without changes
|
@@ -0,0 +1,13 @@
|
|
1
|
+
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
2
|
+
// listed below.
|
3
|
+
//
|
4
|
+
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
5
|
+
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
|
6
|
+
//
|
7
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
8
|
+
// compiled file.
|
9
|
+
//
|
10
|
+
// Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
|
11
|
+
// about supported directives.
|
12
|
+
//
|
13
|
+
//= require_tree .
|
@@ -0,0 +1,13 @@
|
|
1
|
+
/*
|
2
|
+
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
3
|
+
* listed below.
|
4
|
+
*
|
5
|
+
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
6
|
+
* or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
|
7
|
+
*
|
8
|
+
* You're free to add application-wide styles to this file and they'll appear at the top of the
|
9
|
+
* compiled file, but it's generally better to create a new file per style scope.
|
10
|
+
*
|
11
|
+
*= require_self
|
12
|
+
*= require_tree .
|
13
|
+
*/
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,14 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title><%= page_title %></title>
|
5
|
+
<%= stylesheet_link_tag "application", media: "all", "data-turbolinks-track" => true %>
|
6
|
+
<%= javascript_include_tag "application", "data-turbolinks-track" => true %>
|
7
|
+
<%= csrf_meta_tags %>
|
8
|
+
</head>
|
9
|
+
<body>
|
10
|
+
|
11
|
+
<%= yield %>
|
12
|
+
|
13
|
+
</body>
|
14
|
+
</html>
|