implicit_page_titles 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/MIT-LICENSE +20 -0
- data/Rakefile +34 -0
- data/lib/implicit_page_titles/page_title_helper.rb +51 -0
- data/lib/implicit_page_titles/railtie.rb +9 -0
- data/lib/implicit_page_titles/version.rb +3 -0
- data/lib/implicit_page_titles.rb +3 -0
- metadata +120 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 5a8f7384eecad67e17ba4c7a9c68896b73f468e9
|
4
|
+
data.tar.gz: 2dfec6cf77d947bc1377de6787d8b050accd3ce6
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 421159a354d64f1e7d66689fd4810f7d1aa5f39395be462763ab0f4d7d4da6deccb541e805455424c3ff3530861e909b22e78542ce6128cc17761aee6ba093ec
|
7
|
+
data.tar.gz: ba4d42a4237c8f632f5bab5b12ebdc977f5e18b174223e642ec0dafc1f086cc677e4dba20b46471bab990a03cb7b0bd9dd591dd002da004338384680fe7dd34d
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2015 neilang
|
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/Rakefile
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
begin
|
2
|
+
require "bundler/setup"
|
3
|
+
rescue LoadError
|
4
|
+
puts "You must `gem install bundler` and `bundle install` to run rake tasks"
|
5
|
+
end
|
6
|
+
|
7
|
+
require "rdoc/task"
|
8
|
+
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
+
rdoc.rdoc_dir = "rdoc"
|
11
|
+
rdoc.title = "ImplicitPageTitles"
|
12
|
+
rdoc.options << "--line-numbers"
|
13
|
+
rdoc.rdoc_files.include("README.rdoc")
|
14
|
+
rdoc.rdoc_files.include("lib/**/*.rb")
|
15
|
+
end
|
16
|
+
|
17
|
+
Bundler::GemHelper.install_tasks
|
18
|
+
|
19
|
+
require "rspec/core/rake_task"
|
20
|
+
RSpec::Core::RakeTask.new(:spec)
|
21
|
+
|
22
|
+
task test: :spec
|
23
|
+
|
24
|
+
begin
|
25
|
+
require "rubocop/rake_task"
|
26
|
+
RuboCop::RakeTask.new
|
27
|
+
rescue LoadError
|
28
|
+
desc "Run RuboCop"
|
29
|
+
task :rubocop do
|
30
|
+
$stderr.puts "Rubocop is disabled"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
task default: [:spec, :rubocop]
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module ImplicitPageTitles
|
2
|
+
module PageTitleHelper
|
3
|
+
def page_title(page_title = nil)
|
4
|
+
@page_title = page_title unless page_title.nil?
|
5
|
+
@page_title || restful_page_title || path_to_page_title || default_page_title
|
6
|
+
end
|
7
|
+
|
8
|
+
def restful_page_title
|
9
|
+
case action_name
|
10
|
+
when "show"
|
11
|
+
_implicit_variable_title
|
12
|
+
when "edit"
|
13
|
+
"Edit #{_implicit_variable_title}"
|
14
|
+
when "new"
|
15
|
+
path = _path_without_last_segment(_current_path)
|
16
|
+
title = path_to_page_title(path).to_s.singularize
|
17
|
+
"New #{title.downcase}"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def path_to_page_title(path = _current_path)
|
22
|
+
title = path.to_s.split("/").last
|
23
|
+
return nil if title.nil?
|
24
|
+
|
25
|
+
title = title.gsub(/[-_]/, " ")
|
26
|
+
title = title.gsub(/\s+/, " ").strip
|
27
|
+
title.humanize
|
28
|
+
end
|
29
|
+
|
30
|
+
def default_page_title
|
31
|
+
Rails.application.class.to_s.split("::").first.underscore.humanize
|
32
|
+
end
|
33
|
+
|
34
|
+
def _current_path
|
35
|
+
request.try :path
|
36
|
+
end
|
37
|
+
|
38
|
+
def _path_without_last_segment(path)
|
39
|
+
path = path.to_s
|
40
|
+
index = path.rindex("/")
|
41
|
+
index ? path[0, index] : nil
|
42
|
+
end
|
43
|
+
|
44
|
+
def _implicit_variable_title
|
45
|
+
return unless controller && controller_name
|
46
|
+
var_name = "@" + controller_name.singularize
|
47
|
+
variable = controller.instance_variable_get(var_name)
|
48
|
+
variable.try(:title) || variable.try(:name)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
metadata
ADDED
@@ -0,0 +1,120 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: implicit_page_titles
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- neilang
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-04-11 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: '4.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '4.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: sqlite3
|
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: 3.2.1
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 3.2.1
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rubocop
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.30.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.30.0
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: capybara
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 2.4.4
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 2.4.4
|
83
|
+
description: Smart page title defaults for your Rails app.
|
84
|
+
email:
|
85
|
+
- neilang@gmail.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- MIT-LICENSE
|
91
|
+
- Rakefile
|
92
|
+
- lib/implicit_page_titles.rb
|
93
|
+
- lib/implicit_page_titles/page_title_helper.rb
|
94
|
+
- lib/implicit_page_titles/railtie.rb
|
95
|
+
- lib/implicit_page_titles/version.rb
|
96
|
+
homepage: https://github.com/neilang/implicit_page_titles
|
97
|
+
licenses:
|
98
|
+
- MIT
|
99
|
+
metadata: {}
|
100
|
+
post_install_message:
|
101
|
+
rdoc_options: []
|
102
|
+
require_paths:
|
103
|
+
- lib
|
104
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - ">="
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: '0'
|
109
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
110
|
+
requirements:
|
111
|
+
- - ">="
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
version: '0'
|
114
|
+
requirements: []
|
115
|
+
rubyforge_project:
|
116
|
+
rubygems_version: 2.4.5
|
117
|
+
signing_key:
|
118
|
+
specification_version: 4
|
119
|
+
summary: Smart page title defaults for your Rails app.
|
120
|
+
test_files: []
|