ads-rails 0.2.3 → 4.0.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/MIT-LICENSE +1 -1
- data/README.md +17 -20
- data/Rakefile +1 -14
- data/lib/ads-rails.rb +4 -7
- data/lib/ads/configuration.rb +13 -0
- data/lib/ads/rails.rb +2 -1
- data/lib/ads/rails/extensions/action_view/base.rb +34 -0
- data/lib/ads/rails/railtie.rb +4 -2
- data/lib/ads/rails/version.rb +1 -1
- data/lib/generators/ads/install/install_generator.rb +15 -0
- data/lib/generators/ads/install/templates/initializer.rb +8 -0
- data/test/dummy/Rakefile +1 -2
- data/test/dummy/app/assets/javascripts/application.js +2 -2
- data/test/dummy/app/assets/stylesheets/application.css +6 -4
- data/test/dummy/app/views/layouts/application.html.erb +9 -11
- data/test/dummy/bin/bundle +1 -0
- data/test/dummy/bin/rails +2 -1
- data/test/dummy/bin/rake +1 -0
- data/test/dummy/bin/setup +30 -0
- data/test/dummy/config.ru +1 -1
- data/test/dummy/config/application.rb +6 -1
- data/test/dummy/config/boot.rb +1 -1
- data/test/dummy/config/environment.rb +1 -1
- data/test/dummy/config/environments/development.rb +14 -5
- data/test/dummy/config/environments/production.rb +18 -26
- data/test/dummy/config/environments/test.rb +10 -12
- data/test/dummy/config/initializers/ads.rb +8 -0
- data/test/dummy/config/initializers/assets.rb +11 -0
- data/test/dummy/config/initializers/cookies_serializer.rb +3 -0
- data/test/dummy/config/initializers/mime_types.rb +1 -2
- data/test/dummy/config/initializers/session_store.rb +1 -1
- data/test/dummy/config/routes.rb +1 -1
- data/test/dummy/config/secrets.yml +22 -0
- data/test/dummy/log/development.log +0 -0
- data/test/dummy/log/test.log +60 -0
- data/test/dummy/public/404.html +58 -55
- data/test/dummy/public/422.html +58 -55
- data/test/dummy/public/500.html +57 -54
- data/test/generator_test.rb +5 -5
- data/test/test_helper.rb +5 -14
- data/test/view_test.rb +28 -0
- metadata +28 -60
- data/lib/ads/rails/action_view/base.rb +0 -40
- data/lib/generators/ads/install_generator.rb +0 -13
- data/lib/generators/ads/templates/ads.rb +0 -2
- data/test/dummy/README.rdoc +0 -28
- data/test/dummy/config/database.yml +0 -25
- data/test/dummy/config/initializers/secret_token.rb +0 -13
- data/test/dummy/db/schema.rb +0 -16
- data/test/dummy/tmp/cache/assets/development/sprockets/13fe41fee1fe35b49d145bcc06610705 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/2f5173deea6c795b8fdde723bb4b63af +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/357970feca3ac29060c1e3861e2c0953 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/cffd775d018f68ce5dba1ee0d951a994 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/d771ace226fc8215a3572e0aa35bb0d6 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/f7cbd26ba1d28d48de824f0e94586655 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/13fe41fee1fe35b49d145bcc06610705 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/2f5173deea6c795b8fdde723bb4b63af +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/357970feca3ac29060c1e3861e2c0953 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/cffd775d018f68ce5dba1ee0d951a994 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/d771ace226fc8215a3572e0aa35bb0d6 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/f7cbd26ba1d28d48de824f0e94586655 +0 -0
- data/test/include_tag_test.rb +0 -47
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0190c1b28e972966fd01bf07e8d73e334fb7957c
|
4
|
+
data.tar.gz: 728f546a835bb81e00464e84d13a55d339247739
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e5b509117bbe3d2dcd752419f8c9dde2a511fd55e720c5ef1d824e12c3c9b75ec7680a64c06e417b3b449839f3c77803e2912df2671842aea1ceff3669866ed4
|
7
|
+
data.tar.gz: 2fce48ab28e6b9261ba7601ea0d1d9a441d381cbd9c47769dd9a14ec0026f5ef20b948aa95676b48759dcb11168815a233239aa56479a54c5cf05cbeb56ac291
|
data/MIT-LICENSE
CHANGED
data/README.md
CHANGED
@@ -5,7 +5,13 @@
|
|
5
5
|
|
6
6
|
# Ads Rails
|
7
7
|
|
8
|
-
|
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
|
-
|
35
|
+
Customize the sample tag if you want:
|
30
36
|
```ruby
|
31
37
|
Ads.configure do |config|
|
32
|
-
|
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 =
|
57
|
+
google_ad_slot = 1234
|
47
58
|
.
|
48
59
|
.
|
49
60
|
.
|
50
61
|
```
|
51
62
|
|
52
|
-
NOTE: If environment is not production, will
|
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
|
8
|
+
yield configuration
|
8
9
|
end
|
9
10
|
|
10
|
-
def
|
11
|
-
@
|
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
|
data/lib/ads/rails.rb
CHANGED
@@ -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
|
data/lib/ads/rails/railtie.rb
CHANGED
@@ -2,8 +2,10 @@ module Ads
|
|
2
2
|
module Rails
|
3
3
|
class Railtie < ::Rails::Railtie
|
4
4
|
|
5
|
-
initializer 'ads.
|
6
|
-
::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
|
data/lib/ads/rails/version.rb
CHANGED
@@ -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
|
data/test/dummy/Rakefile
CHANGED
@@ -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
|
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/
|
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
|
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
|
9
|
-
* compiled file
|
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
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
</head>
|
9
|
-
<body>
|
10
|
-
|
11
|
-
|
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>
|
data/test/dummy/bin/bundle
CHANGED
data/test/dummy/bin/rails
CHANGED
data/test/dummy/bin/rake
CHANGED
@@ -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,6 +1,11 @@
|
|
1
1
|
require File.expand_path('../boot', __FILE__)
|
2
2
|
|
3
|
-
require '
|
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'
|
data/test/dummy/config/boot.rb
CHANGED
@@ -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.
|
4
|
+
require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
|
5
5
|
$LOAD_PATH.unshift File.expand_path('../../../../lib', __FILE__)
|
@@ -1,4 +1,4 @@
|
|
1
|
-
|
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
|
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
|