ad_sense 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.rspec +1 -0
- data/Gemfile +15 -0
- data/Gemfile.lock +71 -0
- data/LICENSE.txt +20 -0
- data/README.md +4 -0
- data/README.rdoc +19 -0
- data/Rakefile +49 -0
- data/VERSION +1 -0
- data/ad_sense.gemspec +80 -0
- data/lib/ad_sense.rb +32 -0
- data/lib/ad_sense/ad_format.rb +54 -0
- data/lib/ad_sense/ad_sense.rb +7 -0
- data/lib/ad_sense/ad_type.rb +9 -0
- data/lib/ad_sense/rails/action_view/base.rb +96 -0
- data/lib/ad_sense/rails/railtie.rb +10 -0
- data/lib/generators/ad_sense/install/install_generator.rb +18 -0
- data/lib/generators/ad_sense/install/templates/README +3 -0
- data/lib/generators/ad_sense/install/templates/initializer.rb +7 -0
- data/spec/ad_sense/ad_configuration_spec.rb +13 -0
- data/spec/ad_sense/ad_format_spec.rb +45 -0
- data/spec/spec_helper.rb +13 -0
- metadata +186 -0
data/.document
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
rails_verion = ">= 2.3.5"
|
5
|
+
gem "activesupport", rails_verion
|
6
|
+
gem "actionpack", rails_verion
|
7
|
+
# Add dependencies to develop your gem here.
|
8
|
+
# Include everything needed to run rake, tests, features, etc.
|
9
|
+
group :development do
|
10
|
+
gem "rspec", "~> 2.8.0"
|
11
|
+
gem "rdoc", "~> 3.12"
|
12
|
+
gem "bundler", ">= 1.0.0"
|
13
|
+
gem "jeweler", "~> 1.8.4"
|
14
|
+
gem "simplecov", ">= 0"
|
15
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
actionpack (3.2.13)
|
5
|
+
activemodel (= 3.2.13)
|
6
|
+
activesupport (= 3.2.13)
|
7
|
+
builder (~> 3.0.0)
|
8
|
+
erubis (~> 2.7.0)
|
9
|
+
journey (~> 1.0.4)
|
10
|
+
rack (~> 1.4.5)
|
11
|
+
rack-cache (~> 1.2)
|
12
|
+
rack-test (~> 0.6.1)
|
13
|
+
sprockets (~> 2.2.1)
|
14
|
+
activemodel (3.2.13)
|
15
|
+
activesupport (= 3.2.13)
|
16
|
+
builder (~> 3.0.0)
|
17
|
+
activesupport (3.2.13)
|
18
|
+
i18n (= 0.6.1)
|
19
|
+
multi_json (~> 1.0)
|
20
|
+
builder (3.0.4)
|
21
|
+
diff-lcs (1.1.3)
|
22
|
+
erubis (2.7.0)
|
23
|
+
git (1.2.5)
|
24
|
+
hike (1.2.3)
|
25
|
+
i18n (0.6.1)
|
26
|
+
jeweler (1.8.4)
|
27
|
+
bundler (~> 1.0)
|
28
|
+
git (>= 1.2.5)
|
29
|
+
rake
|
30
|
+
rdoc
|
31
|
+
journey (1.0.4)
|
32
|
+
json (1.7.7)
|
33
|
+
multi_json (1.7.2)
|
34
|
+
rack (1.4.5)
|
35
|
+
rack-cache (1.2)
|
36
|
+
rack (>= 0.4)
|
37
|
+
rack-test (0.6.2)
|
38
|
+
rack (>= 1.0)
|
39
|
+
rake (10.0.4)
|
40
|
+
rdoc (3.12.2)
|
41
|
+
json (~> 1.4)
|
42
|
+
rspec (2.8.0)
|
43
|
+
rspec-core (~> 2.8.0)
|
44
|
+
rspec-expectations (~> 2.8.0)
|
45
|
+
rspec-mocks (~> 2.8.0)
|
46
|
+
rspec-core (2.8.0)
|
47
|
+
rspec-expectations (2.8.0)
|
48
|
+
diff-lcs (~> 1.1.2)
|
49
|
+
rspec-mocks (2.8.0)
|
50
|
+
simplecov (0.7.1)
|
51
|
+
multi_json (~> 1.0)
|
52
|
+
simplecov-html (~> 0.7.1)
|
53
|
+
simplecov-html (0.7.1)
|
54
|
+
sprockets (2.2.2)
|
55
|
+
hike (~> 1.2)
|
56
|
+
multi_json (~> 1.0)
|
57
|
+
rack (~> 1.0)
|
58
|
+
tilt (~> 1.1, != 1.3.0)
|
59
|
+
tilt (1.4.1)
|
60
|
+
|
61
|
+
PLATFORMS
|
62
|
+
ruby
|
63
|
+
|
64
|
+
DEPENDENCIES
|
65
|
+
actionpack (>= 2.3.5)
|
66
|
+
activesupport (>= 2.3.5)
|
67
|
+
bundler (>= 1.0.0)
|
68
|
+
jeweler (~> 1.8.4)
|
69
|
+
rdoc (~> 3.12)
|
70
|
+
rspec (~> 2.8.0)
|
71
|
+
simplecov
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2013 Naveed Ahmad
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
data/README.rdoc
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
= ad_sense
|
2
|
+
|
3
|
+
Description goes here.
|
4
|
+
|
5
|
+
== Contributing to ad_sense
|
6
|
+
|
7
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
8
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
|
9
|
+
* Fork the project.
|
10
|
+
* Start a feature/bugfix branch.
|
11
|
+
* Commit and push until you are happy with your contribution.
|
12
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
13
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
14
|
+
|
15
|
+
== Copyright
|
16
|
+
|
17
|
+
Copyright (c) 2013 Naveed Ahmad. See LICENSE.txt for
|
18
|
+
further details.
|
19
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
+
gem.name = "ad_sense"
|
18
|
+
gem.homepage = "http://github.com/naveed-ahmad/ad_sense"
|
19
|
+
gem.license = "MIT"
|
20
|
+
gem.summary = %Q{Ruby wrapper for Google AdSense}
|
21
|
+
gem.description = %Q{A Ruby wrapper of Google AdSense for generating Ads, link ads, or search ads slots.}
|
22
|
+
gem.email = "naveedahmada036@gmail.com"
|
23
|
+
gem.authors = ["Naveed Ahmad"]
|
24
|
+
# dependencies defined in Gemfile
|
25
|
+
end
|
26
|
+
Jeweler::RubygemsDotOrgTasks.new
|
27
|
+
|
28
|
+
require 'rspec/core'
|
29
|
+
require 'rspec/core/rake_task'
|
30
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
31
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
32
|
+
end
|
33
|
+
|
34
|
+
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
35
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
36
|
+
spec.rcov = true
|
37
|
+
end
|
38
|
+
|
39
|
+
task :default => :spec
|
40
|
+
|
41
|
+
require 'rdoc/task'
|
42
|
+
Rake::RDocTask.new do |rdoc|
|
43
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
44
|
+
|
45
|
+
rdoc.rdoc_dir = 'rdoc'
|
46
|
+
rdoc.title = "ad_secene #{version}"
|
47
|
+
rdoc.rdoc_files.include('README*')
|
48
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
49
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.1
|
data/ad_sense.gemspec
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = "ad_sense"
|
8
|
+
s.version = "0.0.1"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Naveed Ahmad"]
|
12
|
+
s.date = "2013-06-21"
|
13
|
+
s.description = "A Ruby wrapper of Google AdSense for generating Ads, link ads, or search ads slots."
|
14
|
+
s.email = "naveedahmada036@gmail.com"
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE.txt",
|
17
|
+
"README.md",
|
18
|
+
"README.rdoc"
|
19
|
+
]
|
20
|
+
s.files = [
|
21
|
+
".document",
|
22
|
+
".rspec",
|
23
|
+
"Gemfile",
|
24
|
+
"Gemfile.lock",
|
25
|
+
"LICENSE.txt",
|
26
|
+
"README.md",
|
27
|
+
"README.rdoc",
|
28
|
+
"Rakefile",
|
29
|
+
"VERSION",
|
30
|
+
"ad_sense.gemspec",
|
31
|
+
"lib/ad_sense.rb",
|
32
|
+
"lib/ad_sense/ad_format.rb",
|
33
|
+
"lib/ad_sense/ad_sense.rb",
|
34
|
+
"lib/ad_sense/ad_type.rb",
|
35
|
+
"lib/ad_sense/rails/action_view/base.rb",
|
36
|
+
"lib/ad_sense/rails/railtie.rb",
|
37
|
+
"lib/generators/ad_sense/install/install_generator.rb",
|
38
|
+
"lib/generators/ad_sense/install/templates/README",
|
39
|
+
"lib/generators/ad_sense/install/templates/initializer.rb",
|
40
|
+
"spec/ad_sense/ad_configuration_spec.rb",
|
41
|
+
"spec/ad_sense/ad_format_spec.rb",
|
42
|
+
"spec/spec_helper.rb"
|
43
|
+
]
|
44
|
+
s.homepage = "http://github.com/naveed-ahmad/ad_sense"
|
45
|
+
s.licenses = ["MIT"]
|
46
|
+
s.require_paths = ["lib"]
|
47
|
+
s.rubygems_version = "1.8.25"
|
48
|
+
s.summary = "Ruby wrapper for Google AdSense"
|
49
|
+
|
50
|
+
if s.respond_to? :specification_version then
|
51
|
+
s.specification_version = 3
|
52
|
+
|
53
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
54
|
+
s.add_runtime_dependency(%q<activesupport>, [">= 2.3.5"])
|
55
|
+
s.add_runtime_dependency(%q<actionpack>, [">= 2.3.5"])
|
56
|
+
s.add_development_dependency(%q<rspec>, ["~> 2.8.0"])
|
57
|
+
s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
|
58
|
+
s.add_development_dependency(%q<bundler>, [">= 1.0.0"])
|
59
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.8.4"])
|
60
|
+
s.add_development_dependency(%q<simplecov>, [">= 0"])
|
61
|
+
else
|
62
|
+
s.add_dependency(%q<activesupport>, [">= 2.3.5"])
|
63
|
+
s.add_dependency(%q<actionpack>, [">= 2.3.5"])
|
64
|
+
s.add_dependency(%q<rspec>, ["~> 2.8.0"])
|
65
|
+
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
66
|
+
s.add_dependency(%q<bundler>, [">= 1.0.0"])
|
67
|
+
s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
|
68
|
+
s.add_dependency(%q<simplecov>, [">= 0"])
|
69
|
+
end
|
70
|
+
else
|
71
|
+
s.add_dependency(%q<activesupport>, [">= 2.3.5"])
|
72
|
+
s.add_dependency(%q<actionpack>, [">= 2.3.5"])
|
73
|
+
s.add_dependency(%q<rspec>, ["~> 2.8.0"])
|
74
|
+
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
75
|
+
s.add_dependency(%q<bundler>, [">= 1.0.0"])
|
76
|
+
s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
|
77
|
+
s.add_dependency(%q<simplecov>, [">= 0"])
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
data/lib/ad_sense.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'active_support/core_ext/object'
|
2
|
+
require 'active_support'
|
3
|
+
require 'ad_sense/ad_sense'
|
4
|
+
|
5
|
+
module AdSense
|
6
|
+
mattr_accessor :client_id
|
7
|
+
mattr_accessor :default_ad_type
|
8
|
+
mattr_accessor :default_ad_format
|
9
|
+
mattr_accessor :default_query_for_search_ad
|
10
|
+
|
11
|
+
class << self
|
12
|
+
def config
|
13
|
+
yield self
|
14
|
+
end
|
15
|
+
|
16
|
+
def default_ad_type
|
17
|
+
@@default_ad_type ||= AdSense::AdType::TextImage
|
18
|
+
end
|
19
|
+
|
20
|
+
def default_ad_format
|
21
|
+
@@default_ad_format ||= AdSense::AdFormat::LeaderBoard
|
22
|
+
end
|
23
|
+
|
24
|
+
def ad_client_id
|
25
|
+
"ca-pub-#{client_id}"
|
26
|
+
end
|
27
|
+
|
28
|
+
def search_ad_client_id
|
29
|
+
"pub-#{client_id}"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
module AdSense
|
2
|
+
module AdFormat
|
3
|
+
# visit for available formats/sizes
|
4
|
+
#http://support.google.com/adsense/bin/answer.py?hl=en&answer=185666
|
5
|
+
LargeLeaderBoard = "970x90"
|
6
|
+
MediumRectangle = "300x250"
|
7
|
+
LargeSkyscraper = "300x600"
|
8
|
+
SmallRrectangle = "180x150"
|
9
|
+
LargeRectangle = "336x280"
|
10
|
+
VerticalBanner = "120x240"
|
11
|
+
WideSkyscraper = "160x600"
|
12
|
+
MobileBanner = "320x50"
|
13
|
+
LeaderBoard = "728x90"
|
14
|
+
SmallSquare = "200x200"
|
15
|
+
Skyscraper = "120x600"
|
16
|
+
HalfBanner = "234x60"
|
17
|
+
Banner = "468x60"
|
18
|
+
Square = "250x250"
|
19
|
+
Button = "125x125"
|
20
|
+
|
21
|
+
class << self
|
22
|
+
def get_dimension(format)
|
23
|
+
format_value = get_format_value(format)
|
24
|
+
format_value.split('x').map(&:to_i)
|
25
|
+
rescue NameError
|
26
|
+
[]
|
27
|
+
end
|
28
|
+
|
29
|
+
def ad_format_string(format, is_links_ad = false)
|
30
|
+
format_value = get_format_value(format)
|
31
|
+
|
32
|
+
if format_value.present?
|
33
|
+
prepend_string = is_links_ad ? '_0ads_al' : '_as'
|
34
|
+
"#{format_value}#{prepend_string}"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def available_formats
|
39
|
+
AdFormat.constants.map { |format| format.to_s.underscore.to_sym }
|
40
|
+
end
|
41
|
+
|
42
|
+
protected
|
43
|
+
def get_format_value(format)
|
44
|
+
if format.is_a?(String) && format.include?('x')
|
45
|
+
format
|
46
|
+
else
|
47
|
+
AdFormat.const_get format.to_s.camelize
|
48
|
+
end
|
49
|
+
rescue
|
50
|
+
''
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
module AdSense
|
2
|
+
module AdType
|
3
|
+
#available ad types
|
4
|
+
#http://support.google.com/adsense/bin/answer.py?hl=en&answer=164735&topic=19363&ctx=topic
|
5
|
+
TextImage = "text_image" # text,images and rich media
|
6
|
+
Text = "text" # only text ads
|
7
|
+
Image = "image" # images, rich media only
|
8
|
+
end
|
9
|
+
end
|
@@ -0,0 +1,96 @@
|
|
1
|
+
module AdSense
|
2
|
+
module Rails
|
3
|
+
module ActionView
|
4
|
+
module Base
|
5
|
+
def ad_slot_tag(ad_slot = nil, options = {})
|
6
|
+
adsense_opts = get_ad_options_from_hash(options.merge!(ad_slot: ad_slot), false)
|
7
|
+
wrapper_class = get_classes_for_ad_wrapper(options)
|
8
|
+
adsense_opts = get_ad_script_from_hash(adsense_opts)
|
9
|
+
|
10
|
+
generate_ad_tag wrapper_class, adsense_opts
|
11
|
+
end
|
12
|
+
|
13
|
+
def ad_search_tag(ad_container_id, options)
|
14
|
+
# based on https://developers.google.com/custom-search-ads/docs/code-generator
|
15
|
+
script = <<-SCRIPT.strip_heredoc
|
16
|
+
var pageOptions = {
|
17
|
+
'pubId': '#{AdSense.search_ad_client_id}',
|
18
|
+
'query': '#{get_query_for_search_ad(options)}',
|
19
|
+
'hl': 'en'
|
20
|
+
};
|
21
|
+
|
22
|
+
var adblock1 = {
|
23
|
+
'container': '#{ad_container_id}',
|
24
|
+
'width': '#{options[:width]}'
|
25
|
+
};
|
26
|
+
new google.ads.search.Ads(pageOptions, adblock1);
|
27
|
+
SCRIPT
|
28
|
+
|
29
|
+
content_tag :div, class: "search_ad_wrapper #{options[:wrapper_class]}" do
|
30
|
+
[content_tag(:div, '', id: ad_container_id),
|
31
|
+
javascript_include_tag('http://www.google.com/adsense/search/ads.js'),
|
32
|
+
javascript_tag { script }].join('').html_safe
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def ad_link_tag(ad_slot, options = {})
|
37
|
+
adsense_opts = get_ad_options_from_hash(options.merge(ad_slot: ad_slot), true)
|
38
|
+
wrapper_class = get_classes_for_ad_wrapper(adsense_opts)
|
39
|
+
adsense_opts = get_ad_script_from_hash(adsense_opts)
|
40
|
+
|
41
|
+
generate_ad_tag wrapper_class, adsense_opts
|
42
|
+
end
|
43
|
+
|
44
|
+
protected
|
45
|
+
|
46
|
+
def get_query_for_search_ad(options)
|
47
|
+
options[:query] || AdSense.default_query_for_search_ad
|
48
|
+
end
|
49
|
+
|
50
|
+
def get_ad_options_from_hash(options, is_links_ad)
|
51
|
+
ad_format = options[:format] || AdSense.default_ad_format
|
52
|
+
width, height = AdSense::AdFormat.get_dimension(ad_format)
|
53
|
+
ad_type = nil
|
54
|
+
|
55
|
+
if options[:ad_slot].blank?
|
56
|
+
add_type = options[:ad_type] || AdSense.default_ad_type
|
57
|
+
ad_format_str = AdSense::AdFormat.ad_format_string(ad_format, is_links_ad)
|
58
|
+
end
|
59
|
+
|
60
|
+
options.merge! ad_type: ad_type, ad_format: ad_format
|
61
|
+
|
62
|
+
adsense_opts = {
|
63
|
+
google_ad_client: AdSense.ad_client_id,
|
64
|
+
google_ad_slot: options[:ad_slot],
|
65
|
+
google_ad_width: width,
|
66
|
+
google_ad_height: height,
|
67
|
+
google_ad_format: ad_format_str,
|
68
|
+
google_ad_type: add_type
|
69
|
+
}
|
70
|
+
end
|
71
|
+
|
72
|
+
def get_classes_for_ad_wrapper(options)
|
73
|
+
wrapper_class = "ad_sense_slot #{options[:wrapper_class]}"
|
74
|
+
if options[:ad_slot].blank?
|
75
|
+
wrapper_class << "#{options[:add_type]}_ad"
|
76
|
+
end
|
77
|
+
wrapper_class
|
78
|
+
end
|
79
|
+
|
80
|
+
def get_ad_script_from_hash(options)
|
81
|
+
options.map do |k, v|
|
82
|
+
v = v.is_a?(String) ? "\"#{v}\"" : v
|
83
|
+
"#{k} = #{v};" unless v.blank?
|
84
|
+
end.compact.sort.join("\n")
|
85
|
+
end
|
86
|
+
|
87
|
+
def generate_ad_tag(wrapper_class, adsense_opts)
|
88
|
+
# based on http://www.adsense-generator.com/
|
89
|
+
content_tag :div, class: wrapper_class do
|
90
|
+
[javascript_tag(adsense_opts), javascript_include_tag('http://pagead2.googlesyndication.com/pagead/show_ads.js')].join('').html_safe
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
module AdSense
|
3
|
+
module Generators
|
4
|
+
class InstallGenerator < ::Rails::Generators::Base
|
5
|
+
source_root File.expand_path("../templates", __FILE__)
|
6
|
+
|
7
|
+
desc "This generator creates an initializer file for AdSense at config/initializers"
|
8
|
+
|
9
|
+
def add_initializer
|
10
|
+
template "initializer.rb", "config/initializers/ad_sense.rb"
|
11
|
+
end
|
12
|
+
|
13
|
+
def show_readme
|
14
|
+
readme "README"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,7 @@
|
|
1
|
+
AdSense.config do |config|
|
2
|
+
config.client_id = "Your AdSense client id"
|
3
|
+
config.default_ad_type = AdSense::AdType::TextImage
|
4
|
+
config.default_ad_format = AdSense::AdFormat::LeaderBoard #728x90 slot
|
5
|
+
#config.default_query_for_search_ad = "Ruby on Rails" # default value for search query in search add text field
|
6
|
+
end
|
7
|
+
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "AdSense" do
|
4
|
+
subject { AdSense }
|
5
|
+
|
6
|
+
describe "default configuration" do
|
7
|
+
specify { subject.default_ad_format.should eql AdSense::AdFormat::LeaderBoard }
|
8
|
+
specify { subject.default_ad_type.should eql AdSense::AdType::TextImage }
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "#ad_slot" do
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "AdFormat" do
|
4
|
+
subject { AdSense::AdFormat }
|
5
|
+
formats_map = {
|
6
|
+
large_leader_board: [970, 90],
|
7
|
+
medium_rectangle: [300, 250],
|
8
|
+
large_skyscraper: [300, 600],
|
9
|
+
small_rrectangle: [180, 150],
|
10
|
+
large_rectangle: [336, 280],
|
11
|
+
vertical_banner: [120, 240],
|
12
|
+
wide_skyscraper: [160, 600],
|
13
|
+
vertical_banner: [120, 240],
|
14
|
+
mobile_banner: [320, 50],
|
15
|
+
leader_board: [728, 90],
|
16
|
+
small_square: [200, 200],
|
17
|
+
skyscraper: [120, 600],
|
18
|
+
half_banner: [234, 60],
|
19
|
+
banner: [468, 60],
|
20
|
+
square: [250, 250],
|
21
|
+
button: [125, 125]
|
22
|
+
}
|
23
|
+
|
24
|
+
|
25
|
+
describe "#available_formats" do
|
26
|
+
specify { subject.available_formats.size.should eql 15 }
|
27
|
+
specify { subject.available_formats.should eql formats_map.keys }
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "#get_dimension" do
|
31
|
+
formats_map.keys.each do |format|
|
32
|
+
it "return #{ formats_map[format] } for #{ format }" do
|
33
|
+
subject.get_dimension(format).should eql formats_map[format]
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
it "return [] for wrong format" do
|
38
|
+
subject.get_dimension(:foo_bar).should eql []
|
39
|
+
end
|
40
|
+
|
41
|
+
it "return dimension if parameter is value of a format" do
|
42
|
+
subject.get_dimension("1x2").should eql [1, 2]
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
+
|
4
|
+
require 'rspec'
|
5
|
+
require 'ad_sense'
|
6
|
+
|
7
|
+
# Requires supporting files with custom matchers and macros, etc,
|
8
|
+
# in ./support/ and its subdirectories.
|
9
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
10
|
+
|
11
|
+
RSpec.configure do |config|
|
12
|
+
|
13
|
+
end
|
metadata
ADDED
@@ -0,0 +1,186 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ad_sense
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Naveed Ahmad
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-06-21 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: activesupport
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 2.3.5
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 2.3.5
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: actionpack
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 2.3.5
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 2.3.5
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rspec
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 2.8.0
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 2.8.0
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: rdoc
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ~>
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '3.12'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ~>
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '3.12'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: bundler
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: 1.0.0
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: 1.0.0
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: jeweler
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ~>
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: 1.8.4
|
102
|
+
type: :development
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ~>
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: 1.8.4
|
110
|
+
- !ruby/object:Gem::Dependency
|
111
|
+
name: simplecov
|
112
|
+
requirement: !ruby/object:Gem::Requirement
|
113
|
+
none: false
|
114
|
+
requirements:
|
115
|
+
- - ! '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
none: false
|
122
|
+
requirements:
|
123
|
+
- - ! '>='
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
126
|
+
description: A Ruby wrapper of Google AdSense for generating Ads, link ads, or search
|
127
|
+
ads slots.
|
128
|
+
email: naveedahmada036@gmail.com
|
129
|
+
executables: []
|
130
|
+
extensions: []
|
131
|
+
extra_rdoc_files:
|
132
|
+
- LICENSE.txt
|
133
|
+
- README.md
|
134
|
+
- README.rdoc
|
135
|
+
files:
|
136
|
+
- .document
|
137
|
+
- .rspec
|
138
|
+
- Gemfile
|
139
|
+
- Gemfile.lock
|
140
|
+
- LICENSE.txt
|
141
|
+
- README.md
|
142
|
+
- README.rdoc
|
143
|
+
- Rakefile
|
144
|
+
- VERSION
|
145
|
+
- ad_sense.gemspec
|
146
|
+
- lib/ad_sense.rb
|
147
|
+
- lib/ad_sense/ad_format.rb
|
148
|
+
- lib/ad_sense/ad_sense.rb
|
149
|
+
- lib/ad_sense/ad_type.rb
|
150
|
+
- lib/ad_sense/rails/action_view/base.rb
|
151
|
+
- lib/ad_sense/rails/railtie.rb
|
152
|
+
- lib/generators/ad_sense/install/install_generator.rb
|
153
|
+
- lib/generators/ad_sense/install/templates/README
|
154
|
+
- lib/generators/ad_sense/install/templates/initializer.rb
|
155
|
+
- spec/ad_sense/ad_configuration_spec.rb
|
156
|
+
- spec/ad_sense/ad_format_spec.rb
|
157
|
+
- spec/spec_helper.rb
|
158
|
+
homepage: http://github.com/naveed-ahmad/ad_sense
|
159
|
+
licenses:
|
160
|
+
- MIT
|
161
|
+
post_install_message:
|
162
|
+
rdoc_options: []
|
163
|
+
require_paths:
|
164
|
+
- lib
|
165
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
166
|
+
none: false
|
167
|
+
requirements:
|
168
|
+
- - ! '>='
|
169
|
+
- !ruby/object:Gem::Version
|
170
|
+
version: '0'
|
171
|
+
segments:
|
172
|
+
- 0
|
173
|
+
hash: -3402824953062022636
|
174
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
175
|
+
none: false
|
176
|
+
requirements:
|
177
|
+
- - ! '>='
|
178
|
+
- !ruby/object:Gem::Version
|
179
|
+
version: '0'
|
180
|
+
requirements: []
|
181
|
+
rubyforge_project:
|
182
|
+
rubygems_version: 1.8.25
|
183
|
+
signing_key:
|
184
|
+
specification_version: 3
|
185
|
+
summary: Ruby wrapper for Google AdSense
|
186
|
+
test_files: []
|