title_helper 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/MIT-LICENSE +20 -0
- data/README.rdoc +20 -0
- data/Rakefile +13 -0
- data/VERSION +1 -0
- data/init.rb +1 -0
- data/lib/title_helper.rb +37 -0
- data/lib/title_helper/railtie.rb +9 -0
- data/rails/init.rb +3 -0
- data/test/title_helper_test.rb +45 -0
- data/title_helper.gemspec +49 -0
- metadata +76 -0
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2008 Jan De Poorter
|
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.rdoc
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
TitleHelper
|
2
|
+
===========
|
3
|
+
|
4
|
+
TitleHelper allows you to keep your <title> attributes synced with your <h1> attributes, which is more SEO friendly. This is 100% done in the view, which is different from some other plugins, who work with a title-method in the controllers.
|
5
|
+
|
6
|
+
Example
|
7
|
+
=======
|
8
|
+
|
9
|
+
This method should be used in your layout and your actions.
|
10
|
+
|
11
|
+
In your action:
|
12
|
+
<%= title "Edit user #{@user.name}" %>
|
13
|
+
# => <h1>Edit user Jan De Poorter</h1>
|
14
|
+
|
15
|
+
In your layout:
|
16
|
+
<head>
|
17
|
+
<title><%= title :site_name => 'Foobar' %></title>
|
18
|
+
# => <title>Edit user Jan De Poorter - Foobar</title>
|
19
|
+
|
20
|
+
Copyright (c) 2008 Jan De Poorter, released under the MIT license
|
data/Rakefile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
begin
|
2
|
+
require 'jeweler'
|
3
|
+
Jeweler::Tasks.new do |gemspec|
|
4
|
+
gemspec.name = "title_helper"
|
5
|
+
gemspec.summary = "TitleHelper allows you to keep your <title> attributes synced with your <h1> attributes, which is more SEO friendly."
|
6
|
+
gemspec.description = "TitleHelper allows you to keep your <title> attributes synced with your <h1> attributes, which is more SEO friendly. This is 100% done in the view, which is different from some other plugins, who work with a title-method in the controllers."
|
7
|
+
gemspec.email = "jan@defv.be"
|
8
|
+
gemspec.homepage = "http://github.com/defv/title_helper"
|
9
|
+
gemspec.authors = ["Jan De Poorter"]
|
10
|
+
end
|
11
|
+
rescue LoadError
|
12
|
+
puts "Jeweler not available. Install it with: gem install jeweler"
|
13
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.4.0
|
data/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'rails/init.rb'
|
data/lib/title_helper.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'title_helper/railtie' if defined?(::Rails::Railtie)
|
2
|
+
|
3
|
+
module DefV
|
4
|
+
module TitleHelper
|
5
|
+
# This method should be used in your layout and your actions.
|
6
|
+
#
|
7
|
+
# In your action:
|
8
|
+
# <%= title "Edit user #{@user.name}" %>
|
9
|
+
# => <h1>Edit user Jan De Poorter</h1>
|
10
|
+
#
|
11
|
+
# In your layout:
|
12
|
+
# <head>
|
13
|
+
# <title><%= title :site_name => 'Foobar' %></title>
|
14
|
+
# ...
|
15
|
+
# => <title>Edit user Jan De Poorter - Foobar</title>
|
16
|
+
#
|
17
|
+
def title arguments, options = {}
|
18
|
+
case arguments
|
19
|
+
when String
|
20
|
+
@title = arguments
|
21
|
+
options[:class] = [options[:class], 'error'].compact.join(' ') if options[:error]
|
22
|
+
|
23
|
+
title = [options[:header], @title, options[:trailer]].compact.join(' ')
|
24
|
+
title = title.html_safe if title.respond_to?(:html_safe)
|
25
|
+
|
26
|
+
return content_tag(:h1, title, options.except(:error, :header, :trailer))
|
27
|
+
when Hash
|
28
|
+
sitename = arguments[:site_name]
|
29
|
+
if @title
|
30
|
+
return "#{strip_tags(@title)} - #{sitename}"
|
31
|
+
else
|
32
|
+
return "#{sitename}"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
data/rails/init.rb
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require File.dirname(__FILE__) + '/../../../../config/boot.rb'
|
3
|
+
require File.dirname(__FILE__) + '/../../../../config/environment.rb'
|
4
|
+
|
5
|
+
|
6
|
+
class TitleHelperTest < Test::Unit::TestCase
|
7
|
+
def setup
|
8
|
+
@helper = ActionView::Base.new
|
9
|
+
end
|
10
|
+
|
11
|
+
# Replace this with your real tests.
|
12
|
+
def test_title_method_with_no_title_set
|
13
|
+
assert_equal "foobar", @helper.title(:site_name => 'foobar')
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_title_method_with_a_title_set
|
17
|
+
assert_equal "<h1>HomePage</h1>", @helper.title("HomePage")
|
18
|
+
assert_equal "HomePage - foobar", @helper.title(:site_name => 'foobar')
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_strip_tags
|
22
|
+
assert_equal "<h1>This is <strong>GREAT</strong></h1>", @helper.title("This is <strong>GREAT</strong>")
|
23
|
+
assert_equal "This is GREAT - foobar", @helper.title(:site_name => 'foobar')
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_error_on_h1
|
27
|
+
assert_equal "<h1 class=\"error\">This is wrong</h1>", @helper.title("This is wrong", :error => true)
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_class_on_h1
|
31
|
+
assert_equal "<h1 class=\"my-class\">Header with class</h1>", @helper.title("Header with class", :class => 'my-class')
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_id_on_h1
|
35
|
+
assert_equal "<h1 id=\"my-id\">Header with id</h1>", @helper.title("Header with id", :id => 'my-id')
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_class_and_id_on_h1
|
39
|
+
assert_equal "<h1 class=\"my-class\" id=\"my-id\">Header with class and id</h1>", @helper.title("Header with class and id", :class => 'my-class', :id => 'my-id')
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_class_and_error_on_h1
|
43
|
+
assert_equal "<h1 class=\"my-class error\">Header with error and class</h1>", @helper.title("Header with error and class", :class => 'my-class', :error => true)
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{title_helper}
|
8
|
+
s.version = "0.4.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Jan De Poorter"]
|
12
|
+
s.date = %q{2010-08-20}
|
13
|
+
s.description = %q{TitleHelper allows you to keep your <title> attributes synced with your <h1> attributes, which is more SEO friendly. This is 100% done in the view, which is different from some other plugins, who work with a title-method in the controllers.}
|
14
|
+
s.email = %q{jan@defv.be}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"README.rdoc"
|
17
|
+
]
|
18
|
+
s.files = [
|
19
|
+
"MIT-LICENSE",
|
20
|
+
"README.rdoc",
|
21
|
+
"Rakefile",
|
22
|
+
"VERSION",
|
23
|
+
"init.rb",
|
24
|
+
"lib/title_helper.rb",
|
25
|
+
"lib/title_helper/railtie.rb",
|
26
|
+
"rails/init.rb",
|
27
|
+
"test/title_helper_test.rb",
|
28
|
+
"title_helper.gemspec"
|
29
|
+
]
|
30
|
+
s.homepage = %q{http://github.com/defv/title_helper}
|
31
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
32
|
+
s.require_paths = ["lib"]
|
33
|
+
s.rubygems_version = %q{1.3.7}
|
34
|
+
s.summary = %q{TitleHelper allows you to keep your <title> attributes synced with your <h1> attributes, which is more SEO friendly.}
|
35
|
+
s.test_files = [
|
36
|
+
"test/title_helper_test.rb"
|
37
|
+
]
|
38
|
+
|
39
|
+
if s.respond_to? :specification_version then
|
40
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
41
|
+
s.specification_version = 3
|
42
|
+
|
43
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
44
|
+
else
|
45
|
+
end
|
46
|
+
else
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
metadata
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: title_helper
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 15
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 4
|
9
|
+
- 0
|
10
|
+
version: 0.4.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Jan De Poorter
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-08-20 00:00:00 +02:00
|
19
|
+
default_executable:
|
20
|
+
dependencies: []
|
21
|
+
|
22
|
+
description: TitleHelper allows you to keep your <title> attributes synced with your <h1> attributes, which is more SEO friendly. This is 100% done in the view, which is different from some other plugins, who work with a title-method in the controllers.
|
23
|
+
email: jan@defv.be
|
24
|
+
executables: []
|
25
|
+
|
26
|
+
extensions: []
|
27
|
+
|
28
|
+
extra_rdoc_files:
|
29
|
+
- README.rdoc
|
30
|
+
files:
|
31
|
+
- MIT-LICENSE
|
32
|
+
- README.rdoc
|
33
|
+
- Rakefile
|
34
|
+
- VERSION
|
35
|
+
- init.rb
|
36
|
+
- lib/title_helper.rb
|
37
|
+
- lib/title_helper/railtie.rb
|
38
|
+
- rails/init.rb
|
39
|
+
- test/title_helper_test.rb
|
40
|
+
- title_helper.gemspec
|
41
|
+
has_rdoc: true
|
42
|
+
homepage: http://github.com/defv/title_helper
|
43
|
+
licenses: []
|
44
|
+
|
45
|
+
post_install_message:
|
46
|
+
rdoc_options:
|
47
|
+
- --charset=UTF-8
|
48
|
+
require_paths:
|
49
|
+
- lib
|
50
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
hash: 3
|
56
|
+
segments:
|
57
|
+
- 0
|
58
|
+
version: "0"
|
59
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
60
|
+
none: false
|
61
|
+
requirements:
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
hash: 3
|
65
|
+
segments:
|
66
|
+
- 0
|
67
|
+
version: "0"
|
68
|
+
requirements: []
|
69
|
+
|
70
|
+
rubyforge_project:
|
71
|
+
rubygems_version: 1.3.7
|
72
|
+
signing_key:
|
73
|
+
specification_version: 3
|
74
|
+
summary: TitleHelper allows you to keep your <title> attributes synced with your <h1> attributes, which is more SEO friendly.
|
75
|
+
test_files:
|
76
|
+
- test/title_helper_test.rb
|