Skip to content
This repository has been archived by the owner on Jul 15, 2018. It is now read-only.

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
olegp committed Jan 29, 2012
0 parents commit 1bdd20b
Show file tree
Hide file tree
Showing 7 changed files with 109 additions and 0 deletions.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Notes

Notes is an example of a [Common Node](http://olegp.github.com/common-node/) application using [Stick](http://github.com/olegp/stick/) and [Mongo Sync](http://github.com/olegp/mongo-sync/).

To try it out, you will need to have Common Node installed globally (via `npm install common-node -g`) as well as MongoDB running on localhost.

Then, simply:

git clone git@github.com:olegp/notes.git
cd notes
npm install
common-node .

From the browser, navigate to http://localhost:8080/ to see the webapp in action.
22 changes: 22 additions & 0 deletions actions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
var Application = require("stick").Application;
var mongo = new (require("mongo-sync").Server)();

var app = exports.app = Application();
app.configure("params", "route", "render");
app.render.base = resolve(module, "templates");
app.render.master = "page.html";

function get(request) {
var context = {
title : "Notes",
notes : mongo.db("test").getCollection("posts").find().toArray()
};
return app.render("index.html", context);
}

app.get("/", get);

app.post("/", function(request) {
mongo.db("test").getCollection("posts").save({name: request.params.name});
return get();
});
6 changes: 6 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
var Application = require("stick").Application;

var app = exports.app = Application();
app.configure("notfound", "error", "static", "params", "mount");
app.static(resolve(module, "public"));
app.mount("/", require("./actions"));
15 changes: 15 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "notes",
"keywords": ["common-node"],
"description": "Common Node example using Stick and Mongo Sync",
"version": "0.1.0",
"author": "Oleg Podsechin <oleg@ionsquare.com>",
"repository": {
"type": "git",
"url": "git://github.com/olegp/notes.git"
},
"main": "./index.js",
"engines": { "node": ">= 0.6.0" },
"dependencies" : { "mongo-sync": ">= 0.1.0", "stick": ">= 0.1.0" },
"licenses": [ { "type": "MIT" } ]
}
29 changes: 29 additions & 0 deletions public/stylesheets/page.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
html, body {
margin: 0;
padding: 0;
font-family: sans-serif;
background: #eeeeee;
}

li {
margin: 0.8em;
}

#header {
background-color: #eeff66;
}

#header h1 {
font-weight: normal;
font-size: 28px;
margin: 0;
}

#body {
background-color: #ffffff;
}

#header, #body {
padding: 30px;
border-bottom: 1px solid #aaaaaa;
}
12 changes: 12 additions & 0 deletions templates/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<div id="header">
<h1>{{title}}</h1>
</div>
<div id="body">
<form method="post" action=".">
<input type="text" name="name" /> <input type="submit" value="Post" />
</form>
<ul>
{{#notes}}
<li>{{name}}</li> {{/notes}}
</ul>
</div>
11 changes: 11 additions & 0 deletions templates/page.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html>
<head>
<title>{{title}}</title>
<link rel="stylesheet" href="/stylesheets/page.css" />
{{{head}}}
</head>
<body>
{{{content}}}
</body>
</html>

0 comments on commit 1bdd20b

Please sign in to comment.