tophat 2.1.0 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,13 +1,13 @@
1
+ bundler_args: --without development
1
2
  language: ruby
2
- matrix:
3
- allow_failures:
4
- - rvm: ruby-head
5
-
6
3
  rvm:
4
+ - rbx-18mode
5
+ - rbx-19mode
7
6
  - 1.8.7
8
7
  - 1.9.2
9
8
  - 1.9.3
10
- - jruby
11
- - rbx
12
- - ree
13
- - ruby-head
9
+ - 2.0.0
10
+ matrix:
11
+ allow_failures:
12
+ - rvm: rbx-18mode
13
+ - rvm: 1.8.7
data/Gemfile CHANGED
@@ -1,3 +1,18 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
+ gem 'rake'
4
+ gem 'yard'
5
+
6
+ group :development do
7
+ gem 'kramdown'
8
+ gem 'guard-rspec'
9
+ end
10
+
11
+ group :test do
12
+ gem 'rspec', '>= 2.11'
13
+ gem 'simplecov', :require => false
14
+ gem 'rails', '>= 3.0.0', '< 4.0.0'
15
+ gem 'webmock'
16
+ end
17
+
3
18
  gemspec
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # TopHat [![Build Status](https://secure.travis-ci.org/spagalloco/tophat.png?branch=master)][travis] [![Dependency Status](https://gemnasium.com/spagalloco/tophat.png?travis)][gemnasium] [![Code Climate](https://codeclimate.com/badge.png)][codeclimate]
1
+ # TopHat [![Build Status](https://secure.travis-ci.org/spagalloco/tophat.png?branch=master)][travis] [![Dependency Status](https://gemnasium.com/spagalloco/tophat.png?travis)][gemnasium] [![Code Climate](https://codeclimate.com/github/spagalloco/tophat.png)][codeclimate]
2
2
 
3
3
 
4
4
  [travis]: http://travis-ci.org/spagalloco/tophat
@@ -13,7 +13,7 @@ Just add it to your Gemfile:
13
13
 
14
14
  gem 'tophat'
15
15
 
16
- Note: TopHat is Rails 3.0+ compatible.
16
+ Note: TopHat is compatible with Rails 3.0+.
17
17
 
18
18
  ## Changes in 2.1
19
19
 
@@ -14,6 +14,10 @@ module TopHat
14
14
  meta_tag(options.merge(:name => 'viewport', :content => viewport), true)
15
15
  end
16
16
 
17
+ def itemprop(name, value)
18
+ meta_tag(:itemprop => name, :content => value)
19
+ end
20
+
17
21
  # page descriptions
18
22
  # <meta name="description" content="Description goes here." />
19
23
  def description(options={})
@@ -12,7 +12,9 @@ module TopHat
12
12
  yield self if block_given?
13
13
  end
14
14
 
15
- def merge(options={})
15
+ def merge(options={}, &block)
16
+ yield self if block_given?
17
+
16
18
  @app_id = options.delete(:app_id) if options && options.has_key?(:app_id)
17
19
  @admins = options.delete(:admins) if options && options.has_key?(:admins)
18
20
  end
@@ -85,15 +87,9 @@ module TopHat
85
87
  end
86
88
 
87
89
  def opengraph(options=nil, &block)
88
- TopHat.current['open_graph_defaults'] = options if options.kind_of? Hash
89
-
90
- if block_given?
91
- TopHat.current['open_graph_generator'] = OpenGraphGenerator.new(TopHat.current['open_graph_defaults'], &block)
92
- else
93
- TopHat.current['open_graph_generator'] ||= OpenGraphGenerator.new
94
- TopHat.current['open_graph_generator'].merge(TopHat.current['open_graph_defaults'])
95
- TopHat.current['open_graph_generator'].to_html
96
- end
90
+ TopHat.current['open_graph_generator'] ||= OpenGraphGenerator.new(options)
91
+ TopHat.current['open_graph_generator'].merge(options, &block)
92
+ TopHat.current['open_graph_generator'].to_html
97
93
  end
98
94
 
99
95
  end
@@ -3,13 +3,21 @@ module TopHat
3
3
 
4
4
  DEFAULT_DESCRIPTOR = 'robots'
5
5
 
6
- def noindex(descriptor=DEFAULT_DESCRIPTOR)
7
- descriptor ||= DEFAULT_DESCRIPTOR
6
+ def noindex(descriptor=nil)
7
+ if descriptor
8
+ TopHat.current['noindex'] = descriptor || DEFAULT_DESCRIPTOR
9
+ else
10
+ descriptor = TopHat.current['noindex'] || DEFAULT_DESCRIPTOR
11
+ end
8
12
  tag(:meta, :name => descriptor, :content => 'noindex')
9
13
  end
10
14
 
11
- def nofollow(descriptor=DEFAULT_DESCRIPTOR)
12
- descriptor ||= DEFAULT_DESCRIPTOR
15
+ def nofollow(descriptor=nil)
16
+ if descriptor
17
+ TopHat.current['nofollow'] = descriptor || DEFAULT_DESCRIPTOR
18
+ else
19
+ descriptor = TopHat.current['nofollow'] || DEFAULT_DESCRIPTOR
20
+ end
13
21
  tag(:meta, :name => descriptor, :content => 'nofollow')
14
22
  end
15
23
 
@@ -16,9 +16,11 @@ module TopHat
16
16
  def to_html
17
17
  output = ActiveSupport::SafeBuffer.new
18
18
  output << tag(:meta, :name => 'twitter:card', :value => @type)
19
+ @card_data = @card_data.delete_if { |k, v| v.nil? }
19
20
  @card_data.each do |key, value|
21
+ tag_name = "twitter:#{key}".squeeze(":")
20
22
  output << "\n".html_safe
21
- output << tag(:meta, :name => "twitter:#{key}", :value => value)
23
+ output << tag(:meta, :name => tag_name, :value => value)
22
24
  end
23
25
  output << "\n".html_safe unless @card_data.empty?
24
26
  output
@@ -40,13 +42,12 @@ module TopHat
40
42
  end
41
43
 
42
44
  def twitter_card(type=nil, &block)
43
- if type.nil?
44
- if TopHat.current['twitter_card']
45
- TopHat.current['twitter_card'].to_html
46
- end
47
- else
45
+ if TopHat.current['twitter_card'].nil?
48
46
  TopHat.current['twitter_card'] = TwitterCardGenerator.new(type, &block)
47
+ else
48
+ TopHat.current['twitter_card'].add_nested_attributes('', &block)
49
49
  end
50
+ TopHat.current['twitter_card'].to_html
50
51
  end
51
52
  end
52
53
  end
@@ -1,3 +1,3 @@
1
1
  module TopHat
2
- VERSION = '2.1.0'
2
+ VERSION = '2.2.0'
3
3
  end
@@ -1,11 +1,13 @@
1
- require 'simplecov'
2
- SimpleCov.start do
3
- add_group 'TopHat', 'lib/tophat'
4
- add_group 'Specs', 'spec'
1
+ unless ENV['CI']
2
+ require 'simplecov'
3
+ SimpleCov.start do
4
+ add_filter '.bundle'
5
+ add_group 'TopHat', 'lib/tophat'
6
+ add_group 'Specs', 'spec'
7
+ end
5
8
  end
6
9
 
7
- require File.expand_path('../../lib/tophat', __FILE__)
8
-
10
+ require 'tophat'
9
11
  require 'rspec'
10
12
  require 'rails/all'
11
13
 
@@ -92,4 +92,10 @@ describe TopHat::MetaHelper do
92
92
  end
93
93
  end
94
94
 
95
- end
95
+ describe ".itemprop" do
96
+ it "renders an itemprop meta tag" do
97
+ @template.itemprop(:rating, '1').should == "<meta content=\"1\" itemprop=\"rating\" />"
98
+ end
99
+ end
100
+
101
+ end
@@ -85,6 +85,19 @@ describe TopHat::OpenGraphHelper do
85
85
  output.should include('<meta content="Austin Powers: International Man of Mystery" property="og:title" />')
86
86
  end
87
87
 
88
+ it 'supports default tags' do
89
+ @template.opengraph do |og|
90
+ og.title @title
91
+ og.type @type
92
+ end
93
+ output = @template.opengraph do |og|
94
+ og.rating '5/10'
95
+ end
96
+
97
+ output.should include('<meta content="movie" property="og:type" />')
98
+ output.should include('<meta content="Rain Man" property="og:title" />')
99
+ output.should include('<meta content="5/10" property="og:rating" />')
100
+ end
88
101
  end
89
102
 
90
103
  context "combined usage" do
@@ -113,6 +126,22 @@ describe TopHat::OpenGraphHelper do
113
126
  output.should include('<meta content="movie" property="og:type" />')
114
127
  output.should include('<meta content="Rain Man" property="og:title" />')
115
128
  end
129
+
130
+ it 'supports default tags' do
131
+ @template.opengraph do |og|
132
+ og.title @title
133
+ og.type @type
134
+ end
135
+ output = @template.opengraph(:app_id => 'MyApp', :admins => [123, 1234]) do |og|
136
+ og.rating '5/10'
137
+ end
138
+
139
+ output.should include('<meta content="MyApp" property="fb:app_id" />')
140
+ output.should include('<meta content="123,1234" property="fb:admins" />')
141
+ output.should include('<meta content="movie" property="og:type" />')
142
+ output.should include('<meta content="Rain Man" property="og:title" />')
143
+ output.should include('<meta content="5/10" property="og:rating" />')
144
+ end
116
145
  end
117
146
 
118
- end
147
+ end
@@ -18,6 +18,11 @@ describe TopHat::RobotsHelper do
18
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
+
22
+ it 'stores a descriptor' do
23
+ @template.nofollow('twitterbot')
24
+ @template.nofollow.should == "<meta content=\"nofollow\" name=\"twitterbot\" />"
25
+ end
21
26
  end
22
27
 
23
28
  describe ".noindex" do
@@ -32,6 +37,11 @@ describe TopHat::RobotsHelper do
32
37
  it "generates a default tag when passed nil" do
33
38
  @template.noindex(nil).should == "<meta content=\"noindex\" name=\"robots\" />"
34
39
  end
40
+
41
+ it 'stores a descriptor' do
42
+ @template.noindex('twitterbot')
43
+ @template.noindex.should == "<meta content=\"noindex\" name=\"twitterbot\" />"
44
+ end
35
45
  end
36
46
 
37
47
  describe ".canonical" do
@@ -48,4 +58,4 @@ describe TopHat::RobotsHelper do
48
58
  end
49
59
  end
50
60
 
51
- end
61
+ end
@@ -61,4 +61,21 @@ describe TopHat::TwitterCardHelper do
61
61
  output.should include('<meta name="twitter:player:stream:content_type" value="123" />')
62
62
  end
63
63
 
64
- end
64
+ it 'supports default tags' do
65
+ @template.twitter_card('player') do |card|
66
+ card.player do |player|
67
+ player.embed 'https://example.com/embed/a'
68
+ end
69
+ end
70
+ output = @template.twitter_card('player') do |card|
71
+ card.player do |player|
72
+ player.site 'https://example.com'
73
+ end
74
+ end
75
+
76
+ output.should include('<meta name="twitter:player:embed" value="https://example.com/embed/a" />')
77
+ output.should include('<meta name="twitter:player:site" value="https://example.com" />')
78
+ output.should_not include('<meta name="twitter:embed" value="https://example.com/embed/a" />')
79
+ end
80
+
81
+ end
@@ -14,14 +14,6 @@ Gem::Specification.new do |s|
14
14
 
15
15
  s.add_runtime_dependency('actionpack', '>= 3.0.0')
16
16
 
17
- s.add_development_dependency('rake')
18
- s.add_development_dependency('rspec')
19
- s.add_development_dependency('yard')
20
- s.add_development_dependency('rdiscount')
21
- s.add_development_dependency('simplecov')
22
- s.add_development_dependency('rails', '>= 3.0.0')
23
- s.add_development_dependency('guard-rspec')
24
-
25
17
  s.files = `git ls-files`.split("\n")
26
18
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
27
19
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
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.1.0
4
+ version: 2.2.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-09-28 00:00:00.000000000 Z
12
+ date: 2013-07-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: actionpack
@@ -27,118 +27,6 @@ dependencies:
27
27
  - - ! '>='
28
28
  - !ruby/object:Gem::Version
29
29
  version: 3.0.0
30
- - !ruby/object:Gem::Dependency
31
- name: rake
32
- requirement: !ruby/object:Gem::Requirement
33
- none: false
34
- requirements:
35
- - - ! '>='
36
- - !ruby/object:Gem::Version
37
- version: '0'
38
- type: :development
39
- prerelease: false
40
- version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
- requirements:
43
- - - ! '>='
44
- - !ruby/object:Gem::Version
45
- version: '0'
46
- - !ruby/object:Gem::Dependency
47
- name: rspec
48
- requirement: !ruby/object:Gem::Requirement
49
- none: false
50
- requirements:
51
- - - ! '>='
52
- - !ruby/object:Gem::Version
53
- version: '0'
54
- type: :development
55
- prerelease: false
56
- version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
- requirements:
59
- - - ! '>='
60
- - !ruby/object:Gem::Version
61
- version: '0'
62
- - !ruby/object:Gem::Dependency
63
- name: yard
64
- requirement: !ruby/object:Gem::Requirement
65
- none: false
66
- requirements:
67
- - - ! '>='
68
- - !ruby/object:Gem::Version
69
- version: '0'
70
- type: :development
71
- prerelease: false
72
- version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
- requirements:
75
- - - ! '>='
76
- - !ruby/object:Gem::Version
77
- version: '0'
78
- - !ruby/object:Gem::Dependency
79
- name: rdiscount
80
- requirement: !ruby/object:Gem::Requirement
81
- none: false
82
- requirements:
83
- - - ! '>='
84
- - !ruby/object:Gem::Version
85
- version: '0'
86
- type: :development
87
- prerelease: false
88
- version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
- requirements:
91
- - - ! '>='
92
- - !ruby/object:Gem::Version
93
- version: '0'
94
- - !ruby/object:Gem::Dependency
95
- name: simplecov
96
- requirement: !ruby/object:Gem::Requirement
97
- none: false
98
- requirements:
99
- - - ! '>='
100
- - !ruby/object:Gem::Version
101
- version: '0'
102
- type: :development
103
- prerelease: false
104
- version_requirements: !ruby/object:Gem::Requirement
105
- none: false
106
- requirements:
107
- - - ! '>='
108
- - !ruby/object:Gem::Version
109
- version: '0'
110
- - !ruby/object:Gem::Dependency
111
- name: rails
112
- requirement: !ruby/object:Gem::Requirement
113
- none: false
114
- requirements:
115
- - - ! '>='
116
- - !ruby/object:Gem::Version
117
- version: 3.0.0
118
- type: :development
119
- prerelease: false
120
- version_requirements: !ruby/object:Gem::Requirement
121
- none: false
122
- requirements:
123
- - - ! '>='
124
- - !ruby/object:Gem::Version
125
- version: 3.0.0
126
- - !ruby/object:Gem::Dependency
127
- name: guard-rspec
128
- requirement: !ruby/object:Gem::Requirement
129
- none: false
130
- requirements:
131
- - - ! '>='
132
- - !ruby/object:Gem::Version
133
- version: '0'
134
- type: :development
135
- prerelease: false
136
- version_requirements: !ruby/object:Gem::Requirement
137
- none: false
138
- requirements:
139
- - - ! '>='
140
- - !ruby/object:Gem::Version
141
- version: '0'
142
30
  description: Simple view helpers for your layouts
143
31
  email:
144
32
  - steve.agalloco@gmail.com
@@ -190,7 +78,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
190
78
  version: '0'
191
79
  segments:
192
80
  - 0
193
- hash: -1469491919120880781
81
+ hash: -2300101656837364012
194
82
  required_rubygems_version: !ruby/object:Gem::Requirement
195
83
  none: false
196
84
  requirements:
@@ -199,10 +87,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
199
87
  version: '0'
200
88
  segments:
201
89
  - 0
202
- hash: -1469491919120880781
90
+ hash: -2300101656837364012
203
91
  requirements: []
204
92
  rubyforge_project:
205
- rubygems_version: 1.8.24
93
+ rubygems_version: 1.8.23
206
94
  signing_key:
207
95
  specification_version: 3
208
96
  summary: Simple view helpers for your layouts