Skip to content

Commit

Permalink
adding three options for boilerplates
Browse files Browse the repository at this point in the history
  • Loading branch information
addyosmani committed Dec 25, 2011
1 parent 7704358 commit 8d81282
Show file tree
Hide file tree
Showing 81 changed files with 40,904 additions and 0 deletions.
28 changes: 28 additions & 0 deletions README.md
@@ -1,2 +1,30 @@
Another work in progress.

Todo application boilerplates demonstrating:

Option 1
=========
* Backbone
* Node.js
* Express
* Mongoose
* MongoDB

Option 2
=========
* Backbone
* Jade
* Node.js
* Express
* Mongoose
* MongoDB

Option 3
==========
* Backbone
* Haml
* Ruby
* Sinatra
* MongoDB

Instructions to come soon.
89 changes: 89 additions & 0 deletions option1/app.js
@@ -0,0 +1,89 @@
var application_root = __dirname,
express = require("express"),
path = require("path"),
mongoose = require('mongoose');

var app = express.createServer();

// model
mongoose.connect('mongodb://localhost/my_database');

var Todo = mongoose.model('Todo', new mongoose.Schema({
text: String,
done: Boolean,
order: Number
}));

app.configure(function(){
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(app.router);
app.use(express.static(path.join(application_root, "public")));
app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
app.set('views', path.join(application_root, "views"));
app.set('view engine', 'jade')
});

app.get('/', function(req, res){
res.send('Hello World');
});

app.get('/todo', function(req, res){
res.render('todo', {title: "MongoDB Backed TODO App"});
});

app.get('/api/todos', function(req, res){
return Todo.find(function(err, todos) {
return res.send(todos);
});
});

app.get('/api/todos/:id', function(req, res){
return Todo.findById(req.params.id, function(err, todo) {
if (!err) {
return res.send(todo);
}
});
});

app.put('/api/todos/:id', function(req, res){
return Todo.findById(req.params.id, function(err, todo) {
todo.text = req.body.text;
todo.done = req.body.done;
todo.order = req.body.order;
return todo.save(function(err) {
if (!err) {
console.log("updated");
}
return res.send(todo);
});
});
});

app.post('/api/todos', function(req, res){
var todo;
todo = new Todo({
text: req.body.text,
done: req.body.done,
order: req.body.order
});
todo.save(function(err) {
if (!err) {
return console.log("created");
}
});
return res.send(todo);
});

app.delete('/api/todos/:id', function(req, res){
return Todo.findById(req.params.id, function(err, todo) {
return todo.remove(function(err) {
if (!err) {
console.log("removed");
return res.send('')
}
});
});
});

app.listen(3000);
5 changes: 5 additions & 0 deletions option1/install.sh
@@ -0,0 +1,5 @@
#!/bin/bash
npm install express
npm install mongodb --mongodb:native
npm install mongoose
npm install jade
38 changes: 38 additions & 0 deletions option1/public/404.html
@@ -0,0 +1,38 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Page Not Found :(</title>
<style>
body { text-align: center;}
h1 { font-size: 50px; text-align: center }
span[frown] { transform: rotate(90deg); display:inline-block; color: #bbb; }
body { font: 20px Constantia, 'Hoefler Text', "Adobe Caslon Pro", Baskerville, Georgia, Times, serif; color: #999; text-shadow: 2px 2px 2px rgba(200, 200, 200, 0.5); }
::-moz-selection{ background:#FF5E99; color:#fff; }
::selection { background:#FF5E99; color:#fff; }
article {display:block; text-align: left; width: 500px; margin: 0 auto; }

a { color: rgb(36, 109, 56); text-decoration:none; }
a:hover { color: rgb(96, 73, 141) ; text-shadow: 2px 2px 2px rgba(36, 109, 56, 0.5); }
</style>
</head>
<body>
<article>
<h1>Not found <span frown>:(</span></h1>
<div>
<p>Sorry, but the page you were trying to view does not exist.</p>
<p>It looks like this was the result of either:</p>
<ul>
<li>a mistyped address</li>
<li>an out-of-date link</li>
</ul>
</div>

<script>
var GOOG_FIXURL_LANG = (navigator.language || '').slice(0,2),
GOOG_FIXURL_SITE = location.host;
</script>
<script src="http://linkhelp.clients.google.com/tbproxy/lh/wm/fixurl.js"></script>
</article>
</body>
</html>
25 changes: 25 additions & 0 deletions option1/public/crossdomain.xml
@@ -0,0 +1,25 @@
<?xml version="1.0"?>
<!DOCTYPE cross-domain-policy SYSTEM "http://www.adobe.com/xml/dtds/cross-domain-policy.dtd">
<cross-domain-policy>


<!-- Read this: www.adobe.com/devnet/articles/crossdomain_policy_file_spec.html -->

<!-- Most restrictive policy: -->
<site-control permitted-cross-domain-policies="none"/>



<!-- Least restrictive policy: -->
<!--
<site-control permitted-cross-domain-policies="all"/>
<allow-access-from domain="*" to-ports="*" secure="false"/>
<allow-http-request-headers-from domain="*" headers="*" secure="false"/>
-->
<!--
If you host a crossdomain.xml file with allow-access-from domain="*"
and don’t understand all of the points described here, you probably
have a nasty security vulnerability. ~ simon willison
-->

</cross-domain-policy>

0 comments on commit 8d81282

Please sign in to comment.