Skip to content
This repository was archived by the owner on Oct 21, 2023. It is now read-only.

Commit 57b76ad

Browse files
committed
Initial commit.
0 parents  commit 57b76ad

File tree

11 files changed

+185
-0
lines changed

11 files changed

+185
-0
lines changed

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
node_modules
2+
.DS_Store
3+
npm-debug.log
4+

LICENSE.md

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
Copyright (c) [Ramesh Nair](http://www.hiddentao.com/) and contributors
2+
3+
Permission is hereby granted, free of charge, to any person
4+
obtaining a copy of this software and associated documentation
5+
files (the "Software"), to deal in the Software without
6+
restriction, including without limitation the rights to use,
7+
copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
copies of the Software, and to permit persons to whom the
9+
Software is furnished to do so, subject to the following
10+
conditions:
11+
12+
The above copyright notice and this permission notice shall be
13+
included in all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22+
OTHER DEALINGS IN THE SOFTWARE.

README.md

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Waigo Examples
2+
3+
A repository containing examples to illustrate the use of the [Waigo](http://waigojs.com) web framework.
4+
5+
## Included Examples
6+
7+
_Note: Run each example using `node --harmony index.js` in the example's folder_
8+
9+
- [hello-world](hello-world) - hello world
10+
- [upload](upload) - multi-file uploading
11+
12+
## Projects using waigo
13+
14+
_These are full open source projects built on Waigo_
15+
16+
- [melkor](https://github.com/hiddentao/melkor) - Git-backed wiki engine.
17+
18+
## License
19+
20+
MIT - see LICENSE.md

hello-world/index.js

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
"use strict";
2+
3+
4+
var co = require('co'),
5+
waigo = require('waigo');
6+
7+
co(function*() {
8+
yield* waigo.init();
9+
yield* waigo.load('application').start();
10+
})(function(err) {
11+
if (err) {
12+
console.error(err);
13+
}
14+
});

hello-world/src/controllers/main.js

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
"use strict";
2+
3+
4+
exports.index = function*(next) {
5+
yield* this.render('index', {
6+
text: 'Hello world!'
7+
});
8+
};

hello-world/src/views/index.jade

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
doctype html
2+
html
3+
head
4+
title Hello world
5+
body
6+
h1= text

package.json

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"name": "waigo-examples",
3+
"version": "0.0.1",
4+
"private": true,
5+
"description": "Examples using the Waigo framework",
6+
"main": "index.js",
7+
"scripts": {
8+
"test": "echo \"Error: no test specified\" && exit 1"
9+
},
10+
"repository": {
11+
"type": "git",
12+
"url": "https://github.com/waigo/examples.git"
13+
},
14+
"keywords": [
15+
"waigo",
16+
"examples"
17+
],
18+
"author": "Ramesh Nair <[email protected]>",
19+
"license": "MIT",
20+
"bugs": {
21+
"url": "https://github.com/waigo/examples/issues"
22+
},
23+
"homepage": "https://github.com/waigo/examples",
24+
"dependencies": {
25+
"co": "^3.0.6",
26+
"co-busboy": "^1.0.2",
27+
"waigo": "^1.1.2"
28+
}
29+
}

upload/index.js

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
"use strict";
2+
3+
4+
var co = require('co'),
5+
waigo = require('waigo');
6+
7+
co(function*() {
8+
yield* waigo.init();
9+
yield* waigo.load('application').start();
10+
})(function(err) {
11+
if (err) {
12+
console.error(err);
13+
}
14+
});

upload/src/controllers/main.js

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
"use strict";
2+
3+
4+
var fs = require('fs'),
5+
parse = require('co-busboy');
6+
7+
8+
exports.index = function*(next) {
9+
yield* this.render('index');
10+
};
11+
12+
13+
14+
exports.upload = function*(next) {
15+
/*
16+
Code taken from https://github.com/koajs/examples/blob/master/upload/index.js
17+
*/
18+
19+
let parts = parse(this);
20+
let part;
21+
22+
let fileNames = {};
23+
24+
while (part = yield parts) {
25+
let stream = fs.createWriteStream('/tmp/' + Math.random());
26+
27+
part.pipe(stream);
28+
console.log('uploading %s -> %s', part.filename, stream.path);
29+
30+
fileNames[part.filename] = stream.path;
31+
}
32+
33+
yield* this.render('index', {
34+
fileNames: fileNames
35+
});
36+
};

upload/src/routes.js

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
"use strict";
2+
3+
4+
module.exports = {
5+
'GET /': 'main.index',
6+
'POST /': 'main.upload'
7+
};

upload/src/views/index.jade

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
doctype html
2+
html
3+
head
4+
title Upload
5+
style.
6+
.result {
7+
font-weight: bold;
8+
}
9+
.result span {
10+
padding-right: 0.5em;
11+
}
12+
body
13+
h1 Multi-part file upload
14+
15+
if fileNames
16+
div.result
17+
div Files uploaded:
18+
each destPath, fileName in fileNames
19+
div #{fileName} -> #{destPath}
20+
21+
p Try uploading multiple files at a time
22+
23+
form(method="post", enctype="multipart/form-data")
24+
input(name="file", type="file", multiple)
25+
input(type="submit", value="Upload")

0 commit comments

Comments
 (0)