Skip to content
Browse files

* Dabbling with a CocoScript port (not intended for master).

  • Loading branch information...
1 parent b2d4c3f commit 7f2ff89a444309e50690cc594f4f233224141e04 @audreyt committed Mar 17, 2012
Showing with 89 additions and 93 deletions.
  1. +4 −1 Makefile
  2. +84 −0 main.co
  3. +0 −92 main.coffee
  4. +1 −0 package.json
View
5 Makefile
@@ -24,7 +24,10 @@ ethercalc.js :: $(ETHERCALC_FILES)
.coffee.js:
coffee -c $<
+.co.js:
+ coco -c $<
+
.sass.css:
sass -t compressed $< > $@
-.SUFFIXES: .js .coffee .css .sass
+.SUFFIXES: .js .coffee .css .sass .co
View
84 main.co
@@ -0,0 +1,84 @@
+@include = ->
+ @enable 'serve jquery'
+ @use @express.static __dirname
+
+ @include \dotcloud
+ db = @include \db
+
+ @get \/ : ->
+ @response.contentType \text/html
+ @response.sendfile \index.html
+ @get \/start : -> @render \start
+ @get \/new : -> @response.redirect \/# + require("uuid-pure").newId(10, 62)
+
+ @view start: ->
+ div id:\topnav_wrap, -> div id:\navigation
+ <- div id:\intro-left
+ h1 "EtherCalc"
+ h2 "EtherCalc is a web spreadsheet."
+ p "Your data is saved on the web, and people can edit the same document at the same time. Everybody's changes are instantly reflected on all screens."
+ p "Work together on inventories, survey forms, list management, brainstorming sessions and more!"
+ <- div id:\intro-links
+ <- a id:\newpadbutton, href:\/new, alt:"Create Spreadsheet"
+ span "Create Spreadsheet"
+ br ""
+ small "No sign-up, start editing instantly"
+
+ @view layout: ->
+ <- html
+ head ->
+ title \EtherCalc
+ link href:\/start.css, rel:\stylesheet, type:\text/css
+ <- body id:\framedpagebody, class:\home
+ div id:\top, -> @body
+ <- a href:\https://github.com/audreyt/ethercalc
+ img {
+ style: "z-order: 9999; position: absolute; top: 0; right: 0; border: 0"
+ src: \//a248.e.akamai.net/assets.github.com/img/7afbc8b248c68eb468279e8c17986ad46549fb71/687474703a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f6461726b626c75655f3132313632312e706e67
+ alt: "Fork me on GitHub"
+ }
+
+ @on broadcast: ->
+ emit = (data) ~> @broadcast broadcast: data
+ {room, msg, user, ecell, cmdstr, type} = @data
+ switch type
+ case \chat
+ db.rpush "chat-#{room}", msg, ~> emit @data
+ case \ask.ecells
+ _, values <~ db.hgetall "ecell-#{room}"
+ emit { type: \ecells, ecells: values, room }
+ case \my.ecell
+ db.hset "ecell-#{room}", user, ecell
+ case \execute
+ <~ db.rpush "log-#{room}", cmdstr
+ <~ db.bgsave
+ emit @data
+ case \ask.snapshot
+ _, snapshot <~ db.get "snapshot-#{room}"
+ _, log <~ db.lrange "log-#{room}", 0, -1
+ _, chat <~ db.lrange "chat-#{room}", 0, -1
+ @emit broadcast: { type: \log, to: user, room, log, chat, snapshot }
+ case \stopHuddle
+ <~ db.del "log-#{room}"
+ <~ db.del "chat-#{room}"
+ <~ db.del "ecell-#{room}"
+ <~ db.del "snapshot-#{room}"
+ emit @data
+ default emit @data
+ return
+
+ @include \player
+
+ @get \/:room : -> @render room: layout: false
+
+ @use \bodyParser
+
+ @post \/:room : ->
+ {room} = @data
+ <~ db.set "snapshot-#{room}", @snapshot
+ _, snapshot <~ db.get "snapshot-#{room}"
+ @response.send \text, \Content-Type : \text/plain, 201
+
+ @view room: ->
+ <- coffeescript
+ window.location = \/# + window.location.pathname.replace /.*\//, ''
View
92 main.coffee
@@ -1,92 +0,0 @@
-@include = ->
- @enable 'serve jquery'
- @use @express.static __dirname
-
- @include 'dotcloud'
- db = @include 'db'
-
- @get '/': ->
- @response.contentType 'text/html'
- @response.sendfile 'index.html'
- @get '/start': -> @render 'start'
- @get '/new': -> @response.redirect '/#' + require("uuid-pure").newId(10, 62)
-
- @view start: ->
- div id:"topnav_wrap", -> div id:"navigation"
- div id:"intro-left", ->
- h1 "EtherCalc"
- h2 "EtherCalc is a web spreadsheet."
- p "Your data is saved on the web, and people can edit the same document at the same time. Everybody's changes are instantly reflected on all screens."
- p "Work together on inventories, survey forms, list management, brainstorming sessions and more!"
- div id:"intro-links", ->
- a id:"newpadbutton", href:"/new", alt: "Create Spreadsheet", ->
- span "Create Spreadsheet"
- br ""
- small "No sign-up, start editing instantly"
-
- @view layout: ->
- html ->
- head ->
- title "EtherCalc"
- link href:"/start.css", rel:"stylesheet", type:"text/css"
- body id:"framedpagebody", class:"home", ->
- div id:"top", -> @body
- a href:"https://github.com/audreyt/ethercalc", ->
- img
- style:"z-order: 9999; position: absolute; top: 0; right: 0; border: 0"
- src:"//a248.e.akamai.net/assets.github.com/img/7afbc8b248c68eb468279e8c17986ad46549fb71/687474703a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f6461726b626c75655f3132313632312e706e67"
- alt:"Fork me on GitHub"
-
- @on broadcast: ->
- emit = (data) => @broadcast broadcast: data
- {room, msg, user, ecell, cmdstr, type} = @data
- switch type
- when 'chat'
- db.rpush "chat-#{room}", msg, => emit @data
- when 'ask.ecells'
- db.hgetall "ecell-#{room}", (err, values) => emit
- type: 'ecells'
- ecells: values
- room: room
- when 'my.ecell'
- db.hset "ecell-#{room}", user, ecell
- when 'execute'
- db.rpush "log-#{room}", cmdstr, =>
- db.bgsave =>
- emit @data
- when 'ask.snapshot'
- db.get "snapshot-#{room}", (err, snapshot) =>
- db.lrange "log-#{room}", 0, -1, (err, log) =>
- db.lrange "chat-#{room}", 0, -1, (err, chat) => @emit broadcast:
- type: 'log'
- to: user
- room: room
- log: log
- chat: chat
- snapshot: snapshot
- when 'stopHuddle'
- db.del "log-#{room}", (err) =>
- db.del "chat-#{room}", (err) =>
- db.del "ecell-#{room}", (err) =>
- db.del "snapshot-#{room}", (err) =>
- emit @data
- else emit @data
- return
-
- @include 'player'
-
- @get '/:room': ->
- @render room: { layout: no }
-
- @use 'bodyParser'
-
- @post '/:room': ->
- {room} = @data
- db.set "snapshot-#{room}", @snapshot, (err) =>
- db.get "snapshot-#{room}", (err, snapshot) =>
- @response.send 'text', { 'Content-Type': 'text/plain' }, 201
-
- @view room: ->
- coffeescript ->
- window.location = '/#' + window.location.pathname.replace(/.*\//, '')
-
View
1 package.json
@@ -8,6 +8,7 @@
"uuid-pure": "*",
"node-uuid": "*",
"coffee-script": "*",
+ "coco": "*",
"express": "*",
"socket.io": "*",
"jsdom": "*",

0 comments on commit 7f2ff89

Please sign in to comment.
Something went wrong with that request. Please try again.