Skip to content

Commit 2a74abc

Browse files
committed
refactor to use bower
1 parent ff2deb0 commit 2a74abc

File tree

588 files changed

+183
-96402
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

588 files changed

+183
-96402
lines changed

.bowerrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"directory": "public/bower_components"
3+
}

app.js

Lines changed: 38 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,64 @@
11

22
/**
3-
* Module dependencies.
3+
* Module dependencies
44
*/
55

66
var express = require('express'),
77
routes = require('./routes'),
8-
socket = require('./routes/socket.js');
8+
api = require('./routes/api'),
9+
http = require('http'),
10+
path = require('path');
911

1012
var app = module.exports = express();
1113
var server = require('http').createServer(app);
12-
13-
// Hook Socket.io into Express
1414
var io = require('socket.io').listen(server);
1515

16-
// Configuration
17-
18-
app.configure(function(){
19-
app.set('views', __dirname + '/views');
20-
app.set('view engine', 'jade');
21-
app.use(express.bodyParser());
22-
app.use(express.methodOverride());
23-
app.use(express.static(__dirname + '/public'));
24-
app.use(app.router);
25-
});
16+
/**
17+
* Configuration
18+
*/
2619

27-
app.configure('development', function(){
28-
app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
29-
});
20+
// all environments
21+
app.set('port', process.env.PORT || 3000);
22+
app.set('views', __dirname + '/views');
23+
app.set('view engine', 'jade');
24+
app.use(express.logger('dev'));
25+
app.use(express.bodyParser());
26+
app.use(express.methodOverride());
27+
app.use(express.static(path.join(__dirname, 'public')));
28+
app.use(app.router);
3029

31-
app.configure('production', function(){
30+
// development only
31+
if (app.get('env') === 'development') {
3232
app.use(express.errorHandler());
33-
});
33+
}
34+
35+
// production only
36+
if (app.get('env') === 'production') {
37+
// TODO
38+
};
3439

35-
// Routes
3640

41+
/**
42+
* Routes
43+
*/
44+
45+
// serve index and view partials
3746
app.get('/', routes.index);
3847
app.get('/partials/:name', routes.partials);
3948

49+
// JSON API
50+
app.get('/api/name', api.name);
51+
4052
// redirect all others to the index (HTML5 history)
4153
app.get('*', routes.index);
4254

4355
// Socket.io Communication
56+
io.sockets.on('connection', require('./routes/socket'));
4457

45-
io.sockets.on('connection', socket);
46-
47-
// Start server
58+
/**
59+
* Start Server
60+
*/
4861

49-
server.listen(3000, function(){
50-
console.log("Express server listening on port %d in %s mode", this.address().port, app.settings.env);
62+
server.listen(app.get('port'), function () {
63+
console.log('Express server listening on port ' + app.get('port'));
5164
});

bower.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"name": "application-name",
3+
"version": "0.0.0",
4+
"ignore": [
5+
"**/.*",
6+
"node_modules",
7+
"components"
8+
],
9+
"dependencies": {
10+
"angular": "~1.0.7",
11+
"angular-socket-io": "~0.0.2"
12+
}
13+
}

package.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
2-
"name": "application-name"
3-
, "version": "0.0.1"
4-
, "private": true
5-
, "dependencies": {
6-
"express": "3.0.0"
7-
, "jade": ">= 0.0.1"
8-
, "socket.io": ">= 0.9.6"
2+
"name": "application-name",
3+
"version": "0.0.0",
4+
"private": true,
5+
"dependencies": {
6+
"socket.io": "~0.9.16",
7+
"express": "~3.2.6",
8+
"jade": "~0.31.2"
99
}
10-
}
10+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# angular-socket-io
2+
Bower Component for using AngularJS with [Socket.IO](http://socket.io/), based on [this](http://briantford.com/blog/angular-socket-io.html).
3+
4+
## Usage
5+
1. `bower install angular-socket-io`
6+
2. Made sure the Socket.IO client lib is loaded. It's often served at `/socket.io/socket.io.js`.
7+
3. Include the `socket.js` script provided by this component into your app.
8+
4. Add `btford.socket-io` as a module dependency to your app.
9+
10+
## License
11+
MIT
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "angular-socket-io",
3+
"version": "0.0.2",
4+
"main": "socket.js",
5+
"dependencies": {
6+
"angular": "~1.0.5"
7+
},
8+
"gitHead": "95e01ea06d9921a916cf43d8080a0f4f4a2bcbb7",
9+
"readme": "# angular-socket-io\nBower Component for using AngularJS with [Socket.IO](http://socket.io/), based on [this](http://briantford.com/blog/angular-socket-io.html).\n\n## Usage\n1. `bower install angular-socket-io`\n2. Made sure the Socket.IO client lib is loaded. It's often served at `/socket.io/socket.io.js`.\n3. Include the `socket.js` script provided by this component into your app.\n4. Add `btford.socket-io` as a module dependency to your app.\n\n## License\nMIT\n",
10+
"readmeFilename": "README.md",
11+
12+
"description": "Bower Component for using AngularJS with [Socket.IO](http://socket.io/), based on [this](http://briantford.com/blog/angular-socket-io.html).",
13+
"repository": {
14+
"type": "git",
15+
"url": "git://github.com/btford/angular-socket-io.git"
16+
}
17+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* angular-socket-io v0.0.2
3+
* (c) 2013 Brian Ford http://briantford.com
4+
* License: MIT
5+
*/
6+
7+
'use strict';
8+
9+
angular.module('btford.socket-io', []).
10+
factory('socket', function ($rootScope, $timeout) {
11+
var socket = io.connect();
12+
return {
13+
on: function (eventName, callback) {
14+
socket.on(eventName, function () {
15+
var args = arguments;
16+
$timeout(function () {
17+
callback.apply(socket, args);
18+
}, 0);
19+
});
20+
},
21+
emit: function (eventName, data, callback) {
22+
socket.emit(eventName, data, function () {
23+
var args = arguments;
24+
$rootScope.$apply(function () {
25+
if (callback) {
26+
callback.apply(socket, args);
27+
}
28+
});
29+
});
30+
}
31+
};
32+
});
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"name": "angular",
3+
"version": "1.0.7",
4+
"main": "./angular.js",
5+
"dependencies": {},
6+
"gitHead": "6c0e81da2073f3831e32ed486d5aabe17bfc915f",
7+
8+
"readme": "ERROR: No README.md file found!",
9+
"description": "ERROR: No README.md file found!",
10+
"repository": {
11+
"type": "git",
12+
"url": "git://github.com/angular/bower-angular.git"
13+
}
14+
}

public/js/app.js

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,29 @@
11
'use strict';
22

3-
43
// Declare app level module which depends on filters, and services
5-
var app = angular.module('myApp', ['myApp.filters', 'myApp.services', 'myApp.directives']).
6-
config(['$routeProvider', '$locationProvider', function($routeProvider, $locationProvider) {
7-
$routeProvider.when('/view1', {templateUrl: 'partials/partial1', controller: MyCtrl1});
8-
$routeProvider.when('/view2', {templateUrl: 'partials/partial2', controller: MyCtrl2});
9-
$routeProvider.otherwise({redirectTo: '/view1'});
10-
$locationProvider.html5Mode(true);
11-
}]);
4+
5+
angular.module('myApp', [
6+
'myApp.controllers',
7+
'myApp.filters',
8+
'myApp.services',
9+
'myApp.directives',
10+
11+
// 3rd party dependencies
12+
'btford.socket-io'
13+
]).
14+
config(function ($routeProvider, $locationProvider) {
15+
$routeProvider.
16+
when('/view1', {
17+
templateUrl: 'partials/partial1',
18+
controller: 'MyCtrl1'
19+
}).
20+
when('/view2', {
21+
templateUrl: 'partials/partial2',
22+
controller: 'MyCtrl2'
23+
}).
24+
otherwise({
25+
redirectTo: '/view1'
26+
});
27+
28+
$locationProvider.html5Mode(true);
29+
});

public/js/controllers.js

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,17 @@
22

33
/* Controllers */
44

5-
function AppCtrl($scope, socket) {
6-
socket.on('send:name', function (data) {
7-
$scope.name = data.name;
5+
angular.module('myApp.controllers', []).
6+
controller('AppCtrl', function ($scope, socket) {
7+
socket.on('send:name', function (data) {
8+
$scope.name = data.name;
9+
});
10+
}).
11+
controller('MyCtrl1', function ($scope, socket) {
12+
socket.on('send:time', function (data) {
13+
$scope.time = data.time;
14+
});
15+
}).
16+
controller('MyCtrl2', function ($scope) {
17+
// write Ctrl here
818
});
9-
}
10-
11-
function MyCtrl1($scope, socket) {
12-
socket.on('send:time', function (data) {
13-
$scope.time = data.time;
14-
});
15-
}
16-
MyCtrl1.$inject = ['$scope', 'socket'];
17-
18-
19-
function MyCtrl2() {
20-
}
21-
MyCtrl2.$inject = [];

public/js/directives.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@
22

33
/* Directives */
44

5-
65
angular.module('myApp.directives', []).
7-
directive('appVersion', ['version', function(version) {
6+
directive('appVersion', function (version) {
87
return function(scope, elm, attrs) {
98
elm.text(version);
109
};
11-
}]);
10+
});

public/js/filters.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
/* Filters */
44

55
angular.module('myApp.filters', []).
6-
filter('interpolate', ['version', function(version) {
7-
return function(text) {
6+
filter('interpolate', function (version) {
7+
return function (text) {
88
return String(text).replace(/\%VERSION\%/mg, version);
99
}
10-
}]);
10+
});

0 commit comments

Comments
 (0)