tophat 1.6.1 → 1.7.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/tophat.rb +20 -11
- data/lib/tophat/html.rb +18 -2
- data/lib/tophat/meta.rb +17 -5
- data/lib/tophat/opengraph.rb +0 -2
- data/lib/tophat/railtie.rb +20 -0
- data/lib/tophat/reset.rb +14 -0
- data/lib/tophat/robots.rb +0 -2
- data/lib/tophat/stylesheet.rb +0 -2
- data/lib/tophat/title.rb +0 -2
- data/lib/tophat/twitter_card.rb +0 -2
- data/lib/tophat/version.rb +1 -1
- data/spec/spec_helper.rb +4 -0
- data/spec/tophat/html_helper_spec.rb +35 -7
- data/spec/tophat/meta_helper_spec.rb +23 -0
- metadata +20 -18
data/lib/tophat.rb
CHANGED
@@ -1,24 +1,33 @@
|
|
1
1
|
require 'action_view'
|
2
|
+
require 'tophat/html'
|
3
|
+
require 'tophat/title'
|
4
|
+
require 'tophat/meta'
|
5
|
+
require 'tophat/stylesheet'
|
6
|
+
require 'tophat/robots'
|
7
|
+
require 'tophat/opengraph'
|
8
|
+
require 'tophat/twitter_card'
|
2
9
|
|
3
10
|
module TopHat
|
4
11
|
extend self
|
5
12
|
|
6
|
-
|
7
|
-
return Thread.current[:tophat] if Thread.current[:tophat]
|
13
|
+
require "tophat/railtie" if defined?(::Rails)
|
8
14
|
|
9
|
-
|
15
|
+
def current
|
16
|
+
Thread.current[:tophat] ||= {}
|
10
17
|
end
|
11
18
|
|
12
19
|
def reset
|
13
20
|
Thread.current[:tophat] = {}
|
14
21
|
end
|
15
22
|
|
16
|
-
|
23
|
+
def setup
|
24
|
+
ActionView::Base.send :include, TopHat::HtmlHelper
|
25
|
+
ActionView::Base.send :include, TopHat::TitleHelper
|
26
|
+
ActionView::Base.send :include, TopHat::MetaHelper
|
27
|
+
ActionView::Base.send :include, TopHat::StylesheetHelper
|
28
|
+
ActionView::Base.send :include, TopHat::RobotsHelper
|
29
|
+
ActionView::Base.send :include, TopHat::OpenGraphHelper
|
30
|
+
ActionView::Base.send :include, TopHat::TwitterCardHelper
|
31
|
+
end
|
17
32
|
|
18
|
-
|
19
|
-
require 'tophat/title'
|
20
|
-
require 'tophat/meta'
|
21
|
-
require 'tophat/stylesheet'
|
22
|
-
require 'tophat/robots'
|
23
|
-
require 'tophat/opengraph'
|
24
|
-
require 'tophat/twitter_card'
|
33
|
+
end
|
data/lib/tophat/html.rb
CHANGED
@@ -12,10 +12,26 @@ module TopHat
|
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
|
+
if options[:prefix]
|
16
|
+
if options[:prefix].kind_of?(Hash)
|
17
|
+
prefix_options = options.delete(:prefix)
|
18
|
+
options['prefix'] = "#{prefix_options[:prefix]}: #{prefix_options[:url]}"
|
19
|
+
elsif options[:prefix].kind_of?(Array)
|
20
|
+
prefixes = []
|
21
|
+
options.delete(:prefix).each do |prefix|
|
22
|
+
if prefix.kind_of?(Hash)
|
23
|
+
prefixes << "#{prefix[:prefix]}: #{prefix[:url]}"
|
24
|
+
else
|
25
|
+
prefixes << prefix
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
options['prefix'] = prefixes.join(' ')
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
15
33
|
tag(:html, options, true)
|
16
34
|
end
|
17
35
|
|
18
36
|
end
|
19
37
|
end
|
20
|
-
|
21
|
-
ActionView::Base.send :include, TopHat::HtmlHelper
|
data/lib/tophat/meta.rb
CHANGED
@@ -1,6 +1,19 @@
|
|
1
1
|
module TopHat
|
2
2
|
module MetaHelper
|
3
3
|
|
4
|
+
# Meta Tag helper
|
5
|
+
def meta_tag(options, open=false, escape=true)
|
6
|
+
tag(:meta, options, open, escape)
|
7
|
+
end
|
8
|
+
|
9
|
+
def charset(charset, options={})
|
10
|
+
meta_tag(options.merge(:charset => charset), true)
|
11
|
+
end
|
12
|
+
|
13
|
+
def viewport(viewport, options={})
|
14
|
+
meta_tag(options.merge(:name => 'viewport', :content => viewport), true)
|
15
|
+
end
|
16
|
+
|
4
17
|
# page descriptions
|
5
18
|
# <meta name="description" content="Description goes here." />
|
6
19
|
def description(options={})
|
@@ -9,10 +22,11 @@ module TopHat
|
|
9
22
|
TopHat.current['description'] = options
|
10
23
|
|
11
24
|
else
|
25
|
+
default_description = options.delete(:default)
|
12
26
|
options[:name] = 'description'
|
13
|
-
options[:content] = TopHat.current['description'] ||
|
27
|
+
options[:content] = TopHat.current['description'] || default_description
|
14
28
|
|
15
|
-
|
29
|
+
meta_tag(options) if options[:content]
|
16
30
|
end
|
17
31
|
end
|
18
32
|
|
@@ -39,10 +53,8 @@ module TopHat
|
|
39
53
|
display_keywords += default_keywords if options.delete(:merge_default) == true
|
40
54
|
|
41
55
|
options.merge!(:content => display_keywords.uniq.join(', ').squeeze(' '))
|
42
|
-
|
56
|
+
meta_tag(options) if display_keywords.any?
|
43
57
|
end
|
44
58
|
end
|
45
59
|
end
|
46
60
|
end
|
47
|
-
|
48
|
-
ActionView::Base.send :include, TopHat::MetaHelper
|
data/lib/tophat/opengraph.rb
CHANGED
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'tophat'
|
2
|
+
require 'tophat/reset'
|
3
|
+
require 'rails'
|
4
|
+
|
5
|
+
module TopHat
|
6
|
+
class Railtie < Rails::Railtie
|
7
|
+
|
8
|
+
initializer "tophat.view_helpers" do |app|
|
9
|
+
TopHat.setup
|
10
|
+
end
|
11
|
+
|
12
|
+
# Clear the identity map after each request
|
13
|
+
initializer "tophat.reset" do |app|
|
14
|
+
ActiveSupport.on_load(:action_controller) do
|
15
|
+
include(TopHat::Reset)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
data/lib/tophat/reset.rb
ADDED
data/lib/tophat/robots.rb
CHANGED
data/lib/tophat/stylesheet.rb
CHANGED
data/lib/tophat/title.rb
CHANGED
data/lib/tophat/twitter_card.rb
CHANGED
data/lib/tophat/version.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -15,15 +15,43 @@ describe TopHat::HtmlHelper do
|
|
15
15
|
output.should eq('<html version="123">')
|
16
16
|
end
|
17
17
|
|
18
|
-
|
19
|
-
|
20
|
-
|
18
|
+
context 'xmlns' do
|
19
|
+
it 'accepts xmlns passed as strings' do
|
20
|
+
output = @template.html_tag(:xmlns => 'http://someurl.com')
|
21
|
+
output.should eq('<html xmlns="http://someurl.com">')
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'accepts xmlns passed as an array of hashes' do
|
25
|
+
xmlns = { :prefix => 'fb', :url => 'http://developers.facebook.com/schema/' }
|
26
|
+
output = @template.html_tag(:xmlns => [xmlns])
|
27
|
+
output.should eq('<html xmlns:fb="http://developers.facebook.com/schema/">')
|
28
|
+
end
|
21
29
|
end
|
22
30
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
31
|
+
context 'prefixes' do
|
32
|
+
it 'accepts prefixes passed as strings' do
|
33
|
+
output = @template.html_tag(:prefix => 'ohai')
|
34
|
+
output.should eq('<html prefix="ohai">')
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'accepts prefixes passed as a hash' do
|
38
|
+
output = @template.html_tag(:prefix => { :prefix => 'og', :url => 'http://ogp.me/ns#' })
|
39
|
+
output.should eq('<html prefix="og: http://ogp.me/ns#">')
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'accepts prefixes passed as an array of hashes' do
|
43
|
+
prefixes = [
|
44
|
+
{ :prefix => 'og', :url => 'http://ogp.me/ns#' },
|
45
|
+
{ :prefix => 'fb', :url => 'http://ogp.me/ns/fb#' }
|
46
|
+
]
|
47
|
+
output = @template.html_tag(:prefix => prefixes)
|
48
|
+
output.should eq('<html prefix="og: http://ogp.me/ns# fb: http://ogp.me/ns/fb#">')
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'accepts prefixes passes and an array of strings' do
|
52
|
+
output = @template.html_tag(:prefix => ['og: http://ogp.me/ns#', 'fb: http://ogp.me/ns/fb#'])
|
53
|
+
output.should eq('<html prefix="og: http://ogp.me/ns# fb: http://ogp.me/ns/fb#">')
|
54
|
+
end
|
27
55
|
end
|
28
56
|
|
29
57
|
end
|
@@ -6,6 +6,24 @@ describe TopHat::MetaHelper do
|
|
6
6
|
@template = ActionView::Base.new
|
7
7
|
end
|
8
8
|
|
9
|
+
describe "charset" do
|
10
|
+
it 'renders a meta tag with a charset' do
|
11
|
+
@template.charset('utf-8').should eq('<meta charset="utf-8">')
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "viewport" do
|
16
|
+
it 'renders a meta tag with a viewport' do
|
17
|
+
@template.viewport('width=device-width').should eq('<meta content="width=device-width" name="viewport">')
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "meta_tag" do
|
22
|
+
it 'renders meta_tags' do
|
23
|
+
@template.meta_tag(:charset => 'utf-8').should eq('<meta charset="utf-8" />')
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
9
27
|
describe "keywords" do
|
10
28
|
context "defined as an array" do
|
11
29
|
before do
|
@@ -67,6 +85,11 @@ describe TopHat::MetaHelper do
|
|
67
85
|
it "returns nil when no default is configured and no description is defined" do
|
68
86
|
@template.description.should be_nil
|
69
87
|
end
|
88
|
+
|
89
|
+
it 'overrides the default' do
|
90
|
+
@template.description('This is a custom description')
|
91
|
+
@template.description(:default => 'This is a default description.').should eq('<meta content="This is a custom description" name="description" />')
|
92
|
+
end
|
70
93
|
end
|
71
94
|
|
72
95
|
end
|
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.7.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-
|
12
|
+
date: 2012-07-24 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: actionpack
|
16
|
-
requirement: &
|
16
|
+
requirement: &70142323594740 !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: *70142323594740
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rake
|
27
|
-
requirement: &
|
27
|
+
requirement: &70142323593260 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70142323593260
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rspec
|
38
|
-
requirement: &
|
38
|
+
requirement: &70142323591560 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70142323591560
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: yard
|
49
|
-
requirement: &
|
49
|
+
requirement: &70142323590340 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70142323590340
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: rdiscount
|
60
|
-
requirement: &
|
60
|
+
requirement: &70142323588840 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: '0'
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *70142323588840
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: simplecov
|
71
|
-
requirement: &
|
71
|
+
requirement: &70142323587760 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ! '>='
|
@@ -76,10 +76,10 @@ dependencies:
|
|
76
76
|
version: '0'
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *70142323587760
|
80
80
|
- !ruby/object:Gem::Dependency
|
81
81
|
name: rails
|
82
|
-
requirement: &
|
82
|
+
requirement: &70142323586680 !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: *70142323586680
|
91
91
|
- !ruby/object:Gem::Dependency
|
92
92
|
name: guard-rspec
|
93
|
-
requirement: &
|
93
|
+
requirement: &70142323585960 !ruby/object:Gem::Requirement
|
94
94
|
none: false
|
95
95
|
requirements:
|
96
96
|
- - ! '>='
|
@@ -98,7 +98,7 @@ dependencies:
|
|
98
98
|
version: '0'
|
99
99
|
type: :development
|
100
100
|
prerelease: false
|
101
|
-
version_requirements: *
|
101
|
+
version_requirements: *70142323585960
|
102
102
|
description: Simple view helpers for your layouts
|
103
103
|
email:
|
104
104
|
- steve.agalloco@gmail.com
|
@@ -119,6 +119,8 @@ files:
|
|
119
119
|
- lib/tophat/html.rb
|
120
120
|
- lib/tophat/meta.rb
|
121
121
|
- lib/tophat/opengraph.rb
|
122
|
+
- lib/tophat/railtie.rb
|
123
|
+
- lib/tophat/reset.rb
|
122
124
|
- lib/tophat/robots.rb
|
123
125
|
- lib/tophat/stylesheet.rb
|
124
126
|
- lib/tophat/title.rb
|