-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
web: coffee 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') | ||
|
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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
exports = {} |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.