ad_man 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +103 -0
- data/app/assets/javascripts/ad_man/advertisements.js +8 -0
- data/app/controllers/ad_man/advertisements_controller.rb +9 -1
- data/app/helpers/ad_man/application_helper.rb +29 -16
- data/app/models/ad_man/advertisement.rb +44 -41
- data/app/views/ad_man/advertisements/get_ad.js.erb +2 -0
- data/app/views/ad_man/advertisements/show.html.erb +2 -2
- data/app/views/ad_man/keywords/show.html.erb +1 -1
- data/config/routes.rb +7 -2
- data/lib/ad_man/version.rb +1 -1
- data/lib/ad_man.rb +5 -5
- data/lib/generators/ad_man/install_generator.rb +14 -16
- data/lib/generators/ad_man/templates/advertisements_controller.rb +4 -0
- data/lib/generators/ad_man/templates/keywords_controller.rb +4 -0
- data/test/dummy/db/development.sqlite3 +0 -0
- data/test/dummy/db/schema.rb +9 -4
- data/test/dummy/db/test.sqlite3 +0 -0
- data/test/dummy/log/development.log +278 -35896
- data/test/fixtures/ad_man/keywords.yml +3 -0
- data/test/functional/ad_man/advertisements_controller_test.rb +33 -14
- data/test/functional/ad_man/keywords_controller_test.rb +13 -14
- data/test/test_helper.rb +8 -4
- data/test/unit/ad_man/keyword_test.rb +1 -1
- metadata +7 -44
- data/README.rdoc +0 -61
- data/test/dummy/log/test.log +0 -1406
- data/test/dummy/public/system/ad_man/advertisements/ad_banners/000/000/001/banner/test.jpeg +0 -0
- data/test/dummy/public/system/ad_man/advertisements/ad_banners/000/000/001/leaderboard/test.jpeg +0 -0
- data/test/dummy/tmp/cache/assets/C02/0A0/sprockets%2F625bdc26802f8c498265353870490587 +0 -0
- data/test/dummy/tmp/cache/assets/CC8/220/sprockets%2F234102a39a522cfab9195fd0d7c12640 +0 -0
- data/test/dummy/tmp/cache/assets/CD6/A60/sprockets%2Fcca4c63026454615fd0a54b65b881d64 +0 -0
- data/test/dummy/tmp/cache/assets/CD8/370/sprockets%2F357970feca3ac29060c1e3861e2c0953 +0 -0
- data/test/dummy/tmp/cache/assets/CE4/9E0/sprockets%2F3f5956491fde7227a651e20e4d756b1a +0 -0
- data/test/dummy/tmp/cache/assets/D31/910/sprockets%2Fc1c18d3d756fe2777d18b236a0aea400 +0 -0
- data/test/dummy/tmp/cache/assets/D32/A10/sprockets%2F13fe41fee1fe35b49d145bcc06610705 +0 -0
- data/test/dummy/tmp/cache/assets/D3A/220/sprockets%2Fce53c5b352a83645d36d96aff26020fb +0 -0
- data/test/dummy/tmp/cache/assets/D3E/AF0/sprockets%2F317881d54abbd5721deee7d204e70e66 +0 -0
- data/test/dummy/tmp/cache/assets/D4E/1B0/sprockets%2Ff7cbd26ba1d28d48de824f0e94586655 +0 -0
- data/test/dummy/tmp/cache/assets/D5A/EA0/sprockets%2Fd771ace226fc8215a3572e0aa35bb0d6 +0 -0
- data/test/dummy/tmp/cache/assets/D79/2D0/sprockets%2F0d684f7bbe7d675f000dff8821d90ae8 +0 -0
- data/test/dummy/tmp/cache/assets/DBA/3C0/sprockets%2F9ca84f8118d29c3fd7bfd2876f83dc7e +0 -0
- data/test/dummy/tmp/cache/assets/DDC/400/sprockets%2Fcffd775d018f68ce5dba1ee0d951a994 +0 -0
- data/test/dummy/tmp/cache/assets/DF7/090/sprockets%2Fb3b1a32b0f923d6741fd5dacdf9f59ab +0 -0
- data/test/dummy/tmp/cache/assets/E04/890/sprockets%2F2f5173deea6c795b8fdde723bb4b63af +0 -0
- data/test/dummy/tmp/cache/assets/E56/460/sprockets%2F5dde4d3dd93c8afa78eb0ba3fb55c20c +0 -0
data/README.md
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
Ad_man
|
2
|
+
======
|
3
|
+
|
4
|
+
Ad_man is an advertising manager mountable engine. It allows the user to upload and manage advertising banners, and provides an easy to use helper for inserting the banners on your website. Also counts the number of times an ad has shown, and the number of times an advertisement has been clicked on. The user must set a keyword for each ad.
|
5
|
+
|
6
|
+
Currently supports two image sizes for advertising: Leaderboard 728 x 90 and Banner 468 x 60.
|
7
|
+
TODO: Will implement 9 different sizes as mentioned by google's adwords requirements.
|
8
|
+
|
9
|
+
Requires Paperclip 3.1, and requires ImageMagick be running on the server.
|
10
|
+
|
11
|
+
## Getting started
|
12
|
+
|
13
|
+
Ad_man works with Rails 3.2 onwards. You can add it to your Gemfile with:
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
gem 'ad_man'
|
17
|
+
```
|
18
|
+
|
19
|
+
After you install Ad_man and add it to your Gemfile, you need to run the generator:
|
20
|
+
|
21
|
+
```console
|
22
|
+
rails generate ad_man:install
|
23
|
+
```
|
24
|
+
|
25
|
+
This will install the migrations and a few controller files, then just rake the database:
|
26
|
+
```console
|
27
|
+
rake db:migrate
|
28
|
+
```
|
29
|
+
|
30
|
+
See where Ad_man is located by running:
|
31
|
+
```console
|
32
|
+
rake routes
|
33
|
+
```
|
34
|
+
|
35
|
+
In our case, we needed to move the line generated by the install in the routes file to our admin space. Then add any before_filters to the controllers that were generated.
|
36
|
+
|
37
|
+
Make sure to change references to the application using the main_app helper:
|
38
|
+
```erb
|
39
|
+
<%= link_to "Home", main_app.root_path %>
|
40
|
+
<%= link_to "Advertising", main_app.ad_man_path %>
|
41
|
+
```
|
42
|
+
|
43
|
+
## Changing default values
|
44
|
+
|
45
|
+
If you need to change the default values set by ad_man, you will need to create an ad_man.rb initializer in your config/initializers folder.
|
46
|
+
|
47
|
+
```ruby
|
48
|
+
# AdMan Default Values
|
49
|
+
AdMan.leaderboard_size = "728x90"
|
50
|
+
AdMan.banner_size = "468x60"
|
51
|
+
AdMan.max_image_size = 50 # 50Kb maximum image size
|
52
|
+
|
53
|
+
# These are configurable dimensions (currently leaderboard default)
|
54
|
+
AdMan.image_dimensions_width = 728
|
55
|
+
AdMan.image_dimensions_height = 90
|
56
|
+
|
57
|
+
# Configurable content type for advertising
|
58
|
+
AdMan.content_type = ["image/jpg", "image/bmp", "image/png", "image/gif", "image/jpeg"]
|
59
|
+
|
60
|
+
# Configurable max advertising for keyword
|
61
|
+
AdMan.max_count = 6
|
62
|
+
```
|
63
|
+
|
64
|
+
## Putting an advertisement in the view
|
65
|
+
|
66
|
+
To put your advertisement in the view just add:
|
67
|
+
```erb
|
68
|
+
<%= link_to_ad %>
|
69
|
+
```
|
70
|
+
Currently there are three parameters that can control which ads get shown on your page. :keyword, :size, and :display_on_all_pages.
|
71
|
+
```erb
|
72
|
+
<%= link_to_ad :keyword => "Your Keyword", :size => "leaderboard", :display_on_all_pages => false %>
|
73
|
+
```
|
74
|
+
|
75
|
+
## Ad_man and Javascript
|
76
|
+
Ad_man supports inserting an advertisement using jQuery. It also uses jQuery in the backend when creating new ads. To use this functionality, include this line in the view:
|
77
|
+
```erb
|
78
|
+
<%= javascript_include_tag "ad_man/advertisements.js" %>
|
79
|
+
```
|
80
|
+
|
81
|
+
You can pass the keyword name through the showAd(); function.
|
82
|
+
```erb
|
83
|
+
<script>
|
84
|
+
// showAd(keyword);
|
85
|
+
showAd('<%= @keyword %>'); // inserts a value from ruby in erb
|
86
|
+
</script>
|
87
|
+
```
|
88
|
+
Then ad a `<DIV>` element with the id 'advertisement' where you want the advertisement to show.
|
89
|
+
```erb
|
90
|
+
<div id="advertisement"></div>
|
91
|
+
```
|
92
|
+
|
93
|
+
## Authors
|
94
|
+
Written by [David Strand](http://www.github.com/wspyder) and [Tyler Hu](http://www.github.com/tylerhu)
|
95
|
+
|
96
|
+
## Contributors
|
97
|
+
[Matenia Rossides](http://www.github.com/matenia)
|
98
|
+
|
99
|
+
## Copyright & Licensing
|
100
|
+
|
101
|
+
Copyright (c) 2012 [Kudelabs](http://kudelabs.com)
|
102
|
+
|
103
|
+
Released under MIT License.
|
@@ -44,3 +44,11 @@ function showFormError(msg, form) {
|
|
44
44
|
form.find('div.errors').remove();
|
45
45
|
form.prepend(errorDiv);
|
46
46
|
}
|
47
|
+
|
48
|
+
function showAd(key) {
|
49
|
+
$.ajax({
|
50
|
+
url: "/ad_man/advertisements/get_ad/" + key,
|
51
|
+
dataType: "script",
|
52
|
+
success: function(data){}
|
53
|
+
});
|
54
|
+
}
|
@@ -1,6 +1,8 @@
|
|
1
1
|
class AdMan::AdvertisementsController < ApplicationController
|
2
2
|
# GET /advertisements
|
3
|
-
# GET /advertisements.json
|
3
|
+
# GET /advertisements.json
|
4
|
+
include AdMan::ApplicationHelper
|
5
|
+
|
4
6
|
def index
|
5
7
|
@advertisements = AdMan::Advertisement.all
|
6
8
|
|
@@ -96,4 +98,10 @@ class AdMan::AdvertisementsController < ApplicationController
|
|
96
98
|
@advertisement.save
|
97
99
|
redirect_to @advertisement.destination_url
|
98
100
|
end
|
101
|
+
|
102
|
+
def get_ad()
|
103
|
+
keyword = params[:id]
|
104
|
+
@ad = js_link_to_ad(keyword)
|
105
|
+
end
|
106
|
+
|
99
107
|
end
|
@@ -1,27 +1,40 @@
|
|
1
1
|
module AdMan
|
2
2
|
module ApplicationHelper
|
3
|
-
|
3
|
+
def link_to_ad(keyword = nil, size = "leaderboard")
|
4
|
+
ad = ad_select(keyword, size)
|
5
|
+
link_to image_tag(ad.ad_banner.url(size)), { :controller => 'ad_man/advertisements', :action => 'click_through', :id => ad.id },
|
6
|
+
:target => '_blank', :method => :post
|
7
|
+
end
|
8
|
+
|
9
|
+
def js_link_to_ad(keyword)
|
10
|
+
ad_select(keyword, size= "leaderboard")
|
11
|
+
end
|
12
|
+
|
13
|
+
protected
|
14
|
+
#grab the keyword form request url
|
15
|
+
def get_keyword_from_url
|
16
|
+
if request.env["REQUEST_PATH"]
|
17
|
+
req_url = request.env["REQUEST_PATH"].split("/")
|
18
|
+
keyword_names = Keyword.all.map{ |keyword| keyword.name }
|
19
|
+
keyword = req_url & keyword_names
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
def ad_select(keyword, size)
|
4
25
|
keyword ||= get_keyword_from_url
|
5
|
-
|
26
|
+
if keyword && !keyword.blank? && !Keyword.find_by_name(keyword).nil?
|
6
27
|
keyword_id = Keyword.find_by_name(keyword).id
|
7
28
|
ad = Advertisement.render_random_ad(keyword_id)
|
8
29
|
#grab size? leaderboard or banner
|
9
|
-
elsif keyword.blank?
|
30
|
+
elsif keyword.nil? || keyword.blank?
|
10
31
|
ad = Advertisement.render_random_ad
|
11
|
-
|
32
|
+
end
|
12
33
|
if !ad.nil?
|
13
|
-
ad.display_count += 1
|
34
|
+
ad.display_count += 1
|
14
35
|
ad.save
|
15
|
-
|
16
|
-
:method => :post, :target => '_blank'
|
36
|
+
ad
|
17
37
|
end
|
18
|
-
end
|
19
|
-
|
20
|
-
#grab the keyword form request url
|
21
|
-
def get_keyword_from_url
|
22
|
-
req_url = request.env["REQUEST_PATH"].split("/")
|
23
|
-
keyword_names = Keyword.all.map{ |keyword| keyword.name }
|
24
|
-
keyword = req_url & keyword_names
|
25
|
-
end
|
26
|
-
end
|
38
|
+
end
|
39
|
+
end
|
27
40
|
end
|
@@ -1,57 +1,60 @@
|
|
1
1
|
module AdMan
|
2
2
|
class Advertisement < ActiveRecord::Base
|
3
|
-
attr_accessible :destination_url, :title, :ad_banner, :display_count,
|
3
|
+
attr_accessible :destination_url, :title, :ad_banner, :display_count,
|
4
|
+
:priority, :start_date, :end_date, :click_count, :keyword_id
|
4
5
|
validates_with AttachmentPresenceValidator, :attributes => :ad_banner
|
5
6
|
belongs_to :keyword
|
6
|
-
has_attached_file :ad_banner, :styles => {
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
7
|
+
has_attached_file :ad_banner, :styles => {
|
8
|
+
:leaderboard => (AdMan.leaderboard_size)?(AdMan.leaderboard_size):'728X90',
|
9
|
+
:banner => (AdMan.banner_size)?(AdMan.banner_size):'468X60'
|
10
|
+
}
|
11
|
+
validates_attachment :ad_banner, :presence => true,
|
12
|
+
:content_type => {
|
13
|
+
:content_type => (AdMan.content_type)?(AdMan.content_type): ["image/jpg","image/bmp","image/png", "image/gif", "image/jpeg"]
|
14
|
+
},
|
15
|
+
:size => { :in => 0..((AdMan.max_image_size)?(AdMan.max_image_size):50).kilobytes }
|
16
|
+
validates_presence_of :destination_url, :title, :keyword_id, :priority
|
17
|
+
validates_uniqueness_of :title
|
18
|
+
validate :image_dimensions, :on => :create
|
19
|
+
after_initialize :init_priority
|
16
20
|
|
17
|
-
|
18
|
-
#
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
21
|
+
def Advertisement.render_random_ad(keyword_id = nil)
|
22
|
+
# ads = Advertisement.find_all_by_keyword_id(keyword_id)
|
23
|
+
if keyword_id.nil?
|
24
|
+
ads = Advertisement.where("start_date <= ? AND end_date >= ?", Date.today, Date.today)
|
25
|
+
else
|
26
|
+
ads = Advertisement.where("keyword_id = ? AND start_date <= ? AND end_date >= ? ", keyword_id, Date.today, Date.today)
|
27
|
+
end
|
28
|
+
if ads.present?
|
29
|
+
total_times = 1.0
|
30
|
+
total_priority = 0.0
|
31
|
+
ads.each { |advertisement|
|
32
|
+
total_times += advertisement.display_count
|
33
|
+
total_priority += advertisement.priority
|
34
|
+
}
|
35
|
+
ad = ads[rand(ads.size)]
|
36
|
+
while((ad.display_count / total_times) > (ad.priority / total_priority))
|
37
|
+
ad = ads[rand(ads.size)]
|
38
|
+
end
|
39
|
+
ad
|
40
|
+
end
|
41
|
+
end
|
38
42
|
|
39
|
-
|
43
|
+
private
|
40
44
|
def image_dimensions
|
41
45
|
temp_file = ad_banner.queued_for_write[:leaderboard] #get the file
|
42
46
|
dimensions = Paperclip::Geometry.from_file(temp_file)
|
43
|
-
|
44
|
-
|
47
|
+
max_width = (AdMan.image_dimensions_width)?(AdMan.image_dimensions_width):728
|
48
|
+
max_height = (AdMan.image_dimensions_height)?(AdMan.image_dimensions_height):90
|
45
49
|
if (dimensions.width > max_width) || (dimensions.height > max_height)
|
46
|
-
|
47
|
-
|
50
|
+
errors.add("banner_dimmensions",
|
51
|
+
"must be image size: #{max_width}X#{max_height}.")
|
48
52
|
end
|
49
53
|
end
|
50
54
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
+
def init_priority
|
56
|
+
self.priority ||= 1
|
57
|
+
end
|
55
58
|
end
|
56
59
|
end
|
57
60
|
|
@@ -34,6 +34,6 @@
|
|
34
34
|
<div style="display:inline-block;">
|
35
35
|
<%= link_to 'Edit', edit_advertisement_path(@advertisement), :method => :get %>
|
36
36
|
<%= link_to "Destroy", @advertisement, :method => :delete,
|
37
|
-
|
37
|
+
:data => { :confirm => "Deleting Advertisement, this cannot be undone. Please confirm."}, :style => "color:#b94a48"%>
|
38
38
|
<%= link_to 'Back', advertisements_path, :method => :get %>
|
39
|
-
</div>
|
39
|
+
</div>
|
@@ -34,6 +34,6 @@
|
|
34
34
|
<div style="display:inline-block;">
|
35
35
|
<%= link_to 'Edit Keyword', edit_keyword_path(@keyword), :method => :get %>
|
36
36
|
<%= link_to "Destroy", @keyword, :method => :delete,
|
37
|
-
|
37
|
+
:data => {:confirm => "Deleting Keyword, this cannot be undone. WARNING: This will delete all advertisements connected with this keyword. Please confirm."}, :style => "color:#b94a48"%>
|
38
38
|
<%= link_to 'Back', advertisements_path, :method => :get %>
|
39
39
|
</div>
|
data/config/routes.rb
CHANGED
@@ -1,7 +1,12 @@
|
|
1
1
|
AdMan::Engine.routes.draw do
|
2
2
|
resources :keywords
|
3
|
-
resources :advertisements
|
3
|
+
resources :advertisements do
|
4
|
+
collection do
|
5
|
+
match 'click_through/:id' => "advertisements#click_through", :as => :click_through
|
6
|
+
match '/advertisements/get_ad/:id' => 'advertisements#get_ad'
|
7
|
+
end
|
8
|
+
end
|
4
9
|
|
5
10
|
root :to => "advertisements#index"
|
6
|
-
|
11
|
+
|
7
12
|
end
|
data/lib/ad_man/version.rb
CHANGED
data/lib/ad_man.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
require "ad_man/engine"
|
2
2
|
|
3
3
|
module AdMan
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
4
|
+
mattr_accessor :leaderboard_size, :banner_size
|
5
|
+
mattr_accessor :image_dimensions_width, :image_dimensions_height
|
6
|
+
mattr_accessor :max_image_size
|
7
|
+
mattr_accessor :content_type
|
8
|
+
mattr_accessor :max_count
|
9
9
|
end
|
@@ -1,20 +1,18 @@
|
|
1
1
|
module AdMan
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
2
|
+
class InstallGenerator < Rails::Generators::Base
|
3
|
+
source_root File.expand_path('../templates', __FILE__)
|
4
|
+
def create_extended_controller_file
|
5
|
+
template "advertisements_controller.rb","app/controllers/ad_man/advertisements_controller.rb"
|
6
|
+
template "keywords_controller.rb","app/controllers/ad_man/keywords_controller.rb"
|
7
|
+
end
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
end
|
18
|
-
end
|
9
|
+
def add_routes
|
10
|
+
route("mount AdMan::Engine, :at => '/ad_man'")
|
11
|
+
end
|
12
|
+
|
13
|
+
def install_migrations
|
14
|
+
rake "ad_man:install:migrations"
|
15
|
+
end
|
16
|
+
end
|
19
17
|
end
|
20
18
|
|
Binary file
|
data/test/dummy/db/schema.rb
CHANGED
@@ -11,22 +11,26 @@
|
|
11
11
|
#
|
12
12
|
# It's strongly recommended to check this file into your version control system.
|
13
13
|
|
14
|
-
|
14
|
+
<<<<<<< HEAD
|
15
|
+
ActiveRecord::Schema.define(:version => 0) do
|
16
|
+
=======
|
17
|
+
ActiveRecord::Schema.define(:version => 20120812095547) do
|
15
18
|
|
16
19
|
create_table "ad_man_advertisements", :force => true do |t|
|
17
20
|
t.string "title"
|
18
21
|
t.string "destination_url"
|
19
|
-
t.datetime "created_at", :null => false
|
20
|
-
t.datetime "updated_at", :null => false
|
21
22
|
t.string "ad_banner_file_name"
|
22
23
|
t.string "ad_banner_content_type"
|
23
24
|
t.integer "ad_banner_file_size"
|
24
25
|
t.datetime "ad_banner_updated_at"
|
25
26
|
t.integer "display_count", :default => 0, :null => false
|
26
|
-
t.integer "priority"
|
27
|
+
t.integer "priority", :default => 1, :null => false
|
27
28
|
t.date "start_date"
|
28
29
|
t.date "end_date"
|
29
30
|
t.integer "keyword_id"
|
31
|
+
t.integer "click_count", :default => 0, :null => false
|
32
|
+
t.datetime "created_at", :null => false
|
33
|
+
t.datetime "updated_at", :null => false
|
30
34
|
end
|
31
35
|
|
32
36
|
create_table "ad_man_keywords", :force => true do |t|
|
@@ -34,5 +38,6 @@ ActiveRecord::Schema.define(:version => 20120808101547) do
|
|
34
38
|
t.datetime "created_at", :null => false
|
35
39
|
t.datetime "updated_at", :null => false
|
36
40
|
end
|
41
|
+
>>>>>>> ebccd78bf25a122cf7949094b969681a8bd1a867
|
37
42
|
|
38
43
|
end
|
data/test/dummy/db/test.sqlite3
CHANGED
Binary file
|