tophat 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.textile +17 -2
- data/lib/tophat.rb +4 -2
- data/lib/tophat/meta.rb +19 -16
- data/lib/tophat/stylesheet.rb +80 -0
- data/lib/tophat/title.rb +24 -19
- data/lib/tophat/version.rb +1 -1
- data/test/helper.rb +1 -0
- data/test/test_tophat.rb +23 -2
- data/test/test_tophat_meta.rb +20 -1
- data/test/test_tophat_stylesheets.rb +109 -0
- data/test/test_tophat_title.rb +14 -9
- data/tophat.gemspec +5 -2
- metadata +6 -3
data/README.textile
CHANGED
@@ -2,6 +2,21 @@ h1. TopHat
|
|
2
2
|
|
3
3
|
TopHat is a set of view helpers to keep your layouts and views DRY.
|
4
4
|
|
5
|
+
h2. Installation
|
6
|
+
|
7
|
+
To install as a gem, add the following to @config/environment.rb@:
|
8
|
+
|
9
|
+
<pre>
|
10
|
+
config.gem 'tophat', :version => '>= x.x'
|
11
|
+
</pre>
|
12
|
+
|
13
|
+
To install as a plugin:
|
14
|
+
|
15
|
+
<pre>
|
16
|
+
script/plugin install git://github.com/spagalloco/tophat.git
|
17
|
+
</pre>
|
18
|
+
|
19
|
+
|
5
20
|
h2. Layout Usage
|
6
21
|
|
7
22
|
You'll want to add the relevant TopHat helpers to your layouts:
|
@@ -9,8 +24,8 @@ You'll want to add the relevant TopHat helpers to your layouts:
|
|
9
24
|
<pre>
|
10
25
|
<head>
|
11
26
|
<%= title :site => "My website" %>
|
12
|
-
<%= keywords "Some default, keywords, that can be overridden" %>
|
13
|
-
<%= description "A description" %>
|
27
|
+
<%= keywords :default => "Some default, keywords, that can be overridden" %>
|
28
|
+
<%= description :default => "A description" %>
|
14
29
|
</head>
|
15
30
|
</pre>
|
16
31
|
|
data/lib/tophat.rb
CHANGED
@@ -3,8 +3,10 @@ require 'tophat/version'
|
|
3
3
|
require 'tophat/core_extensions'
|
4
4
|
require 'tophat/title'
|
5
5
|
require 'tophat/meta'
|
6
|
+
require 'tophat/stylesheet'
|
6
7
|
|
7
8
|
Hash.send :include, TopHat::HashOnly unless Hash.instance_methods.include?("only")
|
8
9
|
|
9
|
-
ActionView::Base.send :include, TopHat::
|
10
|
-
ActionView::Base.send :include, TopHat::
|
10
|
+
ActionView::Base.send :include, TopHat::TitleHelper
|
11
|
+
ActionView::Base.send :include, TopHat::MetaHelper
|
12
|
+
ActionView::Base.send :include, TopHat::StylesheetHelper
|
data/lib/tophat/meta.rb
CHANGED
@@ -1,9 +1,14 @@
|
|
1
1
|
module TopHat
|
2
|
-
module
|
2
|
+
module MetaHelper
|
3
3
|
|
4
|
-
def meta_tag(options)
|
4
|
+
def meta_tag(options={})
|
5
5
|
# tag :meta, :name => options[:name], :content => options[:content]
|
6
|
-
|
6
|
+
if options[:content] && (options[:name] || options[:http_equiv])
|
7
|
+
t = "<meta "
|
8
|
+
t << "name=\"#{options[:name]}\"" if options[:name]
|
9
|
+
t << "http-equiv=\"#{options[:http_equiv]}\"" if options[:http_equiv]
|
10
|
+
t << " content=\"#{options[:content]}\" />"
|
11
|
+
end
|
7
12
|
end
|
8
13
|
|
9
14
|
# page descriptions
|
@@ -40,20 +45,18 @@ module TopHat
|
|
40
45
|
options ||= {}
|
41
46
|
options.merge!(:name => 'keywords')
|
42
47
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
else
|
53
|
-
options.merge!(:content => @tophat_keywords)
|
54
|
-
end
|
48
|
+
default_keywords = options.delete(:default) || []
|
49
|
+
display_keywords = @tophat_keywords.blank? ? default_keywords : @tophat_keywords
|
50
|
+
|
51
|
+
# normalize the keywords
|
52
|
+
default_keywords = default_keywords.is_a?(String) ? default_keywords.split(', ') : default_keywords
|
53
|
+
display_keywords = display_keywords.is_a?(String) ? display_keywords.split(', ') : display_keywords
|
54
|
+
|
55
|
+
# merge keyword arrays if merge is set to true
|
56
|
+
display_keywords += default_keywords if options.delete(:merge_default) == true
|
55
57
|
|
56
|
-
|
58
|
+
options.merge!(:content => display_keywords.uniq.join(', '))
|
59
|
+
meta_tag(options) if display_keywords.any?
|
57
60
|
end
|
58
61
|
end
|
59
62
|
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
module TopHat
|
2
|
+
module StylesheetHelper
|
3
|
+
|
4
|
+
def ie_5_conditional(operator = nil, &block)
|
5
|
+
ie_conditional(5, operator, &block)
|
6
|
+
end
|
7
|
+
|
8
|
+
def ie_5_5_conditional(operator = nil, &block)
|
9
|
+
ie_conditional(5.5, operator, &block)
|
10
|
+
end
|
11
|
+
|
12
|
+
def ie_6_conditional(operator = nil, &block)
|
13
|
+
ie_conditional(6, operator, &block)
|
14
|
+
end
|
15
|
+
|
16
|
+
def ie_7_conditional(operator = nil, &block)
|
17
|
+
ie_conditional(7, operator, &block)
|
18
|
+
end
|
19
|
+
|
20
|
+
def ie_8_conditional(operator = nil, &block)
|
21
|
+
ie_conditional(8, operator, &block)
|
22
|
+
end
|
23
|
+
|
24
|
+
def ie_conditional(version = nil, operator = nil, &block)
|
25
|
+
browser_conditional('IE', version, operator, &block)
|
26
|
+
end
|
27
|
+
|
28
|
+
def gecko_conditional(operator = nil, &block)
|
29
|
+
browser_conditional('Gecko', nil, operator, &block)
|
30
|
+
end
|
31
|
+
|
32
|
+
def webkit_conditional(operator = nil, &block)
|
33
|
+
browser_conditional('Webkit', nil, operator, &block)
|
34
|
+
end
|
35
|
+
|
36
|
+
def mobile_safari_conditional(operator = nil, &block)
|
37
|
+
browser_conditional('SafMob', nil, operator, &block)
|
38
|
+
end
|
39
|
+
|
40
|
+
def opera_conditional(operator = nil, &block)
|
41
|
+
browser_conditional('Opera', nil, operator, &block)
|
42
|
+
end
|
43
|
+
|
44
|
+
def ie_mac_conditional(operator = nil, &block)
|
45
|
+
browser_conditional('IEMac', nil, operator, &block)
|
46
|
+
end
|
47
|
+
|
48
|
+
def konqueror_conditional(operator = nil, &block)
|
49
|
+
browser_conditional('Konq', nil, operator, &block)
|
50
|
+
end
|
51
|
+
|
52
|
+
def ie_mobile_conditional(operator = nil, &block)
|
53
|
+
browser_conditional('IEmob', nil, operator, &block)
|
54
|
+
end
|
55
|
+
|
56
|
+
def psp_conditional(operator = nil, &block)
|
57
|
+
browser_conditional('PSP', nil, operator, &block)
|
58
|
+
end
|
59
|
+
|
60
|
+
def net_front_conditional(operator = nil, &block)
|
61
|
+
browser_conditional('NetF', nil, operator, &block)
|
62
|
+
end
|
63
|
+
|
64
|
+
private
|
65
|
+
|
66
|
+
def browser_conditional(browser, version = nil, operator = nil, &block)
|
67
|
+
unless operator.blank?
|
68
|
+
operator = operator.to_s
|
69
|
+
operator << " " unless operator == '!'
|
70
|
+
end
|
71
|
+
|
72
|
+
browser_version = version.blank? ? "" : " #{version}"
|
73
|
+
|
74
|
+
output = "<!--[if #{operator}#{browser}#{browser_version}]>\n"
|
75
|
+
output << yield if block_given?
|
76
|
+
output << "\n<![endif]-->"
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
80
|
+
end
|
data/lib/tophat/title.rb
CHANGED
@@ -1,22 +1,25 @@
|
|
1
1
|
module TopHat
|
2
|
-
module
|
2
|
+
module TitleHelper
|
3
3
|
|
4
|
-
def title(title, options={})
|
4
|
+
def title(title=nil, options={})
|
5
5
|
if title.is_a? String
|
6
|
-
|
6
|
+
save_tophat_title(title, options)
|
7
7
|
else
|
8
|
-
|
8
|
+
display_tophat_title(title)
|
9
9
|
end
|
10
10
|
end
|
11
|
+
|
12
|
+
private
|
11
13
|
|
12
|
-
def
|
14
|
+
def save_tophat_title(title, options)
|
13
15
|
@tophat_title = title.gsub(/<\/?[^>]*>/, '')
|
14
16
|
@tophat_title_options = options
|
15
17
|
title
|
16
18
|
end
|
17
19
|
|
18
|
-
def
|
19
|
-
options
|
20
|
+
def display_tophat_title(options={})
|
21
|
+
options ||= {}
|
22
|
+
options = options.merge(@tophat_title_options) unless @tophat_title_options.nil?
|
20
23
|
|
21
24
|
# Prefix (leading space)
|
22
25
|
if options[:prefix]
|
@@ -28,11 +31,7 @@ module TopHat
|
|
28
31
|
end
|
29
32
|
|
30
33
|
# Separator
|
31
|
-
|
32
|
-
separator = options[:separator]
|
33
|
-
else
|
34
|
-
separator = '|'
|
35
|
-
end
|
34
|
+
separator = options[:separator] || ''
|
36
35
|
|
37
36
|
# Suffix (trailing space)
|
38
37
|
if options[:suffix]
|
@@ -43,7 +42,8 @@ module TopHat
|
|
43
42
|
suffix = ' '
|
44
43
|
end
|
45
44
|
|
46
|
-
|
45
|
+
# site name
|
46
|
+
site_name = options[:site] || ''
|
47
47
|
|
48
48
|
# Lowercase title?
|
49
49
|
if options[:lowercase] == true
|
@@ -69,18 +69,23 @@ module TopHat
|
|
69
69
|
end
|
70
70
|
|
71
71
|
# Set website/page order
|
72
|
-
|
73
|
-
|
72
|
+
if @tophat_title.blank?
|
73
|
+
# If title is blank, return only website name
|
74
|
+
content_tag :title, site_name if options[:site]
|
75
|
+
else
|
76
|
+
display_title = if @tophat_reverse == true
|
74
77
|
# Reverse order => "Page : Website"
|
75
|
-
|
78
|
+
@tophat_title + prefix + separator + suffix + site_name
|
76
79
|
else
|
77
80
|
# Standard order => "Website : Page"
|
78
|
-
|
81
|
+
site_name + prefix + separator + suffix + @tophat_title
|
79
82
|
end
|
83
|
+
|
84
|
+
return content_tag(:title, display_title.strip)
|
80
85
|
end
|
81
86
|
|
82
|
-
|
83
|
-
|
87
|
+
|
88
|
+
|
84
89
|
end
|
85
90
|
alias t title
|
86
91
|
|
data/lib/tophat/version.rb
CHANGED
data/test/helper.rb
CHANGED
data/test/test_tophat.rb
CHANGED
@@ -9,8 +9,9 @@ class TopHatPluginTestCase < Test::Unit::TestCase
|
|
9
9
|
end
|
10
10
|
|
11
11
|
should "be mixed into ActionView::Base" do
|
12
|
-
assert ActionView::Base.included_modules.include?(TopHat::
|
13
|
-
assert ActionView::Base.included_modules.include?(TopHat::
|
12
|
+
assert ActionView::Base.included_modules.include?(TopHat::TitleHelper)
|
13
|
+
assert ActionView::Base.included_modules.include?(TopHat::MetaHelper)
|
14
|
+
assert ActionView::Base.included_modules.include?(TopHat::StylesheetHelper)
|
14
15
|
end
|
15
16
|
|
16
17
|
should "respond to 'title' helper" do
|
@@ -28,6 +29,26 @@ class TopHatPluginTestCase < Test::Unit::TestCase
|
|
28
29
|
should "respond to 'keywords' helper" do
|
29
30
|
assert @template.respond_to?(:keywords)
|
30
31
|
end
|
32
|
+
|
33
|
+
should "respondo to 'ie_5_conditional' helper" do
|
34
|
+
assert @template.respond_to?(:ie_5_conditional)
|
35
|
+
end
|
36
|
+
|
37
|
+
should "respondo to 'ie_5_5_conditional' helper" do
|
38
|
+
assert @template.respond_to?(:ie_5_5_conditional)
|
39
|
+
end
|
40
|
+
|
41
|
+
should "respondo to 'ie_6_conditional' helper" do
|
42
|
+
assert @template.respond_to?(:ie_6_conditional)
|
43
|
+
end
|
44
|
+
|
45
|
+
should "respond to 'ie_7_conditional' helper" do
|
46
|
+
assert @template.respond_to?(:ie_7_conditional)
|
47
|
+
end
|
48
|
+
|
49
|
+
should "respond to 'ie_8_conditional' helper" do
|
50
|
+
assert @template.respond_to?(:ie_8_conditional)
|
51
|
+
end
|
31
52
|
|
32
53
|
end
|
33
54
|
|
data/test/test_tophat_meta.rb
CHANGED
@@ -2,7 +2,7 @@ require 'helper'
|
|
2
2
|
|
3
3
|
class TopHatMetaTestCase < Test::Unit::TestCase
|
4
4
|
|
5
|
-
context "using the meta
|
5
|
+
context "using the meta helper" do
|
6
6
|
|
7
7
|
setup do
|
8
8
|
@template = ActionView::Base.new
|
@@ -46,6 +46,11 @@ class TopHatMetaTestCase < Test::Unit::TestCase
|
|
46
46
|
assert_nil @template.keywords
|
47
47
|
end
|
48
48
|
|
49
|
+
should "merge default tags with page tags, when merge_default is set to true" do
|
50
|
+
@template.keywords("Stu, Pete")
|
51
|
+
assert_equal @template.keywords(:default => "John, Paul, George, Ringo", :merge_default => true), "<meta name=\"keywords\" content=\"Stu, Pete, John, Paul, George, Ringo\" />"
|
52
|
+
end
|
53
|
+
|
49
54
|
end
|
50
55
|
|
51
56
|
context "descriptions" do
|
@@ -66,6 +71,20 @@ class TopHatMetaTestCase < Test::Unit::TestCase
|
|
66
71
|
|
67
72
|
end
|
68
73
|
|
74
|
+
context "meta" do
|
75
|
+
|
76
|
+
should "render properly" do
|
77
|
+
assert_equal @template.meta_tag(:name => 'viewport', :content => 'width=device-width'), "<meta name=\"viewport\" content=\"width=device-width\" />"
|
78
|
+
assert_equal @template.meta_tag(:name => 'robots', :content => 'all'), "<meta name=\"robots\" content=\"all\" />"
|
79
|
+
assert_equal @template.meta_tag(:http_equiv => 'Content-Language', :content => 'en-us'), "<meta http-equiv=\"Content-Language\" content=\"en-us\" />"
|
80
|
+
end
|
81
|
+
|
82
|
+
should "not render when no arguments are passed" do
|
83
|
+
assert_nil @template.meta_tag
|
84
|
+
end
|
85
|
+
|
86
|
+
end
|
87
|
+
|
69
88
|
end
|
70
89
|
|
71
90
|
end
|
@@ -0,0 +1,109 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TopHatStylesheetTestCase < Test::Unit::TestCase
|
4
|
+
|
5
|
+
context "using the stylesheet helper" do
|
6
|
+
|
7
|
+
setup do
|
8
|
+
@template = ActionView::Base.new
|
9
|
+
end
|
10
|
+
|
11
|
+
context "stylesheets" do
|
12
|
+
setup do
|
13
|
+
@stylesheet = "ie.css"
|
14
|
+
end
|
15
|
+
|
16
|
+
should "define IE conditionals" do
|
17
|
+
assert_equal @template.ie_5_conditional {
|
18
|
+
@template.stylesheet_link_tag(@stylesheet)
|
19
|
+
}, "<!--[if IE 5]>\n<link href=\"/stylesheets/ie.css\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />\n<![endif]-->"
|
20
|
+
|
21
|
+
assert_equal @template.ie_5_5_conditional {
|
22
|
+
@template.stylesheet_link_tag(@stylesheet)
|
23
|
+
}, "<!--[if IE 5.5]>\n<link href=\"/stylesheets/ie.css\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />\n<![endif]-->"
|
24
|
+
|
25
|
+
assert_equal @template.ie_6_conditional {
|
26
|
+
@template.stylesheet_link_tag(@stylesheet)
|
27
|
+
}, "<!--[if IE 6]>\n<link href=\"/stylesheets/ie.css\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />\n<![endif]-->"
|
28
|
+
|
29
|
+
assert_equal @template.ie_7_conditional {
|
30
|
+
@template.stylesheet_link_tag(@stylesheet)
|
31
|
+
}, "<!--[if IE 7]>\n<link href=\"/stylesheets/ie.css\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />\n<![endif]-->"
|
32
|
+
|
33
|
+
assert_equal @template.ie_8_conditional {
|
34
|
+
@template.stylesheet_link_tag(@stylesheet)
|
35
|
+
}, "<!--[if IE 8]>\n<link href=\"/stylesheets/ie.css\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />\n<![endif]-->"
|
36
|
+
end
|
37
|
+
|
38
|
+
should "render defined IE conditional with greater than operator" do
|
39
|
+
assert_equal @template.ie_5_conditional(:gt) {
|
40
|
+
@template.stylesheet_link_tag(@stylesheet)
|
41
|
+
}, "<!--[if gt IE 5]>\n<link href=\"/stylesheets/ie.css\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />\n<![endif]-->"
|
42
|
+
|
43
|
+
assert_equal @template.ie_5_5_conditional(:gt) {
|
44
|
+
@template.stylesheet_link_tag(@stylesheet)
|
45
|
+
}, "<!--[if gt IE 5.5]>\n<link href=\"/stylesheets/ie.css\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />\n<![endif]-->"
|
46
|
+
end
|
47
|
+
|
48
|
+
should "render defined IE conditional with greater than or equal to operator" do
|
49
|
+
assert_equal @template.ie_5_conditional(:gte) {
|
50
|
+
@template.stylesheet_link_tag(@stylesheet)
|
51
|
+
}, "<!--[if gte IE 5]>\n<link href=\"/stylesheets/ie.css\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />\n<![endif]-->"
|
52
|
+
|
53
|
+
assert_equal @template.ie_5_5_conditional(:gte) {
|
54
|
+
@template.stylesheet_link_tag(@stylesheet)
|
55
|
+
}, "<!--[if gte IE 5.5]>\n<link href=\"/stylesheets/ie.css\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />\n<![endif]-->"
|
56
|
+
end
|
57
|
+
|
58
|
+
should "render defined IE conditional with less than operator" do
|
59
|
+
assert_equal @template.ie_5_conditional(:lt) {
|
60
|
+
@template.stylesheet_link_tag(@stylesheet)
|
61
|
+
}, "<!--[if lt IE 5]>\n<link href=\"/stylesheets/ie.css\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />\n<![endif]-->"
|
62
|
+
|
63
|
+
assert_equal @template.ie_5_5_conditional(:lt) {
|
64
|
+
@template.stylesheet_link_tag(@stylesheet)
|
65
|
+
}, "<!--[if lt IE 5.5]>\n<link href=\"/stylesheets/ie.css\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />\n<![endif]-->"
|
66
|
+
end
|
67
|
+
|
68
|
+
should "render defined IE conditional with less than or equal to operator" do
|
69
|
+
assert_equal @template.ie_5_conditional(:lte) {
|
70
|
+
@template.stylesheet_link_tag(@stylesheet)
|
71
|
+
}, "<!--[if lte IE 5]>\n<link href=\"/stylesheets/ie.css\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />\n<![endif]-->"
|
72
|
+
|
73
|
+
assert_equal @template.ie_5_5_conditional(:lte) {
|
74
|
+
@template.stylesheet_link_tag(@stylesheet)
|
75
|
+
}, "<!--[if lte IE 5.5]>\n<link href=\"/stylesheets/ie.css\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />\n<![endif]-->"
|
76
|
+
end
|
77
|
+
|
78
|
+
should "render defined IE conditional with equal to operator" do
|
79
|
+
assert_equal @template.ie_5_conditional(:eq) {
|
80
|
+
@template.stylesheet_link_tag(@stylesheet)
|
81
|
+
}, "<!--[if eq IE 5]>\n<link href=\"/stylesheets/ie.css\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />\n<![endif]-->"
|
82
|
+
|
83
|
+
assert_equal @template.ie_5_5_conditional(:eq) {
|
84
|
+
@template.stylesheet_link_tag(@stylesheet)
|
85
|
+
}, "<!--[if eq IE 5.5]>\n<link href=\"/stylesheets/ie.css\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />\n<![endif]-->"
|
86
|
+
end
|
87
|
+
|
88
|
+
should "render defined conditionals for other browsers" do
|
89
|
+
assert_equal @template.opera_conditional {
|
90
|
+
@template.stylesheet_link_tag(@stylesheet)
|
91
|
+
}, "<!--[if Opera]>\n<link href=\"/stylesheets/ie.css\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />\n<![endif]-->"
|
92
|
+
|
93
|
+
assert_equal @template.webkit_conditional {
|
94
|
+
@template.stylesheet_link_tag(@stylesheet)
|
95
|
+
}, "<!--[if Webkit]>\n<link href=\"/stylesheets/ie.css\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />\n<![endif]-->"
|
96
|
+
|
97
|
+
assert_equal @template.webkit_conditional(:eq) {
|
98
|
+
@template.stylesheet_link_tag(@stylesheet)
|
99
|
+
}, "<!--[if eq Webkit]>\n<link href=\"/stylesheets/ie.css\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />\n<![endif]-->"
|
100
|
+
|
101
|
+
assert_equal @template.gecko_conditional {
|
102
|
+
@template.stylesheet_link_tag(@stylesheet)
|
103
|
+
}, "<!--[if Gecko]>\n<link href=\"/stylesheets/ie.css\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />\n<![endif]-->"
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
end
|
108
|
+
|
109
|
+
end
|
data/test/test_tophat_title.rb
CHANGED
@@ -2,7 +2,7 @@ require 'helper'
|
|
2
2
|
|
3
3
|
class TopHatTitleTestCase < Test::Unit::TestCase
|
4
4
|
|
5
|
-
context "when using the title
|
5
|
+
context "when using the title helper" do
|
6
6
|
|
7
7
|
setup do
|
8
8
|
@template = ActionView::Base.new
|
@@ -22,28 +22,33 @@ class TopHatTitleTestCase < Test::Unit::TestCase
|
|
22
22
|
assert_equal @template.title(:site => "Miles Davis"), "<title>Miles Davis</title>"
|
23
23
|
end
|
24
24
|
|
25
|
+
should "display the title if no website was specified" do
|
26
|
+
save_basic_title
|
27
|
+
assert_equal @template.title(), '<title>Kind of Blue</title>'
|
28
|
+
end
|
29
|
+
|
25
30
|
should "use website before page by default" do
|
26
31
|
save_basic_title
|
27
|
-
assert_equal @template.title(:site => "Miles Davis"), "<title>Miles Davis | Kind of Blue</title>"
|
32
|
+
assert_equal @template.title(:site => "Miles Davis", :separator => '|'), "<title>Miles Davis | Kind of Blue</title>"
|
28
33
|
end
|
29
34
|
|
30
35
|
should "only use markup in titles in the view" do
|
31
36
|
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>"
|
37
|
+
assert_equal @template.title(:site => "Miles Davis", :separator => '|'), "<title>Miles Davis | Kind of Blue</title>"
|
33
38
|
end
|
34
39
|
|
35
40
|
should "use page before website if :reverse" do
|
36
41
|
save_basic_title
|
37
|
-
assert_equal @template.title(:site => "Miles Davis", :reverse => true), "<title>Kind of Blue | Miles Davis</title>"
|
42
|
+
assert_equal @template.title(:site => "Miles Davis", :reverse => true, :separator => '|'), "<title>Kind of Blue | Miles Davis</title>"
|
38
43
|
end
|
39
44
|
|
40
45
|
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>"
|
46
|
+
assert_equal @template.title(:site => "John Coltrane", :default => "My Favorite Things", :reverse => true, :reverse_on_default => false, :separator => '|'), "<title>John Coltrane | My Favorite Things</title>"
|
42
47
|
end
|
43
48
|
|
44
49
|
should "be lowercase if :lowercase" do
|
45
50
|
save_basic_title
|
46
|
-
assert_equal @template.title(:site => "Miles Davis", :lowercase => true), "<title>miles davis | kind of blue</title>"
|
51
|
+
assert_equal @template.title(:site => "Miles Davis", :lowercase => true, :separator => '|'), "<title>miles davis | kind of blue</title>"
|
47
52
|
end
|
48
53
|
|
49
54
|
should "use custom separator if :separator" do
|
@@ -55,7 +60,7 @@ class TopHatTitleTestCase < Test::Unit::TestCase
|
|
55
60
|
|
56
61
|
should "use custom prefix and suffix if available" do
|
57
62
|
save_basic_title
|
58
|
-
assert_equal @template.title(:site => "Miles Davis", :prefix => " |", :suffix => "| "), "<title>Miles Davis ||| Kind of Blue</title>"
|
63
|
+
assert_equal @template.title(:site => "Miles Davis", :prefix => " |", :suffix => "| ", :separator => '|'), "<title>Miles Davis ||| Kind of Blue</title>"
|
59
64
|
end
|
60
65
|
|
61
66
|
should "collapse prefix if false" do
|
@@ -76,12 +81,12 @@ class TopHatTitleTestCase < Test::Unit::TestCase
|
|
76
81
|
|
77
82
|
should "use default one if title is not present or blank" do
|
78
83
|
save_basic_title("")
|
79
|
-
assert_equal @template.title(:site => "Miles Davis", :default => "Round About Midnight"), "<title>Miles Davis | Round About Midnight</title>"
|
84
|
+
assert_equal @template.title(:site => "Miles Davis", :default => "Round About Midnight", :separator => '|'), "<title>Miles Davis | Round About Midnight</title>"
|
80
85
|
end
|
81
86
|
|
82
87
|
should "allow custom options per title" do
|
83
88
|
save_custom_title
|
84
|
-
assert_equal @template.title(:site => "Freddie Freeloader"), "<title>Kind of Blue | Freddie Freeloader</title>"
|
89
|
+
assert_equal @template.title(:site => "Freddie Freeloader", :separator => '|'), "<title>Kind of Blue | Freddie Freeloader</title>"
|
85
90
|
end
|
86
91
|
end
|
87
92
|
|
data/tophat.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{tophat}
|
8
|
-
s.version = "1.
|
8
|
+
s.version = "1.1.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Steve Agalloco"]
|
12
|
-
s.date = %q{2010-05-
|
12
|
+
s.date = %q{2010-05-04}
|
13
13
|
s.description = %q{simple view helpers for your layouts}
|
14
14
|
s.email = %q{steve.agalloco@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -25,12 +25,14 @@ Gem::Specification.new do |s|
|
|
25
25
|
"lib/tophat.rb",
|
26
26
|
"lib/tophat/core_extensions.rb",
|
27
27
|
"lib/tophat/meta.rb",
|
28
|
+
"lib/tophat/stylesheet.rb",
|
28
29
|
"lib/tophat/title.rb",
|
29
30
|
"lib/tophat/version.rb",
|
30
31
|
"rails/init.rb",
|
31
32
|
"test/helper.rb",
|
32
33
|
"test/test_tophat.rb",
|
33
34
|
"test/test_tophat_meta.rb",
|
35
|
+
"test/test_tophat_stylesheets.rb",
|
34
36
|
"test/test_tophat_title.rb",
|
35
37
|
"tophat.gemspec"
|
36
38
|
]
|
@@ -43,6 +45,7 @@ Gem::Specification.new do |s|
|
|
43
45
|
"test/helper.rb",
|
44
46
|
"test/test_tophat.rb",
|
45
47
|
"test/test_tophat_meta.rb",
|
48
|
+
"test/test_tophat_stylesheets.rb",
|
46
49
|
"test/test_tophat_title.rb"
|
47
50
|
]
|
48
51
|
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 1
|
7
|
+
- 1
|
7
8
|
- 0
|
8
|
-
|
9
|
-
version: 1.0.0
|
9
|
+
version: 1.1.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Steve Agalloco
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-05-
|
17
|
+
date: 2010-05-04 00:00:00 -04:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -61,12 +61,14 @@ files:
|
|
61
61
|
- lib/tophat.rb
|
62
62
|
- lib/tophat/core_extensions.rb
|
63
63
|
- lib/tophat/meta.rb
|
64
|
+
- lib/tophat/stylesheet.rb
|
64
65
|
- lib/tophat/title.rb
|
65
66
|
- lib/tophat/version.rb
|
66
67
|
- rails/init.rb
|
67
68
|
- test/helper.rb
|
68
69
|
- test/test_tophat.rb
|
69
70
|
- test/test_tophat_meta.rb
|
71
|
+
- test/test_tophat_stylesheets.rb
|
70
72
|
- test/test_tophat_title.rb
|
71
73
|
- tophat.gemspec
|
72
74
|
has_rdoc: true
|
@@ -103,4 +105,5 @@ test_files:
|
|
103
105
|
- test/helper.rb
|
104
106
|
- test/test_tophat.rb
|
105
107
|
- test/test_tophat_meta.rb
|
108
|
+
- test/test_tophat_stylesheets.rb
|
106
109
|
- test/test_tophat_title.rb
|