tophat 2.0.0 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +8 -2
- data/lib/tophat/html.rb +60 -24
- data/lib/tophat/opengraph.rb +14 -11
- data/lib/tophat/title.rb +19 -16
- data/lib/tophat/twitter_card.rb +3 -2
- data/lib/tophat/version.rb +2 -2
- data/spec/tophat/html_helper_spec.rb +5 -0
- data/spec/tophat/stylesheet_helper_spec.rb +28 -28
- data/spec/tophat/title_helper_spec.rb +20 -20
- metadata +4 -4
data/README.md
CHANGED
@@ -1,7 +1,9 @@
|
|
1
|
-
# TopHat [][travis] [][gemnasium]
|
1
|
+
# TopHat [][travis] [][gemnasium] [][codeclimate]
|
2
|
+
|
2
3
|
|
3
4
|
[travis]: http://travis-ci.org/spagalloco/tophat
|
4
5
|
[gemnasium]: https://gemnasium.com/spagalloco/tophat
|
6
|
+
[codeclimate]: https://codeclimate.com/github/spagalloco/tophat
|
5
7
|
|
6
8
|
TopHat is a set of view helpers to keep your layouts and views DRY. Easily include meta tags like keywords and descriptions, Open Graph and Twitter Cards in your Rails views.
|
7
9
|
|
@@ -13,6 +15,10 @@ Just add it to your Gemfile:
|
|
13
15
|
|
14
16
|
Note: TopHat is Rails 3.0+ compatible.
|
15
17
|
|
18
|
+
## Changes in 2.1
|
19
|
+
|
20
|
+
TopHat version < 2.1 aliased the `title` as `t` and conflicted with an existing Rails helper used for i18n translation. Version 2.1 removes this alias. If you were using `t` as part of TopHat previously, you will need to change your code to use TopHat's `title` helper instead.
|
21
|
+
|
16
22
|
## Layout Usage
|
17
23
|
|
18
24
|
You'll want to add the relevant TopHat helpers to your layouts:
|
@@ -179,7 +185,7 @@ Which will render a twitter card like so:
|
|
179
185
|
<meta name="twitter:player" value="https://example.com/embed/a">
|
180
186
|
<meta name="twitter:player:width" value="435">
|
181
187
|
<meta name="twitter:player:height" value="251">
|
182
|
-
|
188
|
+
|
183
189
|
To render the twitter card in your layout, simply call the twitter_card helper with no arguments:
|
184
190
|
|
185
191
|
<%= twitter_card %>
|
data/lib/tophat/html.rb
CHANGED
@@ -2,35 +2,71 @@ module TopHat
|
|
2
2
|
module HtmlHelper
|
3
3
|
|
4
4
|
def html_tag(options={})
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
5
|
+
opts = options.dup
|
6
|
+
opts.merge!(xmlns_options(opts.delete(:xmlns))) if opts[:xmlns]
|
7
|
+
opts.merge!(prefix_options(opts.delete(:prefix))) if opts[:prefix]
|
8
|
+
|
9
|
+
tag(:html, opts, true)
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def xmlns_options(xmlns)
|
15
|
+
options = {}
|
16
|
+
|
17
|
+
if xmlns.kind_of?(String)
|
18
|
+
options['xmlns'] = xmlns
|
19
|
+
elsif xmlns.kind_of?(Array)
|
20
|
+
options.merge!(xmlns_from_array(xmlns))
|
21
|
+
elsif xmlns.kind_of?(Hash)
|
22
|
+
options.merge!(xmlns_from_hash(xmlns))
|
13
23
|
end
|
14
24
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
options['prefix'] = prefixes.join(' ')
|
25
|
+
options
|
26
|
+
end
|
27
|
+
|
28
|
+
def xmlns_from_array(xmlns)
|
29
|
+
options = {}
|
30
|
+
|
31
|
+
xmlns.each do |x|
|
32
|
+
if x.kind_of?(Hash)
|
33
|
+
options.merge!(xmlns_from_hash(x))
|
34
|
+
else
|
35
|
+
options['xmlns'] = x
|
30
36
|
end
|
31
37
|
end
|
32
38
|
|
33
|
-
|
39
|
+
options
|
40
|
+
end
|
41
|
+
|
42
|
+
def xmlns_from_hash(h)
|
43
|
+
{ "xmlns:#{h[:prefix]}" => h[:url] }
|
44
|
+
end
|
45
|
+
|
46
|
+
def prefix_options(prefix)
|
47
|
+
options = {}
|
48
|
+
|
49
|
+
options['prefix'] = case prefix
|
50
|
+
when String then prefix
|
51
|
+
when Hash then prefix_from_hash(prefix)
|
52
|
+
when Array then prefix_from_array(prefix)
|
53
|
+
end
|
54
|
+
|
55
|
+
options
|
56
|
+
end
|
57
|
+
|
58
|
+
def prefix_from_array(prefixes)
|
59
|
+
prefixes.map do |prefix|
|
60
|
+
if prefix.kind_of?(Hash)
|
61
|
+
prefix_from_hash(prefix)
|
62
|
+
else
|
63
|
+
prefix
|
64
|
+
end
|
65
|
+
end.join(' ')
|
66
|
+
end
|
67
|
+
|
68
|
+
def prefix_from_hash(h)
|
69
|
+
"#{h[:prefix]}: #{h[:url]}"
|
34
70
|
end
|
35
71
|
|
36
72
|
end
|
data/lib/tophat/opengraph.rb
CHANGED
@@ -18,14 +18,14 @@ module TopHat
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def app_id
|
21
|
-
tag(:meta, :property => 'fb:app_id', :content => @app_id) + "\n".html_safe
|
21
|
+
tag(:meta, :property => 'fb:app_id', :content => @app_id) + "\n".html_safe
|
22
22
|
end
|
23
23
|
|
24
24
|
def admins
|
25
|
-
tag(:meta, :property => 'fb:admins', :content => [*@admins].join(',')) + "\n".html_safe
|
25
|
+
tag(:meta, :property => 'fb:admins', :content => [*@admins].join(',')) + "\n".html_safe
|
26
26
|
end
|
27
27
|
|
28
|
-
def
|
28
|
+
def graph_data
|
29
29
|
output = ActiveSupport::SafeBuffer.new
|
30
30
|
@graph_data.each do |key, value|
|
31
31
|
output << tag(:meta, :property => "og:#{key}", :content => value)
|
@@ -48,6 +48,14 @@ module TopHat
|
|
48
48
|
@graph_data[method] = args.shift
|
49
49
|
end
|
50
50
|
|
51
|
+
def to_html
|
52
|
+
output = ActiveSupport::SafeBuffer.new
|
53
|
+
output << app_id if defined?(@app_id) && @app_id
|
54
|
+
output << admins if defined?(@admins) && @admins
|
55
|
+
output << graph_data if has_graph_data?
|
56
|
+
output
|
57
|
+
end
|
58
|
+
|
51
59
|
end
|
52
60
|
|
53
61
|
HTML4_XMLNS = [
|
@@ -77,19 +85,14 @@ module TopHat
|
|
77
85
|
end
|
78
86
|
|
79
87
|
def opengraph(options=nil, &block)
|
80
|
-
if options.kind_of? Hash
|
81
|
-
|
82
|
-
end
|
88
|
+
TopHat.current['open_graph_defaults'] = options if options.kind_of? Hash
|
89
|
+
|
83
90
|
if block_given?
|
84
91
|
TopHat.current['open_graph_generator'] = OpenGraphGenerator.new(TopHat.current['open_graph_defaults'], &block)
|
85
92
|
else
|
86
93
|
TopHat.current['open_graph_generator'] ||= OpenGraphGenerator.new
|
87
94
|
TopHat.current['open_graph_generator'].merge(TopHat.current['open_graph_defaults'])
|
88
|
-
|
89
|
-
output << TopHat.current['open_graph_generator'].app_id
|
90
|
-
output << TopHat.current['open_graph_generator'].admins
|
91
|
-
output << TopHat.current['open_graph_generator'].render_graph_data if TopHat.current['open_graph_generator'].has_graph_data?
|
92
|
-
output
|
95
|
+
TopHat.current['open_graph_generator'].to_html
|
93
96
|
end
|
94
97
|
end
|
95
98
|
|
data/lib/tophat/title.rb
CHANGED
@@ -1,6 +1,10 @@
|
|
1
1
|
module TopHat
|
2
2
|
module TitleHelper
|
3
3
|
|
4
|
+
DEFAULT_PREFIX = ' '.freeze unless defined?(DEFAULT_PREFIX)
|
5
|
+
DEFAULT_SUFFIX = ' '.freeze unless defined?(DEFAULT_SUFFIX)
|
6
|
+
DEFAULT_SEPARATOR = ''.freeze unless defined?(DEFAULT_SEPARATOR)
|
7
|
+
|
4
8
|
def title(title=nil, options={})
|
5
9
|
if title.is_a?(String) || title.is_a?(Array)
|
6
10
|
save_tophat_title(title, options)
|
@@ -8,8 +12,7 @@ module TopHat
|
|
8
12
|
display_tophat_title(title || options)
|
9
13
|
end
|
10
14
|
end
|
11
|
-
|
12
|
-
|
15
|
+
|
13
16
|
private
|
14
17
|
|
15
18
|
def save_tophat_title(title, options)
|
@@ -27,8 +30,6 @@ module TopHat
|
|
27
30
|
|
28
31
|
title_segments.flatten! # flatten out in case the title is an array
|
29
32
|
title_segments.compact! # clean out any nils
|
30
|
-
title_segments.map! { |t| t.downcase! } if options[:lowercase]
|
31
|
-
title_segments.map! { |t| t.upcase! } if options[:uppercase]
|
32
33
|
title_segments.map! { |t| strip_tags(t) }
|
33
34
|
|
34
35
|
reverse = options[:reverse]
|
@@ -36,32 +37,34 @@ module TopHat
|
|
36
37
|
|
37
38
|
title_segments.reverse! if reverse
|
38
39
|
|
39
|
-
|
40
|
+
title_text = title_segments.join(delimiter_from(options))
|
41
|
+
title_text.downcase! if options[:lowercase]
|
42
|
+
title_text.upcase! if options[:uppercase]
|
43
|
+
|
44
|
+
content_tag :title, title_text.strip
|
40
45
|
end
|
41
46
|
|
42
47
|
def delimiter_from(options={})
|
43
48
|
return "" if options.empty?
|
44
49
|
|
45
50
|
# Prefix (leading space)
|
46
|
-
if options[:prefix]
|
47
|
-
|
51
|
+
prefix = if options[:prefix]
|
52
|
+
options[:prefix]
|
48
53
|
elsif options[:prefix] == false
|
49
|
-
|
50
|
-
else
|
51
|
-
prefix = ' '
|
54
|
+
''
|
52
55
|
end
|
56
|
+
prefix ||= DEFAULT_PREFIX
|
53
57
|
|
54
58
|
# Separator
|
55
|
-
separator = options[:separator] ||
|
59
|
+
separator = options[:separator] || DEFAULT_SEPARATOR
|
56
60
|
|
57
61
|
# Suffix (trailing space)
|
58
|
-
if options[:suffix]
|
59
|
-
|
62
|
+
suffix = if options[:suffix]
|
63
|
+
options[:suffix]
|
60
64
|
elsif options[:suffix] == false
|
61
|
-
|
62
|
-
else
|
63
|
-
suffix = ' '
|
65
|
+
''
|
64
66
|
end
|
67
|
+
suffix ||= DEFAULT_SUFFIX
|
65
68
|
|
66
69
|
prefix + separator + suffix
|
67
70
|
end
|
data/lib/tophat/twitter_card.rb
CHANGED
@@ -13,7 +13,7 @@ module TopHat
|
|
13
13
|
yield self if block_given?
|
14
14
|
end
|
15
15
|
|
16
|
-
def
|
16
|
+
def to_html
|
17
17
|
output = ActiveSupport::SafeBuffer.new
|
18
18
|
output << tag(:meta, :name => 'twitter:card', :value => @type)
|
19
19
|
@card_data.each do |key, value|
|
@@ -23,6 +23,7 @@ module TopHat
|
|
23
23
|
output << "\n".html_safe unless @card_data.empty?
|
24
24
|
output
|
25
25
|
end
|
26
|
+
alias render to_html
|
26
27
|
|
27
28
|
def add_nested_attributes(method, &block)
|
28
29
|
image_generator = TwitterCardGenerator.new(method, &block)
|
@@ -41,7 +42,7 @@ module TopHat
|
|
41
42
|
def twitter_card(type=nil, &block)
|
42
43
|
if type.nil?
|
43
44
|
if TopHat.current['twitter_card']
|
44
|
-
TopHat.current['twitter_card'].
|
45
|
+
TopHat.current['twitter_card'].to_html
|
45
46
|
end
|
46
47
|
else
|
47
48
|
TopHat.current['twitter_card'] = TwitterCardGenerator.new(type, &block)
|
data/lib/tophat/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
1
|
module TopHat
|
2
|
-
VERSION = '2.
|
3
|
-
end
|
2
|
+
VERSION = '2.1.0'
|
3
|
+
end
|
@@ -21,6 +21,11 @@ describe TopHat::HtmlHelper do
|
|
21
21
|
output.should eq('<html xmlns="http://someurl.com">')
|
22
22
|
end
|
23
23
|
|
24
|
+
it 'accepts xmlns passed as hashes' do
|
25
|
+
output = @template.html_tag(:xmlns => { :prefix => 'fb', :url => 'http://someurl.com' })
|
26
|
+
output.should eq('<html xmlns:fb="http://someurl.com">')
|
27
|
+
end
|
28
|
+
|
24
29
|
it 'accepts xmlns passed as an array of hashes' do
|
25
30
|
xmlns = { :prefix => 'fb', :url => 'http://developers.facebook.com/schema/' }
|
26
31
|
output = @template.html_tag(:xmlns => [xmlns])
|
@@ -19,129 +19,129 @@ describe TopHat::StylesheetHelper do
|
|
19
19
|
it "defines IE conditionals" do
|
20
20
|
@template.ie_5_conditional {
|
21
21
|
@template.stylesheet_link_tag(@stylesheet)
|
22
|
-
}.should
|
22
|
+
}.should eq("<!--[if IE 5]>\n<link href=\"/stylesheets/ie.css\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />\n<![endif]-->")
|
23
23
|
|
24
24
|
@template.ie_5_5_conditional {
|
25
25
|
@template.stylesheet_link_tag(@stylesheet)
|
26
|
-
}.should
|
26
|
+
}.should eq("<!--[if IE 5.5]>\n<link href=\"/stylesheets/ie.css\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />\n<![endif]-->")
|
27
27
|
|
28
28
|
@template.ie_6_conditional {
|
29
29
|
@template.stylesheet_link_tag(@stylesheet)
|
30
|
-
}.should
|
30
|
+
}.should eq("<!--[if IE 6]>\n<link href=\"/stylesheets/ie.css\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />\n<![endif]-->")
|
31
31
|
|
32
32
|
@template.ie_7_conditional {
|
33
33
|
@template.stylesheet_link_tag(@stylesheet)
|
34
|
-
}.should
|
34
|
+
}.should eq("<!--[if IE 7]>\n<link href=\"/stylesheets/ie.css\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />\n<![endif]-->")
|
35
35
|
|
36
36
|
@template.ie_8_conditional {
|
37
37
|
@template.stylesheet_link_tag(@stylesheet)
|
38
|
-
}.should
|
38
|
+
}.should eq("<!--[if IE 8]>\n<link href=\"/stylesheets/ie.css\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />\n<![endif]-->")
|
39
39
|
|
40
40
|
@template.ie_9_conditional {
|
41
41
|
@template.stylesheet_link_tag(@stylesheet)
|
42
|
-
}.should
|
42
|
+
}.should eq("<!--[if IE 9]>\n<link href=\"/stylesheets/ie.css\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />\n<![endif]-->")
|
43
43
|
end
|
44
44
|
|
45
45
|
it "renders defined IE conditional with greater than operator" do
|
46
46
|
@template.ie_5_conditional(:gt) {
|
47
47
|
@template.stylesheet_link_tag(@stylesheet)
|
48
|
-
}.should
|
48
|
+
}.should eq("<!--[if gt IE 5]>\n<link href=\"/stylesheets/ie.css\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />\n<![endif]-->")
|
49
49
|
|
50
50
|
@template.ie_5_5_conditional(:gt) {
|
51
51
|
@template.stylesheet_link_tag(@stylesheet)
|
52
|
-
}.should
|
52
|
+
}.should eq("<!--[if gt IE 5.5]>\n<link href=\"/stylesheets/ie.css\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />\n<![endif]-->")
|
53
53
|
end
|
54
54
|
|
55
55
|
it "renders defined IE conditional with greater than or equal to operator" do
|
56
56
|
@template.ie_5_conditional(:gte) {
|
57
57
|
@template.stylesheet_link_tag(@stylesheet)
|
58
|
-
}.should
|
58
|
+
}.should eq("<!--[if gte IE 5]>\n<link href=\"/stylesheets/ie.css\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />\n<![endif]-->")
|
59
59
|
|
60
60
|
@template.ie_5_5_conditional(:gte) {
|
61
61
|
@template.stylesheet_link_tag(@stylesheet)
|
62
|
-
}.should
|
62
|
+
}.should eq("<!--[if gte IE 5.5]>\n<link href=\"/stylesheets/ie.css\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />\n<![endif]-->")
|
63
63
|
end
|
64
64
|
|
65
65
|
it "renders defined IE conditional with ! operator" do
|
66
66
|
@template.ie_5_conditional(:not) {
|
67
67
|
@template.stylesheet_link_tag(@stylesheet)
|
68
|
-
}.should
|
68
|
+
}.should eq("<!--[if !IE 5]>\n<link href=\"/stylesheets/ie.css\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />\n<![endif]-->")
|
69
69
|
|
70
70
|
@template.ie_5_5_conditional(:not) {
|
71
71
|
@template.stylesheet_link_tag(@stylesheet)
|
72
|
-
}.should
|
72
|
+
}.should eq("<!--[if !IE 5.5]>\n<link href=\"/stylesheets/ie.css\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />\n<![endif]-->")
|
73
73
|
end
|
74
74
|
|
75
75
|
it "renders defined IE conditional with less than operator" do
|
76
76
|
@template.ie_5_conditional(:lt) {
|
77
77
|
@template.stylesheet_link_tag(@stylesheet)
|
78
|
-
}.should
|
78
|
+
}.should eq("<!--[if lt IE 5]>\n<link href=\"/stylesheets/ie.css\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />\n<![endif]-->")
|
79
79
|
|
80
80
|
@template.ie_5_5_conditional(:lt) {
|
81
81
|
@template.stylesheet_link_tag(@stylesheet)
|
82
|
-
}.should
|
82
|
+
}.should eq("<!--[if lt IE 5.5]>\n<link href=\"/stylesheets/ie.css\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />\n<![endif]-->")
|
83
83
|
end
|
84
84
|
|
85
85
|
it "renders defined IE conditional with less than or equal to operator" do
|
86
86
|
@template.ie_5_conditional(:lte) {
|
87
87
|
@template.stylesheet_link_tag(@stylesheet)
|
88
|
-
}.should
|
88
|
+
}.should eq("<!--[if lte IE 5]>\n<link href=\"/stylesheets/ie.css\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />\n<![endif]-->")
|
89
89
|
|
90
90
|
@template.ie_5_5_conditional(:lte) {
|
91
91
|
@template.stylesheet_link_tag(@stylesheet)
|
92
|
-
}.should
|
92
|
+
}.should eq("<!--[if lte IE 5.5]>\n<link href=\"/stylesheets/ie.css\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />\n<![endif]-->")
|
93
93
|
end
|
94
94
|
|
95
95
|
it "renders defined IE conditional with equal to operator" do
|
96
96
|
@template.ie_5_conditional(:eq) {
|
97
97
|
@template.stylesheet_link_tag(@stylesheet)
|
98
|
-
}.should
|
98
|
+
}.should eq("<!--[if eq IE 5]>\n<link href=\"/stylesheets/ie.css\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />\n<![endif]-->")
|
99
99
|
|
100
100
|
@template.ie_5_5_conditional(:eq) {
|
101
101
|
@template.stylesheet_link_tag(@stylesheet)
|
102
|
-
}.should
|
102
|
+
}.should eq("<!--[if eq IE 5.5]>\n<link href=\"/stylesheets/ie.css\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />\n<![endif]-->")
|
103
103
|
end
|
104
104
|
|
105
105
|
it "renders defined conditionals for other browsers" do
|
106
106
|
@template.opera_conditional {
|
107
107
|
@template.stylesheet_link_tag(@stylesheet)
|
108
|
-
}.should
|
108
|
+
}.should eq("<!--[if Opera]>\n<link href=\"/stylesheets/ie.css\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />\n<![endif]-->")
|
109
109
|
|
110
110
|
@template.webkit_conditional {
|
111
111
|
@template.stylesheet_link_tag(@stylesheet)
|
112
|
-
}.should
|
112
|
+
}.should eq("<!--[if Webkit]>\n<link href=\"/stylesheets/ie.css\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />\n<![endif]-->")
|
113
113
|
|
114
114
|
@template.webkit_conditional(:eq) {
|
115
115
|
@template.stylesheet_link_tag(@stylesheet)
|
116
|
-
}.should
|
116
|
+
}.should eq("<!--[if eq Webkit]>\n<link href=\"/stylesheets/ie.css\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />\n<![endif]-->")
|
117
117
|
|
118
118
|
@template.gecko_conditional {
|
119
119
|
@template.stylesheet_link_tag(@stylesheet)
|
120
|
-
}.should
|
120
|
+
}.should eq("<!--[if Gecko]>\n<link href=\"/stylesheets/ie.css\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />\n<![endif]-->")
|
121
121
|
|
122
122
|
@template.ie_mac_conditional {
|
123
123
|
@template.stylesheet_link_tag(@stylesheet)
|
124
|
-
}.should
|
124
|
+
}.should eq("<!--[if IEMac]>\n<link href=\"/stylesheets/ie.css\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />\n<![endif]-->")
|
125
125
|
|
126
126
|
@template.konqueror_conditional {
|
127
127
|
@template.stylesheet_link_tag(@stylesheet)
|
128
|
-
}.should
|
128
|
+
}.should eq("<!--[if Konq]>\n<link href=\"/stylesheets/ie.css\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />\n<![endif]-->")
|
129
129
|
|
130
130
|
@template.ie_mobile_conditional {
|
131
131
|
@template.stylesheet_link_tag(@stylesheet)
|
132
|
-
}.should
|
132
|
+
}.should eq("<!--[if IEmob]>\n<link href=\"/stylesheets/ie.css\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />\n<![endif]-->")
|
133
133
|
|
134
134
|
@template.psp_conditional {
|
135
135
|
@template.stylesheet_link_tag(@stylesheet)
|
136
|
-
}.should
|
136
|
+
}.should eq("<!--[if PSP]>\n<link href=\"/stylesheets/ie.css\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />\n<![endif]-->")
|
137
137
|
|
138
138
|
@template.net_front_conditional {
|
139
139
|
@template.stylesheet_link_tag(@stylesheet)
|
140
|
-
}.should
|
140
|
+
}.should eq("<!--[if NetF]>\n<link href=\"/stylesheets/ie.css\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />\n<![endif]-->")
|
141
141
|
|
142
142
|
@template.mobile_safari_conditional {
|
143
143
|
@template.stylesheet_link_tag(@stylesheet)
|
144
|
-
}.should
|
144
|
+
}.should eq("<!--[if SafMob]>\n<link href=\"/stylesheets/ie.css\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />\n<![endif]-->")
|
145
145
|
|
146
146
|
end
|
147
147
|
|
@@ -7,91 +7,91 @@ describe TopHat::TitleHelper do
|
|
7
7
|
end
|
8
8
|
|
9
9
|
context "saving a title" do
|
10
|
-
it "
|
11
|
-
@template.title('Kind of Blue').should
|
10
|
+
it "saves the title" do
|
11
|
+
@template.title('Kind of Blue').should eq('Kind of Blue')
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
15
|
context "displaying a title" do
|
16
16
|
it "uses the website name if title is empty" do
|
17
|
-
@template.title(:site => "Miles Davis").should
|
17
|
+
@template.title(:site => "Miles Davis").should eq("<title>Miles Davis</title>")
|
18
18
|
end
|
19
19
|
|
20
20
|
it "displays the title if no website was specified" do
|
21
21
|
save_basic_title
|
22
|
-
@template.title().should
|
22
|
+
@template.title().should eq('<title>Kind of Blue</title>')
|
23
23
|
end
|
24
24
|
|
25
25
|
it "uses website before page by default" do
|
26
26
|
save_basic_title
|
27
|
-
@template.title(:site => "Miles Davis", :separator => '|').should
|
27
|
+
@template.title(:site => "Miles Davis", :separator => '|').should eq("<title>Miles Davis | Kind of Blue</title>")
|
28
28
|
end
|
29
29
|
|
30
30
|
it "only uses markup in titles in the view" do
|
31
31
|
save_basic_title("<b>Kind of Blue</b>").should == "<b>Kind of Blue</b>"
|
32
|
-
@template.title(:site => "Miles Davis", :separator => '|').should
|
32
|
+
@template.title(:site => "Miles Davis", :separator => '|').should eq("<title>Miles Davis | Kind of Blue</title>")
|
33
33
|
end
|
34
34
|
|
35
35
|
it "uses page before website if :reverse" do
|
36
36
|
save_basic_title
|
37
|
-
@template.title(:site => "Miles Davis", :reverse => true, :separator => '|').should
|
37
|
+
@template.title(:site => "Miles Davis", :reverse => true, :separator => '|').should eq("<title>Kind of Blue | Miles Davis</title>")
|
38
38
|
end
|
39
39
|
|
40
40
|
it "uses website before page if :reverse and :reverse_on_default" do
|
41
|
-
@template.title(:site => "John Coltrane", :default => "My Favorite Things", :reverse => true, :reverse_on_default => false, :separator => '|').should
|
41
|
+
@template.title(:site => "John Coltrane", :default => "My Favorite Things", :reverse => true, :reverse_on_default => false, :separator => '|').should eq("<title>John Coltrane | My Favorite Things</title>")
|
42
42
|
end
|
43
43
|
|
44
44
|
it "lowercases the title if :lowercase" do
|
45
45
|
save_basic_title
|
46
|
-
@template.title(:site => "Miles Davis", :lowercase => true, :separator => '|').should
|
46
|
+
@template.title(:site => "Miles Davis", :lowercase => true, :separator => '|').should eq("<title>miles davis | kind of blue</title>")
|
47
47
|
end
|
48
48
|
|
49
49
|
it "uppercases the title if :uppercase" do
|
50
50
|
save_basic_title
|
51
|
-
@template.title(:site => "Miles Davis", :uppercase => true, :separator => '|').should
|
51
|
+
@template.title(:site => "Miles Davis", :uppercase => true, :separator => '|').should eq("<title>MILES DAVIS | KIND OF BLUE</title>")
|
52
52
|
end
|
53
53
|
|
54
54
|
it "uses a custom separator if :separator" do
|
55
55
|
save_basic_title
|
56
|
-
@template.title(:site => "Miles Davis", :separator => "-").should
|
57
|
-
@template.title(:site => "Miles Davis", :separator => ":").should
|
58
|
-
@template.title(:site => "Miles Davis", :separator => "—").should
|
56
|
+
@template.title(:site => "Miles Davis", :separator => "-").should eq("<title>Miles Davis - Kind of Blue</title>")
|
57
|
+
@template.title(:site => "Miles Davis", :separator => ":").should eq("<title>Miles Davis : Kind of Blue</title>")
|
58
|
+
@template.title(:site => "Miles Davis", :separator => "—").should eq("<title>Miles Davis &mdash; Kind of Blue</title>")
|
59
59
|
end
|
60
60
|
|
61
61
|
it "uses custom prefix and suffix if available" do
|
62
62
|
save_basic_title
|
63
|
-
@template.title(:site => "Miles Davis", :prefix => " |", :suffix => "| ", :separator => '|').should
|
63
|
+
@template.title(:site => "Miles Davis", :prefix => " |", :suffix => "| ", :separator => '|').should eq("<title>Miles Davis ||| Kind of Blue</title>")
|
64
64
|
end
|
65
65
|
|
66
66
|
it "collapses prefix if false" do
|
67
67
|
save_basic_title
|
68
|
-
@template.title(:site => "Miles Davis", :prefix => false, :separator => ":").should
|
68
|
+
@template.title(:site => "Miles Davis", :prefix => false, :separator => ":").should eq("<title>Miles Davis: Kind of Blue</title>")
|
69
69
|
end
|
70
70
|
|
71
71
|
it "collapses suffix if false" do
|
72
72
|
save_basic_title
|
73
|
-
@template.title(:site => "Miles Davis", :suffix => false, :separator => "~").should
|
73
|
+
@template.title(:site => "Miles Davis", :suffix => false, :separator => "~").should eq("<title>Miles Davis ~Kind of Blue</title>")
|
74
74
|
end
|
75
75
|
|
76
76
|
it "uses all custom options if available" do
|
77
77
|
save_basic_title
|
78
78
|
custom_options = { :site => "Miles Davis", :prefix => " ", :suffix => " ", :separator => "-", :lowercase => true, :reverse => true }
|
79
|
-
@template.title(custom_options).should
|
79
|
+
@template.title(custom_options).should eq("<title>kind of blue - miles davis</title>")
|
80
80
|
end
|
81
81
|
|
82
82
|
it "uses the default title if title is not present or blank" do
|
83
83
|
save_basic_title("")
|
84
|
-
@template.title(:site => "Miles Davis", :default => "Round About Midnight", :separator => '|').should
|
84
|
+
@template.title(:site => "Miles Davis", :default => "Round About Midnight", :separator => '|').should eq("<title>Miles Davis | Round About Midnight</title>")
|
85
85
|
end
|
86
86
|
|
87
87
|
it "allows custom options per title" do
|
88
88
|
save_custom_title
|
89
|
-
@template.title(:site => "Freddie Freeloader", :separator => '|').should
|
89
|
+
@template.title(:site => "Freddie Freeloader", :separator => '|').should eq("<title>Kind of Blue | Freddie Freeloader</title>")
|
90
90
|
end
|
91
91
|
|
92
92
|
it "accepts an array of strings as the title" do
|
93
93
|
@template.title(['My', 'Favorite', 'Things'])
|
94
|
-
@template.title(:site => "Freddie Freeloader", :separator => '|').should
|
94
|
+
@template.title(:site => "Freddie Freeloader", :separator => '|').should eq("<title>Freddie Freeloader | My | Favorite | Things</title>")
|
95
95
|
end
|
96
96
|
end
|
97
97
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tophat
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-09-28 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: actionpack
|
@@ -190,7 +190,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
190
190
|
version: '0'
|
191
191
|
segments:
|
192
192
|
- 0
|
193
|
-
hash: -
|
193
|
+
hash: -1469491919120880781
|
194
194
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
195
195
|
none: false
|
196
196
|
requirements:
|
@@ -199,7 +199,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
199
199
|
version: '0'
|
200
200
|
segments:
|
201
201
|
- 0
|
202
|
-
hash: -
|
202
|
+
hash: -1469491919120880781
|
203
203
|
requirements: []
|
204
204
|
rubyforge_project:
|
205
205
|
rubygems_version: 1.8.24
|