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.
Files changed (45) hide show
  1. data/README.md +103 -0
  2. data/app/assets/javascripts/ad_man/advertisements.js +8 -0
  3. data/app/controllers/ad_man/advertisements_controller.rb +9 -1
  4. data/app/helpers/ad_man/application_helper.rb +29 -16
  5. data/app/models/ad_man/advertisement.rb +44 -41
  6. data/app/views/ad_man/advertisements/get_ad.js.erb +2 -0
  7. data/app/views/ad_man/advertisements/show.html.erb +2 -2
  8. data/app/views/ad_man/keywords/show.html.erb +1 -1
  9. data/config/routes.rb +7 -2
  10. data/lib/ad_man/version.rb +1 -1
  11. data/lib/ad_man.rb +5 -5
  12. data/lib/generators/ad_man/install_generator.rb +14 -16
  13. data/lib/generators/ad_man/templates/advertisements_controller.rb +4 -0
  14. data/lib/generators/ad_man/templates/keywords_controller.rb +4 -0
  15. data/test/dummy/db/development.sqlite3 +0 -0
  16. data/test/dummy/db/schema.rb +9 -4
  17. data/test/dummy/db/test.sqlite3 +0 -0
  18. data/test/dummy/log/development.log +278 -35896
  19. data/test/fixtures/ad_man/keywords.yml +3 -0
  20. data/test/functional/ad_man/advertisements_controller_test.rb +33 -14
  21. data/test/functional/ad_man/keywords_controller_test.rb +13 -14
  22. data/test/test_helper.rb +8 -4
  23. data/test/unit/ad_man/keyword_test.rb +1 -1
  24. metadata +7 -44
  25. data/README.rdoc +0 -61
  26. data/test/dummy/log/test.log +0 -1406
  27. data/test/dummy/public/system/ad_man/advertisements/ad_banners/000/000/001/banner/test.jpeg +0 -0
  28. data/test/dummy/public/system/ad_man/advertisements/ad_banners/000/000/001/leaderboard/test.jpeg +0 -0
  29. data/test/dummy/tmp/cache/assets/C02/0A0/sprockets%2F625bdc26802f8c498265353870490587 +0 -0
  30. data/test/dummy/tmp/cache/assets/CC8/220/sprockets%2F234102a39a522cfab9195fd0d7c12640 +0 -0
  31. data/test/dummy/tmp/cache/assets/CD6/A60/sprockets%2Fcca4c63026454615fd0a54b65b881d64 +0 -0
  32. data/test/dummy/tmp/cache/assets/CD8/370/sprockets%2F357970feca3ac29060c1e3861e2c0953 +0 -0
  33. data/test/dummy/tmp/cache/assets/CE4/9E0/sprockets%2F3f5956491fde7227a651e20e4d756b1a +0 -0
  34. data/test/dummy/tmp/cache/assets/D31/910/sprockets%2Fc1c18d3d756fe2777d18b236a0aea400 +0 -0
  35. data/test/dummy/tmp/cache/assets/D32/A10/sprockets%2F13fe41fee1fe35b49d145bcc06610705 +0 -0
  36. data/test/dummy/tmp/cache/assets/D3A/220/sprockets%2Fce53c5b352a83645d36d96aff26020fb +0 -0
  37. data/test/dummy/tmp/cache/assets/D3E/AF0/sprockets%2F317881d54abbd5721deee7d204e70e66 +0 -0
  38. data/test/dummy/tmp/cache/assets/D4E/1B0/sprockets%2Ff7cbd26ba1d28d48de824f0e94586655 +0 -0
  39. data/test/dummy/tmp/cache/assets/D5A/EA0/sprockets%2Fd771ace226fc8215a3572e0aa35bb0d6 +0 -0
  40. data/test/dummy/tmp/cache/assets/D79/2D0/sprockets%2F0d684f7bbe7d675f000dff8821d90ae8 +0 -0
  41. data/test/dummy/tmp/cache/assets/DBA/3C0/sprockets%2F9ca84f8118d29c3fd7bfd2876f83dc7e +0 -0
  42. data/test/dummy/tmp/cache/assets/DDC/400/sprockets%2Fcffd775d018f68ce5dba1ee0d951a994 +0 -0
  43. data/test/dummy/tmp/cache/assets/DF7/090/sprockets%2Fb3b1a32b0f923d6741fd5dacdf9f59ab +0 -0
  44. data/test/dummy/tmp/cache/assets/E04/890/sprockets%2F2f5173deea6c795b8fdde723bb4b63af +0 -0
  45. 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
- def link_to_ad(keyword = nil, size = "leaderboard")
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
- if !keyword.blank? && !Keyword.find_by_name(keyword).nil?
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
- end
32
+ end
12
33
  if !ad.nil?
13
- ad.display_count += 1
34
+ ad.display_count += 1
14
35
  ad.save
15
- link_to image_tag(ad.ad_banner.url(size)), { :controller => 'advertisements', :action => 'click_through', :id => ad.id },
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, :priority, :start_date, :end_date, :click_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 => { :leaderboard => (AdMan.leaderboard_size)?(AdMan.leaderboard_size):'728X90',
7
- :banner => (AdMan.banner_size)?(AdMan.banner_size):'468X60' }
8
- validates_attachment :ad_banner, :presence => true,
9
- :content_type => { :content_type => (AdMan.content_type)?(AdMan.content_type):
10
- ["image/jpg","image/bmp","image/png", "image/gif", "image/jpeg"] },
11
- :size => { :in => 0..((AdMan.max_image_size)?(AdMan.max_image_size):50).kilobytes }
12
- validates_presence_of :destination_url, :title, :keyword_id, :priority
13
- validates_uniqueness_of :title
14
- validate :image_dimensions, :on => :create
15
- after_initialize :init_priority
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
- def Advertisement.render_random_ad(keyword_id = nil)
18
- # ads = Advertisement.find_all_by_keyword_id(keyword_id)
19
- if keyword_id.nil?
20
- ads = Advertisement.where("start_date <= ? AND end_date >= ?", Date.today, Date.today)
21
- else
22
- ads = Advertisement.where("keyword_id = ? AND start_date <= ? AND end_date >= ? ", keyword_id, Date.today, Date.today)
23
- end
24
- if !ads.blank?
25
- total_times = 1.0
26
- total_priority = 0.0
27
- ads.each { |advertisement|
28
- total_times += advertisement.display_count
29
- total_priority += advertisement.priority
30
- }
31
- ad = ads[rand(ads.size)]
32
- while((ad.display_count / total_times) > (ad.priority / total_priority))
33
- ad = ads[rand(ads.size)]
34
- end
35
- ad
36
- end
37
- end
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
- private
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
- max_width = (AdMan.image_dimensions_width)?(AdMan.image_dimensions_width):728
44
- max_height = (AdMan.image_dimensions_height)?(AdMan.image_dimensions_height):90
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
- errors.add("banner_dimmensions",
47
- "must be image size: #{max_width}X#{max_height}.")
50
+ errors.add("banner_dimmensions",
51
+ "must be image size: #{max_width}X#{max_height}.")
48
52
  end
49
53
  end
50
54
 
51
- def init_priority
52
- self.priority ||= 1
53
- end
54
-
55
+ def init_priority
56
+ self.priority ||= 1
57
+ end
55
58
  end
56
59
  end
57
60
 
@@ -0,0 +1,2 @@
1
+ $('div#advertisement').html('<%= link_to image_tag(@ad.ad_banner.url),
2
+ click_through_path(@ad.id), :target => "_blank", :method => :post %>');
@@ -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
- :confirm => "Deleting Advertisement, this cannot be undone. Please confirm.", :style => "color:#b94a48"%>
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
- :confirm => "Deleting Keyword, this cannot be undone. WARNING: This will delete all advertisements connected with this keyword. Please confirm.", :style => "color:#b94a48"%>
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
- match 'advertisements/click_through' => 'advertisements#click_through'
11
+
7
12
  end
@@ -1,3 +1,3 @@
1
1
  module AdMan
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
data/lib/ad_man.rb CHANGED
@@ -1,9 +1,9 @@
1
1
  require "ad_man/engine"
2
2
 
3
3
  module AdMan
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
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
- class InstallGenerator < Rails::Generators::Base
3
- def create_extended_controller_file
4
- create_file "app/controllers/ad_man/advertisements_controller.rb",
5
- %Q[require AdMan::Engine.config.root + 'app' + 'controllers' + 'ad_man' + 'advertisements_controller'
6
- AdMan::AdvertisementsController.class_eval do
7
- end]
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
- create_file "app/controllers/ad_man/keywords_controller.rb",
10
- %Q[require AdMan::Engine.config.root + 'app' + 'controllers' + 'ad_man' + 'keywords_controller'
11
- AdMan::KeywordsController.class_eval do
12
- end]
13
- end
14
-
15
- def add_routes
16
- route("mount AdMan::Engine, :at => '/ad_man'")
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
 
@@ -0,0 +1,4 @@
1
+ require File.join(AdMan::Engine.config.root,'app','controllers','ad_man','advertisements_controller')
2
+ AdMan::AdvertisementsController.class_eval do
3
+ # overrides go here
4
+ end
@@ -0,0 +1,4 @@
1
+ require File.join(AdMan::Engine.config.root,'app','controllers','ad_man','keywords_controller')
2
+ AdMan::KeywordsController.class_eval do
3
+ # overrides go here
4
+ end
Binary file
@@ -11,22 +11,26 @@
11
11
  #
12
12
  # It's strongly recommended to check this file into your version control system.
13
13
 
14
- ActiveRecord::Schema.define(:version => 20120808101547) do
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
Binary file