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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6e3631ccff398d44be0e1a07e2a3ef55298ecd51
4
- data.tar.gz: 08fd7244266fc90c3d9cc06562cd2eaa9d607835
3
+ metadata.gz: aefcb9222a068807926d5be7ea94fa88e1596bff
4
+ data.tar.gz: 3065730fd22ae0b307a5beead62ee424ada2f4a5
5
5
  SHA512:
6
- metadata.gz: f1de5d731c51f67e3fdd8f710e74ebc71dc2a6c08cd1fc1ef328ed3889d90d4f5eec282e52a48ea337468954a1da08bd292b19c592e3f7225b2185a566b68ac0
7
- data.tar.gz: 9daa6d7394c0ddf2bf817b475bf006985e51fb011b15d5e1b8394651298f51b5b177bb050760f1498682850d9a99a1b3690287886a365dfa14fee0d0b6ec9070
6
+ metadata.gz: 2425f7fb9a04661cc7d28747d81a06df1cd3a307b17b272c414c1b039b14a535a62c8cf39e76428ab2f736bd341d50240436ff4826bbab3b5fa479f402fac093
7
+ data.tar.gz: 20e75a062c5a62c8bd03720de792ac520766d0dfdc5bf2889d8a4c6785d7bfd88d4f2cc4352ca0b0d9629dc7d5a7c9ae2fec2b7f318f119ed1a7b09bdf971cb2
@@ -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.
@@ -1 +1,19 @@
1
1
  require 'ads/rails'
2
+
3
+ module Ads
4
+ class << self
5
+
6
+ def configure
7
+ yield config
8
+ end
9
+
10
+ def config
11
+ @config ||= begin
12
+ ActiveSupport::OrderedOptions.new.tap do |config|
13
+ config.renderer = nil
14
+ end
15
+ end
16
+ end
17
+
18
+ end
19
+ end
@@ -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
- value = "'#{value}'" if value.is_a? String
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 ::Rails.application.config.ads.renderer.is_a? Proc
27
- instance_exec options, &::Rails.application.config.ads.renderer
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,
@@ -2,9 +2,6 @@ module Ads
2
2
  module Rails
3
3
  class Railtie < ::Rails::Railtie
4
4
 
5
- config.ads = ActiveSupport::OrderedOptions.new
6
- config.ads.renderer = nil
7
-
8
5
  initializer 'ads.rails' do
9
6
  ::ActionView::Base.send :include, Ads::Rails::ActionView::Base
10
7
  end
@@ -1,7 +1,7 @@
1
1
  module Ads
2
2
  module Rails
3
3
 
4
- VERSION = '0.1.1'
4
+ VERSION = '0.2.0'
5
5
 
6
6
  end
7
7
  end
@@ -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
@@ -0,0 +1,2 @@
1
+ Ads.configure do |config|
2
+ end
@@ -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
   (0.0ms) rollback transaction
1343
+  (0.3ms) CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL) 
1344
+  (0.1ms) select sqlite_version(*)
1345
+  (0.2ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
1346
+  (0.1ms) SELECT version FROM "schema_migrations"
1347
+  (0.1ms) INSERT INTO "schema_migrations" (version) VALUES ('0')
1348
+  (0.1ms) begin transaction
1349
+ ------------------------------------------------------------------------------------
1350
+ IncludeTagTest: test_show_adsense_code_if_env_is_production_and_there_is_no_renderer
1351
+ ------------------------------------------------------------------------------------
1352
+  (0.0ms) rollback transaction
1353
+  (0.0ms) begin transaction
1354
+ ------------------------------------------------------------------------------------
1355
+ IncludeTagTest: test_show_gray_div_if_env_is_not_production_and_there_is_no_renderer
1356
+ ------------------------------------------------------------------------------------
1357
+  (0.0ms) rollback transaction
1358
+  (0.0ms) begin transaction
1359
+ ------------------------------------------------------------------------------------------
1360
+ IncludeTagTest: test_show_renderer_output_if_env_is_not_production_and_there_is_a_renderer
1361
+ ------------------------------------------------------------------------------------------
1362
+  (0.0ms) rollback transaction
1363
+  (0.3ms) CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL) 
1364
+  (0.1ms) select sqlite_version(*)
1365
+  (0.1ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
1366
+  (0.0ms) SELECT version FROM "schema_migrations"
1367
+  (0.1ms) INSERT INTO "schema_migrations" (version) VALUES ('0')
1368
+  (0.1ms) begin transaction
1369
+ ------------------------------------------------------------------------------------
1370
+ IncludeTagTest: test_show_adsense_code_if_env_is_production_and_there_is_no_renderer
1371
+ ------------------------------------------------------------------------------------
1372
+  (0.0ms) rollback transaction
1373
+  (0.0ms) begin transaction
1374
+ ------------------------------------------------------------------------------------
1375
+ IncludeTagTest: test_show_gray_div_if_env_is_not_production_and_there_is_no_renderer
1376
+ ------------------------------------------------------------------------------------
1377
+  (0.0ms) rollback transaction
1378
+  (0.0ms) begin transaction
1379
+ ------------------------------------------------------------------------------------------
1380
+ IncludeTagTest: test_show_renderer_output_if_env_is_not_production_and_there_is_a_renderer
1381
+ ------------------------------------------------------------------------------------------
1382
+  (0.0ms) rollback transaction
1383
+  (0.3ms) CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL) 
1384
+  (0.2ms) select sqlite_version(*)
1385
+  (0.2ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
1386
+  (0.1ms) SELECT version FROM "schema_migrations"
1387
+  (0.1ms) INSERT INTO "schema_migrations" (version) VALUES ('0')
1388
+  (0.2ms) CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL) 
1389
+  (0.1ms) select sqlite_version(*)
1390
+  (0.1ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
1391
+  (0.1ms) SELECT version FROM "schema_migrations"
1392
+  (0.1ms) INSERT INTO "schema_migrations" (version) VALUES ('0')
1393
+  (0.1ms) begin transaction
1394
+ ------------------------------------------------------------------------------------
1395
+ IncludeTagTest: test_show_adsense_code_if_env_is_production_and_there_is_no_renderer
1396
+ ------------------------------------------------------------------------------------
1397
+  (0.0ms) rollback transaction
1398
+  (0.0ms) begin transaction
1399
+ ------------------------------------------------------------------------------------
1400
+ IncludeTagTest: test_show_gray_div_if_env_is_not_production_and_there_is_no_renderer
1401
+ ------------------------------------------------------------------------------------
1402
+  (0.0ms) rollback transaction
1403
+  (0.0ms) begin transaction
1404
+ ------------------------------------------------------------------------------------------
1405
+ IncludeTagTest: test_show_renderer_output_if_env_is_not_production_and_there_is_a_renderer
1406
+ ------------------------------------------------------------------------------------------
1407
+  (0.0ms) rollback transaction
1408
+  (0.0ms) begin transaction
1409
+ -----------------------------------------
1410
+ GeneratorsTest: test_generate_initializer
1411
+ -----------------------------------------
1412
+  (0.1ms) rollback transaction
1413
+  (0.3ms) CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL) 
1414
+  (0.1ms) select sqlite_version(*)
1415
+  (0.1ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
1416
+  (0.0ms) SELECT version FROM "schema_migrations"
1417
+  (0.1ms) INSERT INTO "schema_migrations" (version) VALUES ('0')
1418
+  (0.1ms) begin transaction
1419
+ ------------------------------------------
1420
+ GeneratorsTest: test_initializer_generator
1421
+ ------------------------------------------
1422
+  (0.1ms) rollback transaction
1423
+  (0.1ms) begin transaction
1424
+ ---------------------------------
1425
+ IncludeTagTest: test_adsense_code
1426
+ ---------------------------------
1427
+  (0.0ms) rollback transaction
1428
+  (0.0ms) begin transaction
1429
+ -----------------------------
1430
+ IncludeTagTest: test_gray_div
1431
+ -----------------------------
1432
+  (0.0ms) rollback transaction
1433
+  (0.0ms) begin transaction
1434
+ -----------------------------
1435
+ IncludeTagTest: test_renderer
1436
+ -----------------------------
1437
+  (0.0ms) rollback transaction
@@ -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
@@ -6,8 +6,8 @@ class IncludeTagTest < ActionView::TestCase
6
6
  self.request = OpenStruct.new(protocol: 'http://')
7
7
  end
8
8
 
9
- test "show adsense code if env is production and there is no renderer" do
10
- ::Rails.application.config.ads.renderer = nil
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 "show renderer output if env is not production and there is a renderer" do
21
- ::Rails.application.config.ads.renderer = lambda { |options|
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 "show gray div if env is not production and there is no renderer" do
36
- ::Rails.application.config.ads.renderer = nil
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.1.1
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-06-24 00:00:00.000000000 Z
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.rdoc
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
@@ -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.