dfp_helper 0.0.1 → 0.0.2

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.
@@ -1,4 +1,4 @@
1
- Copyright 2011 YOURNAME
1
+ Copyright 2011 Jason Ling
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
@@ -1,3 +1,36 @@
1
- = DfpHelper
1
+ = dfp_helper
2
+
3
+ Rails plugin to add DFP tags to your site.
4
+
5
+ AKA Dart for Publishers Small Business, Google Ad Manager, Google Publisher Tags, GPT...
6
+
7
+ == Installation
8
+
9
+ $ gem install dfp_helper
10
+
11
+ == Usage
12
+
13
+ === In your layout between <head></head> put:
14
+
15
+ <%= dfp_helper_head %>
16
+
17
+ === In your views:
18
+
19
+ <%= dfp_helper_slot '/1010898/sglinks_160x600' %>
20
+
21
+ Size needs to be declared if it cannot be guessed from the slot name:
22
+
23
+ <%= dfp_helper_slot '/11800773/moneymoney', {:size => [728,90]} %>
24
+
25
+ Supports targeting options:
26
+
27
+ <%= dfp_helper_slot '/11800773/moneymoney', {:size => [728,90], :targeting => {:host => 'sgforums.com', :countries => ['Singapore', 'Malaysia']}} %>
28
+
29
+ === Slots in layout
30
+
31
+ If you have ad slots in your layout, you will need to make the calls to 'dfp_helper_slot' before 'dfp_helper_head', capture the output and then display it in the layout after.
32
+
33
+
34
+ == Licence
2
35
 
3
36
  This project rocks and uses MIT-LICENSE.
@@ -6,30 +6,34 @@ module DfpHelper
6
6
  end
7
7
 
8
8
  module ViewHelpers
9
+ def dfp_helper_slots
10
+ @dfp_helper_slots||=[]
11
+ end
9
12
  def dfp_helper_slot(_i, options = {})
10
13
  @@dfp_helper_id ||= (Time.now.to_f*1000).to_i
11
- @dfp_helper_slots ||= []
12
14
 
13
- _id = "div-gpt-ad-#{@@dfp_helper_id}-#{@dfp_helper_slots.size}"
15
+ _id = "div-gpt-ad-#{@@dfp_helper_id}-#{dfp_helper_slots.size}"
14
16
  _size = options[:size] || _i.match(/\d+x\d+/)[0].split('x')
15
- @dfp_helper_slots << {:id => _i, :div_id => _id, :size => _size}
17
+ dfp_helper_slots << options.merge({:id => _i, :div_id => _id, :size => _size})
16
18
 
17
- raw <<-END
19
+ raw <<-END.strip
18
20
  <!-- #{_i} -->
19
21
  <div id='#{_id}' style='width:#{_size[0]}px; height:#{_size[1]}px;'>
20
22
  <script type='text/javascript'>
21
- googletag.display('#{_id}');
23
+ googletag.cmd.push(function() { googletag.display('#{_id}'); });
22
24
  </script>
23
25
  </div>
24
26
  END
25
27
  end
26
28
 
27
29
  def dfp_helper_head
28
- o = @dfp_helper_slots.collect{|i|
29
- "googletag.defineSlot('#{i[:id]}', [#{i[:size].join(', ')}], '#{i[:div_id]}').addService(googletag.pubads());"
30
+ return unless dfp_helper_slots.size > 0
31
+ o = dfp_helper_slots.collect{|i|
32
+ _targeting = (i[:targeting]||[]).collect{|k,v| ".setTargeting(#{k.to_json}, #{v.to_json})"}.join
33
+ "googletag.defineSlot('#{i[:id]}', [#{i[:size].join(', ')}], '#{i[:div_id]}').addService(googletag.pubads())#{_targeting};"
30
34
  }.join("\n")
31
35
 
32
- raw <<-END
36
+ raw <<-END.strip
33
37
  <script type='text/javascript'>
34
38
  var googletag = googletag || {};
35
39
  googletag.cmd = googletag.cmd || [];
@@ -1,3 +1,3 @@
1
1
  module DfpHelper
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -2,5 +2,6 @@
2
2
  <p><%= dfp_helper_slot '/1010898/sglinks_160x600' %></p>
3
3
  <p><%= dfp_helper_slot '/1010898/sglinks_300x250' %></p>
4
4
  <p><%= dfp_helper_slot '/11800773/moneymoney_160x600' %></p>
5
- <p><%= dfp_helper_slot '/11800773/moneymoney', {:size => [728,90]} %></p>
5
+ <p><%= dfp_helper_slot '/11800773/moneymoney', :size => [728,90] %></p>
6
+ <p><%= dfp_helper_slot '/11800773/moneymoney', :size => [728,90], :targeting => {:host => 'sgforums.com', :countries => ['Singapore', 'Malaysia']} %></p>
6
7
 
@@ -0,0 +1 @@
1
+ <h1>Info#about_blank</h1>
@@ -1,5 +1,6 @@
1
1
  Dummy::Application.routes.draw do
2
2
  get "info/about"
3
+ get "info/about_blank"
3
4
 
4
5
  # The priority is based upon order of creation:
5
6
  # first created -> highest priority.
@@ -106,3 +106,99 @@ Completed 200 OK in 8ms (Views: 7.9ms | ActiveRecord: 0.0ms)
106
106
  Processing by InfoController#about as HTML
107
107
  Rendered info/about.html.erb within layouts/application (1.1ms)
108
108
  Completed 200 OK in 9ms (Views: 8.4ms | ActiveRecord: 0.0ms)
109
+ Processing by InfoController#about_blank as HTML
110
+ Rendered info/about_blank.html.erb within layouts/application (0.9ms)
111
+ Completed 500 Internal Server Error in 19ms
112
+ Processing by InfoController#about_blank as HTML
113
+ Rendered info/about_blank.html.erb within layouts/application (0.9ms)
114
+ Completed 500 Internal Server Error in 70ms
115
+ Processing by InfoController#about_blank as HTML
116
+ Rendered info/about_blank.html.erb within layouts/application (0.9ms)
117
+ Completed 200 OK in 8ms (Views: 7.5ms | ActiveRecord: 0.0ms)
118
+ Processing by InfoController#about as HTML
119
+ Rendered info/about.html.erb within layouts/application (0.3ms)
120
+ Completed 200 OK in 2ms (Views: 1.3ms | ActiveRecord: 0.0ms)
121
+ Processing by InfoController#about_blank as HTML
122
+ Rendered info/about_blank.html.erb within layouts/application (15.7ms)
123
+ Completed 200 OK in 52ms (Views: 51.7ms | ActiveRecord: 0.0ms)
124
+ Processing by InfoController#about as HTML
125
+ Rendered info/about.html.erb within layouts/application (0.6ms)
126
+ Completed 200 OK in 2ms (Views: 1.8ms | ActiveRecord: 0.0ms)
127
+ Processing by InfoController#about_blank as HTML
128
+ Rendered info/about_blank.html.erb within layouts/application (1.0ms)
129
+ Completed 200 OK in 8ms (Views: 8.2ms | ActiveRecord: 0.0ms)
130
+ Processing by InfoController#about as HTML
131
+ Rendered info/about.html.erb within layouts/application (0.3ms)
132
+ Completed 200 OK in 2ms (Views: 1.7ms | ActiveRecord: 0.0ms)
133
+ Processing by InfoController#about_blank as HTML
134
+ Rendered info/about_blank.html.erb within layouts/application (5.2ms)
135
+ Completed 200 OK in 12ms (Views: 12.0ms | ActiveRecord: 0.0ms)
136
+ Processing by InfoController#about as HTML
137
+ Rendered info/about.html.erb within layouts/application (0.4ms)
138
+ Completed 200 OK in 2ms (Views: 1.5ms | ActiveRecord: 0.0ms)
139
+ Processing by InfoController#about_blank as HTML
140
+ Rendered info/about_blank.html.erb within layouts/application (1.0ms)
141
+ Completed 200 OK in 65ms (Views: 64.8ms | ActiveRecord: 0.0ms)
142
+ Processing by InfoController#about as HTML
143
+ Rendered info/about.html.erb within layouts/application (0.3ms)
144
+ Completed 200 OK in 2ms (Views: 2.2ms | ActiveRecord: 0.0ms)
145
+ Processing by InfoController#about_blank as HTML
146
+ Rendered info/about_blank.html.erb within layouts/application (0.9ms)
147
+ Completed 200 OK in 8ms (Views: 7.7ms | ActiveRecord: 0.0ms)
148
+ Processing by InfoController#about as HTML
149
+ Rendered info/about.html.erb within layouts/application (0.3ms)
150
+ Completed 200 OK in 2ms (Views: 1.4ms | ActiveRecord: 0.0ms)
151
+ Processing by InfoController#about_blank as HTML
152
+ Rendered info/about_blank.html.erb within layouts/application (0.9ms)
153
+ Completed 200 OK in 8ms (Views: 7.4ms | ActiveRecord: 0.0ms)
154
+ Processing by InfoController#about as HTML
155
+ Rendered info/about.html.erb within layouts/application (0.3ms)
156
+ Completed 200 OK in 2ms (Views: 1.5ms | ActiveRecord: 0.0ms)
157
+ Processing by InfoController#about_blank as HTML
158
+ Rendered info/about_blank.html.erb within layouts/application (1.0ms)
159
+ Completed 500 Internal Server Error in 57ms
160
+ Processing by InfoController#about_blank as HTML
161
+ Rendered info/about_blank.html.erb within layouts/application (0.9ms)
162
+ Completed 500 Internal Server Error in 54ms
163
+ Processing by InfoController#about_blank as HTML
164
+ Rendered info/about_blank.html.erb within layouts/application (0.9ms)
165
+ Completed 200 OK in 8ms (Views: 7.5ms | ActiveRecord: 0.0ms)
166
+ Processing by InfoController#about as HTML
167
+ Rendered info/about.html.erb within layouts/application (0.4ms)
168
+ Completed 200 OK in 2ms (Views: 1.5ms | ActiveRecord: 0.0ms)
169
+ Processing by InfoController#about_blank as HTML
170
+ Rendered info/about_blank.html.erb within layouts/application (0.8ms)
171
+ Completed 200 OK in 8ms (Views: 7.3ms | ActiveRecord: 0.0ms)
172
+ Processing by InfoController#about as HTML
173
+ Rendered info/about.html.erb within layouts/application (0.3ms)
174
+ Completed 200 OK in 2ms (Views: 1.4ms | ActiveRecord: 0.0ms)
175
+ Processing by InfoController#about_blank as HTML
176
+ Rendered info/about_blank.html.erb within layouts/application (1.0ms)
177
+ Completed 200 OK in 8ms (Views: 8.0ms | ActiveRecord: 0.0ms)
178
+ Processing by InfoController#about as HTML
179
+ Rendered info/about.html.erb within layouts/application (2.1ms)
180
+ Completed 500 Internal Server Error in 3ms
181
+ Processing by InfoController#about_blank as HTML
182
+ Rendered info/about_blank.html.erb within layouts/application (0.9ms)
183
+ Completed 200 OK in 8ms (Views: 7.4ms | ActiveRecord: 0.0ms)
184
+ Processing by InfoController#about as HTML
185
+ Rendered info/about.html.erb within layouts/application (1.8ms)
186
+ Completed 500 Internal Server Error in 3ms
187
+ Processing by InfoController#about_blank as HTML
188
+ Rendered info/about_blank.html.erb within layouts/application (1.1ms)
189
+ Completed 200 OK in 8ms (Views: 7.8ms | ActiveRecord: 0.0ms)
190
+ Processing by InfoController#about as HTML
191
+ Rendered info/about.html.erb within layouts/application (1.8ms)
192
+ Completed 500 Internal Server Error in 3ms
193
+ Processing by InfoController#about_blank as HTML
194
+ Rendered info/about_blank.html.erb within layouts/application (0.9ms)
195
+ Completed 200 OK in 21ms (Views: 20.7ms | ActiveRecord: 0.0ms)
196
+ Processing by InfoController#about as HTML
197
+ Rendered info/about.html.erb within layouts/application (0.6ms)
198
+ Completed 200 OK in 2ms (Views: 2.1ms | ActiveRecord: 0.0ms)
199
+ Processing by InfoController#about_blank as HTML
200
+ Rendered info/about_blank.html.erb within layouts/application (0.9ms)
201
+ Completed 200 OK in 8ms (Views: 7.3ms | ActiveRecord: 0.0ms)
202
+ Processing by InfoController#about as HTML
203
+ Rendered info/about.html.erb within layouts/application (0.3ms)
204
+ Completed 200 OK in 2ms (Views: 1.5ms | ActiveRecord: 0.0ms)
@@ -3,6 +3,9 @@ require 'pp'
3
3
 
4
4
  class InfoControllerTest < ActionController::TestCase
5
5
  test "should get about" do
6
+ get :about_blank
7
+ assert_response :success
8
+
6
9
  get :about
7
10
  assert_response :success
8
11
  puts response.body
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dfp_helper
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 27
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 1
10
- version: 0.0.1
9
+ - 2
10
+ version: 0.0.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Jason Ling
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-12-20 00:00:00 Z
18
+ date: 2011-12-21 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  prerelease: false
@@ -47,7 +47,7 @@ dependencies:
47
47
  - 0
48
48
  version: "0"
49
49
  requirement: *id002
50
- description: Description of DfpHelper.
50
+ description: "AKA Dart for Publishers Small Business, Google Ad Manager, Google Publisher Tags, GPT\xE2\x80\xA6"
51
51
  email:
52
52
  - jason@jeyel.com
53
53
  executables: []
@@ -92,6 +92,7 @@ files:
92
92
  - test/dummy/test/functional/info_controller_test.rb
93
93
  - test/dummy/app/helpers/info_helper.rb
94
94
  - test/dummy/app/helpers/application_helper.rb
95
+ - test/dummy/app/views/info/about_blank.html.erb
95
96
  - test/dummy/app/views/info/about.html.erb
96
97
  - test/dummy/app/views/layouts/application.html.erb
97
98
  - test/dummy/app/assets/stylesheets/info.css
@@ -134,7 +135,7 @@ rubyforge_project:
134
135
  rubygems_version: 1.8.12
135
136
  signing_key:
136
137
  specification_version: 3
137
- summary: Summary of DfpHelper.
138
+ summary: Rails plugin to add DFP tags to your site.
138
139
  test_files:
139
140
  - test/test_helper.rb
140
141
  - test/dfp_helper_test.rb
@@ -165,6 +166,7 @@ test_files:
165
166
  - test/dummy/test/functional/info_controller_test.rb
166
167
  - test/dummy/app/helpers/info_helper.rb
167
168
  - test/dummy/app/helpers/application_helper.rb
169
+ - test/dummy/app/views/info/about_blank.html.erb
168
170
  - test/dummy/app/views/info/about.html.erb
169
171
  - test/dummy/app/views/layouts/application.html.erb
170
172
  - test/dummy/app/assets/stylesheets/info.css