ads-rails 0.2.3 → 4.0.0.0

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.
Files changed (63) hide show
  1. checksums.yaml +4 -4
  2. data/MIT-LICENSE +1 -1
  3. data/README.md +17 -20
  4. data/Rakefile +1 -14
  5. data/lib/ads-rails.rb +4 -7
  6. data/lib/ads/configuration.rb +13 -0
  7. data/lib/ads/rails.rb +2 -1
  8. data/lib/ads/rails/extensions/action_view/base.rb +34 -0
  9. data/lib/ads/rails/railtie.rb +4 -2
  10. data/lib/ads/rails/version.rb +1 -1
  11. data/lib/generators/ads/install/install_generator.rb +15 -0
  12. data/lib/generators/ads/install/templates/initializer.rb +8 -0
  13. data/test/dummy/Rakefile +1 -2
  14. data/test/dummy/app/assets/javascripts/application.js +2 -2
  15. data/test/dummy/app/assets/stylesheets/application.css +6 -4
  16. data/test/dummy/app/views/layouts/application.html.erb +9 -11
  17. data/test/dummy/bin/bundle +1 -0
  18. data/test/dummy/bin/rails +2 -1
  19. data/test/dummy/bin/rake +1 -0
  20. data/test/dummy/bin/setup +30 -0
  21. data/test/dummy/config.ru +1 -1
  22. data/test/dummy/config/application.rb +6 -1
  23. data/test/dummy/config/boot.rb +1 -1
  24. data/test/dummy/config/environment.rb +1 -1
  25. data/test/dummy/config/environments/development.rb +14 -5
  26. data/test/dummy/config/environments/production.rb +18 -26
  27. data/test/dummy/config/environments/test.rb +10 -12
  28. data/test/dummy/config/initializers/ads.rb +8 -0
  29. data/test/dummy/config/initializers/assets.rb +11 -0
  30. data/test/dummy/config/initializers/cookies_serializer.rb +3 -0
  31. data/test/dummy/config/initializers/mime_types.rb +1 -2
  32. data/test/dummy/config/initializers/session_store.rb +1 -1
  33. data/test/dummy/config/routes.rb +1 -1
  34. data/test/dummy/config/secrets.yml +22 -0
  35. data/test/dummy/log/development.log +0 -0
  36. data/test/dummy/log/test.log +60 -0
  37. data/test/dummy/public/404.html +58 -55
  38. data/test/dummy/public/422.html +58 -55
  39. data/test/dummy/public/500.html +57 -54
  40. data/test/generator_test.rb +5 -5
  41. data/test/test_helper.rb +5 -14
  42. data/test/view_test.rb +28 -0
  43. metadata +28 -60
  44. data/lib/ads/rails/action_view/base.rb +0 -40
  45. data/lib/generators/ads/install_generator.rb +0 -13
  46. data/lib/generators/ads/templates/ads.rb +0 -2
  47. data/test/dummy/README.rdoc +0 -28
  48. data/test/dummy/config/database.yml +0 -25
  49. data/test/dummy/config/initializers/secret_token.rb +0 -13
  50. data/test/dummy/db/schema.rb +0 -16
  51. data/test/dummy/tmp/cache/assets/development/sprockets/13fe41fee1fe35b49d145bcc06610705 +0 -0
  52. data/test/dummy/tmp/cache/assets/development/sprockets/2f5173deea6c795b8fdde723bb4b63af +0 -0
  53. data/test/dummy/tmp/cache/assets/development/sprockets/357970feca3ac29060c1e3861e2c0953 +0 -0
  54. data/test/dummy/tmp/cache/assets/development/sprockets/cffd775d018f68ce5dba1ee0d951a994 +0 -0
  55. data/test/dummy/tmp/cache/assets/development/sprockets/d771ace226fc8215a3572e0aa35bb0d6 +0 -0
  56. data/test/dummy/tmp/cache/assets/development/sprockets/f7cbd26ba1d28d48de824f0e94586655 +0 -0
  57. data/test/dummy/tmp/cache/assets/test/sprockets/13fe41fee1fe35b49d145bcc06610705 +0 -0
  58. data/test/dummy/tmp/cache/assets/test/sprockets/2f5173deea6c795b8fdde723bb4b63af +0 -0
  59. data/test/dummy/tmp/cache/assets/test/sprockets/357970feca3ac29060c1e3861e2c0953 +0 -0
  60. data/test/dummy/tmp/cache/assets/test/sprockets/cffd775d018f68ce5dba1ee0d951a994 +0 -0
  61. data/test/dummy/tmp/cache/assets/test/sprockets/d771ace226fc8215a3572e0aa35bb0d6 +0 -0
  62. data/test/dummy/tmp/cache/assets/test/sprockets/f7cbd26ba1d28d48de824f0e94586655 +0 -0
  63. data/test/include_tag_test.rb +0 -47
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b1684aa3ac086681a3e6d6a6677e9efd5c3e6c87
4
- data.tar.gz: d21f4915c2c048012fad37fe2ed20f47da54e0e8
3
+ metadata.gz: 0190c1b28e972966fd01bf07e8d73e334fb7957c
4
+ data.tar.gz: 728f546a835bb81e00464e84d13a55d339247739
5
5
  SHA512:
6
- metadata.gz: cc7ea328ea577df7808d96d9bce3f8c398ae6b81ab5b29dcc664f5072c73930c682229ada698c6d4ac8773e28d72a3c22515ed5fa63025355aa456a3c5286719
7
- data.tar.gz: 5a7a61fad6d960bb655ed050df928341daaac249137ab6263a56322fac0b8c5fe629e28b5d86d0bc28008a63b7b2fa2d3e32a46ce4b68edb2b3cbed9f4e9d1d0
6
+ metadata.gz: e5b509117bbe3d2dcd752419f8c9dde2a511fd55e720c5ef1d824e12c3c9b75ec7680a64c06e417b3b449839f3c77803e2912df2671842aea1ceff3669866ed4
7
+ data.tar.gz: 2fce48ab28e6b9261ba7601ea0d1d9a441d381cbd9c47769dd9a14ec0026f5ef20b948aa95676b48759dcb11168815a233239aa56479a54c5cf05cbeb56ac291
data/MIT-LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright 2015 Mathías Montossi
1
+ Copyright 2016 Mathías Montossi
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
data/README.md CHANGED
@@ -5,7 +5,13 @@
5
5
 
6
6
  # Ads Rails
7
7
 
8
- Adds a simple helper to create the google adsense include tag in rails.
8
+ Helper to create the google adsense include tag in rails.
9
+
10
+ ## Why
11
+
12
+ I did this gem to:
13
+
14
+ - Have a simple but versatile way to include google adsense.
9
15
 
10
16
  ## Install
11
17
 
@@ -23,13 +29,18 @@ $ bundle
23
29
 
24
30
  Generate the configuration file:
25
31
  ```
26
- rails g ads:install
32
+ $ bundle exec rails g ads:install
27
33
  ```
28
34
 
29
- The defaults values are:
35
+ Customize the sample tag if you want:
30
36
  ```ruby
31
37
  Ads.configure do |config|
32
- config.renderer = nil
38
+
39
+ config.sample_tag do |options|
40
+ style = "width: #{options[:width]}px; height: #{options[:height]}px; background: #c8c8c8;"
41
+ content_tag :div, nil, style: style
42
+ end
43
+
33
44
  end
34
45
  ```
35
46
 
@@ -43,27 +54,13 @@ In your views call the helper like this:
43
54
  All the arguments will be mapped to the the corresponding google_ad variable:
44
55
  ```ruby
45
56
  google_ad_client = 'pub-1234'
46
- google_ad_slot = '1234'
57
+ google_ad_slot = 1234
47
58
  .
48
59
  .
49
60
  .
50
61
  ```
51
62
 
52
- NOTE: If environment is not production, will show a gray rectangle.
53
-
54
- ## Renderer
55
-
56
- To change the output when the environment is not production, add a custom renderer:
57
- ```ruby
58
- Ads.configure do |config|
59
- config.renderer = lambda { |options|
60
- tag(
61
- :img,
62
- src: "http://placehold.it/#{options[:width]}x#{options[:height]}&text=Adsense"
63
- )
64
- }
65
- end
66
- ```
63
+ NOTE: If environment is not production, the sample tag will be use instead.
67
64
 
68
65
  ## Credits
69
66
 
data/Rakefile CHANGED
@@ -4,19 +4,6 @@ rescue LoadError
4
4
  puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
5
  end
6
6
 
7
- require 'rdoc/task'
8
-
9
- RDoc::Task.new(:rdoc) do |rdoc|
10
- rdoc.rdoc_dir = 'rdoc'
11
- rdoc.title = 'AdsRails'
12
- rdoc.options << '--line-numbers'
13
- rdoc.rdoc_files.include('README.rdoc')
14
- rdoc.rdoc_files.include('lib/**/*.rb')
15
- end
16
-
17
-
18
-
19
-
20
7
  Bundler::GemHelper.install_tasks
21
8
 
22
9
  require 'rake/testtask'
@@ -26,7 +13,7 @@ Rake::TestTask.new(:test) do |t|
26
13
  t.libs << 'test'
27
14
  t.pattern = 'test/**/*_test.rb'
28
15
  t.verbose = false
16
+ t.warning = false
29
17
  end
30
18
 
31
-
32
19
  task default: :test
data/lib/ads-rails.rb CHANGED
@@ -1,18 +1,15 @@
1
+ require 'ads/configuration'
1
2
  require 'ads/rails'
2
3
 
3
4
  module Ads
4
5
  class << self
5
6
 
6
7
  def configure
7
- yield config
8
+ yield configuration
8
9
  end
9
10
 
10
- def config
11
- @config ||= begin
12
- ActiveSupport::OrderedOptions.new.tap do |config|
13
- config.renderer = nil
14
- end
15
- end
11
+ def configuration
12
+ @configuration ||= Configuration.new
16
13
  end
17
14
 
18
15
  end
@@ -0,0 +1,13 @@
1
+ module Ads
2
+ class Configuration
3
+
4
+ def sample_tag(&block)
5
+ if block_given?
6
+ @sample_tag = block
7
+ else
8
+ @sample_tag
9
+ end
10
+ end
11
+
12
+ end
13
+ end
data/lib/ads/rails.rb CHANGED
@@ -1,5 +1,6 @@
1
- require 'ads/rails/action_view/base'
1
+ require 'ads/rails/extensions/action_view/base'
2
2
  require 'ads/rails/railtie'
3
+ require 'ads/rails/version'
3
4
 
4
5
  module Ads
5
6
  module Rails
@@ -0,0 +1,34 @@
1
+ module Ads
2
+ module Rails
3
+ module Extensions
4
+ module ActionView
5
+ module Base
6
+ extend ActiveSupport::Concern
7
+
8
+ def google_adsense_include_tag(*args)
9
+ options = args.extract_options!
10
+ if ::Rails.env.production?
11
+ variables = options.map do |key, value|
12
+ "google_ad_#{key} = #{value.to_json};"
13
+ end
14
+ content_tag(
15
+ :script,
16
+ variables.join("\n").html_safe,
17
+ type: 'text/javascript'
18
+ ) +
19
+ content_tag(
20
+ :script,
21
+ nil,
22
+ type: 'text/javascript',
23
+ src: "#{request.protocol}pagead2.googlesyndication.com/pagead/show_ads.js"
24
+ )
25
+ else
26
+ instance_exec options, &Ads.configuration.sample_tag
27
+ end
28
+ end
29
+
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -2,8 +2,10 @@ module Ads
2
2
  module Rails
3
3
  class Railtie < ::Rails::Railtie
4
4
 
5
- initializer 'ads.rails' do
6
- ::ActionView::Base.send :include, Ads::Rails::ActionView::Base
5
+ initializer 'ads.extensions' do
6
+ ::ActionView::Base.include(
7
+ Ads::Rails::Extensions::ActionView::Base
8
+ )
7
9
  end
8
10
 
9
11
  end
@@ -1,7 +1,7 @@
1
1
  module Ads
2
2
  module Rails
3
3
 
4
- VERSION = '0.2.3'
4
+ VERSION = '4.0.0.0'
5
5
 
6
6
  end
7
7
  end
@@ -0,0 +1,15 @@
1
+ require 'rails/generators'
2
+
3
+ module Ads
4
+ module Generators
5
+ class InstallGenerator < ::Rails::Generators::Base
6
+
7
+ source_root File.expand_path('../templates', __FILE__)
8
+
9
+ def create_initializer_file
10
+ copy_file 'initializer.rb', 'config/initializers/ads.rb'
11
+ end
12
+
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,8 @@
1
+ Ads.configure do |config|
2
+
3
+ config.sample_tag do |options|
4
+ style = "width: #{options[:width]}px; height: #{options[:height]}px; background: #c8c8c8;"
5
+ content_tag :div, nil, style: style
6
+ end
7
+
8
+ end
data/test/dummy/Rakefile CHANGED
@@ -2,5 +2,4 @@
2
2
  # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
3
 
4
4
  require File.expand_path('../config/application', __FILE__)
5
-
6
- Dummy::Application.load_tasks
5
+ Rails.application.load_tasks
@@ -2,12 +2,12 @@
2
2
  // listed below.
3
3
  //
4
4
  // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
- // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
5
+ // or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
6
6
  //
7
7
  // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
8
  // compiled file.
9
9
  //
10
- // Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
10
+ // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
11
11
  // about supported directives.
12
12
  //
13
13
  //= require_tree .
@@ -3,11 +3,13 @@
3
3
  * listed below.
4
4
  *
5
5
  * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
- * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
6
+ * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
7
7
  *
8
- * You're free to add application-wide styles to this file and they'll appear at the top of the
9
- * compiled file, but it's generally better to create a new file per style scope.
8
+ * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
+ * compiled file so the styles you add here take precedence over styles defined in any styles
10
+ * defined in the other CSS/SCSS files in this directory. It is generally better to create a new
11
+ * file per style scope.
10
12
  *
11
- *= require_self
12
13
  *= require_tree .
14
+ *= require_self
13
15
  */
@@ -1,14 +1,12 @@
1
1
  <!DOCTYPE html>
2
2
  <html>
3
- <head>
4
- <title>Dummy</title>
5
- <%= stylesheet_link_tag 'application', media: 'all' %>
6
- <%= javascript_include_tag 'application' %>
7
- <%= csrf_meta_tags %>
8
- </head>
9
- <body>
10
-
11
- <%= yield %>
12
-
13
- </body>
3
+ <head>
4
+ <title>Dummy</title>
5
+ <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
6
+ <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
7
+ <%= csrf_meta_tags %>
8
+ </head>
9
+ <body>
10
+ <%= yield %>
11
+ </body>
14
12
  </html>
@@ -1,3 +1,4 @@
1
1
  #!/usr/bin/env ruby
2
+
2
3
  ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
3
4
  load Gem.bin_path('bundler', 'bundle')
data/test/dummy/bin/rails CHANGED
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
- APP_PATH = File.expand_path('../../config/application', __FILE__)
2
+
3
+ APP_PATH = File.expand_path('../../config/application', __FILE__)
3
4
  require_relative '../config/boot'
4
5
  require 'rails/commands'
data/test/dummy/bin/rake CHANGED
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+
2
3
  require_relative '../config/boot'
3
4
  require 'rake'
4
5
  Rake.application.run
@@ -0,0 +1,30 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'pathname'
4
+
5
+ # path to your application root.
6
+ APP_ROOT = Pathname.new File.expand_path('../../', __FILE__)
7
+
8
+ Dir.chdir APP_ROOT do
9
+ # This script is a starting point to setup your application.
10
+ # Add necessary setup steps to this file:
11
+
12
+ puts '== Installing dependencies =='
13
+ system 'gem install bundler --conservative'
14
+ system 'bundle check || bundle install'
15
+
16
+ # puts "\n== Copying sample files =="
17
+ # unless File.exist?('config/database.yml')
18
+ # system 'cp config/database.yml.sample config/database.yml'
19
+ # end
20
+
21
+ puts "\n== Preparing database =="
22
+ system 'bin/rake db:setup'
23
+
24
+ puts "\n== Removing old logs and tempfiles =="
25
+ system 'rm -f log/*'
26
+ system 'rm -rf tmp/cache'
27
+
28
+ puts "\n== Restarting application server =="
29
+ system 'touch tmp/restart.txt'
30
+ end
data/test/dummy/config.ru CHANGED
@@ -1,4 +1,4 @@
1
1
  # This file is used by Rack-based servers to start the application.
2
2
 
3
- require ::File.expand_path('../config/environment', __FILE__)
3
+ require ::File.expand_path('../config/environment', __FILE__)
4
4
  run Rails.application
@@ -1,6 +1,11 @@
1
1
  require File.expand_path('../boot', __FILE__)
2
2
 
3
- require 'rails/all'
3
+ require 'active_model/railtie'
4
+ require 'action_controller/railtie'
5
+ require 'action_mailer/railtie'
6
+ require 'action_view/railtie'
7
+ require 'sprockets/railtie'
8
+ require 'rails/test_unit/railtie'
4
9
 
5
10
  Bundler.require(*Rails.groups)
6
11
  require 'ads-rails'
@@ -1,5 +1,5 @@
1
1
  # Set up gems listed in the Gemfile.
2
2
  ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../../../Gemfile', __FILE__)
3
3
 
4
- require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
4
+ require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
5
5
  $LOAD_PATH.unshift File.expand_path('../../../../lib', __FILE__)
@@ -2,4 +2,4 @@
2
2
  require File.expand_path('../application', __FILE__)
3
3
 
4
4
  # Initialize the Rails application.
5
- Dummy::Application.initialize!
5
+ Rails.application.initialize!
@@ -1,4 +1,4 @@
1
- Dummy::Application.configure do
1
+ Rails.application.configure do
2
2
  # Settings specified here will take precedence over those in config/application.rb.
3
3
 
4
4
  # In the development environment your application's code is reloaded on
@@ -10,7 +10,7 @@ Dummy::Application.configure do
10
10
  config.eager_load = false
11
11
 
12
12
  # Show full error reports and disable caching.
13
- config.consider_all_requests_local = true
13
+ config.consider_all_requests_local = true
14
14
  config.action_controller.perform_caching = false
15
15
 
16
16
  # Don't care if the mailer can't send.
@@ -19,11 +19,20 @@ Dummy::Application.configure do
19
19
  # Print deprecation notices to the Rails logger.
20
20
  config.active_support.deprecation = :log
21
21
 
22
- # Raise an error on page load if there are pending migrations
23
- config.active_record.migration_error = :page_load
24
-
25
22
  # Debug mode disables concatenation and preprocessing of assets.
26
23
  # This option may cause significant delays in view rendering with a large
27
24
  # number of complex assets.
28
25
  config.assets.debug = true
26
+
27
+ # Asset digests allow you to set far-future HTTP expiration dates on all assets,
28
+ # yet still be able to expire them through the digest params.
29
+ config.assets.digest = true
30
+
31
+ # Adds additional error checking when serving assets at runtime.
32
+ # Checks for improperly declared sprockets dependencies.
33
+ # Raises helpful error messages.
34
+ config.assets.raise_runtime_errors = true
35
+
36
+ # Raises error for missing translations
37
+ # config.action_view.raise_on_missing_translations = true
29
38
  end