Skip to content

Commit

Permalink
Created landing page in glorious Bootstrap 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ggoodman committed Feb 2, 2012
1 parent b5155d0 commit 66b37dd
Show file tree
Hide file tree
Showing 18 changed files with 6,458 additions and 25 deletions.
8 changes: 8 additions & 0 deletions api/plunks.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ module.exports = (store) ->

cb(null, plunk)

index: (req, res, next) ->
store.list (err, plunks) ->
return next({number: 500, message: err}) if err

_.each plunks, (plunk) ->
delete plunk.token

res.json(plunks)

create: (req, res, next) ->
json = _.clone(req.body)
Expand Down
41 changes: 28 additions & 13 deletions app.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,39 @@ config = _.defaults require("./config"),
app = module.exports = express.createServer()

app.configure ->
app.set "views", "#{__dirname}/views"
app.set "view engine", "jade"
app.set "view options", layout: false

app.use express.logger()
app.use express.methodOverride()
app.use express.bodyParser()

app.use express.compiler
src: "#{__dirname}/assets"
dest: "#{__dirname}/public"
enable: ["coffeescript"]
app.use express.static("#{__dirname}/public")

{Store} = require("./lib/stores/#{config.store}")
store = new Store(config)

app.all "/api/*", (req, res, next) ->
res.header("Access-Control-Allow-Origin", "*")
res.header("Access-Control-Allow-Headers", req.header("Access-Control-Request-Headers")) # I hear an echo. Do you?
res.header("Access-Control-Allow-Methods", "GET, POST, PATCH, PUT, DELETE")
res.header("Access-Control-Max-Age", 60 * 60 * 24 * 2) # 2 days
if req.method == "OPTIONS"
res.header("Access-Control-Allow-Origin", "*")
res.header("Access-Control-Allow-Headers", req.header("Access-Control-Request-Headers")) # I hear an echo. Do you?
res.header("Access-Control-Allow-Methods", "GET, POST, PATCH, PUT, DELETE")
res.header("Access-Control-Max-Age", 60 * 60 * 24 * 2) # 2 days

return res.send()

next()

# Expose the public api for plunks
app.resource "api/v1/plunks", require("./api/plunks")(store)



app.get "/", (req, res, next) ->
res.render("index")

# Serve up a plunk
app.get "/:id/", (req, res, next) ->
Expand All @@ -53,10 +67,11 @@ app.get "/:id/*", (req, res, next) ->
return res.send(404) unless file
return res.send(file.content, {"Content-Type": file.mime})

app.error (err, req, res, next) ->
body = _.extend({}, err)
if err.message then body.message = err.message
if err.errors then body.errors = err.errors
if err.stack then body.stack = err.stack

res.json body, err.number or 400

#app.error (err, req, res, next) ->
# body = _.extend({}, err)
# if err.message then body.message = err.message
# if err.errors then body.errors = err.errors
# if err.stack then body.stack = err.stack
#
# res.json body, err.number or 400
21 changes: 21 additions & 0 deletions assets/lib/plunker.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
$ ->
jQuery.getJSON "http://stsh.ggoodman.c9.io/api/v1/plunks", (json) ->
for plunk in json
$li = $("<li></li>").addClass("span3")
$a = $("<a></a>").attr("href", plunk.url).addClass("thumbnail").appendTo($li)
$img = $("<img />")
.attr("src", "http://placehold.it/205x154&text=Loading...")
.attr("data-original", "http://immediatenet.com/t/l3?Size=1024x768&URL=#{plunk.url}")
.attr("alt", plunk.description or "Plunk: #{plunk.id}")
.addClass("lazy")
.appendTo($a)
$caption = $("<div><h5>Plunk #{plunk.id}</h5><p>#{plunk.description or 'Untitled'}</p></div>")
.addClass("caption")
.appendTo($a)

$li.appendTo("#recent")

$("img.lazy").lazyload
threshold: 200
effect: "fadeIn"

2 changes: 1 addition & 1 deletion config.coffee
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports =
server: "http://plunker.no.de"
server: "http://stsh.ggoodman.c9.io"
ttl: 60 * 60 * 24 * 2
store: "memory"
23 changes: 13 additions & 10 deletions lib/schema/create.coffee
Original file line number Diff line number Diff line change
@@ -1,29 +1,32 @@
module.exports =
type: "object"
additionalProperties: false
properties:
description:
type: "string"
index:
type: "string"
default: "index.html"
additionalProperties: false
files:
required: true
type: "object"
minProperties: 1
additionalProperties:
type: [
type: "string"
,
type: [
type: "array"
minItems: 1
items:
type: "object"
additionalProperties: false
properties:
filename:
type: "string"
required: true
content:
type: "string"
required: true
mime:
type: "string"
encoding:
type: "string"
]
,
type: "object"
minProperties: 1
items:
type: "string"
]
19 changes: 18 additions & 1 deletion lib/stores/memory.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,19 @@ deepClone = (obj) ->
clone

class exports.Store
constructor: ({@ttl, @server} = {ttl: 60 * 60 * 24 * 2, server: ""})->
constructor: ({@ttl, @server, @queueSize} = {ttl: 60 * 60 * 24 * 2, server: "", queueSize: 12})->
@plunks = {}
@timeouts = {}
@destructors = {}
@queue = []

createDestructor: (id) ->
self = @
@destructors[id] = ->
clearTimeout(self.timeouts[id])

self.queue = _.without(self.queue, id)

delete self.plunks[id]
delete self.timeouts[id]

Expand All @@ -50,9 +54,22 @@ class exports.Store

@plunks[json.id] = json
@timeouts[json.id] = setTimeout(@createDestructor(json.id), json.ttl * 1000)
@queue.push json.id
@queue = _.last(@queue, 12)

cb(null, json)

list: (options, cb) ->
if _.isFunction(options) then [cb, options] = [options, {}]

options = _.defaults options,
start: 0
end: 12

self = @

cb null, _.map self.queue, (id) -> self.plunks[id]

fetch: (id, cb) ->
if plunk = @plunks[id]
plunk = deepClone(plunk)
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
"coffee-script": "1.2.0",
"cromag": "0.1.1",
"express": "2.5.6",
"jade": "0.20.0",
"less": "1.2.1",
"lingo": "0.0.4",
"express-resource": "0.2.4",
"json-schema": "0.2.0",
Expand Down
Binary file added public/img/glyphicons-halflings-white.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/img/glyphicons-halflings.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/img/loading.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 66b37dd

Please sign in to comment.