Skip to content

Commit

Permalink
Cleaned up white space.
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenmcd committed May 15, 2011
1 parent 5cde1d1 commit 5a9cb35
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 51 deletions.
7 changes: 3 additions & 4 deletions LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice,
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright

2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.

Expand All @@ -25,4 +25,3 @@ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

20 changes: 10 additions & 10 deletions app.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,18 @@ app.register ".coffee", require "coffeekup"


# Homepage - redirect to the default URL.
app.get "/", (req, res) ->
app.get "/", (req, res) ->
res.redirect(settings.DEFAULT_URL)

# About - parses README.md and pass it to the empty template.
app.get "/about", (req, res) ->
app.get "/about", (req, res) ->
fs.readFile (path.join __dirname, "README.md"), (err, data) ->
about = (markdown String data).replace "<h1>Overview</h1>", ""
context = title: "About", about: about
res.render "about.coffee", context: context

# Form for adding a named room.
app.all "/rooms/add", (req, res) ->
app.all "/rooms/add", (req, res) ->
room = message = ""
if req.body?.room?
room = req.body.room.trim().substr 0, settings.MAX_ROOMNAME_LENGTH
Expand All @@ -50,7 +50,7 @@ app.get "/rooms/:room", (req, res) ->
res.render "room.coffee", context: context, layout: false

# Lists rooms and users in each room.
app.get "/rooms", (req, res) ->
app.get "/rooms", (req, res) ->
if settings.ADDABLE_ROMS_VISIBLE
visibleRooms = process.rooms
else
Expand All @@ -60,7 +60,7 @@ app.get "/rooms", (req, res) ->
context = title: "Home", rooms: visibleRooms
res.render "rooms.coffee", context: context

# Starts a matchup room - a randomly named private room that goes into
# Starts a matchup room - a randomly named private room that goes into
# the matchup list while waiting for someone else to join.
app.get "/wait", (req, res) ->
room = uid settings.MAX_ROOMNAME_LENGTH, layout: false
Expand All @@ -73,7 +73,7 @@ app.get "/waiting", (req, res) ->
context = title: "Waiting", clients: clients, since: since
res.render "waiting.coffee", context: context

# Join the earliest created dynamic room someone is waiting in, eg first in
# Join the earliest created dynamic room someone is waiting in, eg first in
# the matchup list.
app.get "/match", (req, res) ->
if room = process.matchups.shift()
Expand All @@ -82,7 +82,7 @@ app.get "/match", (req, res) ->
context = title: "Match"
res.render "no_match.coffee", context: context

# Chatroulette style matchup - if there is a room in the matchup list, join
# Chatroulette style matchup - if there is a room in the matchup list, join
# it, otherwise create a dynamic room that will go into the matchup list.
app.get "/random", (req, res) ->
if room = process.matchups.shift()
Expand All @@ -101,5 +101,5 @@ app.get "/client.coffee", (req, res) ->
data = "alert(\"#{err}\");"
res.header "Content-Type", "text/plain"
res.send data

exports.app = app
16 changes: 8 additions & 8 deletions html.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
htmlparser = require "htmlparser"


exports.stripTags = (html="", allowed={}) ->
exports.stripTags = (html="", allowed={}) ->
###
Strips the given HTML string of all tags, other than those
specified in the ``allowed`` param, which should be in the
Strips the given HTML string of all tags, other than those
specified in the ``allowed`` param, which should be in the
format: {tag1: [allowedAttribute1, allowedAttribute2], tag2: []}
###
escapeHtml = (html) ->

escapeHtml = (html) ->
###
Replace brackets and quotes with their HTML entities.
###
Expand All @@ -25,10 +25,10 @@ exports.stripTags = (html="", allowed={}) ->
parser = new htmlparser.Parser(handler);
parser.parseComplete(html);

buildAll = (parts) ->
buildAll = (parts) ->
###
Takes a list of dom nodes and returns each node as a string
if it's text or an allowed tag. Called recursively on the
Takes a list of dom nodes and returns each node as a string
if it's text or an allowed tag. Called recursively on the
node's child nodes.
###

Expand Down
4 changes: 2 additions & 2 deletions public/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ form {background:#ddd; margin:0; padding:20px; border-top:1px solid #ccc;}

.text {border:1px solid #999; padding:7px; width:50%;
border-radius:5px;
-moz-border-radius:5px;
-moz-border-radius:5px;
-webkit-border-radius:5px;}

.rooms {float:left; width:50%; min-height:120px; margin:5px 0;}
.rooms li.first {background:#eee; padding:10px;
border-radius:5px;
-moz-border-radius:5px;
-moz-border-radius:5px;
-webkit-border-radius:5px;}
.rooms li {padding:2px 10px;}

Expand Down
6 changes: 3 additions & 3 deletions server.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ settings = require "./settings"
process.rooms = {}
process.rooms[room] = [] for room in settings.ROOMS

# Global queue of room names for random matchups. Added to when a user
# starts a new room, and pulled from when another user joins that room.
# Allows for chatroulette style random matchups, or a customer support
# Global queue of room names for random matchups. Added to when a user
# starts a new room, and pulled from when another user joins that room.
# Allows for chatroulette style random matchups, or a customer support
# type of service.
process.matchups = []

Expand Down
18 changes: 9 additions & 9 deletions settings.coffee
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@


# Tag/attribs mapping of allowed tags and attributes.
exports.ALLOWED_TAGS =
exports.ALLOWED_TAGS =
b : []
strong : []
code : []
hr : []
ul : []
li : []
strong : []
code : []
hr : []
ul : []
li : []
i : []
em : []
blockquote : []
em : []
blockquote : []
img : ["src"]
a : ["href"]
a : ["href"]
center : []
font : ["face", "color", "size"]

Expand Down
20 changes: 10 additions & 10 deletions socket.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,27 @@ settings = require "./settings"


# Convenience method for removing an item from an array.
Array.prototype.remove = (item) ->
Array.prototype.remove = (item) ->
if item in this
index = this.indexOf item
this.splice index, 1

# Send the given message string to all clients for the given room.
broadcast = (room, message, addr) ->
broadcast = (room, message, addr) ->
datetime = (new Date).toUTCString()
time = (datetime.split(" ").filter (s) -> (s.indexOf ":") isnt -1)[0]
data =
data =
users: c.name for c in process.rooms[room]
message: "[#{time}] #{message}"
data = JSON.stringify data
c.send data for c in process.rooms[room]
c.send data for c in process.rooms[room]
if settings.LOGGING
output = "#{addr} - - [#{datetime}] \"#{room} #{message}\" - - - -\n"
process.stdout.write output

# Passed to socket.io in server.coffee to handle each socket connection.
exports.handler = (client) ->

client.on "message", (data) ->
data = JSON.parse data
if data.room? and not client.room?
Expand Down Expand Up @@ -59,7 +59,7 @@ exports.handler = (client) ->
message = message: "Name is in use, please enter another"
client.send JSON.stringify message
else
# Add the client to the room, set the client's name
# Add the client to the room, set the client's name
# and send the join message.
empty = process.rooms[room].length is 0
if process.rooms[room]?.dynamic and empty
Expand All @@ -79,17 +79,17 @@ exports.handler = (client) ->
users = process.rooms[room]?.length
addr = client.addr
if joined
# Client had joined a room - send the leave message and
# Client had joined a room - send the leave message and
# remove the client from the room.
process.rooms[room].remove client
broadcast room, "#{displayName} leaves", addr
if joined and room in process.matchups
# Client created the matchup room without anyone else
# Client created the matchup room without anyone else
# joining it, so remove it from the matchup list.
process.matchups.remove room
if not joined and dynamic and users is 1
# Client was assigned to a matchup room but didn't
# actually join, so return the room to the front of
# Client was assigned to a matchup room but didn't
# actually join, so return the room to the front of
# the matchup list.
process.matchups.unshift room
if dynamic and users is 0
Expand Down
2 changes: 1 addition & 1 deletion views/rooms.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ for room, users of @rooms
" (#{users.length})"
for user in users
li user.name
if ++i % 2 is 0
if ++i % 2 is 0
br clear: "all"
7 changes: 3 additions & 4 deletions views/waiting.coffee
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@

if @clients.length is 0
div "No one is waiting!", id: "error"
ul ->
ul ->
for client in @clients
li ->
li ->
a href: "/rooms/#{client.room}/", -> "#{client.name}"
minutes = @since client.start
s = if minutes isnt 1 then "s" else ""
" - waiting #{minutes} minute#{s}"

" - waiting #{minutes} minute#{s}"

0 comments on commit 5a9cb35

Please sign in to comment.