tophat 1.5.0 → 1.6.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/LICENSE.md +1 -1
- data/README.md +43 -6
- data/lib/tophat.rb +2 -4
- data/lib/tophat/html.rb +28 -0
- data/lib/tophat/opengraph.rb +48 -20
- data/lib/tophat/twitter_card.rb +55 -0
- data/lib/tophat/version.rb +1 -1
- data/spec/tophat/html_helper_spec.rb +35 -0
- data/spec/tophat/meta_helper_spec.rb +11 -11
- data/spec/tophat/opengraph_helper_spec.rb +55 -22
- data/spec/tophat/robots_helper_spec.rb +9 -9
- data/spec/tophat/stylesheet_helper_spec.rb +8 -8
- data/spec/tophat/title_helper_spec.rb +16 -16
- data/spec/tophat/twitter_card_helper_spec.rb +54 -0
- data/spec/tophat_spec.rb +8 -0
- metadata +24 -18
data/LICENSE.md
CHANGED
data/README.md
CHANGED
@@ -124,9 +124,9 @@ A lot of browsers are supported, check the code for the full listing.
|
|
124
124
|
|
125
125
|
TopHat can also generate Facebook OpenGraph tags. In your views, you can assign any number of attributes by passing a block to the opengraph helper. This will store the attributes for that page.
|
126
126
|
|
127
|
-
opengraph do
|
128
|
-
|
129
|
-
|
127
|
+
opengraph do
|
128
|
+
title 'Rain Man'
|
129
|
+
type 'Movie'
|
130
130
|
end
|
131
131
|
|
132
132
|
To embed OpenGraph tags on your page, you'll need to reference opengraph in your layout.
|
@@ -146,11 +146,48 @@ When used in combination, TopHat will render:
|
|
146
146
|
|
147
147
|
There's also a helper for the html tag along with the opengraph namespaces:
|
148
148
|
|
149
|
-
|
150
|
-
|
149
|
+
opengraph_html => <html xmlns:fb...>
|
151
150
|
|
152
151
|
Note: TopHat does not include a "Like" button helper. TopHat's focus is inside the `<head>` tag.
|
153
152
|
|
153
|
+
TopHat previously supported a different syntax for defining the opengraph which has been deprecated:
|
154
|
+
|
155
|
+
opengraph do |graph|
|
156
|
+
graph.title 'Rain Man'
|
157
|
+
graph.type 'Movie'
|
158
|
+
end
|
159
|
+
|
160
|
+
## Twitter Card Helpers
|
161
|
+
|
162
|
+
TopHat has support for [Twitter Cards](https://dev.twitter.com/docs/cards).
|
163
|
+
|
164
|
+
twitter_card('summary') do
|
165
|
+
url 'http://mysite.com/page'
|
166
|
+
title 'this is my page title'
|
167
|
+
description 'some interesting info about my page'
|
168
|
+
image 'http://mysite.com/animage.jpg'
|
169
|
+
end
|
170
|
+
|
171
|
+
You can nest attributes inside a twitter card:
|
172
|
+
|
173
|
+
twitter_card('player') do
|
174
|
+
player 'https://example.com/embed/a' do
|
175
|
+
height '251'
|
176
|
+
width '435'
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
Which will render a twitter card like so:
|
181
|
+
|
182
|
+
<meta name="twitter:card" value="player">
|
183
|
+
<meta name="twitter:player" value="https://example.com/embed/a">
|
184
|
+
<meta name="twitter:player:width" value="435">
|
185
|
+
<meta name="twitter:player:height" value="251">
|
186
|
+
|
187
|
+
To render the twitter card in your layout, simply call the twitter_card helper with no arguments:
|
188
|
+
|
189
|
+
<%= twitter_card %>
|
190
|
+
|
154
191
|
## <a name="build"></a>Build Status
|
155
192
|
[][travis]
|
156
193
|
|
@@ -173,4 +210,4 @@ Note: TopHat does not include a "Like" button helper. TopHat's focus is inside t
|
|
173
210
|
|
174
211
|
## Copyright
|
175
212
|
|
176
|
-
Copyright (c)
|
213
|
+
Copyright (c) 2012 Steve Agalloco. See [LICENSE](https://github.com/spagalloco/tophat/blob/master/LICENSE.md) for details.
|
data/lib/tophat.rb
CHANGED
data/lib/tophat/html.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
module TopHat
|
2
|
+
module HtmlHelper
|
3
|
+
|
4
|
+
def html_tag(options={})
|
5
|
+
output = '<html'
|
6
|
+
if options[:version]
|
7
|
+
output << " version=\"#{options[:version]}\""
|
8
|
+
end
|
9
|
+
if options[:xmlns]
|
10
|
+
if options[:xmlns].kind_of?(String)
|
11
|
+
output << " xmlns=\"#{options[:xmlns]}\""
|
12
|
+
elsif options[:xmlns].kind_of?(Array)
|
13
|
+
output = options[:xmlns].inject(output) do |html, xmlns|
|
14
|
+
if xmlns.kind_of?(Hash)
|
15
|
+
html << " xmlns:#{xmlns[:prefix]}=\"#{xmlns[:url]}\""
|
16
|
+
else
|
17
|
+
html << " xmlns=\"#{xmlns}\""
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
output << '>'
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
ActionView::Base.send :include, TopHat::HtmlHelper
|
data/lib/tophat/opengraph.rb
CHANGED
@@ -5,57 +5,77 @@ module TopHat
|
|
5
5
|
include ActionView::Helpers
|
6
6
|
|
7
7
|
def initialize(options={})
|
8
|
-
|
9
|
-
|
10
|
-
|
8
|
+
@app_id = options.delete(:app_id) if options && options.has_key?(:app_id)
|
9
|
+
@admins = options.delete(:admins) if options && options.has_key?(:admins)
|
10
|
+
@graph_data = {}
|
11
11
|
end
|
12
12
|
|
13
13
|
def merge(options={})
|
14
|
-
|
15
|
-
|
14
|
+
@app_id = options.delete(:app_id) if options && options.has_key?(:app_id)
|
15
|
+
@admins = options.delete(:admins) if options && options.has_key?(:admins)
|
16
16
|
end
|
17
17
|
|
18
18
|
def app_id
|
19
|
-
output =
|
19
|
+
output = @app_id ? tag(:meta, :property => 'fb:app_id', :content => @app_id) : ""
|
20
20
|
output << '\n' unless output.blank?
|
21
21
|
output
|
22
22
|
end
|
23
23
|
|
24
24
|
def admins
|
25
|
-
output =
|
25
|
+
output = @admins ? tag(:meta, :property => 'fb:admins', :content => [*@admins].join(',')) : ""
|
26
26
|
output << '\n' unless output.blank?
|
27
27
|
output
|
28
28
|
end
|
29
29
|
|
30
30
|
def render_graph_data
|
31
31
|
output = ""
|
32
|
-
|
32
|
+
@graph_data.each do |key, value|
|
33
33
|
output << tag(:meta, :property => "og:#{key}", :content => value)
|
34
|
-
output << '\n' if
|
34
|
+
output << '\n' if @graph_data.size > 1
|
35
35
|
end
|
36
36
|
output
|
37
37
|
end
|
38
38
|
|
39
39
|
def type(t)
|
40
|
-
|
41
|
-
|
40
|
+
@graph_data ||= {}
|
41
|
+
@graph_data[:type] = t
|
42
42
|
end
|
43
43
|
|
44
44
|
def has_graph_data?
|
45
|
-
|
45
|
+
!!@graph_data
|
46
46
|
end
|
47
47
|
|
48
48
|
def method_missing(method, *args, &block) #:nodoc
|
49
|
-
|
50
|
-
|
49
|
+
@graph_data ||= {}
|
50
|
+
@graph_data[method] = args.shift
|
51
51
|
end
|
52
52
|
|
53
53
|
end
|
54
54
|
|
55
|
-
|
56
|
-
'
|
57
|
-
|
58
|
-
|
55
|
+
HTML4_XMLNS = [
|
56
|
+
'http://www.w3.org/1999/xhtml',
|
57
|
+
{ :prefix => 'og', :url => 'http://ogp.me/ns#' },
|
58
|
+
{ :prefix => 'fb', :url => 'https://www.facebook.com/2008/fbml' }
|
59
|
+
]
|
60
|
+
|
61
|
+
HTML5_XMLNS = [
|
62
|
+
{ :prefix => 'og', :url => 'http://opengraphprotocol.org/schema/' },
|
63
|
+
{ :prefix => 'fb', :url => 'http://developers.facebook.com/schema/' }
|
64
|
+
]
|
65
|
+
|
66
|
+
def html_with_opengraph(style='html4')
|
67
|
+
Kernel.warn("html_with_opengraph has been deprecated, use opengraph_html instead.")
|
68
|
+
opengraph_html(style)
|
69
|
+
end
|
70
|
+
|
71
|
+
def opengraph_html(style='html4')
|
72
|
+
if style == 'html4'
|
73
|
+
html_tag(:xmlns => HTML4_XMLNS)
|
74
|
+
elsif style == 'html5'
|
75
|
+
html_tag(:version => 'HTML+RDFa 1.0', :xmlns => HTML5_XMLNS)
|
76
|
+
else
|
77
|
+
html_tag
|
78
|
+
end
|
59
79
|
end
|
60
80
|
|
61
81
|
def opengraph(options=nil, &block)
|
@@ -63,8 +83,16 @@ module TopHat
|
|
63
83
|
TopHat.current['open_graph_defaults'] = options
|
64
84
|
end
|
65
85
|
if block_given?
|
66
|
-
|
67
|
-
|
86
|
+
if block.arity == 1
|
87
|
+
Kernel.warn("passing the graph object into the opengraph method has been deprecated, see README for details.")
|
88
|
+
|
89
|
+
TopHat.current['open_graph_generator'] = OpenGraphGenerator.new(TopHat.current['open_graph_defaults'])
|
90
|
+
yield(TopHat.current['open_graph_generator'])
|
91
|
+
else
|
92
|
+
opengraph_generator = OpenGraphGenerator.new(TopHat.current['open_graph_defaults'])
|
93
|
+
opengraph_generator.instance_eval(&block)
|
94
|
+
TopHat.current['open_graph_generator'] = opengraph_generator
|
95
|
+
end
|
68
96
|
else
|
69
97
|
TopHat.current['open_graph_generator'] ||= OpenGraphGenerator.new
|
70
98
|
TopHat.current['open_graph_generator'].merge(TopHat.current['open_graph_defaults'])
|
@@ -0,0 +1,55 @@
|
|
1
|
+
module TopHat
|
2
|
+
module TwitterCardHelper
|
3
|
+
|
4
|
+
class TwitterCardGenerator
|
5
|
+
include ActionView::Helpers
|
6
|
+
|
7
|
+
attr_reader :card_data
|
8
|
+
|
9
|
+
def initialize(type)
|
10
|
+
@type = type
|
11
|
+
@card_data = {}
|
12
|
+
end
|
13
|
+
|
14
|
+
def render
|
15
|
+
output = ""
|
16
|
+
output << tag(:meta, :name => 'twitter:card', :value => @type)
|
17
|
+
@card_data.each do |key, value|
|
18
|
+
output << '\n'
|
19
|
+
output << tag(:meta, :name => "twitter:#{key}", :value => value)
|
20
|
+
end
|
21
|
+
output << '\n' unless @card_data.empty?
|
22
|
+
output
|
23
|
+
end
|
24
|
+
|
25
|
+
def add_nested_attributes(method, &block)
|
26
|
+
image_generator = TwitterCardGenerator.new(method)
|
27
|
+
image_generator.instance_eval(&block) if block_given?
|
28
|
+
image_generator.card_data.each do |key, value|
|
29
|
+
@card_data["#{method}:#{key}"] = value
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def method_missing(method, *args, &block) #:nodoc
|
34
|
+
@card_data ||= {}
|
35
|
+
@card_data[method] = args.shift
|
36
|
+
add_nested_attributes(method, &block) if block_given?
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def twitter_card(type=nil, &block)
|
41
|
+
if type.nil?
|
42
|
+
if TopHat.current['twitter_card']
|
43
|
+
TopHat.current['twitter_card'].render
|
44
|
+
end
|
45
|
+
else
|
46
|
+
card_generator = TwitterCardGenerator.new(type)
|
47
|
+
card_generator.instance_eval(&block) if block_given?
|
48
|
+
|
49
|
+
TopHat.current['twitter_card'] = card_generator
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
ActionView::Base.send :include, TopHat::TwitterCardHelper
|
data/lib/tophat/version.rb
CHANGED
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe TopHat::HtmlHelper do
|
4
|
+
before(:each) do
|
5
|
+
@template = ActionView::Base.new
|
6
|
+
end
|
7
|
+
|
8
|
+
describe 'html_tag' do
|
9
|
+
it 'returns a simple tag by default' do
|
10
|
+
@template.html_tag.should eq('<html>')
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'accepts a version in an options hash' do
|
14
|
+
output = @template.html_tag(:version => '123')
|
15
|
+
output.should eq('<html version="123">')
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'accepts xmlns in an options hash' do
|
19
|
+
output = @template.html_tag(:xmlns => 'http://someurl.com')
|
20
|
+
output.should eq('<html xmlns="http://someurl.com">')
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'accepts and array of xmlns in an options hash' do
|
24
|
+
output = @template.html_tag(:xmlns => ['http://someurl.com', 'http://otherurl.com'])
|
25
|
+
output.should eq('<html xmlns="http://someurl.com" xmlns="http://otherurl.com">')
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'accepts an array of xmlns including prefixes' do
|
29
|
+
xmlns = { :prefix => 'fb', :url => 'http://developers.facebook.com/schema/' }
|
30
|
+
output = @template.html_tag(:xmlns => [xmlns])
|
31
|
+
output.should eq('<html xmlns:fb="http://developers.facebook.com/schema/">')
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
@@ -12,11 +12,11 @@ describe TopHat::MetaHelper do
|
|
12
12
|
@keywords = %w{ John Paul George Ringo }
|
13
13
|
end
|
14
14
|
|
15
|
-
it "
|
15
|
+
it "saves keywords" do
|
16
16
|
@template.keywords(@keywords).should == @keywords.join(', ')
|
17
17
|
end
|
18
18
|
|
19
|
-
it "
|
19
|
+
it "uses default keywords if keywords is empty" do
|
20
20
|
@template.keywords(:default => @keywords).should == "<meta content=\"#{@keywords.join(', ')}\" name=\"keywords\" />"
|
21
21
|
end
|
22
22
|
end
|
@@ -26,45 +26,45 @@ describe TopHat::MetaHelper do
|
|
26
26
|
@keywords = "John, Paul, George, Ringo"
|
27
27
|
end
|
28
28
|
|
29
|
-
it "
|
29
|
+
it "saves keywords" do
|
30
30
|
@template.keywords(@keywords).should == @keywords
|
31
31
|
end
|
32
32
|
|
33
|
-
it "
|
33
|
+
it "uses default keywords passed as a string if keywords is empty" do
|
34
34
|
@template.keywords(:default => @keywords).should == "<meta content=\"#{@keywords}\" name=\"keywords\" />"
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
|
-
it "
|
38
|
+
it "return nil when no default is configured and no keywords are defined" do
|
39
39
|
@template.keywords.should be_nil
|
40
40
|
end
|
41
41
|
|
42
|
-
it "
|
42
|
+
it "returns nil when passed nil" do
|
43
43
|
@template.keywords(nil).should be_nil
|
44
44
|
end
|
45
45
|
|
46
|
-
it "
|
46
|
+
it "merges default tags with page tags, when merge_default is set to true" do
|
47
47
|
@template.keywords("Stu, Pete")
|
48
48
|
@template.keywords(:default => "John, Paul, George, Ringo", :merge_default => true).should == "<meta content=\"Stu, Pete, John, Paul, George, Ringo\" name=\"keywords\" />"
|
49
49
|
end
|
50
50
|
end
|
51
51
|
|
52
52
|
describe ".description" do
|
53
|
-
it "
|
53
|
+
it "saves the description" do
|
54
54
|
desc = "Cinderella story. Outta nowhere. A former greenskeeper, now, about to become the Masters champion."
|
55
55
|
@template.description(desc).should == desc
|
56
56
|
end
|
57
57
|
|
58
|
-
it "
|
58
|
+
it "uses the default description if no description is defined" do
|
59
59
|
desc = "A flute without holes, is not a flute. A donut without a hole, is a Danish."
|
60
60
|
@template.description(:default => desc).should == "<meta content=\"#{desc}\" name=\"description\" />"
|
61
61
|
end
|
62
62
|
|
63
|
-
it "
|
63
|
+
it "returns nil when passed nil" do
|
64
64
|
@template.description(nil).should be_nil
|
65
65
|
end
|
66
66
|
|
67
|
-
it "
|
67
|
+
it "returns nil when no default is configured and no description is defined" do
|
68
68
|
@template.description.should be_nil
|
69
69
|
end
|
70
70
|
end
|
@@ -6,24 +6,46 @@ describe TopHat::OpenGraphHelper do
|
|
6
6
|
@template = ActionView::Base.new
|
7
7
|
end
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
9
|
+
describe 'opengraph_html' do
|
10
|
+
context 'default style' do
|
11
|
+
it 'renders an html tag with namespace' do
|
12
|
+
output = @template.opengraph_html
|
13
|
+
output.should =~ /<html/
|
14
|
+
output.should =~ /xmlns\:og/
|
15
|
+
output.should =~ /xmlns\:fb/
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
context 'html5 style' do
|
20
|
+
it 'renders an html tag with namespace' do
|
21
|
+
output = @template.opengraph_html('html5')
|
22
|
+
output.should =~ /<html/
|
23
|
+
output.should =~ /xmlns\:og/
|
24
|
+
output.should =~ /xmlns\:fb/
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
context 'unknown style' do
|
29
|
+
it 'returns an empty html tag' do
|
30
|
+
@template.opengraph_html('funny').should eq('<html>')
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'it supports deprecated html_with_opengraph' do
|
35
|
+
@template.opengraph_html.should eq(@template.html_with_opengraph)
|
14
36
|
end
|
15
37
|
end
|
16
38
|
|
17
39
|
context "site admins when configured" do
|
18
40
|
context "as a string" do
|
19
|
-
it "
|
41
|
+
it "generates a site admin tag" do
|
20
42
|
@template.opengraph(:admins => '123,124')
|
21
43
|
@template.opengraph.should be_dom_equivalent_to('<meta content="123,124" property="fb:admins" />\n')
|
22
44
|
end
|
23
45
|
end
|
24
46
|
|
25
47
|
context "as an array" do
|
26
|
-
it "
|
48
|
+
it "generates a site admin tag" do
|
27
49
|
@template.opengraph(:admins => [123, 124])
|
28
50
|
@template.opengraph.should be_dom_equivalent_to('<meta content="123,124" property="fb:admins" />\n')
|
29
51
|
end
|
@@ -31,27 +53,27 @@ describe TopHat::OpenGraphHelper do
|
|
31
53
|
end
|
32
54
|
|
33
55
|
context "app_id when configured" do
|
34
|
-
it "
|
56
|
+
it "generates an app_id meta tag" do
|
35
57
|
@template.opengraph(:app_id => 'MyApp')
|
36
58
|
@template.opengraph.should be_dom_equivalent_to('<meta content="MyApp" property="fb:app_id" />\n')
|
37
59
|
end
|
38
60
|
end
|
39
61
|
|
40
62
|
context "additional open graph properties" do
|
41
|
-
it "
|
42
|
-
@template.opengraph {
|
63
|
+
it "generates opengraph meta tags" do
|
64
|
+
@template.opengraph { title 'The Great Gatsby' }
|
43
65
|
@template.opengraph.should be_dom_equivalent_to('<meta content="The Great Gatsby" property="og:title" />')
|
44
66
|
end
|
45
67
|
|
46
|
-
it "
|
47
|
-
@template.opengraph {
|
68
|
+
it "allows use of the tag 'type'" do
|
69
|
+
@template.opengraph { type 'sports_team' }
|
48
70
|
@template.opengraph.should be_dom_equivalent_to('<meta content="sports_team" property="og:type" />')
|
49
71
|
end
|
50
72
|
|
51
|
-
it "
|
52
|
-
@template.opengraph {
|
53
|
-
|
54
|
-
|
73
|
+
it "supports multiple tags" do
|
74
|
+
@template.opengraph {
|
75
|
+
title 'Austin Powers: International Man of Mystery'
|
76
|
+
type 'movie'
|
55
77
|
}
|
56
78
|
@template.opengraph.should be_dom_equivalent_to('<meta content="movie" property="og:type" />\n<meta content="Austin Powers: International Man of Mystery" property="og:title" />\n')
|
57
79
|
end
|
@@ -59,20 +81,31 @@ describe TopHat::OpenGraphHelper do
|
|
59
81
|
end
|
60
82
|
|
61
83
|
context "combined usage" do
|
62
|
-
it "
|
63
|
-
@template.opengraph(:app_id => 'MyApp', :admins => [123, 1234]) {
|
64
|
-
|
65
|
-
|
84
|
+
it "generates all tags when app_id and admins passed as part of definition" do
|
85
|
+
@template.opengraph(:app_id => 'MyApp', :admins => [123, 1234]) {
|
86
|
+
title 'Rain Man'
|
87
|
+
type 'movie'
|
66
88
|
}
|
67
89
|
@template.opengraph.should be_dom_equivalent_to('<meta content="MyApp" property="fb:app_id" />\n<meta content="123,1234" property="fb:admins" />\n<meta content="movie" property="og:type" />\n<meta content="Rain Man" property="og:title" />\n')
|
68
90
|
end
|
69
91
|
|
70
|
-
it "
|
92
|
+
it "generates all tags when app_id and admins passed as part of rendering" do
|
93
|
+
@template.opengraph {
|
94
|
+
title 'Rain Man'
|
95
|
+
type 'movie'
|
96
|
+
}
|
97
|
+
@template.opengraph(:app_id => 'MyApp', :admins => [123, 1234]).should be_dom_equivalent_to('<meta content="MyApp" property="fb:app_id" />\n<meta content="123,1234" property="fb:admins" />\n<meta content="movie" property="og:type" />\n<meta content="Rain Man" property="og:title" />\n')
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
context 'deprecated support' do
|
102
|
+
it 'generates multiple tags' do
|
71
103
|
@template.opengraph { |graph|
|
72
104
|
graph.title 'Rain Man'
|
73
105
|
graph.type 'movie'
|
74
106
|
}
|
75
|
-
|
107
|
+
|
108
|
+
@template.opengraph.should be_dom_equivalent_to('<meta content="movie" property="og:type" />\n<meta content="Rain Man" property="og:title" />\n')
|
76
109
|
end
|
77
110
|
end
|
78
111
|
|
@@ -7,43 +7,43 @@ describe TopHat::RobotsHelper do
|
|
7
7
|
end
|
8
8
|
|
9
9
|
describe ".nofollow" do
|
10
|
-
it "
|
10
|
+
it "defaults to all robots" do
|
11
11
|
@template.nofollow.should == "<meta content=\"nofollow\" name=\"robots\" />"
|
12
12
|
end
|
13
13
|
|
14
|
-
it "
|
14
|
+
it "uses a descriptor if one is provided" do
|
15
15
|
@template.nofollow('googlebot').should == "<meta content=\"nofollow\" name=\"googlebot\" />"
|
16
16
|
end
|
17
17
|
|
18
|
-
it "
|
18
|
+
it "generates a default tag when passed nil" do
|
19
19
|
@template.nofollow(nil).should == "<meta content=\"nofollow\" name=\"robots\" />"
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
23
|
describe ".noindex" do
|
24
|
-
it "
|
24
|
+
it "defaults to all robots" do
|
25
25
|
@template.noindex.should == "<meta content=\"noindex\" name=\"robots\" />"
|
26
26
|
end
|
27
27
|
|
28
|
-
it "
|
28
|
+
it "uses a descriptor if one is provided" do
|
29
29
|
@template.noindex('googlebot').should == "<meta content=\"noindex\" name=\"googlebot\" />"
|
30
30
|
end
|
31
31
|
|
32
|
-
it "
|
32
|
+
it "generates a default tag when passed nil" do
|
33
33
|
@template.noindex(nil).should == "<meta content=\"noindex\" name=\"robots\" />"
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
37
|
describe ".canonical" do
|
38
|
-
it "
|
38
|
+
it "returns nil when not passed a path" do
|
39
39
|
@template.canonical.should be_nil
|
40
40
|
end
|
41
41
|
|
42
|
-
it "
|
42
|
+
it "renders a tag when passed a path" do
|
43
43
|
@template.canonical('http://mysite.com/somepath/').should == "<link href=\"http://mysite.com/somepath/\" rel=\"canonical\" />"
|
44
44
|
end
|
45
45
|
|
46
|
-
it "
|
46
|
+
it "returns nil when passed nil" do
|
47
47
|
@template.canonical(nil).should be_nil
|
48
48
|
end
|
49
49
|
end
|
@@ -16,7 +16,7 @@ describe TopHat::StylesheetHelper do
|
|
16
16
|
@stylesheet = "ie.css"
|
17
17
|
end
|
18
18
|
|
19
|
-
it "
|
19
|
+
it "defines IE conditionals" do
|
20
20
|
@template.ie_5_conditional {
|
21
21
|
@template.stylesheet_link_tag(@stylesheet)
|
22
22
|
}.should == "<!--[if IE 5]>\n<link href=\"/stylesheets/ie.css\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />\n<![endif]-->"
|
@@ -42,7 +42,7 @@ describe TopHat::StylesheetHelper do
|
|
42
42
|
}.should == "<!--[if IE 9]>\n<link href=\"/stylesheets/ie.css\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />\n<![endif]-->"
|
43
43
|
end
|
44
44
|
|
45
|
-
it "
|
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
48
|
}.should == "<!--[if gt IE 5]>\n<link href=\"/stylesheets/ie.css\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />\n<![endif]-->"
|
@@ -52,7 +52,7 @@ describe TopHat::StylesheetHelper do
|
|
52
52
|
}.should == "<!--[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
|
-
it "
|
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
58
|
}.should == "<!--[if gte IE 5]>\n<link href=\"/stylesheets/ie.css\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />\n<![endif]-->"
|
@@ -62,7 +62,7 @@ describe TopHat::StylesheetHelper do
|
|
62
62
|
}.should == "<!--[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
|
-
it "
|
65
|
+
it "renders defined IE conditional with ! operator" do
|
66
66
|
@template.ie_5_conditional(:not) {
|
67
67
|
@template.stylesheet_link_tag(@stylesheet)
|
68
68
|
}.should == "<!--[if !IE 5]>\n<link href=\"/stylesheets/ie.css\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />\n<![endif]-->"
|
@@ -72,7 +72,7 @@ describe TopHat::StylesheetHelper do
|
|
72
72
|
}.should == "<!--[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
|
-
it "
|
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
78
|
}.should == "<!--[if lt IE 5]>\n<link href=\"/stylesheets/ie.css\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />\n<![endif]-->"
|
@@ -82,7 +82,7 @@ describe TopHat::StylesheetHelper do
|
|
82
82
|
}.should == "<!--[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
|
-
it "
|
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
88
|
}.should == "<!--[if lte IE 5]>\n<link href=\"/stylesheets/ie.css\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />\n<![endif]-->"
|
@@ -92,7 +92,7 @@ describe TopHat::StylesheetHelper do
|
|
92
92
|
}.should == "<!--[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
|
-
it "
|
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
98
|
}.should == "<!--[if eq IE 5]>\n<link href=\"/stylesheets/ie.css\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />\n<![endif]-->"
|
@@ -102,7 +102,7 @@ describe TopHat::StylesheetHelper do
|
|
102
102
|
}.should == "<!--[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
|
-
it "
|
105
|
+
it "renders defined conditionals for other browsers" do
|
106
106
|
@template.opera_conditional {
|
107
107
|
@template.stylesheet_link_tag(@stylesheet)
|
108
108
|
}.should == "<!--[if Opera]>\n<link href=\"/stylesheets/ie.css\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />\n<![endif]-->"
|
@@ -13,83 +13,83 @@ describe TopHat::TitleHelper do
|
|
13
13
|
end
|
14
14
|
|
15
15
|
context "displaying a title" do
|
16
|
-
it "
|
16
|
+
it "uses the website name if title is empty" do
|
17
17
|
@template.title(:site => "Miles Davis").should == "<title>Miles Davis</title>"
|
18
18
|
end
|
19
19
|
|
20
|
-
it "
|
20
|
+
it "displays the title if no website was specified" do
|
21
21
|
save_basic_title
|
22
22
|
@template.title().should == '<title>Kind of Blue</title>'
|
23
23
|
end
|
24
24
|
|
25
|
-
it "
|
25
|
+
it "uses website before page by default" do
|
26
26
|
save_basic_title
|
27
27
|
@template.title(:site => "Miles Davis", :separator => '|').should == "<title>Miles Davis | Kind of Blue</title>"
|
28
28
|
end
|
29
29
|
|
30
|
-
it "
|
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
32
|
@template.title(:site => "Miles Davis", :separator => '|').should == "<title>Miles Davis | Kind of Blue</title>"
|
33
33
|
end
|
34
34
|
|
35
|
-
it "
|
35
|
+
it "uses page before website if :reverse" do
|
36
36
|
save_basic_title
|
37
37
|
@template.title(:site => "Miles Davis", :reverse => true, :separator => '|').should == "<title>Kind of Blue | Miles Davis</title>"
|
38
38
|
end
|
39
39
|
|
40
|
-
it "
|
40
|
+
it "uses website before page if :reverse and :reverse_on_default" do
|
41
41
|
@template.title(:site => "John Coltrane", :default => "My Favorite Things", :reverse => true, :reverse_on_default => false, :separator => '|').should == "<title>John Coltrane | My Favorite Things</title>"
|
42
42
|
end
|
43
43
|
|
44
|
-
it "
|
44
|
+
it "lowercases the title if :lowercase" do
|
45
45
|
save_basic_title
|
46
46
|
@template.title(:site => "Miles Davis", :lowercase => true, :separator => '|').should == "<title>miles davis | kind of blue</title>"
|
47
47
|
end
|
48
48
|
|
49
|
-
it "
|
49
|
+
it "uppercases the title if :uppercase" do
|
50
50
|
save_basic_title
|
51
51
|
@template.title(:site => "Miles Davis", :uppercase => true, :separator => '|').should == "<title>MILES DAVIS | KIND OF BLUE</title>"
|
52
52
|
end
|
53
53
|
|
54
|
-
it "
|
54
|
+
it "uses a custom separator if :separator" do
|
55
55
|
save_basic_title
|
56
56
|
@template.title(:site => "Miles Davis", :separator => "-").should == "<title>Miles Davis - Kind of Blue</title>"
|
57
57
|
@template.title(:site => "Miles Davis", :separator => ":").should == "<title>Miles Davis : Kind of Blue</title>"
|
58
58
|
@template.title(:site => "Miles Davis", :separator => "—").should == "<title>Miles Davis &mdash; Kind of Blue</title>"
|
59
59
|
end
|
60
60
|
|
61
|
-
it "
|
61
|
+
it "uses custom prefix and suffix if available" do
|
62
62
|
save_basic_title
|
63
63
|
@template.title(:site => "Miles Davis", :prefix => " |", :suffix => "| ", :separator => '|').should == "<title>Miles Davis ||| Kind of Blue</title>"
|
64
64
|
end
|
65
65
|
|
66
|
-
it "
|
66
|
+
it "collapses prefix if false" do
|
67
67
|
save_basic_title
|
68
68
|
@template.title(:site => "Miles Davis", :prefix => false, :separator => ":").should == "<title>Miles Davis: Kind of Blue</title>"
|
69
69
|
end
|
70
70
|
|
71
|
-
it "
|
71
|
+
it "collapses suffix if false" do
|
72
72
|
save_basic_title
|
73
73
|
@template.title(:site => "Miles Davis", :suffix => false, :separator => "~").should == "<title>Miles Davis ~Kind of Blue</title>"
|
74
74
|
end
|
75
75
|
|
76
|
-
it "
|
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
79
|
@template.title(custom_options).should == "<title>kind of blue - miles davis</title>"
|
80
80
|
end
|
81
81
|
|
82
|
-
it "
|
82
|
+
it "uses the default title if title is not present or blank" do
|
83
83
|
save_basic_title("")
|
84
84
|
@template.title(:site => "Miles Davis", :default => "Round About Midnight", :separator => '|').should == "<title>Miles Davis | Round About Midnight</title>"
|
85
85
|
end
|
86
86
|
|
87
|
-
it "
|
87
|
+
it "allows custom options per title" do
|
88
88
|
save_custom_title
|
89
89
|
@template.title(:site => "Freddie Freeloader", :separator => '|').should == "<title>Kind of Blue | Freddie Freeloader</title>"
|
90
90
|
end
|
91
91
|
|
92
|
-
it "
|
92
|
+
it "accepts an array of strings as the title" do
|
93
93
|
@template.title(['My', 'Favorite', 'Things'])
|
94
94
|
@template.title(:site => "Freddie Freeloader", :separator => '|').should == "<title>Freddie Freeloader | My | Favorite | Things</title>"
|
95
95
|
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe TopHat::TwitterCardHelper do
|
4
|
+
|
5
|
+
before(:each) do
|
6
|
+
@template = ActionView::Base.new
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'generates a twitter:card meta tag' do
|
10
|
+
@template.twitter_card('summary')
|
11
|
+
output = @template.twitter_card
|
12
|
+
output.should eq('<meta name="twitter:card" value="summary" />')
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'generates twitter:card meta tags' do
|
16
|
+
@template.twitter_card('summary') do
|
17
|
+
url 'http://someurl.com'
|
18
|
+
title 'a title'
|
19
|
+
description 'blah blah'
|
20
|
+
image 'http://someurl.com/animage.jpg'
|
21
|
+
end
|
22
|
+
|
23
|
+
output = @template.twitter_card
|
24
|
+
output.should include('twitter:title')
|
25
|
+
output.should include('twitter:url')
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'generates nested twitter:card meta tags' do
|
29
|
+
@template.twitter_card('player') do
|
30
|
+
image 'http://someurl.com/image.jpg' do
|
31
|
+
height '123'
|
32
|
+
width '456'
|
33
|
+
end
|
34
|
+
end
|
35
|
+
output = @template.twitter_card
|
36
|
+
output.should include('twitter:image')
|
37
|
+
output.should include('twitter:image:height')
|
38
|
+
output.should include('twitter:image:width')
|
39
|
+
end
|
40
|
+
|
41
|
+
|
42
|
+
it 'generates multiple nested twitter:card meta tags' do
|
43
|
+
@template.twitter_card('player') do
|
44
|
+
player 'https://example.com/embed/a' do
|
45
|
+
stream 'http://example.com/raw-stream/a.mp4' do
|
46
|
+
content_type '123'
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
output = @template.twitter_card
|
51
|
+
output.should include('twitter:player:stream:content_type')
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
data/spec/tophat_spec.rb
CHANGED
@@ -68,6 +68,14 @@ describe TopHat do
|
|
68
68
|
it "should respond to the 'canonical' helper" do
|
69
69
|
@template.respond_to?(:canonical).should be_true
|
70
70
|
end
|
71
|
+
|
72
|
+
it "should respond to the 'twitter_card' helper" do
|
73
|
+
@template.respond_to?(:twitter_card).should be_true
|
74
|
+
end
|
75
|
+
|
76
|
+
it "should respond to the 'html_tag' helper" do
|
77
|
+
@template.respond_to?(:html_tag).should be_true
|
78
|
+
end
|
71
79
|
end
|
72
80
|
|
73
81
|
describe '.current' do
|
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: 1.
|
4
|
+
version: 1.6.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-06-
|
12
|
+
date: 2012-06-18 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: actionpack
|
16
|
-
requirement: &
|
16
|
+
requirement: &70176171567820 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 3.0.0
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70176171567820
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rake
|
27
|
-
requirement: &
|
27
|
+
requirement: &70176171565740 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0.9'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70176171565740
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rspec
|
38
|
-
requirement: &
|
38
|
+
requirement: &70176171564300 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ~>
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '2.7'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70176171564300
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: yard
|
49
|
-
requirement: &
|
49
|
+
requirement: &70176171563140 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ~>
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '0.7'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70176171563140
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: rdiscount
|
60
|
-
requirement: &
|
60
|
+
requirement: &70176171559300 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ~>
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: '1.6'
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *70176171559300
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: simplecov
|
71
|
-
requirement: &
|
71
|
+
requirement: &70176171558300 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ~>
|
@@ -76,10 +76,10 @@ dependencies:
|
|
76
76
|
version: '0.5'
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *70176171558300
|
80
80
|
- !ruby/object:Gem::Dependency
|
81
81
|
name: rails
|
82
|
-
requirement: &
|
82
|
+
requirement: &70176171557480 !ruby/object:Gem::Requirement
|
83
83
|
none: false
|
84
84
|
requirements:
|
85
85
|
- - ! '>='
|
@@ -87,10 +87,10 @@ dependencies:
|
|
87
87
|
version: 3.0.0
|
88
88
|
type: :development
|
89
89
|
prerelease: false
|
90
|
-
version_requirements: *
|
90
|
+
version_requirements: *70176171557480
|
91
91
|
- !ruby/object:Gem::Dependency
|
92
92
|
name: guard-rspec
|
93
|
-
requirement: &
|
93
|
+
requirement: &70176171556620 !ruby/object:Gem::Requirement
|
94
94
|
none: false
|
95
95
|
requirements:
|
96
96
|
- - ~>
|
@@ -98,7 +98,7 @@ dependencies:
|
|
98
98
|
version: '0.5'
|
99
99
|
type: :development
|
100
100
|
prerelease: false
|
101
|
-
version_requirements: *
|
101
|
+
version_requirements: *70176171556620
|
102
102
|
description: Simple view helpers for your layouts
|
103
103
|
email:
|
104
104
|
- steve.agalloco@gmail.com
|
@@ -116,18 +116,22 @@ files:
|
|
116
116
|
- README.md
|
117
117
|
- Rakefile
|
118
118
|
- lib/tophat.rb
|
119
|
+
- lib/tophat/html.rb
|
119
120
|
- lib/tophat/meta.rb
|
120
121
|
- lib/tophat/opengraph.rb
|
121
122
|
- lib/tophat/robots.rb
|
122
123
|
- lib/tophat/stylesheet.rb
|
123
124
|
- lib/tophat/title.rb
|
125
|
+
- lib/tophat/twitter_card.rb
|
124
126
|
- lib/tophat/version.rb
|
125
127
|
- spec/spec_helper.rb
|
128
|
+
- spec/tophat/html_helper_spec.rb
|
126
129
|
- spec/tophat/meta_helper_spec.rb
|
127
130
|
- spec/tophat/opengraph_helper_spec.rb
|
128
131
|
- spec/tophat/robots_helper_spec.rb
|
129
132
|
- spec/tophat/stylesheet_helper_spec.rb
|
130
133
|
- spec/tophat/title_helper_spec.rb
|
134
|
+
- spec/tophat/twitter_card_helper_spec.rb
|
131
135
|
- spec/tophat_spec.rb
|
132
136
|
- tophat.gemspec
|
133
137
|
homepage: https://github.com/spagalloco/tophat
|
@@ -156,10 +160,12 @@ specification_version: 3
|
|
156
160
|
summary: Simple view helpers for your layouts
|
157
161
|
test_files:
|
158
162
|
- spec/spec_helper.rb
|
163
|
+
- spec/tophat/html_helper_spec.rb
|
159
164
|
- spec/tophat/meta_helper_spec.rb
|
160
165
|
- spec/tophat/opengraph_helper_spec.rb
|
161
166
|
- spec/tophat/robots_helper_spec.rb
|
162
167
|
- spec/tophat/stylesheet_helper_spec.rb
|
163
168
|
- spec/tophat/title_helper_spec.rb
|
169
|
+
- spec/tophat/twitter_card_helper_spec.rb
|
164
170
|
- spec/tophat_spec.rb
|
165
171
|
has_rdoc:
|