ad_man 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (27) hide show
  1. data/MIT-LICENSE +1 -1
  2. data/README.md +5 -9
  3. data/app/assets/javascripts/ad_man/advertisements.js +9 -7
  4. data/app/controllers/ad_man/advertisements_controller.rb +3 -1
  5. data/app/controllers/ad_man/keywords_controller.rb +3 -3
  6. data/app/helpers/ad_man/application_helper.rb +31 -26
  7. data/app/models/ad_man/keyword.rb +15 -14
  8. data/app/views/ad_man/advertisements/get_ad.js.erb +4 -2
  9. data/config/routes.rb +7 -5
  10. data/lib/ad_man/version.rb +1 -1
  11. data/lib/generators/ad_man/install_generator.rb +1 -1
  12. data/test/dummy/app/controllers/ad_man/advertisements_controller.rb +4 -0
  13. data/test/dummy/app/controllers/ad_man/keywords_controller.rb +4 -0
  14. data/test/dummy/app/views/layouts/application.html.erb +15 -0
  15. data/test/dummy/db/migrate/20120817083909_create_ad_man_advertisements.ad_man.rb +17 -0
  16. data/test/dummy/db/migrate/20120817083910_create_ad_man_keywords.ad_man.rb +9 -0
  17. data/test/dummy/db/schema.rb +1 -5
  18. data/test/dummy/public/system/ad_man/advertisements/ad_banners/000/000/001/banner/1-NR-728x90-cool-b.gif +0 -0
  19. data/test/dummy/public/system/ad_man/advertisements/ad_banners/000/000/001/leaderboard/1-NR-728x90-cool-b.gif +0 -0
  20. data/test/dummy/public/system/ad_man/advertisements/ad_banners/000/000/001/original/1-NR-728x90-cool-b.gif +0 -0
  21. data/test/dummy/public/system/ad_man/advertisements/ad_banners/000/000/002/banner/61f8516ab0e6471b99443e17bf7533d5.jpeg +0 -0
  22. data/test/dummy/public/system/ad_man/advertisements/ad_banners/000/000/002/leaderboard/61f8516ab0e6471b99443e17bf7533d5.jpeg +0 -0
  23. data/test/dummy/public/system/ad_man/advertisements/ad_banners/000/000/002/original/61f8516ab0e6471b99443e17bf7533d5.jpeg +0 -0
  24. metadata +22 -8
  25. data/test/dummy/db/development.sqlite3 +0 -0
  26. data/test/dummy/db/test.sqlite3 +0 -0
  27. data/test/dummy/log/development.log +0 -789
data/MIT-LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright 2012 YOURNAME
1
+ Copyright 2012 Kudelabs
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
@@ -78,16 +78,15 @@ Ad_man supports inserting an advertisement using jQuery. It also uses jQuery in
78
78
  <%= javascript_include_tag "ad_man/advertisements.js" %>
79
79
  ```
80
80
 
81
- You can pass the keyword name through the showAd(); function.
81
+ You can pass a `<DIV>` id element, the keyword name, and size to show an advertisement using the showAd(); function. Currently supported sizes are: `leaderboard` and `banner`.
82
82
  ```erb
83
83
  <script>
84
- // showAd(keyword);
85
- showAd('<%= @keyword %>'); // inserts a value from ruby in erb
84
+ AdMan.showAd('div_id', 'keyword', 'size');
86
85
  </script>
87
86
  ```
88
- Then ad a `<DIV>` element with the id 'advertisement' where you want the advertisement to show.
87
+ Then make sure you have a `<DIV>` element with the `div_id` you gave to the showAd function.
89
88
  ```erb
90
- <div id="advertisement"></div>
89
+ <div id="banner_ad"></div>
91
90
  ```
92
91
 
93
92
  ## Authors
@@ -97,7 +96,4 @@ Written by [David Strand](http://www.github.com/wspyder) and [Tyler Hu](http://w
97
96
  [Matenia Rossides](http://www.github.com/matenia)
98
97
 
99
98
  ## Copyright & Licensing
100
-
101
- Copyright (c) 2012 [Kudelabs](http://kudelabs.com)
102
-
103
- Released under MIT License.
99
+ This project is maintained by an intern team of developers and is freely available for commercial use under the terms of the MIT License.
@@ -44,11 +44,13 @@ 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
- });
47
+ AdMan = {
48
+ //function showAd(div, key, size) {
49
+ showAd: function(div, key, size) {
50
+ $.ajax({
51
+ url: "/ad_man/advertisements/get_ad/" + div + "/" + key + "/" + size,
52
+ dataType: "script",
53
+ success: function(data){}
54
+ });
55
+ }
54
56
  }
@@ -100,7 +100,9 @@ class AdMan::AdvertisementsController < ApplicationController
100
100
  end
101
101
 
102
102
  def get_ad()
103
- keyword = params[:id]
103
+ keyword = params[:key]
104
+ @div = params[:div]
105
+ @size = params[:size]
104
106
  @ad = js_link_to_ad(keyword)
105
107
  end
106
108
 
@@ -13,9 +13,9 @@ class AdMan::KeywordsController < ApplicationController
13
13
  # GET /keywords/1
14
14
  # GET /keywords/1.json
15
15
  def show
16
- @keyword = AdMan::Keyword.find(params[:id])
17
- @advertisements = AdMan::Advertisement.find_all_by_keyword_id(params[:id])
18
- @keywords = AdMan::Keyword.all
16
+ @keyword = AdMan::Keyword.find(params[:id])
17
+ @advertisements = AdMan::Advertisement.find_all_by_keyword_id(params[:id])
18
+ @keywords = AdMan::Keyword.all
19
19
  end
20
20
 
21
21
  # GET /keywords/new
@@ -1,40 +1,45 @@
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
4
+ # def link_to_ad(hash = {:keyword => nil, :size => "leaderboard"})
5
+ # keyword = hash[:keyword]
6
+ # size = hash[:size]
7
+ ad = ad_select(keyword)
8
+ if ad
9
+ link_to image_tag(ad.ad_banner.url(size)), ad_man.click_through_advertisements_path(ad.id), :target => '_blank', :method => :post
10
+ end
7
11
  end
8
12
 
9
13
  def js_link_to_ad(keyword)
10
- ad_select(keyword, size= "leaderboard")
14
+ ad_select(keyword)
11
15
  end
12
16
 
13
17
  protected
14
18
  #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
19
+ def get_keyword_from_url
20
+ if request.env["REQUEST_PATH"]
21
+ req_url = request.env["REQUEST_PATH"].split("/")
22
+ keyword_names = Keyword.all.map{ |keyword| keyword.name }
23
+ keyword = req_url & keyword_names
21
24
  end
25
+ end
22
26
 
23
27
 
24
- def ad_select(keyword, size)
25
- keyword ||= get_keyword_from_url
26
- if keyword && !keyword.blank? && !Keyword.find_by_name(keyword).nil?
27
- keyword_id = Keyword.find_by_name(keyword).id
28
- ad = Advertisement.render_random_ad(keyword_id)
29
- #grab size? leaderboard or banner
30
- elsif keyword.nil? || keyword.blank?
31
- ad = Advertisement.render_random_ad
32
- end
33
- if !ad.nil?
34
- ad.display_count += 1
35
- ad.save
36
- ad
37
- end
38
- end
39
- end
28
+ def ad_select(keyword)
29
+ keyword ||= get_keyword_from_url
30
+ if keyword && !keyword.blank? && Keyword.find_by_name(keyword)
31
+ keyword_id = Keyword.find_by_name(keyword).id
32
+ ad = Advertisement.render_random_ad(keyword_id)
33
+ #grab size? leaderboard or banner
34
+ elsif keyword.nil? || keyword.blank?
35
+ ad = Advertisement.render_random_ad
36
+ end
37
+ if ad
38
+ ad.display_count += 1
39
+ ad.save
40
+ ad
41
+ end
42
+ end
43
+
44
+ end
40
45
  end
@@ -1,23 +1,24 @@
1
1
  module AdMan
2
2
  class Keyword < ActiveRecord::Base
3
3
  attr_accessible :name
4
- has_many :advertisements, :dependent => :destroy
4
+ has_many :advertisements, :dependent => :destroy
5
5
  validates :name, :presence => true, :uniqueness => true
6
- MAX_COUNT = (AdMan.max_count)?(AdMan.max_count):5
6
+ MAX_COUNT = (AdMan.max_count)?(AdMan.max_count):5
7
7
 
8
- def to_s
9
- name
10
- end
8
+ def to_s
9
+ name
10
+ end
11
11
 
12
- def number_of_ads
13
- self.advertisements.count
14
- end
15
- def self.available
16
- Keyword.all.select { |keyword| keyword.advertisements.count < MAX_COUNT}
17
- end
12
+ def number_of_ads
13
+ self.advertisements.count
14
+ end
15
+
16
+ def self.available
17
+ Keyword.all.select { |keyword| keyword.advertisements.count < MAX_COUNT}
18
+ end
18
19
 
19
- def self.unavailable
20
- Keyword.all.select { |keyword| keyword.advertisements.count >= MAX_COUNT}
21
- end
20
+ def self.unavailable
21
+ Keyword.all.select { |keyword| keyword.advertisements.count >= MAX_COUNT}
22
+ end
22
23
  end
23
24
  end
@@ -1,2 +1,4 @@
1
- $('div#advertisement').html('<%= link_to image_tag(@ad.ad_banner.url),
2
- click_through_path(@ad.id), :target => "_blank", :method => :post %>');
1
+ <% if @ad %>
2
+ $(<%= @div %>).html('<%= link_to image_tag(@ad.ad_banner.url(@size)),
3
+ ad_man.click_through_advertisements_path(@ad.id), :target => "_blank", :method => :post %>');
4
+ <% end %>
data/config/routes.rb CHANGED
@@ -1,10 +1,12 @@
1
1
  AdMan::Engine.routes.draw do
2
2
  resources :keywords
3
- resources :advertisements
4
-
5
- match 'ad_man/advertisements/click_through/:id' => "advertisements#click_through", :as => :click_through
6
- match 'ad_man/advertisements/get_ad/:id' => 'advertisements#get_ad'
7
-
3
+ resources :advertisements do
4
+ collection do
5
+ match 'click_through/:id' => "advertisements#click_through", :as => :click_through
6
+ match 'get_ad/:div/:key/:size' => 'advertisements#get_ad', :as => :get_ad
7
+ end
8
+ end
9
+
8
10
  root :to => "advertisements#index"
9
11
 
10
12
  end
@@ -1,3 +1,3 @@
1
1
  module AdMan
2
- VERSION = "0.0.7"
2
+ VERSION = "0.0.8"
3
3
  end
@@ -7,7 +7,7 @@ module AdMan
7
7
  end
8
8
 
9
9
  def add_routes
10
- route("mount AdMan::Engine, :at => '/ad_man'")
10
+ route("mount AdMan::Engine => "/ad_man")
11
11
  end
12
12
 
13
13
  def install_migrations
@@ -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
@@ -5,11 +5,26 @@
5
5
  <%= stylesheet_link_tag "application", :media => "all" %>
6
6
  <%= javascript_include_tag "application" %>
7
7
  <%= javascript_include_tag "ad_man/advertisements.js" %>
8
+
9
+ <script>
10
+ // showAd(keyword)
11
+ <% if AdMan::Keyword.first %>
12
+ AdMan.showAd('<%= AdMan::Keyword.first.name %>', 'banner', 'advertisement1'); //
13
+ AdMan.showAd('<%= AdMan::Keyword.last.name %>', 'leaderboard', 'advertisement2');
14
+ <% end %>
15
+ </script>
16
+
8
17
  <%= csrf_meta_tags %>
9
18
  </head>
10
19
  <body>
11
20
 
21
+ <%= link_to_ad %>
22
+ <hr/>
23
+
12
24
  <%= yield %>
13
25
 
26
+
27
+ <div id="advertisement1"></div>
28
+ <div id="advertisement2"></div>
14
29
  </body>
15
30
  </html>
@@ -0,0 +1,17 @@
1
+ # This migration comes from ad_man (originally 20120808085322)
2
+ class CreateAdManAdvertisements < ActiveRecord::Migration
3
+ def change
4
+ create_table :ad_man_advertisements do |t|
5
+ t.string :title
6
+ t.string :destination_url
7
+ t.has_attached_file :ad_banner
8
+ t.integer :display_count, :null => false, :default => 0
9
+ t.integer :priority, :null => false, :default => 1
10
+ t.date :start_date
11
+ t.date :end_date
12
+ t.integer :keyword_id
13
+ t.integer :click_count, :null => false, :default => 0
14
+ t.timestamps
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,9 @@
1
+ # This migration comes from ad_man (originally 20120808091446)
2
+ class CreateAdManKeywords < ActiveRecord::Migration
3
+ def change
4
+ create_table :ad_man_keywords do |t|
5
+ t.string :name
6
+ t.timestamps
7
+ end
8
+ end
9
+ end
@@ -11,10 +11,7 @@
11
11
  #
12
12
  # It's strongly recommended to check this file into your version control system.
13
13
 
14
- <<<<<<< HEAD
15
- ActiveRecord::Schema.define(:version => 0) do
16
- =======
17
- ActiveRecord::Schema.define(:version => 20120812095547) do
14
+ ActiveRecord::Schema.define(:version => 20120817083910) do
18
15
 
19
16
  create_table "ad_man_advertisements", :force => true do |t|
20
17
  t.string "title"
@@ -38,6 +35,5 @@ ActiveRecord::Schema.define(:version => 20120812095547) do
38
35
  t.datetime "created_at", :null => false
39
36
  t.datetime "updated_at", :null => false
40
37
  end
41
- >>>>>>> ebccd78bf25a122cf7949094b969681a8bd1a867
42
38
 
43
39
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ad_man
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-08-15 00:00:00.000000000 Z
13
+ date: 2012-08-21 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rails
@@ -110,6 +110,8 @@ files:
110
110
  - test/ad_man_test.rb
111
111
  - test/dummy/app/assets/javascripts/application.js
112
112
  - test/dummy/app/assets/stylesheets/application.css
113
+ - test/dummy/app/controllers/ad_man/advertisements_controller.rb
114
+ - test/dummy/app/controllers/ad_man/keywords_controller.rb
113
115
  - test/dummy/app/controllers/application_controller.rb
114
116
  - test/dummy/app/helpers/application_helper.rb
115
117
  - test/dummy/app/views/layouts/application.html.erb
@@ -130,17 +132,22 @@ files:
130
132
  - test/dummy/config/locales/en.yml
131
133
  - test/dummy/config/routes.rb
132
134
  - test/dummy/config.ru
133
- - test/dummy/db/development.sqlite3
135
+ - test/dummy/db/migrate/20120817083909_create_ad_man_advertisements.ad_man.rb
136
+ - test/dummy/db/migrate/20120817083910_create_ad_man_keywords.ad_man.rb
134
137
  - test/dummy/db/schema.rb
135
- - test/dummy/db/test.sqlite3
136
- - test/dummy/log/development.log
137
138
  - test/dummy/public/404.html
138
139
  - test/dummy/public/422.html
139
140
  - test/dummy/public/500.html
140
141
  - test/dummy/public/favicon.ico
142
+ - test/dummy/public/system/ad_man/advertisements/ad_banners/000/000/001/banner/1-NR-728x90-cool-b.gif
143
+ - test/dummy/public/system/ad_man/advertisements/ad_banners/000/000/001/leaderboard/1-NR-728x90-cool-b.gif
144
+ - test/dummy/public/system/ad_man/advertisements/ad_banners/000/000/001/original/1-NR-728x90-cool-b.gif
141
145
  - test/dummy/public/system/ad_man/advertisements/ad_banners/000/000/001/original/FabTable_01.jpg
142
146
  - test/dummy/public/system/ad_man/advertisements/ad_banners/000/000/001/original/test.jpeg
143
147
  - test/dummy/public/system/ad_man/advertisements/ad_banners/000/000/001/small/FabTable_01.jpg
148
+ - test/dummy/public/system/ad_man/advertisements/ad_banners/000/000/002/banner/61f8516ab0e6471b99443e17bf7533d5.jpeg
149
+ - test/dummy/public/system/ad_man/advertisements/ad_banners/000/000/002/leaderboard/61f8516ab0e6471b99443e17bf7533d5.jpeg
150
+ - test/dummy/public/system/ad_man/advertisements/ad_banners/000/000/002/original/61f8516ab0e6471b99443e17bf7533d5.jpeg
144
151
  - test/dummy/public/system/ad_man/advertisements/ad_banners/000/000/002/original/728x90_2MM.jpg
145
152
  - test/dummy/public/system/ad_man/advertisements/ad_banners/000/000/002/original/d893babe671c41118c1fece177e0a21a.jpeg
146
153
  - test/dummy/public/system/ad_man/advertisements/ad_banners/000/000/002/small/728x90_2MM.jpg
@@ -197,6 +204,8 @@ test_files:
197
204
  - test/ad_man_test.rb
198
205
  - test/dummy/app/assets/javascripts/application.js
199
206
  - test/dummy/app/assets/stylesheets/application.css
207
+ - test/dummy/app/controllers/ad_man/advertisements_controller.rb
208
+ - test/dummy/app/controllers/ad_man/keywords_controller.rb
200
209
  - test/dummy/app/controllers/application_controller.rb
201
210
  - test/dummy/app/helpers/application_helper.rb
202
211
  - test/dummy/app/views/layouts/application.html.erb
@@ -217,17 +226,22 @@ test_files:
217
226
  - test/dummy/config/locales/en.yml
218
227
  - test/dummy/config/routes.rb
219
228
  - test/dummy/config.ru
220
- - test/dummy/db/development.sqlite3
229
+ - test/dummy/db/migrate/20120817083909_create_ad_man_advertisements.ad_man.rb
230
+ - test/dummy/db/migrate/20120817083910_create_ad_man_keywords.ad_man.rb
221
231
  - test/dummy/db/schema.rb
222
- - test/dummy/db/test.sqlite3
223
- - test/dummy/log/development.log
224
232
  - test/dummy/public/404.html
225
233
  - test/dummy/public/422.html
226
234
  - test/dummy/public/500.html
227
235
  - test/dummy/public/favicon.ico
236
+ - test/dummy/public/system/ad_man/advertisements/ad_banners/000/000/001/banner/1-NR-728x90-cool-b.gif
237
+ - test/dummy/public/system/ad_man/advertisements/ad_banners/000/000/001/leaderboard/1-NR-728x90-cool-b.gif
238
+ - test/dummy/public/system/ad_man/advertisements/ad_banners/000/000/001/original/1-NR-728x90-cool-b.gif
228
239
  - test/dummy/public/system/ad_man/advertisements/ad_banners/000/000/001/original/FabTable_01.jpg
229
240
  - test/dummy/public/system/ad_man/advertisements/ad_banners/000/000/001/original/test.jpeg
230
241
  - test/dummy/public/system/ad_man/advertisements/ad_banners/000/000/001/small/FabTable_01.jpg
242
+ - test/dummy/public/system/ad_man/advertisements/ad_banners/000/000/002/banner/61f8516ab0e6471b99443e17bf7533d5.jpeg
243
+ - test/dummy/public/system/ad_man/advertisements/ad_banners/000/000/002/leaderboard/61f8516ab0e6471b99443e17bf7533d5.jpeg
244
+ - test/dummy/public/system/ad_man/advertisements/ad_banners/000/000/002/original/61f8516ab0e6471b99443e17bf7533d5.jpeg
231
245
  - test/dummy/public/system/ad_man/advertisements/ad_banners/000/000/002/original/728x90_2MM.jpg
232
246
  - test/dummy/public/system/ad_man/advertisements/ad_banners/000/000/002/original/d893babe671c41118c1fece177e0a21a.jpeg
233
247
  - test/dummy/public/system/ad_man/advertisements/ad_banners/000/000/002/small/728x90_2MM.jpg
Binary file
File without changes