Skip to content

Commit 6f98ade

Browse files
committed
Merge branch 'develop' of https://github.com/ecleel/ads into develop
2 parents 724110a + 1832e54 commit 6f98ade

File tree

29 files changed

+618
-64
lines changed

29 files changed

+618
-64
lines changed

Gemfile.lock

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ GEM
3333
tzinfo (~> 0.3.37)
3434
arel (4.0.0)
3535
atomic (1.1.10)
36+
bcrypt-ruby (3.1.2)
3637
builder (3.1.4)
3738
carrierwave (0.8.0)
3839
activemodel (>= 3.2.0)
@@ -44,6 +45,12 @@ GEM
4445
coffee-script-source
4546
execjs
4647
coffee-script-source (1.6.3)
48+
devise (3.2.2)
49+
bcrypt-ruby (~> 3.0)
50+
orm_adapter (~> 0.1)
51+
railties (>= 3.2.6, < 5)
52+
thread_safe (~> 0.1)
53+
warden (~> 1.2.3)
4754
erubis (2.7.0)
4855
execjs (2.0.2)
4956
hike (1.2.3)
@@ -57,6 +64,7 @@ GEM
5764
mime-types (1.23)
5865
minitest (4.7.5)
5966
multi_json (1.7.7)
67+
orm_adapter (0.5.0)
6068
polyglot (0.3.3)
6169
rack (1.5.2)
6270
rack-test (0.6.2)
@@ -98,6 +106,8 @@ GEM
98106
polyglot
99107
polyglot (>= 0.3.1)
100108
tzinfo (0.3.37)
109+
warden (1.2.3)
110+
rack (>= 1.0)
101111

102112
PLATFORMS
103113
ruby
@@ -106,6 +116,7 @@ DEPENDENCIES
106116
ads!
107117
carrierwave
108118
coffee-rails (~> 4.0.0)
119+
devise (~> 3.2.2)
109120
jquery-rails
110121
sass-rails (~> 4.0.0)
111122
sqlite3

README

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
= Ads
2+
3+
This project rocks and uses MIT-LICENSE.
4+
5+
#To be continued ..
6+
7+
#Todo
8+
<strike>1. Track every click of ad.</strike>
9+
2. Show some stat.
10+
3. Add Configuration table.
11+
4. Give ability to choose showing duplicate ad for one banner.
12+
5. Login requirment

README.rdoc

Lines changed: 0 additions & 5 deletions
This file was deleted.

ads.gemspec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,5 @@ Gem::Specification.new do |s|
2020

2121
s.add_development_dependency 'jquery-rails'
2222
s.add_development_dependency "sqlite3"
23+
s.add_development_dependency 'devise', '~> 3.2.2'
2324
end
Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,46 @@
1-
jQuery ->
2-
# alert('hi')
1+
$ = jQuery
2+
3+
$.fn.extend
4+
5+
ads: (options) ->
6+
settings =
7+
rotate: true
8+
period: 10000
9+
debug: false
10+
11+
settings = $.extend settings, options
12+
13+
log = (msg) ->
14+
console?.log msg if settings.debug
15+
16+
get_ad = ->
17+
log "#{this} get ad"
18+
# each type of banner in the page
19+
bt = []
20+
bc = $('.banner').size()
21+
$('.banner').each (i, elm) ->
22+
bt.push $(elm).data('name')
23+
24+
banner_link = "/ads/ads?bc=#{bc}&bt=#{bt.toString()}"
25+
log "Banner Link: #{banner_link}"
26+
$.getJSON banner_link, (data)->
27+
log "Date from server: #{data}"
28+
for type, info of data
29+
banner_div = $(".#{type}")
30+
width = banner_div.data 'width'
31+
height = banner_div.data 'height'
32+
banner_div.html "<a href='#{info[0].link}' target='_blank'><img src='#{info[0].image_path}' width='#{width}' height='#{height}' /></a>"
33+
log "Type: #{type} info: #{info[0].link}"
34+
35+
# get ads limit by number of banners and respect the banner name.
36+
# add image into the banner.
37+
38+
if settings.rotate
39+
setInterval(get_ad, settings.period)
40+
41+
get_ad()
42+
43+
return @each ()->
44+
# log "Preparing magic show."
45+
# You can use your settings in here now.
46+
# log "Option 1 value: #{settings.rotate}"

app/controllers/ads/admin/ads_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
module Ads
44
module Admin
55

6-
class AdsController < ApplicationController
6+
class AdsController < BaseController
77
before_action :set_ad, only: [:show, :edit, :update, :destroy]
88
before_action :set_campaign
99
before_action :set_banner_list, only: [:new, :edit, :update, :create]

app/controllers/ads/admin/banners_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
module Ads
44
module Admin
55

6-
class BannersController < ApplicationController
6+
class BannersController < BaseController
77
before_action :set_banner, only: [:show, :edit, :update, :destroy]
88

99
# GET /banners
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
require_dependency "ads/application_controller"
2+
3+
module Ads
4+
module Admin
5+
class BaseController < ApplicationController
6+
# TODO use nested layout to use with what user have
7+
layout :set_layout
8+
before_filter :authenticate_ads_user
9+
10+
private
11+
12+
def set_layout
13+
'ads/application'
14+
end
15+
16+
def authenticate_ads_user
17+
if !ads_user
18+
session["user_return_to"] = request.fullpath
19+
flash.alert = t("ads.errors.not_signed_in")
20+
devise_route = "new_#{Ads.user_class.to_s.underscore}_session_path"
21+
sign_in_path = Ads.sign_in_path ||
22+
(main_app.respond_to?(devise_route) && main_app.send(devise_route)) ||
23+
(main_app.respond_to?(:sign_in_path) && main_app.send(:sign_in_path))
24+
if sign_in_path
25+
redirect_to sign_in_path
26+
else
27+
raise "Ads could not determine the sign in path for your application. Please do one of these things:
28+
29+
1) Define sign_in_path in the config/routes.rb of your application like this:
30+
31+
or; 2) Set Ads.sign_in_path to a String value that represents the location of your sign in form, such as '/users/sign_in'."
32+
end
33+
end
34+
end
35+
36+
end
37+
end
38+
end

app/controllers/ads/admin/campaigns_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
module Ads
44
module Admin
55

6-
class CampaignsController < ApplicationController
6+
class CampaignsController < BaseController
77
before_action :set_campaign, only: [:show, :edit, :update, :destroy]
88

99
# GET /campaigns

app/controllers/ads/ads_controller.rb

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
module Ads
44
class AdsController < ApplicationController
5+
56
def index
67
ads_types = params[:bt].split(',') if params[:bt]
78
ads_count = params[:bc]
@@ -10,10 +11,22 @@ def index
1011
puts "ads_types: #{ads_types}"
1112
banner_ids = Banner.where(name: ads_types).pluck(:id)
1213
@ads = Ad.active.includes(:banner).where(banner_id: banner_ids)
13-
render json: @ads.each_with_object( Hash.new {|h,k| h[k] = [] } ) {|ad, hsh| hsh[ad.banner.name] << {id: ad.id, link: ad.link, image_path: ad.file.url, banner_name: ad.banner.name} }
14+
render json: @ads.each_with_object( Hash.new {|h,k| h[k] = [] } ) {|ad, hsh| hsh[ad.banner.name] << {id: ad.id, link: ad_path(ad), image_path: ad.file.url, banner_name: ad.banner.name, } }
1415
else
1516
render json: {error: "There is no Ads Types gived."}
1617
end
1718
end
19+
20+
def show
21+
# TODO check if there is ad before create state
22+
ad = Ad.active.find params[:id]
23+
if ad
24+
ad.stats.create referer: request.referer,
25+
session_hash: request.session_options[:id],
26+
ip_address: request.remote_ip
27+
28+
redirect_to ad.link
29+
end
30+
end
1831
end
1932
end

0 commit comments

Comments
 (0)