tophat 1.2.0 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +3 -21
- data/.rspec +3 -0
- data/Gemfile +2 -0
- data/LICENSE +1 -1
- data/README.md +100 -0
- data/Rakefile +18 -58
- data/lib/tophat/meta.rb +16 -25
- data/lib/tophat/opengraph.rb +11 -12
- data/lib/tophat/robots.rb +4 -6
- data/lib/tophat/stylesheet.rb +32 -28
- data/lib/tophat/title.rb +64 -68
- data/lib/tophat/version.rb +1 -1
- data/lib/tophat.rb +0 -4
- data/spec/spec_helper.rb +43 -0
- data/spec/tophat/meta_helper_spec.rb +64 -0
- data/spec/tophat/opengraph_helper_spec.rb +71 -0
- data/spec/tophat/robots_helper_spec.rb +39 -0
- data/spec/tophat/stylesheet_helper_spec.rb +148 -0
- data/spec/tophat/title_helper_spec.rb +96 -0
- data/spec/tophat_spec.rb +73 -0
- data/tophat.gemspec +23 -65
- metadata +108 -49
- data/README.textile +0 -123
- data/rails/init.rb +0 -1
- data/test/helper.rb +0 -9
- data/test/test_opengraph.rb +0 -88
- data/test/test_robots.rb +0 -54
- data/test/test_tophat.rb +0 -55
- data/test/test_tophat_meta.rb +0 -76
- data/test/test_tophat_stylesheets.rb +0 -119
- data/test/test_tophat_title.rb +0 -103
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'simplecov'
|
2
|
+
SimpleCov.start do
|
3
|
+
add_group 'TopHat', 'lib/tophat'
|
4
|
+
add_group 'Specs', 'spec'
|
5
|
+
end
|
6
|
+
|
7
|
+
require File.expand_path('../../lib/tophat', __FILE__)
|
8
|
+
|
9
|
+
require 'rspec'
|
10
|
+
require 'rails/all'
|
11
|
+
|
12
|
+
require 'action_controller/vendor/html-scanner'
|
13
|
+
|
14
|
+
module HTML
|
15
|
+
class Node
|
16
|
+
def ==(node)
|
17
|
+
return false unless self.class == node.class && children.size == node.children.size
|
18
|
+
|
19
|
+
equivalent = true
|
20
|
+
|
21
|
+
children.size.times do |i|
|
22
|
+
equivalent &&= children.include?(node.children[i])
|
23
|
+
end
|
24
|
+
|
25
|
+
equivalent
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
RSpec::Matchers.define :be_dom_equivalent_to do |expected|
|
31
|
+
match do |actual|
|
32
|
+
expected_dom = HTML::Document.new(expected).root
|
33
|
+
actual_dom = HTML::Document.new(actual).root
|
34
|
+
|
35
|
+
expected_dom == actual_dom
|
36
|
+
end
|
37
|
+
|
38
|
+
failure_message_for_should do |actual|
|
39
|
+
"expected #{actual} would be dom equivalent to #{expected}"
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe TopHat::MetaHelper do
|
4
|
+
|
5
|
+
before(:each) do
|
6
|
+
@template = ActionView::Base.new
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "keywords" do
|
10
|
+
context "defined as an array" do
|
11
|
+
before do
|
12
|
+
@keywords = %w{ John Paul George Ringo }
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should save keywords" do
|
16
|
+
@template.keywords(@keywords).should == @keywords.join(', ')
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should use default keywords if keywords is empty" do
|
20
|
+
@template.keywords(:default => @keywords).should == "<meta content=\"#{@keywords.join(', ')}\" name=\"keywords\" />"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
context "defined as a string" do
|
25
|
+
before do
|
26
|
+
@keywords = "John, Paul, George, Ringo"
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should save keywords" do
|
30
|
+
@template.keywords(@keywords).should == @keywords
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should use default keywords passed as a string if keywords is empty" do
|
34
|
+
@template.keywords(:default => @keywords).should == "<meta content=\"#{@keywords}\" name=\"keywords\" />"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should not return a tag if no default is configured and no keywords are defined" do
|
39
|
+
@template.keywords.should be_nil
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should merge default tags with page tags, when merge_default is set to true" do
|
43
|
+
@template.keywords("Stu, Pete")
|
44
|
+
@template.keywords(:default => "John, Paul, George, Ringo", :merge_default => true).should == "<meta content=\"Stu, Pete, John, Paul, George, Ringo\" name=\"keywords\" />"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
describe ".description" do
|
49
|
+
it "should save the description" do
|
50
|
+
desc = "Cinderella story. Outta nowhere. A former greenskeeper, now, about to become the Masters champion."
|
51
|
+
@template.description(desc).should == desc
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should use the default description if no description is defined" do
|
55
|
+
desc = "A flute without holes, is not a flute. A donut without a hole, is a Danish."
|
56
|
+
@template.description(:default => desc).should == "<meta content=\"#{desc}\" name=\"description\" />"
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should not return a tag if no default is configured and no description is defined" do
|
60
|
+
@template.description.should be_nil
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe TopHat::OpenGraphHelper do
|
4
|
+
|
5
|
+
before(:each) do
|
6
|
+
@template = ActionView::Base.new
|
7
|
+
end
|
8
|
+
|
9
|
+
context "site admins when configured" do
|
10
|
+
context "as a string" do
|
11
|
+
it "should generate a site admin tag" do
|
12
|
+
@template.opengraph(:admins => '123,124')
|
13
|
+
@template.opengraph.should be_dom_equivalent_to('<meta content="123,124" property="fb:admins" />\n')
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
context "as an array" do
|
18
|
+
it "should generate a site admin tag" do
|
19
|
+
@template.opengraph(:admins => [123, 124])
|
20
|
+
@template.opengraph.should be_dom_equivalent_to('<meta content="123,124" property="fb:admins" />\n')
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
context "app_id when configured" do
|
26
|
+
it "should generate an app_id meta tag" do
|
27
|
+
@template.opengraph(:app_id => 'MyApp')
|
28
|
+
@template.opengraph.should be_dom_equivalent_to('<meta content="MyApp" property="fb:app_id" />\n')
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
context "additional open graph properties" do
|
33
|
+
it "should generate tags" do
|
34
|
+
@template.opengraph { |graph| graph.title 'The Great Gatsby' }
|
35
|
+
@template.opengraph.should be_dom_equivalent_to('<meta content="The Great Gatsby" property="og:title" />')
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should allow use of the tag 'type'" do
|
39
|
+
@template.opengraph { |graph| graph.type 'sports_team' }
|
40
|
+
@template.opengraph.should be_dom_equivalent_to('<meta content="sports_team" property="og:type" />')
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should support multiple tags" do
|
44
|
+
@template.opengraph { |graph|
|
45
|
+
graph.title 'Austin Powers: International Man of Mystery'
|
46
|
+
graph.type 'movie'
|
47
|
+
}
|
48
|
+
@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')
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
context "combined usage" do
|
54
|
+
it "should generate all tags" do
|
55
|
+
@template.opengraph(:app_id => 'MyApp', :admins => [123, 1234]) { |graph|
|
56
|
+
graph.title 'Rain Man'
|
57
|
+
graph.type 'movie'
|
58
|
+
}
|
59
|
+
@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')
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should generate all tags - alternative usage" do
|
63
|
+
@template.opengraph { |graph|
|
64
|
+
graph.title 'Rain Man'
|
65
|
+
graph.type 'movie'
|
66
|
+
}
|
67
|
+
@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')
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe TopHat::RobotsHelper do
|
4
|
+
|
5
|
+
before(:all) do
|
6
|
+
@template = ActionView::Base.new
|
7
|
+
end
|
8
|
+
|
9
|
+
describe ".nofollow" do
|
10
|
+
it "should default to all robots" do
|
11
|
+
@template.nofollow.should == "<meta content=\"nofollow\" name=\"robots\" />"
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should use a descriptor if one is provided" do
|
15
|
+
@template.nofollow('googlebot').should == "<meta content=\"nofollow\" name=\"googlebot\" />"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe ".noindex" do
|
20
|
+
it "should default to all robots" do
|
21
|
+
@template.noindex.should == "<meta content=\"noindex\" name=\"robots\" />"
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should use a descriptor if one is provided" do
|
25
|
+
@template.noindex('googlebot').should == "<meta content=\"noindex\" name=\"googlebot\" />"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe ".canonical" do
|
30
|
+
it "should not render when not passed a path" do
|
31
|
+
@template.canonical.should be_nil
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should render a tag when passed a path" do
|
35
|
+
@template.canonical('http://mysite.com/somepath/').should == "<link href=\"http://mysite.com/somepath/\" rel=\"canonical\" />"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
@@ -0,0 +1,148 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe TopHat::StylesheetHelper do
|
4
|
+
|
5
|
+
before(:each) do
|
6
|
+
ENV["RAILS_ASSET_ID"] = ''
|
7
|
+
public_dir = File.join(File.dirname(__FILE__), 'public')
|
8
|
+
@helpers = ActionController::Base.helpers
|
9
|
+
@helpers.config.perform_caching = false
|
10
|
+
@helpers.config.assets_dir = public_dir
|
11
|
+
@helpers.config.javascripts_dir = "#{public_dir}/javascripts"
|
12
|
+
@helpers.config.stylesheets_dir = "#{public_dir}/stylesheets"
|
13
|
+
|
14
|
+
@template = ActionView::Base.new
|
15
|
+
|
16
|
+
@stylesheet = "ie.css"
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should define IE conditionals" do
|
20
|
+
@template.ie_5_conditional {
|
21
|
+
@template.stylesheet_link_tag(@stylesheet)
|
22
|
+
}.should == "<!--[if IE 5]>\n<link href=\"/stylesheets/ie.css\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />\n<![endif]-->"
|
23
|
+
|
24
|
+
@template.ie_5_5_conditional {
|
25
|
+
@template.stylesheet_link_tag(@stylesheet)
|
26
|
+
}.should == "<!--[if IE 5.5]>\n<link href=\"/stylesheets/ie.css\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />\n<![endif]-->"
|
27
|
+
|
28
|
+
@template.ie_6_conditional {
|
29
|
+
@template.stylesheet_link_tag(@stylesheet)
|
30
|
+
}.should == "<!--[if IE 6]>\n<link href=\"/stylesheets/ie.css\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />\n<![endif]-->"
|
31
|
+
|
32
|
+
@template.ie_7_conditional {
|
33
|
+
@template.stylesheet_link_tag(@stylesheet)
|
34
|
+
}.should == "<!--[if IE 7]>\n<link href=\"/stylesheets/ie.css\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />\n<![endif]-->"
|
35
|
+
|
36
|
+
@template.ie_8_conditional {
|
37
|
+
@template.stylesheet_link_tag(@stylesheet)
|
38
|
+
}.should == "<!--[if IE 8]>\n<link href=\"/stylesheets/ie.css\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />\n<![endif]-->"
|
39
|
+
|
40
|
+
@template.ie_9_conditional {
|
41
|
+
@template.stylesheet_link_tag(@stylesheet)
|
42
|
+
}.should == "<!--[if IE 9]>\n<link href=\"/stylesheets/ie.css\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />\n<![endif]-->"
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should render defined IE conditional with greater than operator" do
|
46
|
+
@template.ie_5_conditional(:gt) {
|
47
|
+
@template.stylesheet_link_tag(@stylesheet)
|
48
|
+
}.should == "<!--[if gt IE 5]>\n<link href=\"/stylesheets/ie.css\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />\n<![endif]-->"
|
49
|
+
|
50
|
+
@template.ie_5_5_conditional(:gt) {
|
51
|
+
@template.stylesheet_link_tag(@stylesheet)
|
52
|
+
}.should == "<!--[if gt IE 5.5]>\n<link href=\"/stylesheets/ie.css\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />\n<![endif]-->"
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should render defined IE conditional with greater than or equal to operator" do
|
56
|
+
@template.ie_5_conditional(:gte) {
|
57
|
+
@template.stylesheet_link_tag(@stylesheet)
|
58
|
+
}.should == "<!--[if gte IE 5]>\n<link href=\"/stylesheets/ie.css\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />\n<![endif]-->"
|
59
|
+
|
60
|
+
@template.ie_5_5_conditional(:gte) {
|
61
|
+
@template.stylesheet_link_tag(@stylesheet)
|
62
|
+
}.should == "<!--[if gte IE 5.5]>\n<link href=\"/stylesheets/ie.css\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />\n<![endif]-->"
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should render defined IE conditional with ! operator" do
|
66
|
+
@template.ie_5_conditional(:not) {
|
67
|
+
@template.stylesheet_link_tag(@stylesheet)
|
68
|
+
}.should == "<!--[if !IE 5]>\n<link href=\"/stylesheets/ie.css\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />\n<![endif]-->"
|
69
|
+
|
70
|
+
@template.ie_5_5_conditional(:not) {
|
71
|
+
@template.stylesheet_link_tag(@stylesheet)
|
72
|
+
}.should == "<!--[if !IE 5.5]>\n<link href=\"/stylesheets/ie.css\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />\n<![endif]-->"
|
73
|
+
end
|
74
|
+
|
75
|
+
it "should render defined IE conditional with less than operator" do
|
76
|
+
@template.ie_5_conditional(:lt) {
|
77
|
+
@template.stylesheet_link_tag(@stylesheet)
|
78
|
+
}.should == "<!--[if lt IE 5]>\n<link href=\"/stylesheets/ie.css\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />\n<![endif]-->"
|
79
|
+
|
80
|
+
@template.ie_5_5_conditional(:lt) {
|
81
|
+
@template.stylesheet_link_tag(@stylesheet)
|
82
|
+
}.should == "<!--[if lt IE 5.5]>\n<link href=\"/stylesheets/ie.css\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />\n<![endif]-->"
|
83
|
+
end
|
84
|
+
|
85
|
+
it "should render defined IE conditional with less than or equal to operator" do
|
86
|
+
@template.ie_5_conditional(:lte) {
|
87
|
+
@template.stylesheet_link_tag(@stylesheet)
|
88
|
+
}.should == "<!--[if lte IE 5]>\n<link href=\"/stylesheets/ie.css\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />\n<![endif]-->"
|
89
|
+
|
90
|
+
@template.ie_5_5_conditional(:lte) {
|
91
|
+
@template.stylesheet_link_tag(@stylesheet)
|
92
|
+
}.should == "<!--[if lte IE 5.5]>\n<link href=\"/stylesheets/ie.css\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />\n<![endif]-->"
|
93
|
+
end
|
94
|
+
|
95
|
+
it "should render defined IE conditional with equal to operator" do
|
96
|
+
@template.ie_5_conditional(:eq) {
|
97
|
+
@template.stylesheet_link_tag(@stylesheet)
|
98
|
+
}.should == "<!--[if eq IE 5]>\n<link href=\"/stylesheets/ie.css\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />\n<![endif]-->"
|
99
|
+
|
100
|
+
@template.ie_5_5_conditional(:eq) {
|
101
|
+
@template.stylesheet_link_tag(@stylesheet)
|
102
|
+
}.should == "<!--[if eq IE 5.5]>\n<link href=\"/stylesheets/ie.css\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />\n<![endif]-->"
|
103
|
+
end
|
104
|
+
|
105
|
+
it "should render defined conditionals for other browsers" do
|
106
|
+
@template.opera_conditional {
|
107
|
+
@template.stylesheet_link_tag(@stylesheet)
|
108
|
+
}.should == "<!--[if Opera]>\n<link href=\"/stylesheets/ie.css\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />\n<![endif]-->"
|
109
|
+
|
110
|
+
@template.webkit_conditional {
|
111
|
+
@template.stylesheet_link_tag(@stylesheet)
|
112
|
+
}.should == "<!--[if Webkit]>\n<link href=\"/stylesheets/ie.css\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />\n<![endif]-->"
|
113
|
+
|
114
|
+
@template.webkit_conditional(:eq) {
|
115
|
+
@template.stylesheet_link_tag(@stylesheet)
|
116
|
+
}.should == "<!--[if eq Webkit]>\n<link href=\"/stylesheets/ie.css\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />\n<![endif]-->"
|
117
|
+
|
118
|
+
@template.gecko_conditional {
|
119
|
+
@template.stylesheet_link_tag(@stylesheet)
|
120
|
+
}.should == "<!--[if Gecko]>\n<link href=\"/stylesheets/ie.css\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />\n<![endif]-->"
|
121
|
+
|
122
|
+
@template.ie_mac_conditional {
|
123
|
+
@template.stylesheet_link_tag(@stylesheet)
|
124
|
+
}.should == "<!--[if IEMac]>\n<link href=\"/stylesheets/ie.css\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />\n<![endif]-->"
|
125
|
+
|
126
|
+
@template.konqueror_conditional {
|
127
|
+
@template.stylesheet_link_tag(@stylesheet)
|
128
|
+
}.should == "<!--[if Konq]>\n<link href=\"/stylesheets/ie.css\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />\n<![endif]-->"
|
129
|
+
|
130
|
+
@template.ie_mobile_conditional {
|
131
|
+
@template.stylesheet_link_tag(@stylesheet)
|
132
|
+
}.should == "<!--[if IEmob]>\n<link href=\"/stylesheets/ie.css\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />\n<![endif]-->"
|
133
|
+
|
134
|
+
@template.psp_conditional {
|
135
|
+
@template.stylesheet_link_tag(@stylesheet)
|
136
|
+
}.should == "<!--[if PSP]>\n<link href=\"/stylesheets/ie.css\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />\n<![endif]-->"
|
137
|
+
|
138
|
+
@template.net_front_conditional {
|
139
|
+
@template.stylesheet_link_tag(@stylesheet)
|
140
|
+
}.should == "<!--[if NetF]>\n<link href=\"/stylesheets/ie.css\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />\n<![endif]-->"
|
141
|
+
|
142
|
+
@template.mobile_safari_conditional {
|
143
|
+
@template.stylesheet_link_tag(@stylesheet)
|
144
|
+
}.should == "<!--[if SafMob]>\n<link href=\"/stylesheets/ie.css\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />\n<![endif]-->"
|
145
|
+
|
146
|
+
end
|
147
|
+
|
148
|
+
end
|
@@ -0,0 +1,96 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe TopHat::TitleHelper do
|
4
|
+
|
5
|
+
before(:each) do
|
6
|
+
@template = ActionView::Base.new
|
7
|
+
end
|
8
|
+
|
9
|
+
context "saving a title" do
|
10
|
+
it "should save the title" do
|
11
|
+
@template.title('Kind of Blue').should == 'Kind of Blue'
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
context "displaying a title" do
|
16
|
+
it "should use the website name if title is empty" do
|
17
|
+
@template.title(:site => "Miles Davis").should == "<title>Miles Davis</title>"
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should display the title if no website was specified" do
|
21
|
+
save_basic_title
|
22
|
+
@template.title().should == '<title>Kind of Blue</title>'
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should use website before page by default" do
|
26
|
+
save_basic_title
|
27
|
+
@template.title(:site => "Miles Davis", :separator => '|').should == "<title>Miles Davis | Kind of Blue</title>"
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should only use markup in titles in the view" do
|
31
|
+
save_basic_title("<b>Kind of Blue</b>").should == "<b>Kind of Blue</b>"
|
32
|
+
@template.title(:site => "Miles Davis", :separator => '|').should == "<title>Miles Davis | Kind of Blue</title>"
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should use page before website if :reverse" do
|
36
|
+
save_basic_title
|
37
|
+
@template.title(:site => "Miles Davis", :reverse => true, :separator => '|').should == "<title>Kind of Blue | Miles Davis</title>"
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should use 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 == "<title>John Coltrane | My Favorite Things</title>"
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should be lowercase if :lowercase" do
|
45
|
+
save_basic_title
|
46
|
+
@template.title(:site => "Miles Davis", :lowercase => true, :separator => '|').should == "<title>miles davis | kind of blue</title>"
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should use custom separator if :separator" do
|
50
|
+
save_basic_title
|
51
|
+
@template.title(:site => "Miles Davis", :separator => "-").should == "<title>Miles Davis - Kind of Blue</title>"
|
52
|
+
@template.title(:site => "Miles Davis", :separator => ":").should == "<title>Miles Davis : Kind of Blue</title>"
|
53
|
+
@template.title(:site => "Miles Davis", :separator => "—").should == "<title>Miles Davis &mdash; Kind of Blue</title>"
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should use custom prefix and suffix if available" do
|
57
|
+
save_basic_title
|
58
|
+
@template.title(:site => "Miles Davis", :prefix => " |", :suffix => "| ", :separator => '|').should == "<title>Miles Davis ||| Kind of Blue</title>"
|
59
|
+
end
|
60
|
+
|
61
|
+
it "should collapse prefix if false" do
|
62
|
+
save_basic_title
|
63
|
+
@template.title(:site => "Miles Davis", :prefix => false, :separator => ":").should == "<title>Miles Davis: Kind of Blue</title>"
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should collapse suffix if false" do
|
67
|
+
save_basic_title
|
68
|
+
@template.title(:site => "Miles Davis", :suffix => false, :separator => "~").should == "<title>Miles Davis ~Kind of Blue</title>"
|
69
|
+
end
|
70
|
+
|
71
|
+
it "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
|
+
@template.title(custom_options).should == "<title>kind of blue - miles davis</title>"
|
75
|
+
end
|
76
|
+
|
77
|
+
it "should use default one if title is not present or blank" do
|
78
|
+
save_basic_title("")
|
79
|
+
@template.title(:site => "Miles Davis", :default => "Round About Midnight", :separator => '|').should == "<title>Miles Davis | Round About Midnight</title>"
|
80
|
+
end
|
81
|
+
|
82
|
+
it "should allow custom options per title" do
|
83
|
+
save_custom_title
|
84
|
+
@template.title(:site => "Freddie Freeloader", :separator => '|').should == "<title>Kind of Blue | Freddie Freeloader</title>"
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def save_basic_title(title='Kind of Blue')
|
89
|
+
@template.title(title)
|
90
|
+
end
|
91
|
+
|
92
|
+
def save_custom_title(title='Kind of Blue')
|
93
|
+
@template.title(title, { :reverse => true })
|
94
|
+
end
|
95
|
+
|
96
|
+
end
|
data/spec/tophat_spec.rb
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe TopHat do
|
4
|
+
|
5
|
+
context "loading the TopHat plugin" do
|
6
|
+
before(:each) do
|
7
|
+
@template = ActionView::Base.new
|
8
|
+
end
|
9
|
+
|
10
|
+
it "be mixed into ActionView::Base" do
|
11
|
+
ActionView::Base.included_modules.include?(TopHat::TitleHelper).should be_true
|
12
|
+
ActionView::Base.included_modules.include?(TopHat::MetaHelper).should be_true
|
13
|
+
ActionView::Base.included_modules.include?(TopHat::StylesheetHelper).should be_true
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should respond to the 'title' helper" do
|
17
|
+
@template.respond_to?(:title).should be_true
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should respond to the 'title' helper alias" do
|
21
|
+
@template.respond_to?(:t).should be_true
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should respond to the 'description' helper" do
|
25
|
+
@template.respond_to?(:description).should be_true
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should respond to the 'keywords' helper" do
|
29
|
+
@template.respond_to?(:keywords).should be_true
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should respond to the 'ie_5_conditional' helper" do
|
33
|
+
@template.respond_to?(:ie_5_conditional).should be_true
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should respond to the 'ie_5_5_conditional' helper" do
|
37
|
+
@template.respond_to?(:ie_5_5_conditional).should be_true
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should respond to the 'ie_6_conditional' helper" do
|
41
|
+
@template.respond_to?(:ie_6_conditional).should be_true
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should respond to the 'ie_7_conditional' helper" do
|
45
|
+
@template.respond_to?(:ie_7_conditional).should be_true
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should respond to the 'ie_8_conditional' helper" do
|
49
|
+
@template.respond_to?(:ie_8_conditional).should be_true
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should respond to the 'ie_9_conditional' helper" do
|
53
|
+
@template.respond_to?(:ie_9_conditional).should be_true
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should respond to the 'opengraph' helper" do
|
57
|
+
@template.respond_to?(:opengraph).should be_true
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should respond to the 'noindex' helper" do
|
61
|
+
@template.respond_to?(:noindex).should be_true
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should respond to the 'nofollow' helper" do
|
65
|
+
@template.respond_to?(:nofollow).should be_true
|
66
|
+
end
|
67
|
+
|
68
|
+
it "should respond to the 'canonical' helper" do
|
69
|
+
@template.respond_to?(:canonical).should be_true
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
data/tophat.gemspec
CHANGED
@@ -1,73 +1,31 @@
|
|
1
|
-
# Generated by jeweler
|
2
|
-
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
1
|
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "tophat/version"
|
5
4
|
|
6
5
|
Gem::Specification.new do |s|
|
7
|
-
s.name
|
8
|
-
s.version
|
9
|
-
|
10
|
-
s.
|
11
|
-
s.
|
12
|
-
s.
|
6
|
+
s.name = 'tophat'
|
7
|
+
s.version = TopHat::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Steve Agalloco"]
|
10
|
+
s.email = ['steve.agalloco@gmail.com']
|
11
|
+
s.homepage = "https://github.com/spagalloco/tophat"
|
13
12
|
s.description = %q{simple view helpers for your layouts}
|
14
|
-
s.
|
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/meta.rb",
|
27
|
-
"lib/tophat/opengraph.rb",
|
28
|
-
"lib/tophat/robots.rb",
|
29
|
-
"lib/tophat/stylesheet.rb",
|
30
|
-
"lib/tophat/title.rb",
|
31
|
-
"lib/tophat/version.rb",
|
32
|
-
"rails/init.rb",
|
33
|
-
"test/helper.rb",
|
34
|
-
"test/test_opengraph.rb",
|
35
|
-
"test/test_robots.rb",
|
36
|
-
"test/test_tophat.rb",
|
37
|
-
"test/test_tophat_meta.rb",
|
38
|
-
"test/test_tophat_stylesheets.rb",
|
39
|
-
"test/test_tophat_title.rb",
|
40
|
-
"tophat.gemspec"
|
41
|
-
]
|
42
|
-
s.homepage = %q{http://github.com/spagalloco/tophat}
|
43
|
-
s.rdoc_options = ["--charset=UTF-8"]
|
44
|
-
s.require_paths = ["lib"]
|
45
|
-
s.rubygems_version = %q{1.3.7}
|
46
|
-
s.summary = %q{simple view helpers for your layouts}
|
47
|
-
s.test_files = [
|
48
|
-
"test/helper.rb",
|
49
|
-
"test/test_opengraph.rb",
|
50
|
-
"test/test_robots.rb",
|
51
|
-
"test/test_tophat.rb",
|
52
|
-
"test/test_tophat_meta.rb",
|
53
|
-
"test/test_tophat_stylesheets.rb",
|
54
|
-
"test/test_tophat_title.rb"
|
55
|
-
]
|
13
|
+
s.summary = %q{simple view helpers for your layouts}
|
56
14
|
|
57
|
-
|
58
|
-
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
59
|
-
s.specification_version = 3
|
15
|
+
s.add_runtime_dependency('actionpack', '>= 3.0.0')
|
60
16
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
17
|
+
s.add_development_dependency('bundler', '~> 1.0')
|
18
|
+
s.add_development_dependency('rake', '~> 0.8')
|
19
|
+
s.add_development_dependency('rspec', '~> 2.5.0')
|
20
|
+
s.add_development_dependency('yard', '~> 0.6')
|
21
|
+
s.add_development_dependency('maruku', '~> 0.6')
|
22
|
+
s.add_development_dependency('simplecov', '~> 0.3')
|
23
|
+
s.add_development_dependency('shoulda', '>= 0')
|
24
|
+
s.add_development_dependency('rails', '>= 3.0.0')
|
25
|
+
|
26
|
+
s.files = `git ls-files`.split("\n")
|
27
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
28
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
29
|
+
s.require_paths = ["lib"]
|
72
30
|
end
|
73
31
|
|