ad_man 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (115) hide show
  1. data/MIT-LICENSE +20 -0
  2. data/README.rdoc +3 -0
  3. data/Rakefile +40 -0
  4. data/app/assets/javascripts/ad_man/advertisements.js +46 -0
  5. data/app/assets/javascripts/ad_man/application.js +15 -0
  6. data/app/assets/javascripts/ad_man/keywords.js +2 -0
  7. data/app/assets/stylesheets/ad_man/advertisements.css +4 -0
  8. data/app/assets/stylesheets/ad_man/application.css +13 -0
  9. data/app/assets/stylesheets/ad_man/keywords.css +4 -0
  10. data/app/assets/stylesheets/scaffold.css +56 -0
  11. data/app/controllers/ad_man/advertisements_controller.rb +99 -0
  12. data/app/controllers/ad_man/application_controller.rb +4 -0
  13. data/app/controllers/ad_man/keywords_controller.rb +77 -0
  14. data/app/helpers/ad_man/advertisements_helper.rb +4 -0
  15. data/app/helpers/ad_man/application_helper.rb +28 -0
  16. data/app/helpers/ad_man/keywords_helper.rb +4 -0
  17. data/app/models/ad_man/advertisement.rb +54 -0
  18. data/app/models/ad_man/keyword.rb +22 -0
  19. data/app/views/ad_man/advertisements/_form.html.erb +57 -0
  20. data/app/views/ad_man/advertisements/edit.html.erb +6 -0
  21. data/app/views/ad_man/advertisements/index.html.erb +48 -0
  22. data/app/views/ad_man/advertisements/new.html.erb +5 -0
  23. data/app/views/ad_man/advertisements/show.html.erb +39 -0
  24. data/app/views/ad_man/keywords/_form.html.erb +22 -0
  25. data/app/views/ad_man/keywords/edit.html.erb +6 -0
  26. data/app/views/ad_man/keywords/index.html.erb +16 -0
  27. data/app/views/ad_man/keywords/new.html.erb +5 -0
  28. data/app/views/ad_man/keywords/show.html.erb +39 -0
  29. data/app/views/layouts/ad_man/application.html.erb +15 -0
  30. data/config/routes.rb +7 -0
  31. data/db/migrate/20120808085322_create_ad_man_advertisements.rb +10 -0
  32. data/db/migrate/20120808085909_add_attachment_ad_banner_to_advertisements.rb +11 -0
  33. data/db/migrate/20120808091446_create_ad_man_keywords.rb +9 -0
  34. data/db/migrate/20120808095330_add_display_count_to_ad_man_advertisements.rb +5 -0
  35. data/db/migrate/20120808095742_add_priority_to_ad_man_advertisements.rb +6 -0
  36. data/db/migrate/20120808100040_add_start_date_and_end_date_to_ad_man_advertisements.rb +8 -0
  37. data/db/migrate/20120808101547_add_keyword_id_to_ad_man_advertisements.rb +5 -0
  38. data/db/migrate/20120809065243_add_click_count_to_ad_man_advertisements.rb +5 -0
  39. data/lib/ad_man/engine.rb +14 -0
  40. data/lib/ad_man/version.rb +3 -0
  41. data/lib/ad_man.rb +9 -0
  42. data/lib/tasks/ad_man_tasks.rake +4 -0
  43. data/test/ad_man_test.rb +7 -0
  44. data/test/dummy/README.rdoc +261 -0
  45. data/test/dummy/Rakefile +7 -0
  46. data/test/dummy/app/assets/javascripts/application.js +15 -0
  47. data/test/dummy/app/assets/stylesheets/application.css +13 -0
  48. data/test/dummy/app/controllers/application_controller.rb +3 -0
  49. data/test/dummy/app/helpers/application_helper.rb +2 -0
  50. data/test/dummy/app/views/layouts/application.html.erb +15 -0
  51. data/test/dummy/config/application.rb +59 -0
  52. data/test/dummy/config/boot.rb +10 -0
  53. data/test/dummy/config/database.yml +25 -0
  54. data/test/dummy/config/environment.rb +5 -0
  55. data/test/dummy/config/environments/development.rb +37 -0
  56. data/test/dummy/config/environments/production.rb +67 -0
  57. data/test/dummy/config/environments/test.rb +37 -0
  58. data/test/dummy/config/initializers/ad_man.rb +22 -0
  59. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  60. data/test/dummy/config/initializers/inflections.rb +15 -0
  61. data/test/dummy/config/initializers/mime_types.rb +5 -0
  62. data/test/dummy/config/initializers/secret_token.rb +7 -0
  63. data/test/dummy/config/initializers/session_store.rb +8 -0
  64. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  65. data/test/dummy/config/locales/en.yml +5 -0
  66. data/test/dummy/config/routes.rb +6 -0
  67. data/test/dummy/config.ru +4 -0
  68. data/test/dummy/db/development.sqlite3 +0 -0
  69. data/test/dummy/db/schema.rb +38 -0
  70. data/test/dummy/log/development.log +35507 -0
  71. data/test/dummy/public/404.html +26 -0
  72. data/test/dummy/public/422.html +26 -0
  73. data/test/dummy/public/500.html +25 -0
  74. data/test/dummy/public/favicon.ico +0 -0
  75. data/test/dummy/public/system/ad_man/advertisements/ad_banners/000/000/001/original/FabTable_01.jpg +0 -0
  76. data/test/dummy/public/system/ad_man/advertisements/ad_banners/000/000/001/small/FabTable_01.jpg +0 -0
  77. data/test/dummy/public/system/ad_man/advertisements/ad_banners/000/000/002/original/728x90_2MM.jpg +0 -0
  78. data/test/dummy/public/system/ad_man/advertisements/ad_banners/000/000/002/original/d893babe671c41118c1fece177e0a21a.jpeg +0 -0
  79. data/test/dummy/public/system/ad_man/advertisements/ad_banners/000/000/002/small/728x90_2MM.jpg +0 -0
  80. data/test/dummy/public/system/ad_man/advertisements/ad_banners/000/000/002/small/d893babe671c41118c1fece177e0a21a.jpeg +0 -0
  81. data/test/dummy/public/system/ad_man/advertisements/ad_banners/000/000/014/banner/1-NR-728x90-cool-b.gif +0 -0
  82. data/test/dummy/public/system/ad_man/advertisements/ad_banners/000/000/014/leaderboard/1-NR-728x90-cool-b.gif +0 -0
  83. data/test/dummy/public/system/ad_man/advertisements/ad_banners/000/000/014/original/1-NR-728x90-cool-b.gif +0 -0
  84. data/test/dummy/public/system/ad_man/advertisements/ad_banners/000/000/015/banner/9241eb4107b24c588c0ca0042534c03e.png +0 -0
  85. data/test/dummy/public/system/ad_man/advertisements/ad_banners/000/000/015/leaderboard/9241eb4107b24c588c0ca0042534c03e.png +0 -0
  86. data/test/dummy/public/system/ad_man/advertisements/ad_banners/000/000/015/original/9241eb4107b24c588c0ca0042534c03e.png +0 -0
  87. data/test/dummy/public/system/ad_man/advertisements/ad_banners/000/000/016/banner/d893babe671c41118c1fece177e0a21a.jpeg +0 -0
  88. data/test/dummy/public/system/ad_man/advertisements/ad_banners/000/000/016/leaderboard/d893babe671c41118c1fece177e0a21a.jpeg +0 -0
  89. data/test/dummy/public/system/ad_man/advertisements/ad_banners/000/000/016/original/d893babe671c41118c1fece177e0a21a.jpeg +0 -0
  90. data/test/dummy/script/rails +6 -0
  91. data/test/dummy/tmp/cache/assets/C02/0A0/sprockets%2F625bdc26802f8c498265353870490587 +0 -0
  92. data/test/dummy/tmp/cache/assets/CD8/370/sprockets%2F357970feca3ac29060c1e3861e2c0953 +0 -0
  93. data/test/dummy/tmp/cache/assets/CE4/9E0/sprockets%2F3f5956491fde7227a651e20e4d756b1a +0 -0
  94. data/test/dummy/tmp/cache/assets/D31/910/sprockets%2Fc1c18d3d756fe2777d18b236a0aea400 +0 -0
  95. data/test/dummy/tmp/cache/assets/D32/A10/sprockets%2F13fe41fee1fe35b49d145bcc06610705 +0 -0
  96. data/test/dummy/tmp/cache/assets/D3A/220/sprockets%2Fce53c5b352a83645d36d96aff26020fb +0 -0
  97. data/test/dummy/tmp/cache/assets/D3E/AF0/sprockets%2F317881d54abbd5721deee7d204e70e66 +0 -0
  98. data/test/dummy/tmp/cache/assets/D4E/1B0/sprockets%2Ff7cbd26ba1d28d48de824f0e94586655 +0 -0
  99. data/test/dummy/tmp/cache/assets/D5A/EA0/sprockets%2Fd771ace226fc8215a3572e0aa35bb0d6 +0 -0
  100. data/test/dummy/tmp/cache/assets/DBA/3C0/sprockets%2F9ca84f8118d29c3fd7bfd2876f83dc7e +0 -0
  101. data/test/dummy/tmp/cache/assets/DDC/400/sprockets%2Fcffd775d018f68ce5dba1ee0d951a994 +0 -0
  102. data/test/dummy/tmp/cache/assets/DF7/090/sprockets%2Fb3b1a32b0f923d6741fd5dacdf9f59ab +0 -0
  103. data/test/dummy/tmp/cache/assets/E04/890/sprockets%2F2f5173deea6c795b8fdde723bb4b63af +0 -0
  104. data/test/dummy/tmp/pids/server.pid +1 -0
  105. data/test/fixtures/ad_man/advertisements.yml +9 -0
  106. data/test/fixtures/ad_man/keywords.yml +7 -0
  107. data/test/functional/ad_man/advertisements_controller_test.rb +51 -0
  108. data/test/functional/ad_man/keywords_controller_test.rb +51 -0
  109. data/test/integration/navigation_test.rb +10 -0
  110. data/test/test_helper.rb +15 -0
  111. data/test/unit/ad_man/advertisement_test.rb +9 -0
  112. data/test/unit/ad_man/keyword_test.rb +9 -0
  113. data/test/unit/helpers/ad_man/advertisements_helper_test.rb +6 -0
  114. data/test/unit/helpers/ad_man/keywords_helper_test.rb +6 -0
  115. metadata +280 -0
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2012 YOURNAME
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.rdoc ADDED
@@ -0,0 +1,3 @@
1
+ = AdMan
2
+
3
+ This project rocks and uses MIT-LICENSE.
data/Rakefile ADDED
@@ -0,0 +1,40 @@
1
+ #!/usr/bin/env rake
2
+ begin
3
+ require 'bundler/setup'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
7
+ begin
8
+ require 'rdoc/task'
9
+ rescue LoadError
10
+ require 'rdoc/rdoc'
11
+ require 'rake/rdoctask'
12
+ RDoc::Task = Rake::RDocTask
13
+ end
14
+
15
+ RDoc::Task.new(:rdoc) do |rdoc|
16
+ rdoc.rdoc_dir = 'rdoc'
17
+ rdoc.title = 'AdMan'
18
+ rdoc.options << '--line-numbers'
19
+ rdoc.rdoc_files.include('README.rdoc')
20
+ rdoc.rdoc_files.include('lib/**/*.rb')
21
+ end
22
+
23
+ APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
24
+ load 'rails/tasks/engine.rake'
25
+
26
+
27
+
28
+ Bundler::GemHelper.install_tasks
29
+
30
+ require 'rake/testtask'
31
+
32
+ Rake::TestTask.new(:test) do |t|
33
+ t.libs << 'lib'
34
+ t.libs << 'test'
35
+ t.pattern = 'test/**/*_test.rb'
36
+ t.verbose = false
37
+ end
38
+
39
+
40
+ task :default => :test
@@ -0,0 +1,46 @@
1
+ // Place all the behaviors and hooks related to the matching controller here.
2
+ // All this logic will automatically be available in application.js.
3
+ var MAX_FILE_SIZE = 5242880; // 5MB
4
+ var ACCEPT_FILE_TYPE = /image\/(jpg|jpeg|png|gif|bmp)/i;
5
+
6
+ function handleFileSelect(evt) {
7
+ var files = evt.target.files; // FileList object
8
+ var form = $(evt.target).closest('form');
9
+
10
+ // Loop through the FileList and render image files as thumbnails.
11
+ for (var i = 0, f; f = files[i]; i++) {
12
+ // Only process image files.
13
+ if (!f.type.match(ACCEPT_FILE_TYPE)) {
14
+ showFormError('File is not an image', form);
15
+ continue;
16
+ }
17
+
18
+ if (parseInt(f.size) > MAX_FILE_SIZE) {
19
+ showFormError('File size exceeds 5MB.', form);
20
+ continue;
21
+ }
22
+
23
+ var reader = new FileReader();
24
+ // Closure to capture the file information.
25
+ reader.onload = (function(theFile) {
26
+ return function(e) {
27
+ // Render thumbnail.
28
+ var img = ['<img src="', e.target.result,
29
+ '" title="', theFile.name, '"/>'].join('');
30
+ form.find('.preview').html(img);
31
+ form.find('.preview').show();
32
+ };
33
+ })(f);
34
+
35
+ // Read in the image file as a data URL.
36
+ reader.readAsDataURL(f);
37
+ }
38
+ }
39
+
40
+ function showFormError(msg, form) {
41
+ var errorDiv = document.createElement('div');
42
+ errorDiv.className = 'errors';
43
+ errorDiv.innerHTML = msg;
44
+ form.find('div.errors').remove();
45
+ form.prepend(errorDiv);
46
+ }
@@ -0,0 +1,15 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // the compiled file.
9
+ //
10
+ // WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
11
+ // GO AFTER THE REQUIRES BELOW.
12
+ //
13
+ //= require jquery
14
+ //= require jquery_ujs
15
+ //= require_tree .
@@ -0,0 +1,2 @@
1
+ // Place all the behaviors and hooks related to the matching controller here.
2
+ // All this logic will automatically be available in application.js.
@@ -0,0 +1,4 @@
1
+ /*
2
+ Place all the styles related to the matching controller here.
3
+ They will automatically be included in application.css.
4
+ */
@@ -0,0 +1,13 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the top of the
9
+ * compiled file, but it's generally better to create a new file per style scope.
10
+ *
11
+ *= require_self
12
+ *= require_tree .
13
+ */
@@ -0,0 +1,4 @@
1
+ /*
2
+ Place all the styles related to the matching controller here.
3
+ They will automatically be included in application.css.
4
+ */
@@ -0,0 +1,56 @@
1
+ body { background-color: #fff; color: #333; }
2
+
3
+ body, p, ol, ul, td {
4
+ font-family: verdana, arial, helvetica, sans-serif;
5
+ font-size: 13px;
6
+ line-height: 18px;
7
+ }
8
+
9
+ pre {
10
+ background-color: #eee;
11
+ padding: 10px;
12
+ font-size: 11px;
13
+ }
14
+
15
+ a { color: #000; }
16
+ a:visited { color: #666; }
17
+ a:hover { color: #fff; background-color:#000; }
18
+
19
+ div.field, div.actions {
20
+ margin-bottom: 10px;
21
+ }
22
+
23
+ #notice {
24
+ color: green;
25
+ }
26
+
27
+ .field_with_errors {
28
+ padding: 2px;
29
+ background-color: red;
30
+ display: table;
31
+ }
32
+
33
+ #error_explanation {
34
+ width: 450px;
35
+ border: 2px solid red;
36
+ padding: 7px;
37
+ padding-bottom: 0;
38
+ margin-bottom: 20px;
39
+ background-color: #f0f0f0;
40
+ }
41
+
42
+ #error_explanation h2 {
43
+ text-align: left;
44
+ font-weight: bold;
45
+ padding: 5px 5px 5px 15px;
46
+ font-size: 12px;
47
+ margin: -7px;
48
+ margin-bottom: 0px;
49
+ background-color: #c00;
50
+ color: #fff;
51
+ }
52
+
53
+ #error_explanation ul li {
54
+ font-size: 12px;
55
+ list-style: square;
56
+ }
@@ -0,0 +1,99 @@
1
+ class AdMan::AdvertisementsController < ApplicationController
2
+ # GET /advertisements
3
+ # GET /advertisements.json
4
+ def index
5
+ @advertisements = AdMan::Advertisement.all
6
+
7
+ # depends on the "will_paginate" gem
8
+ #@advertisements = AdMan::Advertisement.paginate :page => params[:page], :order => 'created_at desc',
9
+ # :per_page => 5
10
+ @keywords = AdMan::Keyword.all
11
+
12
+ respond_to do |format|
13
+ format.html # index.html.erb
14
+ format.json { render json: @advertisements }
15
+ end
16
+ end
17
+
18
+ # GET /advertisements/1
19
+ # GET /advertisements/1.json
20
+ def show
21
+ @advertisement = AdMan::Advertisement.find(params[:id])
22
+
23
+ respond_to do |format|
24
+ format.html # show.html.erb
25
+ format.json { render json: @advertisement }
26
+ end
27
+ end
28
+
29
+ # GET /advertisements/new
30
+ # GET /advertisements/new.json
31
+ def new
32
+ @advertisement = AdMan::Advertisement.new
33
+
34
+ respond_to do |format|
35
+ format.html # new.html.erb
36
+ format.json { render json: @advertisement }
37
+ end
38
+ end
39
+
40
+ # GET /advertisements/1/edit
41
+ def edit
42
+ @advertisement = AdMan::Advertisement.find(params[:id])
43
+ end
44
+
45
+ # POST /advertisements
46
+ # POST /advertisements.json
47
+ def create
48
+ @advertisement = AdMan::Advertisement.new(params[:advertisement])
49
+ @advertisement.keyword_id = params[:keyword_id]
50
+ @advertisement.priority = params[:priority]
51
+ respond_to do |format|
52
+ if @advertisement.save
53
+ format.html { redirect_to @advertisement, notice: 'Advertisement was successfully created.' }
54
+ format.json { render json: @advertisement, status: :created, location: @advertisement }
55
+ else
56
+ format.html { render action: "new" }
57
+ format.json { render json: @advertisement.errors, status: :unprocessable_entity }
58
+ end
59
+ end
60
+ end
61
+
62
+ # PUT /advertisements/1
63
+ # PUT /advertisements/1.json
64
+ def update
65
+ @advertisement = AdMan::Advertisement.find(params[:id])
66
+ @advertisement.keyword_id = params[:keyword_id]
67
+ @advertisement.priority = params[:priority]
68
+
69
+ respond_to do |format|
70
+ if @advertisement.update_attributes(params[:advertisement])
71
+ format.html { redirect_to @advertisement, notice: 'Advertisement was successfully updated.' }
72
+ format.json { head :no_content }
73
+ else
74
+ format.html { render action: "edit" }
75
+ format.json { render json: @advertisement.errors, status: :unprocessable_entity }
76
+ end
77
+ end
78
+ end
79
+
80
+ # DELETE /advertisements/1
81
+ # DELETE /advertisements/1.json
82
+ def destroy
83
+ @advertisement = AdMan::Advertisement.find(params[:id])
84
+ @advertisement.destroy
85
+
86
+ respond_to do |format|
87
+ format.html { redirect_to advertisements_url }
88
+ format.json { head :no_content }
89
+ end
90
+ end
91
+
92
+ # Click Through
93
+ def click_through
94
+ @advertisement = AdMan::Advertisement.find(params[:id])
95
+ @advertisement.click_count += 1
96
+ @advertisement.save
97
+ redirect_to @advertisement.destination_url
98
+ end
99
+ end
@@ -0,0 +1,4 @@
1
+ module AdMan
2
+ class ApplicationController < ActionController::Base
3
+ end
4
+ end
@@ -0,0 +1,77 @@
1
+ class AdMan::KeywordsController < ApplicationController
2
+
3
+ # GET /keywords
4
+ # GET /keywords.json
5
+ def index
6
+ @keywords = AdMan::Keyword.all
7
+ respond_to do |format|
8
+ format.html
9
+ format.json { render json: @advertisements }
10
+ end
11
+ end
12
+
13
+ # GET /keywords/1
14
+ # GET /keywords/1.json
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
19
+ end
20
+
21
+ # GET /keywords/new
22
+ # GET /keywords/new.json
23
+ def new
24
+ @keyword = AdMan::Keyword.new
25
+ respond_to do |format|
26
+ format.html
27
+ format.json { render json: @keyword }
28
+ end
29
+ end
30
+
31
+ # GET /keywords/1/edit
32
+ def edit
33
+ @keyword = AdMan::Keyword.find(params[:id])
34
+ end
35
+
36
+ # POST /keywords
37
+ # POST /keywords.json
38
+ def create
39
+ @keyword = AdMan::Keyword.new(params[:keyword])
40
+ respond_to do |format|
41
+ if @keyword.save
42
+ format.html { redirect_to advertisements_path, notice: "Keyword successfully created."}
43
+ format.json { render json: @keyword, status: :created, location: @keyword }
44
+ else
45
+ format.html { render action: "new"}
46
+ format.json { render json: @keyword.errors, status: :unprocessable_entity }
47
+ end
48
+ end
49
+ end
50
+
51
+ # PUT /keywords/1
52
+ # PUT /keywords/1.json
53
+ def update
54
+ @keyword = AdMan::Keyword.find(params[:id])
55
+ respond_to do |format|
56
+ if @keyword.update_attributes(params[:keyword])
57
+ format.html { redirect_to advertisements_path, notice: "Keyword successfully updated."}
58
+ format.json { head :no_content }
59
+ else
60
+ format.html { render action: "edit"}
61
+ format.json { render json: @keyword.errors, status: :unprocessable_entity }
62
+ end
63
+ end
64
+ end
65
+
66
+ # DELETE /keywords/1
67
+ # DELETE /keywords/1.json
68
+ def destroy
69
+ @keyword = AdMan::Keyword.find(params[:id])
70
+ @keyword.destroy
71
+ respond_to do |format|
72
+ format.html { redirect_to advertisements_path }
73
+ format.json { head :no_content }
74
+ end
75
+ end
76
+
77
+ end
@@ -0,0 +1,4 @@
1
+ module AdMan
2
+ module AdvertisementsHelper
3
+ end
4
+ end
@@ -0,0 +1,28 @@
1
+ module AdMan
2
+ module ApplicationHelper
3
+ def link_to_ad(keyword = nil, size = "leaderboard")
4
+ keyword ||= get_keyword_from_url
5
+ if keyword && !keyword.blank?
6
+ keyword_id = Keyword.find_by_name(keyword).id
7
+ ad = Advertisement.render_random_ad(keyword_id)
8
+ #grab size? leaderboard or banner
9
+ else
10
+ ad = Advertisement.render_random_ad
11
+ end
12
+ if !ad.nil?
13
+ ad.display_count += 1
14
+ 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'
17
+ 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
+ #return (keyword)?(keyword):(Keyword.all[rand(Keyword.all.size)])
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,4 @@
1
+ module AdMan
2
+ module KeywordsHelper
3
+ end
4
+ end
@@ -0,0 +1,54 @@
1
+ module AdMan
2
+ class Advertisement < ActiveRecord::Base
3
+ attr_accessible :destination_url, :title, :ad_banner, :display_count, :priority, :start_date, :end_date, :click_count
4
+ validates_with AttachmentPresenceValidator, :attributes => :ad_banner
5
+ 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.kilobytes }
12
+ validates_presence_of :destination_url, :title, :keyword_id, :priority
13
+ validates_uniqueness_of :title
14
+ validate :image_dimensions, :on => :create
15
+
16
+ def Advertisement.render_random_ad(keyword_id)
17
+ # ads = Advertisement.find_all_by_keyword_id(keyword_id)
18
+ ads = Advertisement.where("keyword_id = ? AND start_date <= ? AND end_date >= ? ", keyword_id, Date.today, Date.today)
19
+ if !ads.blank?
20
+ total_times = 1.0
21
+ total_priority = 0.0
22
+ ads.each { |advertisement|
23
+ total_times += advertisement.display_count
24
+ total_priority += advertisement.priority
25
+ }
26
+ ad = ads[rand(ads.size)]
27
+ while((ad.display_count / total_times) > (ad.priority / total_priority))
28
+ ad = ads[rand(ads.size)]
29
+ end
30
+ ad
31
+ end
32
+ end
33
+
34
+ def Advertisement.render_random_ad
35
+ ads = Advertisement.all
36
+ ad = ads[rand(ads.size)]
37
+ end
38
+
39
+ private
40
+ def image_dimensions
41
+ temp_file = ad_banner.queued_for_write[:leaderboard] #get the file
42
+ 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
45
+ if (dimensions.width > max_width) || (dimensions.height > max_height)
46
+ errors.add("banner_dimmensions",
47
+ "must be image size: #{max_width}X#{max_height}.")
48
+ end
49
+ end
50
+
51
+ end
52
+ end
53
+
54
+
@@ -0,0 +1,22 @@
1
+ module AdMan
2
+ class Keyword < ActiveRecord::Base
3
+ attr_accessible :name
4
+ has_many :advertisements, :dependent => :destroy
5
+ MAX_COUNT = (AdMan.max_count)?(AdMan.max_count):5
6
+
7
+ def to_s
8
+ name
9
+ end
10
+
11
+ def number_of_ads
12
+ self.advertisements.count
13
+ end
14
+ def self.available
15
+ Keyword.all.select { |keyword| keyword.advertisements.count < MAX_COUNT}
16
+ end
17
+
18
+ def self.unavailable
19
+ Keyword.all.select { |keyword| keyword.advertisements.count >= MAX_COUNT}
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,57 @@
1
+ <%= form_for(@advertisement) do |f| %>
2
+ <% if @advertisement.errors.any? %>
3
+ <div id="error_explanation">
4
+ <h2><%= pluralize(@advertisement.errors.count, "error") %> prohibited this advertisement from being saved:</h2>
5
+
6
+ <ul>
7
+ <% @advertisement.errors.full_messages.each do |msg| %>
8
+ <li><%= msg %></li>
9
+ <% end %>
10
+ </ul>
11
+ </div>
12
+ <% end %>
13
+
14
+ <div class="field">
15
+ <%= f.label :ad_banner, "Acceptable sizes: 728x90 or 468x60" %><br />
16
+ <%= f.file_field :ad_banner %>
17
+ <div class="preview"></div>
18
+ </div><br />
19
+ <div class="field">
20
+ <%= f.label :title %><br />
21
+ <%= f.text_field :title %>
22
+ </div><br />
23
+ <div class="field">
24
+ <%= f.label :destination_url %><br />
25
+ <%= f.url_field :destination_url %>
26
+ </div><br />
27
+ <div class="field">
28
+ <%= f.label :keyword %>
29
+ <%= select_tag :keyword_id, options_for_select(AdMan::Keyword.available.collect { |keyword| [keyword.name, keyword.id]})%>
30
+ <% if AdMan::Keyword.unavailable.count > 0%>
31
+ <p><b><%= AdMan::Keyword.unavailable.collect { |keyword| keyword.name } %></b> keyword has allready been used 5 times.</p>
32
+ <% end %>
33
+ </div><br />
34
+ <div class="field">
35
+ <%= f.label :priority %>
36
+ <%= select_tag :priority, options_for_select(1..10) %>
37
+ </div><br />
38
+ <div class="field">
39
+ <%= f.label :start_date %><br />
40
+ <%= date_select("advertisement", "start_date") %>
41
+ </div><br />
42
+ <div class="field">
43
+ <%=f.label :end_date %><br />
44
+ <!--
45
+ <#% TODO : end date should be 30 days plus %> -->
46
+ <%= date_select("advertisement", "end_date") %>
47
+ </div><br />
48
+
49
+
50
+ <div class="actions">
51
+ <%= f.submit %>
52
+ </div>
53
+ <% end %>
54
+
55
+ <script>
56
+ $('input[type=file]').change(handleFileSelect);
57
+ </script>
@@ -0,0 +1,6 @@
1
+ <h1>Editing advertisement</h1>
2
+
3
+ <%= render 'form' %>
4
+
5
+ <%= link_to 'Show', @advertisement %> |
6
+ <%= link_to 'Back', advertisements_path %>
@@ -0,0 +1,48 @@
1
+ <h1>Advertisements</h1>
2
+ <div>
3
+ <% if !@keywords.blank? %>
4
+ <div id="ads" style="display:inline-block; vertical-align:top;margin:10px;padding:10px;">
5
+ <% if !@advertisements.blank? %>
6
+ <table>
7
+ <% @advertisements.each do |advertisement| %>
8
+ <tr>
9
+ <td><%= link_to advertisement.title, advertisement %></td>
10
+ <td><%= advertisement.destination_url%></td>
11
+ </tr>
12
+ <tr>
13
+ <td colspan="2"><%= link_to image_tag(advertisement.ad_banner.url(:banner)), advertisement %></td>
14
+ </tr>
15
+ <% end %>
16
+ </table>
17
+ <% else %>
18
+ <h3>You don't have any advertisements yet, <br/>why don't you create one:</h3>
19
+ <% end %>
20
+
21
+ <!-- Paginate Advertisements -- uncomment
22
+ <#%= will_paginate @advertisements %>
23
+ -->
24
+
25
+ </div >
26
+
27
+ <div id="keywords" style="display:inline-block;">
28
+ <h2>Keywords</h2>
29
+ <% if !@keywords.blank? %>
30
+ <ul><h3>
31
+ <% @keywords.each do |keyword| %>
32
+ <li><%= link_to keyword.name, keyword %>(<%= keyword.number_of_ads %>)</li>
33
+ <% end %>
34
+ </h3></ul>
35
+ <% else %>
36
+ <b>You don't have any keywords yet, <br/>why don't you create one:</b><br/>
37
+ <% end %>
38
+ <br />
39
+ <%= button_to 'New Keyword', new_keyword_path, :method => :get %>
40
+ <div style="clear:;"></div>
41
+ </div>
42
+
43
+ <%= button_to 'New Advertisement', new_advertisement_path, :method => :get %>
44
+ <% else %>
45
+ <h3>You don't have any keywords yet, <br/>why don't you create one:<h3>
46
+
47
+ <%= button_to 'New Keyword', new_keyword_path, :method => :get %>
48
+ <% end %>
@@ -0,0 +1,5 @@
1
+ <h1>Upload a New Advertisement</h1>
2
+
3
+ <%= render 'form' %>
4
+
5
+ <%= link_to 'Back', advertisements_path %>
@@ -0,0 +1,39 @@
1
+ <p id="notice"><%= notice %></p>
2
+
3
+ <h2><%= @advertisement.title %></h2>
4
+
5
+ <div style="margin-left:10px;">
6
+ <p>
7
+ <b>Leaderboard: &nbsp;&nbsp;728x90</b><br/>
8
+ <%= image_tag @advertisement.ad_banner.url(:leaderboard) %>
9
+ <br/><br/>
10
+ <b>Banner: &nbsp;&nbsp;468x60</b><br/>
11
+ <%= image_tag @advertisement.ad_banner.url(:banner) %><br/>
12
+ </p>
13
+ <p>
14
+ <b>Keyword:</b>
15
+ <%= link_to @advertisement.keyword.name, @advertisement.keyword %>
16
+ </p>
17
+ <p>
18
+ <b>Page Views:</b>
19
+ <%= @advertisement.display_count %>
20
+ </p>
21
+ <p>
22
+ <b>Clicks:</b>
23
+ <%= @advertisement.click_count %>
24
+ </p>
25
+ <p>
26
+ <b>File Size:</b>
27
+ <%= number_to_human_size(@advertisement.ad_banner.size) %>
28
+ </p>
29
+ <p>
30
+ <b>Destination url:</b>
31
+ <%= link_to @advertisement.destination_url, @advertisement.destination_url %>
32
+ </p>
33
+ </div>
34
+ <div style="display:inline-block;">
35
+ <%= link_to 'Edit', edit_advertisement_path(@advertisement), :method => :get %>
36
+ <%= link_to "Destroy", @advertisement, :method => :delete,
37
+ :confirm => "Deleting Advertisement, this cannot be undone. Please confirm.", :style => "color:#b94a48"%>
38
+ <%= link_to 'Back', advertisements_path, :method => :get %>
39
+ </div>