tophat 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +21 -0
- data/LICENSE +20 -0
- data/README.textile +108 -0
- data/Rakefile +59 -0
- data/lib/tophat.rb +10 -0
- data/lib/tophat/core_extensions.rb +13 -0
- data/lib/tophat/meta.rb +60 -0
- data/lib/tophat/title.rb +88 -0
- data/lib/tophat/version.rb +3 -0
- data/rails/init.rb +1 -0
- data/test/helper.rb +8 -0
- data/test/test_tophat.rb +34 -0
- data/test/test_tophat_meta.rb +71 -0
- data/test/test_tophat_title.rb +98 -0
- data/tophat.gemspec +65 -0
- metadata +106 -0
data/.document
ADDED
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Steve Agalloco
|
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.textile
ADDED
@@ -0,0 +1,108 @@
|
|
1
|
+
h1. TopHat
|
2
|
+
|
3
|
+
TopHat is a set of view helpers to keep your layouts and views DRY.
|
4
|
+
|
5
|
+
h2. Layout Usage
|
6
|
+
|
7
|
+
You'll want to add the relevant TopHat helpers to your layouts:
|
8
|
+
|
9
|
+
<pre>
|
10
|
+
<head>
|
11
|
+
<%= title :site => "My website" %>
|
12
|
+
<%= keywords "Some default, keywords, that can be overridden" %>
|
13
|
+
<%= description "A description" %>
|
14
|
+
</head>
|
15
|
+
</pre>
|
16
|
+
|
17
|
+
h2. View Usage
|
18
|
+
|
19
|
+
To set the page title, use the title method to each of your views:
|
20
|
+
|
21
|
+
<pre>
|
22
|
+
<% title "My page title" %>
|
23
|
+
</pre>
|
24
|
+
|
25
|
+
When rendered, the page title will be included in your view.
|
26
|
+
|
27
|
+
<pre>
|
28
|
+
<head>
|
29
|
+
<title>My website | My page title</title>
|
30
|
+
</head>
|
31
|
+
</pre>
|
32
|
+
|
33
|
+
h2. Usage Options
|
34
|
+
|
35
|
+
Use these options to customize the title format:
|
36
|
+
|
37
|
+
* :prefix (text between site name and separator)
|
38
|
+
* :separator (text used to separate website name from page title)
|
39
|
+
* :suffix (text between separator and page title)
|
40
|
+
* :lowercase (when true, the page name will be lowercase)
|
41
|
+
* :reverse (when true, the page and site names will be reversed)
|
42
|
+
* :default (default title to use when title is blank)
|
43
|
+
|
44
|
+
And here are a few examples to give you ideas.
|
45
|
+
|
46
|
+
<pre>
|
47
|
+
<%= title :separator => "—" %>
|
48
|
+
<%= title :prefix => false, :separator => ":" %>
|
49
|
+
<%= title :lowercase => true %>
|
50
|
+
<%= title :reverse => true, :prefix => false %>
|
51
|
+
<%= title :default => "The ultimate site for Rails" %>
|
52
|
+
</pre>
|
53
|
+
|
54
|
+
These options can be set as defaults for your layout, or when setting the title in your views, you can override any of the default settings by passing an optional hash
|
55
|
+
|
56
|
+
<pre>
|
57
|
+
<% title "My page title", :lowercase => true, :separator => "~" %>
|
58
|
+
</pre>
|
59
|
+
|
60
|
+
h2. Meta Tag Usage
|
61
|
+
|
62
|
+
TopHat also works with keywords and descriptions. In your view, simply declare the keywords and description.
|
63
|
+
|
64
|
+
<pre>
|
65
|
+
<% description('You say goodbye, I say hello.') %>
|
66
|
+
<% keywords('John, Paul, George, Ringo') %>
|
67
|
+
</pre>
|
68
|
+
|
69
|
+
Keywords can also be passed as an array:
|
70
|
+
|
71
|
+
<pre>
|
72
|
+
<% keywords(%w{ John Paul George Ringo }) %>
|
73
|
+
</pre>
|
74
|
+
|
75
|
+
Then in your layout, add the keyword and description helpers:
|
76
|
+
|
77
|
+
<pre>
|
78
|
+
<%= keywords %>
|
79
|
+
<%= description %>
|
80
|
+
</pre>
|
81
|
+
|
82
|
+
which will output the meta-tag:
|
83
|
+
|
84
|
+
<pre>
|
85
|
+
<meta name="keywords" content="John, Paul, George, Ringo" />
|
86
|
+
<meta name="description" content="You say goodbye, I say hello." />
|
87
|
+
</pre>
|
88
|
+
|
89
|
+
keywords and descriptions can also take a default in the layout:
|
90
|
+
|
91
|
+
<pre>
|
92
|
+
<%= keywords :default => 'default keywords if none are passed' %>
|
93
|
+
<%= description :default => 'default description if none is passed' %>
|
94
|
+
</pre>
|
95
|
+
|
96
|
+
h2. Note on Patches/Pull Requests
|
97
|
+
|
98
|
+
* Fork the project.
|
99
|
+
* Make your feature addition or bug fix.
|
100
|
+
* Add tests for it. This is important so I don't break it in a
|
101
|
+
future version unintentionally.
|
102
|
+
* Commit, do not mess with rakefile, version, or history.
|
103
|
+
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
104
|
+
* Send me a pull request. Bonus points for topic branches.
|
105
|
+
|
106
|
+
h2. Copyright
|
107
|
+
|
108
|
+
Copyright (c) 2010 Steve Agalloco. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
$LOAD_PATH.unshift 'lib/'
|
5
|
+
require 'tophat/version'
|
6
|
+
|
7
|
+
begin
|
8
|
+
require 'jeweler'
|
9
|
+
|
10
|
+
Jeweler::Tasks.new do |gem|
|
11
|
+
gem.name = "tophat"
|
12
|
+
gem.summary = %Q{simple view helpers for your layouts}
|
13
|
+
gem.description = %Q{simple view helpers for your layouts}
|
14
|
+
gem.email = "steve.agalloco@gmail.com"
|
15
|
+
gem.homepage = "http://github.com/spagalloco/tophat"
|
16
|
+
gem.authors = ["Steve Agalloco"]
|
17
|
+
gem.add_dependency "actionpack", ">= 2.3.5"
|
18
|
+
gem.add_development_dependency "shoulda", ">= 0"
|
19
|
+
gem.version = TopHat::VERSION
|
20
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
21
|
+
end
|
22
|
+
Jeweler::GemcutterTasks.new
|
23
|
+
rescue LoadError
|
24
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
25
|
+
end
|
26
|
+
|
27
|
+
require 'rake/testtask'
|
28
|
+
Rake::TestTask.new(:test) do |test|
|
29
|
+
test.libs << 'lib' << 'test'
|
30
|
+
test.pattern = 'test/**/test_*.rb'
|
31
|
+
test.verbose = true
|
32
|
+
end
|
33
|
+
|
34
|
+
begin
|
35
|
+
require 'rcov/rcovtask'
|
36
|
+
Rcov::RcovTask.new do |test|
|
37
|
+
test.libs << 'test'
|
38
|
+
test.pattern = 'test/**/test_*.rb'
|
39
|
+
test.verbose = true
|
40
|
+
end
|
41
|
+
rescue LoadError
|
42
|
+
task :rcov do
|
43
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
task :test => :check_dependencies
|
48
|
+
|
49
|
+
task :default => :test
|
50
|
+
|
51
|
+
require 'rake/rdoctask'
|
52
|
+
Rake::RDocTask.new do |rdoc|
|
53
|
+
version = TopHat::VERSION
|
54
|
+
|
55
|
+
rdoc.rdoc_dir = 'rdoc'
|
56
|
+
rdoc.title = "tophat #{version}"
|
57
|
+
rdoc.rdoc_files.include('README*')
|
58
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
59
|
+
end
|
data/lib/tophat.rb
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'action_view'
|
2
|
+
require 'tophat/version'
|
3
|
+
require 'tophat/core_extensions'
|
4
|
+
require 'tophat/title'
|
5
|
+
require 'tophat/meta'
|
6
|
+
|
7
|
+
Hash.send :include, TopHat::HashOnly unless Hash.instance_methods.include?("only")
|
8
|
+
|
9
|
+
ActionView::Base.send :include, TopHat::TitleHelpers
|
10
|
+
ActionView::Base.send :include, TopHat::MetaHelpers
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module TopHat
|
2
|
+
module HashOnly
|
3
|
+
# Returns a new hash with only the given keys.
|
4
|
+
def only(*keys)
|
5
|
+
reject {|key, value| !keys.include?(key) }
|
6
|
+
end
|
7
|
+
|
8
|
+
# Replaces the hash without only the given keys.
|
9
|
+
def only!(*keys)
|
10
|
+
replace(only(*keys))
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
data/lib/tophat/meta.rb
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
module TopHat
|
2
|
+
module MetaHelpers
|
3
|
+
|
4
|
+
def meta_tag(options)
|
5
|
+
# tag :meta, :name => options[:name], :content => options[:content]
|
6
|
+
"<meta name=\"#{options[:name]}\" content=\"#{options[:content]}\" />"
|
7
|
+
end
|
8
|
+
|
9
|
+
# page descriptions
|
10
|
+
# <meta name="description" content="Description goes here." />
|
11
|
+
def description(options=nil)
|
12
|
+
if options.is_a? String
|
13
|
+
@tophat_description = options
|
14
|
+
|
15
|
+
else
|
16
|
+
options ||= {}
|
17
|
+
options.merge!(:name => 'description')
|
18
|
+
|
19
|
+
if @tophat_description.blank?
|
20
|
+
options.merge!(:content => options.delete(:default))
|
21
|
+
|
22
|
+
else
|
23
|
+
options.merge!(:content => @tophat_description)
|
24
|
+
end
|
25
|
+
|
26
|
+
meta_tag(options) if options[:content]
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
# keywords
|
31
|
+
# <meta name="keywords" content="Keywords go here." />
|
32
|
+
def keywords(options=nil)
|
33
|
+
if options.is_a?(String)
|
34
|
+
@tophat_keywords = options
|
35
|
+
|
36
|
+
elsif options.is_a?(Array)
|
37
|
+
@tophat_keywods = options.join(', ')
|
38
|
+
|
39
|
+
else
|
40
|
+
options ||= {}
|
41
|
+
options.merge!(:name => 'keywords')
|
42
|
+
|
43
|
+
if @tophat_keywords.blank?
|
44
|
+
keywords = options.delete(:default)
|
45
|
+
|
46
|
+
if keywords && keywords.is_a?(Array)
|
47
|
+
keywords = keywords.join(', ')
|
48
|
+
end
|
49
|
+
|
50
|
+
options.merge!(:content => keywords)
|
51
|
+
|
52
|
+
else
|
53
|
+
options.merge!(:content => @tophat_keywords)
|
54
|
+
end
|
55
|
+
|
56
|
+
meta_tag(options) if options[:content]
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
data/lib/tophat/title.rb
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
module TopHat
|
2
|
+
module TitleHelpers
|
3
|
+
|
4
|
+
def title(title, options={})
|
5
|
+
if title.is_a? String
|
6
|
+
save_title(title, options)
|
7
|
+
else
|
8
|
+
display_title(title)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def save_title(title, options)
|
13
|
+
@tophat_title = title.gsub(/<\/?[^>]*>/, '')
|
14
|
+
@tophat_title_options = options
|
15
|
+
title
|
16
|
+
end
|
17
|
+
|
18
|
+
def display_title(options)
|
19
|
+
options = options.merge(@tophat_title_options) unless @tophat_title_options.nil? || @tophat_title_options.empty?
|
20
|
+
|
21
|
+
# Prefix (leading space)
|
22
|
+
if options[:prefix]
|
23
|
+
prefix = options[:prefix]
|
24
|
+
elsif options[:prefix] == false
|
25
|
+
prefix = ''
|
26
|
+
else
|
27
|
+
prefix = ' '
|
28
|
+
end
|
29
|
+
|
30
|
+
# Separator
|
31
|
+
unless options[:separator].blank?
|
32
|
+
separator = options[:separator]
|
33
|
+
else
|
34
|
+
separator = '|'
|
35
|
+
end
|
36
|
+
|
37
|
+
# Suffix (trailing space)
|
38
|
+
if options[:suffix]
|
39
|
+
suffix = options[:suffix]
|
40
|
+
elsif options[:suffix] == false
|
41
|
+
suffix = ''
|
42
|
+
else
|
43
|
+
suffix = ' '
|
44
|
+
end
|
45
|
+
|
46
|
+
site_name = options[:site]
|
47
|
+
|
48
|
+
# Lowercase title?
|
49
|
+
if options[:lowercase] == true
|
50
|
+
@tophat_title.downcase! unless @tophat_title.blank?
|
51
|
+
site_name.downcase! unless site_name.blank?
|
52
|
+
end
|
53
|
+
|
54
|
+
# Default page title
|
55
|
+
if @tophat_title.blank? && options[:default]
|
56
|
+
@tophat_title = options[:default]
|
57
|
+
@tophat_title_defaulted = true
|
58
|
+
end
|
59
|
+
|
60
|
+
# figure out reversing
|
61
|
+
if options[:reverse] == true
|
62
|
+
if @tophat_title_defaulted
|
63
|
+
@tophat_reserve = options[:reverse_on_default] != false
|
64
|
+
else
|
65
|
+
@tophat_reverse = true
|
66
|
+
end
|
67
|
+
else
|
68
|
+
@tophat_reverse = false
|
69
|
+
end
|
70
|
+
|
71
|
+
# Set website/page order
|
72
|
+
unless @tophat_title.blank?
|
73
|
+
if @tophat_reverse == true
|
74
|
+
# Reverse order => "Page : Website"
|
75
|
+
return content_tag(:title, @tophat_title + prefix + separator + suffix + site_name)
|
76
|
+
else
|
77
|
+
# Standard order => "Website : Page"
|
78
|
+
return content_tag(:title, site_name + prefix + separator + suffix + @tophat_title)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
# If title is blank, return only website name
|
83
|
+
content_tag :title, site_name if options[:site]
|
84
|
+
end
|
85
|
+
alias t title
|
86
|
+
|
87
|
+
end
|
88
|
+
end
|
data/rails/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'tophat'
|
data/test/helper.rb
ADDED
data/test/test_tophat.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TopHatPluginTestCase < Test::Unit::TestCase
|
4
|
+
|
5
|
+
context "loading the TopHat plugin" do
|
6
|
+
|
7
|
+
setup do
|
8
|
+
@template = ActionView::Base.new
|
9
|
+
end
|
10
|
+
|
11
|
+
should "be mixed into ActionView::Base" do
|
12
|
+
assert ActionView::Base.included_modules.include?(TopHat::TitleHelpers)
|
13
|
+
assert ActionView::Base.included_modules.include?(TopHat::MetaHelpers)
|
14
|
+
end
|
15
|
+
|
16
|
+
should "respond to 'title' helper" do
|
17
|
+
assert @template.respond_to?(:title)
|
18
|
+
end
|
19
|
+
|
20
|
+
should "respond to 'title' helper alias" do
|
21
|
+
assert @template.respond_to?(:t)
|
22
|
+
end
|
23
|
+
|
24
|
+
should "respond to 'description' helper" do
|
25
|
+
assert @template.respond_to?(:description)
|
26
|
+
end
|
27
|
+
|
28
|
+
should "respond to 'keywords' helper" do
|
29
|
+
assert @template.respond_to?(:keywords)
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TopHatMetaTestCase < Test::Unit::TestCase
|
4
|
+
|
5
|
+
context "using the meta helpers" do
|
6
|
+
|
7
|
+
setup do
|
8
|
+
@template = ActionView::Base.new
|
9
|
+
end
|
10
|
+
|
11
|
+
context "keywords" do
|
12
|
+
|
13
|
+
context "defined as an array" do
|
14
|
+
|
15
|
+
setup do
|
16
|
+
@keywords = %w{ John Paul George Ringo }
|
17
|
+
end
|
18
|
+
|
19
|
+
should "save keywords" do
|
20
|
+
assert_equal @template.keywords(@keywords), @keywords.join(', ')
|
21
|
+
end
|
22
|
+
|
23
|
+
should "use default keywords if keywords is empty" do
|
24
|
+
assert_equal @template.keywords(:default => @keywords), "<meta name=\"keywords\" content=\"#{@keywords.join(', ')}\" />"
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
context "defined as a string" do
|
30
|
+
|
31
|
+
setup do
|
32
|
+
@keywords = "John, Paul, George, Ringo"
|
33
|
+
end
|
34
|
+
|
35
|
+
should "save keywords" do
|
36
|
+
assert_equal @template.keywords(@keywords), @keywords
|
37
|
+
end
|
38
|
+
|
39
|
+
should "use default keywords passed as a string if keywords is empty" do
|
40
|
+
assert_equal @template.keywords(:default => @keywords), "<meta name=\"keywords\" content=\"#{@keywords}\" />"
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
should "not return a tag if no default is configured and no keywords are defined" do
|
46
|
+
assert_nil @template.keywords
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
context "descriptions" do
|
52
|
+
|
53
|
+
should "save the description" do
|
54
|
+
desc = "Cinderella story. Outta nowhere. A former greenskeeper, now, about to become the Masters champion."
|
55
|
+
assert_equal @template.description(desc), desc
|
56
|
+
end
|
57
|
+
|
58
|
+
should "use the default description if no description is defined" do
|
59
|
+
desc = "A flute without holes, is not a flute. A donut without a hole, is a Danish."
|
60
|
+
assert_equal @template.description(:default => desc), "<meta name=\"description\" content=\"#{desc}\" />"
|
61
|
+
end
|
62
|
+
|
63
|
+
should "not return a tag if no default is configured and no description is defined" do
|
64
|
+
assert_nil @template.description
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
@@ -0,0 +1,98 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TopHatTitleTestCase < Test::Unit::TestCase
|
4
|
+
|
5
|
+
context "when using the title helpers" do
|
6
|
+
|
7
|
+
setup do
|
8
|
+
@template = ActionView::Base.new
|
9
|
+
end
|
10
|
+
|
11
|
+
context "saving a title" do
|
12
|
+
|
13
|
+
should "save the title" do
|
14
|
+
assert_equal @template.title('Kind of Blue'), 'Kind of Blue'
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
context "displaying a title" do
|
20
|
+
|
21
|
+
should "use the website name if title is empty" do
|
22
|
+
assert_equal @template.title(:site => "Miles Davis"), "<title>Miles Davis</title>"
|
23
|
+
end
|
24
|
+
|
25
|
+
should "use website before page by default" do
|
26
|
+
save_basic_title
|
27
|
+
assert_equal @template.title(:site => "Miles Davis"), "<title>Miles Davis | Kind of Blue</title>"
|
28
|
+
end
|
29
|
+
|
30
|
+
should "only use markup in titles in the view" do
|
31
|
+
assert_equal save_basic_title("<b>Kind of Blue</b>"), "<b>Kind of Blue</b>"
|
32
|
+
assert_equal @template.title(:site => "Miles Davis"), "<title>Miles Davis | Kind of Blue</title>"
|
33
|
+
end
|
34
|
+
|
35
|
+
should "use page before website if :reverse" do
|
36
|
+
save_basic_title
|
37
|
+
assert_equal @template.title(:site => "Miles Davis", :reverse => true), "<title>Kind of Blue | Miles Davis</title>"
|
38
|
+
end
|
39
|
+
|
40
|
+
should "use website before page if :reverse and :reverse_on_default" do
|
41
|
+
assert_equal @template.title(:site => "John Coltrane", :default => "My Favorite Things", :reverse => true, :reverse_on_default => false), "<title>John Coltrane | My Favorite Things</title>"
|
42
|
+
end
|
43
|
+
|
44
|
+
should "be lowercase if :lowercase" do
|
45
|
+
save_basic_title
|
46
|
+
assert_equal @template.title(:site => "Miles Davis", :lowercase => true), "<title>miles davis | kind of blue</title>"
|
47
|
+
end
|
48
|
+
|
49
|
+
should "use custom separator if :separator" do
|
50
|
+
save_basic_title
|
51
|
+
assert_equal @template.title(:site => "Miles Davis", :separator => "-"), "<title>Miles Davis - Kind of Blue</title>"
|
52
|
+
assert_equal @template.title(:site => "Miles Davis", :separator => ":"), "<title>Miles Davis : Kind of Blue</title>"
|
53
|
+
assert_equal @template.title(:site => "Miles Davis", :separator => "—"), "<title>Miles Davis — Kind of Blue</title>"
|
54
|
+
end
|
55
|
+
|
56
|
+
should "use custom prefix and suffix if available" do
|
57
|
+
save_basic_title
|
58
|
+
assert_equal @template.title(:site => "Miles Davis", :prefix => " |", :suffix => "| "), "<title>Miles Davis ||| Kind of Blue</title>"
|
59
|
+
end
|
60
|
+
|
61
|
+
should "collapse prefix if false" do
|
62
|
+
save_basic_title
|
63
|
+
assert_equal @template.title(:site => "Miles Davis", :prefix => false, :separator => ":"), "<title>Miles Davis: Kind of Blue</title>"
|
64
|
+
end
|
65
|
+
|
66
|
+
should "collapse suffix if false" do
|
67
|
+
save_basic_title
|
68
|
+
assert_equal @template.title(:site => "Miles Davis", :suffix => false, :separator => "~"), "<title>Miles Davis ~Kind of Blue</title>"
|
69
|
+
end
|
70
|
+
|
71
|
+
should "use all custom options if available" do
|
72
|
+
save_basic_title
|
73
|
+
custom_options = { :site => "Miles Davis", :prefix => " ", :suffix => " ", :separator => "-", :lowercase => true, :reverse => true }
|
74
|
+
assert_equal @template.title(custom_options), "<title>kind of blue - miles davis</title>"
|
75
|
+
end
|
76
|
+
|
77
|
+
should "use default one if title is not present or blank" do
|
78
|
+
save_basic_title("")
|
79
|
+
assert_equal @template.title(:site => "Miles Davis", :default => "Round About Midnight"), "<title>Miles Davis | Round About Midnight</title>"
|
80
|
+
end
|
81
|
+
|
82
|
+
should "allow custom options per title" do
|
83
|
+
save_custom_title
|
84
|
+
assert_equal @template.title(:site => "Freddie Freeloader"), "<title>Kind of Blue | Freddie Freeloader</title>"
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
end
|
89
|
+
|
90
|
+
def save_basic_title(title='Kind of Blue')
|
91
|
+
@template.title(title)
|
92
|
+
end
|
93
|
+
|
94
|
+
def save_custom_title(title='Kind of Blue')
|
95
|
+
@template.title(title, { :reverse => true })
|
96
|
+
end
|
97
|
+
|
98
|
+
end
|
data/tophat.gemspec
ADDED
@@ -0,0 +1,65 @@
|
|
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{tophat}
|
8
|
+
s.version = "1.0.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Steve Agalloco"]
|
12
|
+
s.date = %q{2010-05-01}
|
13
|
+
s.description = %q{simple view helpers for your layouts}
|
14
|
+
s.email = %q{steve.agalloco@gmail.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README.textile"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".gitignore",
|
22
|
+
"LICENSE",
|
23
|
+
"README.textile",
|
24
|
+
"Rakefile",
|
25
|
+
"lib/tophat.rb",
|
26
|
+
"lib/tophat/core_extensions.rb",
|
27
|
+
"lib/tophat/meta.rb",
|
28
|
+
"lib/tophat/title.rb",
|
29
|
+
"lib/tophat/version.rb",
|
30
|
+
"rails/init.rb",
|
31
|
+
"test/helper.rb",
|
32
|
+
"test/test_tophat.rb",
|
33
|
+
"test/test_tophat_meta.rb",
|
34
|
+
"test/test_tophat_title.rb",
|
35
|
+
"tophat.gemspec"
|
36
|
+
]
|
37
|
+
s.homepage = %q{http://github.com/spagalloco/tophat}
|
38
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
39
|
+
s.require_paths = ["lib"]
|
40
|
+
s.rubygems_version = %q{1.3.6}
|
41
|
+
s.summary = %q{simple view helpers for your layouts}
|
42
|
+
s.test_files = [
|
43
|
+
"test/helper.rb",
|
44
|
+
"test/test_tophat.rb",
|
45
|
+
"test/test_tophat_meta.rb",
|
46
|
+
"test/test_tophat_title.rb"
|
47
|
+
]
|
48
|
+
|
49
|
+
if s.respond_to? :specification_version then
|
50
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
51
|
+
s.specification_version = 3
|
52
|
+
|
53
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
54
|
+
s.add_runtime_dependency(%q<actionpack>, [">= 2.3.5"])
|
55
|
+
s.add_development_dependency(%q<shoulda>, [">= 0"])
|
56
|
+
else
|
57
|
+
s.add_dependency(%q<actionpack>, [">= 2.3.5"])
|
58
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
59
|
+
end
|
60
|
+
else
|
61
|
+
s.add_dependency(%q<actionpack>, [">= 2.3.5"])
|
62
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
metadata
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: tophat
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 1
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
version: 1.0.0
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Steve Agalloco
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-05-01 00:00:00 -04:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: actionpack
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 2
|
29
|
+
- 3
|
30
|
+
- 5
|
31
|
+
version: 2.3.5
|
32
|
+
type: :runtime
|
33
|
+
version_requirements: *id001
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
name: shoulda
|
36
|
+
prerelease: false
|
37
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
segments:
|
42
|
+
- 0
|
43
|
+
version: "0"
|
44
|
+
type: :development
|
45
|
+
version_requirements: *id002
|
46
|
+
description: simple view helpers for your layouts
|
47
|
+
email: steve.agalloco@gmail.com
|
48
|
+
executables: []
|
49
|
+
|
50
|
+
extensions: []
|
51
|
+
|
52
|
+
extra_rdoc_files:
|
53
|
+
- LICENSE
|
54
|
+
- README.textile
|
55
|
+
files:
|
56
|
+
- .document
|
57
|
+
- .gitignore
|
58
|
+
- LICENSE
|
59
|
+
- README.textile
|
60
|
+
- Rakefile
|
61
|
+
- lib/tophat.rb
|
62
|
+
- lib/tophat/core_extensions.rb
|
63
|
+
- lib/tophat/meta.rb
|
64
|
+
- lib/tophat/title.rb
|
65
|
+
- lib/tophat/version.rb
|
66
|
+
- rails/init.rb
|
67
|
+
- test/helper.rb
|
68
|
+
- test/test_tophat.rb
|
69
|
+
- test/test_tophat_meta.rb
|
70
|
+
- test/test_tophat_title.rb
|
71
|
+
- tophat.gemspec
|
72
|
+
has_rdoc: true
|
73
|
+
homepage: http://github.com/spagalloco/tophat
|
74
|
+
licenses: []
|
75
|
+
|
76
|
+
post_install_message:
|
77
|
+
rdoc_options:
|
78
|
+
- --charset=UTF-8
|
79
|
+
require_paths:
|
80
|
+
- lib
|
81
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - ">="
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
segments:
|
86
|
+
- 0
|
87
|
+
version: "0"
|
88
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
89
|
+
requirements:
|
90
|
+
- - ">="
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
segments:
|
93
|
+
- 0
|
94
|
+
version: "0"
|
95
|
+
requirements: []
|
96
|
+
|
97
|
+
rubyforge_project:
|
98
|
+
rubygems_version: 1.3.6
|
99
|
+
signing_key:
|
100
|
+
specification_version: 3
|
101
|
+
summary: simple view helpers for your layouts
|
102
|
+
test_files:
|
103
|
+
- test/helper.rb
|
104
|
+
- test/test_tophat.rb
|
105
|
+
- test/test_tophat_meta.rb
|
106
|
+
- test/test_tophat_title.rb
|