Skip to content

Commit be4a07f

Browse files
committed
Add asset builder.
1 parent e762e16 commit be4a07f

28 files changed

+766
-2122
lines changed

Jakefile.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/**
2+
* Jake is a JavaScript build tool for Node.js
3+
* http://howtonode.org/intro-to-jake
4+
* https://github.com/mde/jake
5+
*
6+
* To find out the available tasks for Jake run:
7+
* jake -T
8+
*
9+
* To run a task do:
10+
* jake db:reset
11+
*
12+
* To run a task with params do:
13+
* jake db:populate[20]
14+
*/
15+
var assetBuilder = require('./scripts/assetBuilder')
16+
, colors = require('colors')
17+
, log = console.log
18+
, ENV = process.env.NODE_ENV || 'development'
19+
, JK = {}
20+
21+
namespace('app', function() {
22+
23+
desc('Compress JS & CSS and make 1 JS && 1 CSS file. Run this before deploying to production.');
24+
task('build', [], function(done) {
25+
assetBuilder(function() {
26+
log('- packed up JS & CSS files'.yellow);
27+
complete();
28+
});
29+
}, { async: true });
30+
31+
});

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Node-Backbone-Require Example Blog
2+
A RESTful example blog built with Node.js, Backbone.js, Require.js, and Mongoose.
3+
4+
## Usage
5+
```sh
6+
git clone git://github.com/trantorLiu/Node-Backbone-Require-Example-Blog.git
7+
cd Node-Backbone-Require-Example-Blog
8+
npm install
9+
#development mode: http://localhost/dev.html
10+
node app.js
11+
#production mode: http://localhost
12+
npm install -g jake
13+
jake app:build
14+
NODE_ENV=production node app.js
15+
```
16+
## LICENSE
17+
MIT

app.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ if (cluster.isMaster) {
2727
server;
2828

2929
if (config.DB_USER && config.DB_PASSWORD) {
30-
mongoose.connect('mongodb://' + config.DB_USER + ':' + config.DB_PASSWORD + '@localhost/' + config.DB_NAME);
30+
mongoose.createConnection('mongodb://' + config.DB_USER + ':' + config.DB_PASSWORD + '@localhost/' + config.DB_NAME);
3131
} else {
32-
mongoose.connect('mongodb://localhost/' + config.DB_NAME);
32+
mongoose.createConnection('mongodb://localhost/' + config.DB_NAME);
3333
}
3434

3535
mongoose.connect('mongodb://localhost/' + config.DB_NAME);

config.js

Lines changed: 0 additions & 4 deletions
This file was deleted.

config/db.json

Lines changed: 0 additions & 29 deletions
This file was deleted.

config/environments/development.json

Lines changed: 0 additions & 5 deletions
This file was deleted.

config/environments/production.json

Lines changed: 0 additions & 6 deletions
This file was deleted.

config/environments/test.json

Lines changed: 0 additions & 5 deletions
This file was deleted.

config/error_messages.json

Lines changed: 0 additions & 7 deletions
This file was deleted.

config/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module.exports = {
22
PORT: 8000,
3-
DB_NAME: 'ntugsa-dev',
3+
DB_NAME: 'example-blog',
44
DB_USER: null,
55
DB_PASSWORD: null,
66
API: '/api/v1'

package.json

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
{
2-
"name": "Node-Backbone-Require Example Blog"
3-
, "version": "0.0.1"
4-
, "author": "Chun-Yi Liu <[email protected]>"
5-
, "private": true
6-
, "scripts": {
2+
"name": "Node-Backbone-Require-Example-Blog",
3+
"version": "0.0.1",
4+
"author": "Chun-Yi Liu <[email protected]>",
5+
"private": true,
6+
"scripts": {
77
"start": "node app"
8-
}
9-
, "dependencies": {
10-
"express": "3.1.2"
11-
, "connect": "*"
12-
, "mongoose": "*"
13-
, "underscore": "*"
14-
, "async": "*"
15-
}
16-
, "engines": {
8+
},
9+
"dependencies": {
10+
"express": "3.1.2",
11+
"connect": "*",
12+
"mongoose": "*",
13+
"underscore": "*",
14+
"async": "*",
15+
"requirejs": "*",
16+
"colors": "*"
17+
},
18+
"engines": {
1719
"node": "0.10.4"
1820
}
1921
}

public/built/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Ignore everything in this directory
2+
*
3+
# Except this file
4+
!.gitignore

public/dev.html

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<!DOCTYPE HTML>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>Node-Backbone Sample Blog</title>
6+
7+
<!-- Le HTML5 shim, for IE6-8 support of HTML5 elements -->
8+
<!--[if lt IE 9]>
9+
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
10+
<![endif]-->
11+
12+
<!-- Le styles -->
13+
<link rel="stylesheet" href="/stylesheets/style.css" />
14+
</head>
15+
<body>
16+
17+
<header>
18+
</header>
19+
20+
<!-- Container -->
21+
<div class="container">
22+
<section id="page-content"></section>
23+
</div>
24+
25+
<footer>
26+
</footer>
27+
28+
<!-- Le javascript
29+
================================================== -->
30+
<!-- Placed at the end of the document so the pages load faster -->
31+
<script data-main="/javascripts/main" src="/javascripts/lib/require.min.js"></script>
32+
33+
</body>
34+
</html>

public/index.html

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,29 +7,28 @@
77
<!-- Le HTML5 shim, for IE6-8 support of HTML5 elements -->
88
<!--[if lt IE 9]>
99
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
10-
<![endif]-->
10+
<![endif]-->
1111

1212
<!-- Le styles -->
13-
<link rel="stylesheet" href="/stylesheets/style.css" />
13+
<link rel="stylesheet" href="built/main-built.css">
1414
</head>
1515
<body>
1616

1717
<header>
1818
</header>
1919

20+
<!-- Container -->
2021
<div class="container">
21-
22-
<section class="page-content"></section>
23-
24-
</div> <!-- /container -->
22+
<section id="page-content"></section>
23+
</div>
2524

2625
<footer>
2726
</footer>
2827

2928
<!-- Le javascript
3029
================================================== -->
3130
<!-- Placed at the end of the document so the pages load faster -->
32-
<script data-main="/javascripts/main" src="/javascripts/lib/require.min.js"></script>
31+
<script data-main="/built/main-built" src="/javascripts/lib/require.min.js"></script>
3332

3433
</body>
3534
</html>

public/javascripts/app.js

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,38 @@ define('app', [
44
'backbone',
55
'router'
66
], function($, _, backbone, router) {
7+
8+
// extend router with appView()
9+
_.extend(router.prototype, {
10+
appView: {
11+
show: function (view, callback) {
12+
if (this.currentView) {
13+
this.currentView.close();
14+
}
15+
16+
this.currentView = view;
17+
this.currentView.render(callback);
18+
19+
$("#page-content").hide().html(this.currentView.el).fadeIn();
20+
21+
}
22+
}
23+
});
24+
_.extend(backbone.View.prototype, {
25+
close: function() {
26+
this.remove();
27+
this.unbind();
28+
if (this.onClose) {
29+
this.onClose();
30+
}
31+
}
32+
});
33+
734
var initialize = function() {
835
var app = new router();
936
backbone.history.start();
1037
}
1138

12-
// TODO: error handling with window.onerror
13-
// http://www.slideshare.net/nzakas/enterprise-javascript-error-handling-presentation
14-
1539
return {
1640
initialize: initialize
1741
};

0 commit comments

Comments
 (0)