Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
typicode committed Sep 20, 2013
1 parent b879ee7 commit d706702
Show file tree
Hide file tree
Showing 1,336 changed files with 174,889 additions and 0 deletions.
1 change: 1 addition & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web: coffee app.coffee
40 changes: 40 additions & 0 deletions app.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@

###
Module dependencies.
###
express = require 'express'
cors = require 'cors'
routes = require './routes'
resource = require './routes/resource'
http = require 'http'
path = require 'path'
seed = require './database/seed'
seed.run()
app = express()

# all environments
app.set 'port', process.env.PORT or 3000
app.set 'views', __dirname + '/views'
app.set 'view engine', 'jade'
app.use express.favicon()
app.use express.logger('dev')
app.use express.bodyParser()
app.use express.methodOverride()
app.use require('stylus').middleware(__dirname + '/public')
app.use express.static(path.join(__dirname, 'public'))
app.use app.router

# development only
app.use express.errorHandler() if 'development' is app.get('env')

app.get '/', routes.index
app.get '/:resource', resource.list
app.get '/:parent/:parent_id/:resource', resource.nestedList
app.get '/:resource/:id', resource.show
app.post '/:resource', resource.create
app.put '/:resource', resource.update
app.delete '/:resource', resource.destroy

http.createServer(app).listen app.get('port'), ->
console.log 'Express server listening on port ' + app.get('port')

10 changes: 10 additions & 0 deletions collections/collection.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Backbone = require 'backbone'

class Collection extends Backbone.Collection
autoIncrement: (model) ->
model.set 'id', @length

initialize: ->
@on 'add', @autoIncrement, @

module.exports = Collection
1 change: 1 addition & 0 deletions database/db.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
exports = {}
50 changes: 50 additions & 0 deletions database/seed.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
db = require './db'
Faker = require 'Faker'
_ = require 'underscore'
Backbone = require 'backbone'
Collection = require '../collections/collection'
Post = require '../models/post'
Comment = require '../models/comment'
Album = require '../models/album'
Photo = require '../models/photo'
User = require '../models/user'
Todo = require '../models/todo'

# No syncing
Backbone.sync = ->

run = ->
db.posts = new (Collection.extend model: Post)
db.comments = new (Collection.extend model: Comment)
db.albums = new (Collection.extend model: Album)
db.photos = new (Collection.extend model: Photo)
db.users = new (Collection.extend model: User)
db.todos = new (Collection.extend model: Todo)

# Has many relationships
# Users
_(10).times ->
user = db.users.create()

# Posts
_(10).times ->
# userId not set in create so that it appears as the last
# attribute
post = db.posts.create().set userId: user.id

# Comments
_(5).times ->
db.comments.create().set postId: post.id

# Albums
_(10).times ->
album = db.albums.create().set userId: user.id

# Photos
_(50).times ->
db.photos.create().set albumId: album.id

# Todos
_(20).times -> db.todos.create().set userId: user.id

exports.run = run
12 changes: 12 additions & 0 deletions models/album.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
_ = require 'underscore'
Backbone = require 'backbone'
Faker = require 'Faker'

class Photo extends Backbone.Model
initialize: ->
@set
id : 0
title : Faker.Lorem.sentence()


module.exports = Photo
13 changes: 13 additions & 0 deletions models/comment.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
_ = require 'underscore'
Backbone = require 'backbone'
Faker = require 'Faker'

class Comment extends Backbone.Model
initialize: ->
@set
id : 0
name : Faker.Lorem.sentence()
email : Faker.Internet.email()
body : Faker.Lorem.sentences(4)

module.exports = Comment
18 changes: 18 additions & 0 deletions models/photo.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
_ = require 'underscore'
Backbone = require 'backbone'
Faker = require 'Faker'

class Photo extends Backbone.Model
_randomHex: ->
# Credit http://www.paulirish.com/2009/random-hex-color-code-snippets/
Math.floor(Math.random()*16777215).toString(16);

initialize: ->
hex = @_randomHex()
@set
id : 0
title : Faker.Lorem.sentence()
url : "http://placehold.it/600/#{hex}"
thumbnailUrl : "http://placehold.it/150/#{hex}"

module.exports = Photo
13 changes: 13 additions & 0 deletions models/post.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
_ = require 'underscore'
Backbone = require 'backbone'
Faker = require 'Faker'

class Post extends Backbone.Model
initialize: ->
@set
id : 0
title : Faker.Lorem.sentence()
body : Faker.Lorem.sentences(4)


module.exports = Post
12 changes: 12 additions & 0 deletions models/todo.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
_ = require 'underscore'
Backbone = require 'backbone'
Faker = require 'Faker'

class Todo extends Backbone.Model
initialize: ->
@set
id: 0
title: Faker.Lorem.sentence()
completed: if _.random(1) then true else false

module.exports = Todo
11 changes: 11 additions & 0 deletions models/user.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
_ = require 'underscore'
Backbone = require 'backbone'
Faker = require 'Faker'

class User extends Backbone.Model
initialize: ->
card = Faker.Helpers.userCard();
@set id: 0
@set card

module.exports = User
1 change: 1 addition & 0 deletions node_modules/.bin/cake

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

1 change: 1 addition & 0 deletions node_modules/.bin/coffee

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

1 change: 1 addition & 0 deletions node_modules/.bin/express

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

1 change: 1 addition & 0 deletions node_modules/.bin/jade

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

1 change: 1 addition & 0 deletions node_modules/.bin/stylus

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

3 changes: 3 additions & 0 deletions node_modules/Faker/.jshintignore

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

87 changes: 87 additions & 0 deletions node_modules/Faker/.jshintrc

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

16 changes: 16 additions & 0 deletions node_modules/Faker/.npmignore

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

Loading

0 comments on commit d706702

Please sign in to comment.