Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions app.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,13 @@ compileMethod = (str, path) ->
app.get "/", (req, res) ->
res.render "index", title: "Twitter Raffle", subtitle: "By <a href='http://comorichweb.posterous.com/'>Como Rich Web</a>"

app.get '/disqualified', (req, res) ->
# load disqualified users from yaml file
fs = require 'fs'
yaml = require 'yaml'
fs.readFile 'config/settings.yml', (err, data) ->
contents = data.toString('utf-8')
res.json(yaml.eval(contents))

app.listen 3000
console.log "Express server listening on port %d in %s mode", app.address().port, app.settings.env
1 change: 1 addition & 0 deletions config/settings.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
disqualified: ['CoMORichWeb']
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"express": "2.4.3",
"jade": ">= 0.0.1",
"coffee-script": ">=1.1.1",
"stylus": "*"
"stylus": "*",
"yaml": "0.2.2"
},
"devDependencies": {},
"engines": {
Expand Down
50 changes: 48 additions & 2 deletions public/javascripts/application.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions views/javascripts/application.coffee
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
$ ->
class Tweet extends Backbone.Model
class DisqualifiedUser extends Backbone.Model

class DisqualifiedUsers extends Backbone.Collection
model: DisqualifiedUser
initialize: ->
@url = "http://localhost:3000/disqualified"
parse: (response)->
results = response.disqualified
{user: name} for name in response.disqualified

class Tweets extends Backbone.Collection
model: Tweet
Expand All @@ -21,6 +30,12 @@ $ ->

randomUpTo: (ceiling) ->
Math.floor(Math.random()*ceiling)

disqualify: (usernames) ->
raw_names = usernames.map (item) =>
item.get('user')
@reset @reject (tweet) =>
$.inArray(tweet.get('from_user'), raw_names) > -1

class TweetView extends Backbone.View
tagName:'li'
Expand All @@ -45,14 +60,18 @@ $ ->
'change #search':'getTweets'
initialize: ->
@tweets = new Tweets();
@banlist = new DisqualifiedUsers();
@tweets.bind 'reset', (tweets) =>
$("#tweets").empty()
tweets.each (tweet) =>
@render(new TweetView(model:tweet).render().el)
@getTweets()
@getBanlist()
getTweets: ->
@tweets.setURL(@searchInput.val())
@tweets.fetch()
getBanlist: ->
@banlist.fetch()

hilightRandom: =>
if(@tweet)
Expand All @@ -67,6 +86,7 @@ $ ->
@$('#winner').text tweet.get('from_user')

pickRandom: ->
@tweets.disqualify(@banlist)
@interval = setInterval @hilightRandom, @RANDOM_SELECTION_INTERVAL
setTimeout @selectWinner, @SELECTION_LENGTH

Expand Down