ads-rails 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +71 -0
- data/lib/ads-rails.rb +18 -0
- data/lib/ads/rails/action_view/base.rb +5 -3
- data/lib/ads/rails/railtie.rb +0 -3
- data/lib/ads/rails/version.rb +1 -1
- data/lib/generators/ads/install_generator.rb +13 -0
- data/lib/generators/ads/templates/ads.rb +2 -0
- data/test/dummy/log/test.log +95 -0
- data/test/generator_test.rb +18 -0
- data/test/include_tag_test.rb +7 -7
- metadata +7 -3
- data/README.rdoc +0 -45
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aefcb9222a068807926d5be7ea94fa88e1596bff
|
4
|
+
data.tar.gz: 3065730fd22ae0b307a5beead62ee424ada2f4a5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2425f7fb9a04661cc7d28747d81a06df1cd3a307b17b272c414c1b039b14a535a62c8cf39e76428ab2f736bd341d50240436ff4826bbab3b5fa479f402fac093
|
7
|
+
data.tar.gz: 20e75a062c5a62c8bd03720de792ac520766d0dfdc5bf2889d8a4c6785d7bfd88d4f2cc4352ca0b0d9629dc7d5a7c9ae2fec2b7f318f119ed1a7b09bdf971cb2
|
data/README.md
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
[![Gem Version](https://badge.fury.io/rb/ads-rails.svg)](http://badge.fury.io/rb/ads-rails) [![Code Climate](https://codeclimate.com/github/museways/ads-rails/badges/gpa.svg)](https://codeclimate.com/github/museways/ads-rails) [![Build Status](https://travis-ci.org/museways/ads-rails.svg?branch=0.1.1)](https://travis-ci.org/museways/ads-rails)
|
2
|
+
|
3
|
+
# Ads Rails
|
4
|
+
|
5
|
+
Adds a simple helper to create the google adsense include tag in rails.
|
6
|
+
|
7
|
+
## Install
|
8
|
+
|
9
|
+
Put this line in your Gemfile:
|
10
|
+
```ruby
|
11
|
+
gem 'ads-rails'
|
12
|
+
```
|
13
|
+
|
14
|
+
Then bundle:
|
15
|
+
```
|
16
|
+
$ bundle
|
17
|
+
```
|
18
|
+
|
19
|
+
## Configuration
|
20
|
+
|
21
|
+
Generate the configuration file:
|
22
|
+
```
|
23
|
+
rails g ads:install
|
24
|
+
```
|
25
|
+
|
26
|
+
The defaults values are:
|
27
|
+
```ruby
|
28
|
+
Ads.configure do |config|
|
29
|
+
config.renderer = nil
|
30
|
+
end
|
31
|
+
```
|
32
|
+
|
33
|
+
## Usage
|
34
|
+
|
35
|
+
In your views call the helper like this:
|
36
|
+
```erb
|
37
|
+
<%= google_adsense_include_tag client: 'pub-1234', slot: '1234', ... %>
|
38
|
+
```
|
39
|
+
|
40
|
+
All the arguments will be mapped to the the corresponding google_ad variable:
|
41
|
+
```ruby
|
42
|
+
google_ad_client = 'pub-1234'
|
43
|
+
google_ad_slot = '1234'
|
44
|
+
.
|
45
|
+
.
|
46
|
+
.
|
47
|
+
```
|
48
|
+
|
49
|
+
NOTE: If environment is not production, will show a gray rectangle.
|
50
|
+
|
51
|
+
## Renderer
|
52
|
+
|
53
|
+
To change the output when the environment is not production, add a custom renderer:
|
54
|
+
```ruby
|
55
|
+
Ads.configure do |config|
|
56
|
+
config.renderer = lambda { |options|
|
57
|
+
tag(
|
58
|
+
:img,
|
59
|
+
src: "http://placehold.it/#{options[:width]}x#{options[:height]}&text=Adsense"
|
60
|
+
)
|
61
|
+
}
|
62
|
+
end
|
63
|
+
```
|
64
|
+
|
65
|
+
## Credits
|
66
|
+
|
67
|
+
This gem is maintained and funded by [museways](http://museways.com).
|
68
|
+
|
69
|
+
## License
|
70
|
+
|
71
|
+
It is free software, and may be redistributed under the terms specified in the MIT-LICENSE file.
|
data/lib/ads-rails.rb
CHANGED
@@ -8,7 +8,9 @@ module Ads
|
|
8
8
|
if ::Rails.env.production?
|
9
9
|
script = ''.tap do |script|
|
10
10
|
options.each do |key, value|
|
11
|
-
|
11
|
+
if value.is_a? String
|
12
|
+
value = "'#{value}'"
|
13
|
+
end
|
12
14
|
script << "google_ad_#{key} = #{value};\n"
|
13
15
|
end
|
14
16
|
end
|
@@ -23,8 +25,8 @@ module Ads
|
|
23
25
|
type: 'text/javascript',
|
24
26
|
src: "#{request.protocol}pagead2.googlesyndication.com/pagead/show_ads.js"
|
25
27
|
)
|
26
|
-
elsif
|
27
|
-
instance_exec options,
|
28
|
+
elsif Ads.config.renderer.is_a? Proc
|
29
|
+
instance_exec options, &Ads.config.renderer
|
28
30
|
else
|
29
31
|
content_tag(
|
30
32
|
:div,
|
data/lib/ads/rails/railtie.rb
CHANGED
data/lib/ads/rails/version.rb
CHANGED
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
|
3
|
+
module Ads
|
4
|
+
class InstallGenerator < ::Rails::Generators::Base
|
5
|
+
|
6
|
+
source_root File.expand_path('../templates', __FILE__)
|
7
|
+
|
8
|
+
def create_initializer
|
9
|
+
copy_file 'ads.rb', 'config/initializers/ads.rb'
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
13
|
+
end
|
data/test/dummy/log/test.log
CHANGED
@@ -1340,3 +1340,98 @@ IncludeTagTest: test_show_gray_div_if_env_is_not_production_and_there_is_no_rend
|
|
1340
1340
|
IncludeTagTest: test_show_renderer_output_if_env_is_not_production_and_there_is_a_renderer
|
1341
1341
|
------------------------------------------------------------------------------------------
|
1342
1342
|
[1m[36m (0.0ms)[0m [1mrollback transaction[0m
|
1343
|
+
[1m[36m (0.3ms)[0m [1mCREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL) [0m
|
1344
|
+
[1m[35m (0.1ms)[0m select sqlite_version(*)
|
1345
|
+
[1m[36m (0.2ms)[0m [1mCREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")[0m
|
1346
|
+
[1m[35m (0.1ms)[0m SELECT version FROM "schema_migrations"
|
1347
|
+
[1m[36m (0.1ms)[0m [1mINSERT INTO "schema_migrations" (version) VALUES ('0')[0m
|
1348
|
+
[1m[35m (0.1ms)[0m begin transaction
|
1349
|
+
------------------------------------------------------------------------------------
|
1350
|
+
IncludeTagTest: test_show_adsense_code_if_env_is_production_and_there_is_no_renderer
|
1351
|
+
------------------------------------------------------------------------------------
|
1352
|
+
[1m[36m (0.0ms)[0m [1mrollback transaction[0m
|
1353
|
+
[1m[35m (0.0ms)[0m begin transaction
|
1354
|
+
------------------------------------------------------------------------------------
|
1355
|
+
IncludeTagTest: test_show_gray_div_if_env_is_not_production_and_there_is_no_renderer
|
1356
|
+
------------------------------------------------------------------------------------
|
1357
|
+
[1m[36m (0.0ms)[0m [1mrollback transaction[0m
|
1358
|
+
[1m[35m (0.0ms)[0m begin transaction
|
1359
|
+
------------------------------------------------------------------------------------------
|
1360
|
+
IncludeTagTest: test_show_renderer_output_if_env_is_not_production_and_there_is_a_renderer
|
1361
|
+
------------------------------------------------------------------------------------------
|
1362
|
+
[1m[36m (0.0ms)[0m [1mrollback transaction[0m
|
1363
|
+
[1m[36m (0.3ms)[0m [1mCREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL) [0m
|
1364
|
+
[1m[35m (0.1ms)[0m select sqlite_version(*)
|
1365
|
+
[1m[36m (0.1ms)[0m [1mCREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")[0m
|
1366
|
+
[1m[35m (0.0ms)[0m SELECT version FROM "schema_migrations"
|
1367
|
+
[1m[36m (0.1ms)[0m [1mINSERT INTO "schema_migrations" (version) VALUES ('0')[0m
|
1368
|
+
[1m[35m (0.1ms)[0m begin transaction
|
1369
|
+
------------------------------------------------------------------------------------
|
1370
|
+
IncludeTagTest: test_show_adsense_code_if_env_is_production_and_there_is_no_renderer
|
1371
|
+
------------------------------------------------------------------------------------
|
1372
|
+
[1m[36m (0.0ms)[0m [1mrollback transaction[0m
|
1373
|
+
[1m[35m (0.0ms)[0m begin transaction
|
1374
|
+
------------------------------------------------------------------------------------
|
1375
|
+
IncludeTagTest: test_show_gray_div_if_env_is_not_production_and_there_is_no_renderer
|
1376
|
+
------------------------------------------------------------------------------------
|
1377
|
+
[1m[36m (0.0ms)[0m [1mrollback transaction[0m
|
1378
|
+
[1m[35m (0.0ms)[0m begin transaction
|
1379
|
+
------------------------------------------------------------------------------------------
|
1380
|
+
IncludeTagTest: test_show_renderer_output_if_env_is_not_production_and_there_is_a_renderer
|
1381
|
+
------------------------------------------------------------------------------------------
|
1382
|
+
[1m[36m (0.0ms)[0m [1mrollback transaction[0m
|
1383
|
+
[1m[36m (0.3ms)[0m [1mCREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL) [0m
|
1384
|
+
[1m[35m (0.2ms)[0m select sqlite_version(*)
|
1385
|
+
[1m[36m (0.2ms)[0m [1mCREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")[0m
|
1386
|
+
[1m[35m (0.1ms)[0m SELECT version FROM "schema_migrations"
|
1387
|
+
[1m[36m (0.1ms)[0m [1mINSERT INTO "schema_migrations" (version) VALUES ('0')[0m
|
1388
|
+
[1m[36m (0.2ms)[0m [1mCREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL) [0m
|
1389
|
+
[1m[35m (0.1ms)[0m select sqlite_version(*)
|
1390
|
+
[1m[36m (0.1ms)[0m [1mCREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")[0m
|
1391
|
+
[1m[35m (0.1ms)[0m SELECT version FROM "schema_migrations"
|
1392
|
+
[1m[36m (0.1ms)[0m [1mINSERT INTO "schema_migrations" (version) VALUES ('0')[0m
|
1393
|
+
[1m[35m (0.1ms)[0m begin transaction
|
1394
|
+
------------------------------------------------------------------------------------
|
1395
|
+
IncludeTagTest: test_show_adsense_code_if_env_is_production_and_there_is_no_renderer
|
1396
|
+
------------------------------------------------------------------------------------
|
1397
|
+
[1m[36m (0.0ms)[0m [1mrollback transaction[0m
|
1398
|
+
[1m[35m (0.0ms)[0m begin transaction
|
1399
|
+
------------------------------------------------------------------------------------
|
1400
|
+
IncludeTagTest: test_show_gray_div_if_env_is_not_production_and_there_is_no_renderer
|
1401
|
+
------------------------------------------------------------------------------------
|
1402
|
+
[1m[36m (0.0ms)[0m [1mrollback transaction[0m
|
1403
|
+
[1m[35m (0.0ms)[0m begin transaction
|
1404
|
+
------------------------------------------------------------------------------------------
|
1405
|
+
IncludeTagTest: test_show_renderer_output_if_env_is_not_production_and_there_is_a_renderer
|
1406
|
+
------------------------------------------------------------------------------------------
|
1407
|
+
[1m[36m (0.0ms)[0m [1mrollback transaction[0m
|
1408
|
+
[1m[35m (0.0ms)[0m begin transaction
|
1409
|
+
-----------------------------------------
|
1410
|
+
GeneratorsTest: test_generate_initializer
|
1411
|
+
-----------------------------------------
|
1412
|
+
[1m[36m (0.1ms)[0m [1mrollback transaction[0m
|
1413
|
+
[1m[36m (0.3ms)[0m [1mCREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL) [0m
|
1414
|
+
[1m[35m (0.1ms)[0m select sqlite_version(*)
|
1415
|
+
[1m[36m (0.1ms)[0m [1mCREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")[0m
|
1416
|
+
[1m[35m (0.0ms)[0m SELECT version FROM "schema_migrations"
|
1417
|
+
[1m[36m (0.1ms)[0m [1mINSERT INTO "schema_migrations" (version) VALUES ('0')[0m
|
1418
|
+
[1m[35m (0.1ms)[0m begin transaction
|
1419
|
+
------------------------------------------
|
1420
|
+
GeneratorsTest: test_initializer_generator
|
1421
|
+
------------------------------------------
|
1422
|
+
[1m[36m (0.1ms)[0m [1mrollback transaction[0m
|
1423
|
+
[1m[35m (0.1ms)[0m begin transaction
|
1424
|
+
---------------------------------
|
1425
|
+
IncludeTagTest: test_adsense_code
|
1426
|
+
---------------------------------
|
1427
|
+
[1m[36m (0.0ms)[0m [1mrollback transaction[0m
|
1428
|
+
[1m[35m (0.0ms)[0m begin transaction
|
1429
|
+
-----------------------------
|
1430
|
+
IncludeTagTest: test_gray_div
|
1431
|
+
-----------------------------
|
1432
|
+
[1m[36m (0.0ms)[0m [1mrollback transaction[0m
|
1433
|
+
[1m[35m (0.0ms)[0m begin transaction
|
1434
|
+
-----------------------------
|
1435
|
+
IncludeTagTest: test_renderer
|
1436
|
+
-----------------------------
|
1437
|
+
[1m[36m (0.0ms)[0m [1mrollback transaction[0m
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'rails/generators'
|
3
|
+
require 'generators/ads/install_generator'
|
4
|
+
|
5
|
+
class GeneratorsTest < ::Rails::Generators::TestCase
|
6
|
+
tests Ads::InstallGenerator
|
7
|
+
destination File.expand_path('../tmp', File.dirname(__FILE__))
|
8
|
+
|
9
|
+
teardown do
|
10
|
+
FileUtils.rm_rf self.destination_root
|
11
|
+
end
|
12
|
+
|
13
|
+
test 'initializer generator' do
|
14
|
+
run_generator
|
15
|
+
assert_file 'config/initializers/ads.rb'
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
data/test/include_tag_test.rb
CHANGED
@@ -6,8 +6,8 @@ class IncludeTagTest < ActionView::TestCase
|
|
6
6
|
self.request = OpenStruct.new(protocol: 'http://')
|
7
7
|
end
|
8
8
|
|
9
|
-
test
|
10
|
-
|
9
|
+
test 'adsense code' do
|
10
|
+
Ads.config.renderer = nil
|
11
11
|
with_env 'production' do
|
12
12
|
assert_equal(
|
13
13
|
%Q(<script type="text/javascript">google_ad_client = 'pub-1234';\ngoogle_ad_width = 728;\n</script>) +
|
@@ -16,9 +16,9 @@ class IncludeTagTest < ActionView::TestCase
|
|
16
16
|
)
|
17
17
|
end
|
18
18
|
end
|
19
|
-
|
20
|
-
test
|
21
|
-
|
19
|
+
|
20
|
+
test 'renderer' do
|
21
|
+
Ads.config.renderer = lambda { |options|
|
22
22
|
tag(
|
23
23
|
:img,
|
24
24
|
src: "http://placehold.it/#{options[:width]}x#{options[:height]}&text=Adsense"
|
@@ -32,8 +32,8 @@ class IncludeTagTest < ActionView::TestCase
|
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
|
-
test
|
36
|
-
|
35
|
+
test 'gray div' do
|
36
|
+
Ads.config.renderer = nil
|
37
37
|
with_env 'development' do
|
38
38
|
assert_equal(
|
39
39
|
'<div style="width:728px;height:90px;background:#c8c8c8;"></div>',
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ads-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Museways
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-09-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -53,13 +53,15 @@ extensions: []
|
|
53
53
|
extra_rdoc_files: []
|
54
54
|
files:
|
55
55
|
- MIT-LICENSE
|
56
|
-
- README.
|
56
|
+
- README.md
|
57
57
|
- Rakefile
|
58
58
|
- lib/ads-rails.rb
|
59
59
|
- lib/ads/rails.rb
|
60
60
|
- lib/ads/rails/action_view/base.rb
|
61
61
|
- lib/ads/rails/railtie.rb
|
62
62
|
- lib/ads/rails/version.rb
|
63
|
+
- lib/generators/ads/install_generator.rb
|
64
|
+
- lib/generators/ads/templates/ads.rb
|
63
65
|
- test/dummy/README.rdoc
|
64
66
|
- test/dummy/Rakefile
|
65
67
|
- test/dummy/app/assets/javascripts/application.js
|
@@ -108,6 +110,7 @@ files:
|
|
108
110
|
- test/dummy/tmp/cache/assets/test/sprockets/cffd775d018f68ce5dba1ee0d951a994
|
109
111
|
- test/dummy/tmp/cache/assets/test/sprockets/d771ace226fc8215a3572e0aa35bb0d6
|
110
112
|
- test/dummy/tmp/cache/assets/test/sprockets/f7cbd26ba1d28d48de824f0e94586655
|
113
|
+
- test/generator_test.rb
|
111
114
|
- test/include_tag_test.rb
|
112
115
|
- test/test_helper.rb
|
113
116
|
homepage: https://github.com/museways/ads-rails
|
@@ -183,5 +186,6 @@ test_files:
|
|
183
186
|
- test/dummy/tmp/cache/assets/test/sprockets/cffd775d018f68ce5dba1ee0d951a994
|
184
187
|
- test/dummy/tmp/cache/assets/test/sprockets/d771ace226fc8215a3572e0aa35bb0d6
|
185
188
|
- test/dummy/tmp/cache/assets/test/sprockets/f7cbd26ba1d28d48de824f0e94586655
|
189
|
+
- test/generator_test.rb
|
186
190
|
- test/include_tag_test.rb
|
187
191
|
- test/test_helper.rb
|
data/README.rdoc
DELETED
@@ -1,45 +0,0 @@
|
|
1
|
-
{<img src="https://badge.fury.io/rb/ads-rails.png" alt="Gem Version" />}[http://badge.fury.io/rb/ads-rails] {<img src="https://codeclimate.com/github/museways/ads-rails.png" />}[https://codeclimate.com/github/museways/ads-rails] {<img src="https://travis-ci.org/museways/ads-rails.png?branch=master" alt="Build Status" />}[https://travis-ci.org/museways/ads-rails]
|
2
|
-
|
3
|
-
= Ads Rails
|
4
|
-
|
5
|
-
Adds a simple helper to create the google adsense include tag in rails.
|
6
|
-
|
7
|
-
= Install
|
8
|
-
|
9
|
-
Put this line in your Gemfile:
|
10
|
-
gem 'ads-rails'
|
11
|
-
|
12
|
-
Then bundle:
|
13
|
-
$ bundle
|
14
|
-
|
15
|
-
= Usage
|
16
|
-
|
17
|
-
In your views call the helper like this:
|
18
|
-
<%= google_adsense_include_tag client: 'pub-1234', slot: '1234', ... %>
|
19
|
-
|
20
|
-
All the arguments will be mapped to the the corresponding google_ad variable:
|
21
|
-
google_ad_client = 'pub-1234'
|
22
|
-
google_ad_slot = '1234'
|
23
|
-
.
|
24
|
-
.
|
25
|
-
.
|
26
|
-
|
27
|
-
NOTE: If environment is not production, will show a gray rectangle.
|
28
|
-
|
29
|
-
= Configuration
|
30
|
-
|
31
|
-
To change the output when the environment is not production, add a custom renderer in your application.rb:
|
32
|
-
config.ads.renderer = lambda { |options|
|
33
|
-
tag(
|
34
|
-
:img,
|
35
|
-
src: "http://placehold.it/#{options[:width]}x#{options[:height]}&text=Adsense"
|
36
|
-
)
|
37
|
-
}
|
38
|
-
|
39
|
-
= Credits
|
40
|
-
|
41
|
-
This gem is maintained and funded by museways[http://museways.com].
|
42
|
-
|
43
|
-
= License
|
44
|
-
|
45
|
-
It is free software, and may be redistributed under the terms specified in the MIT-LICENSE file.
|