Skip to content

Commit

Permalink
Spaces -> tabs
Browse files Browse the repository at this point in the history
  • Loading branch information
dxg committed Nov 24, 2013
1 parent 6ff996f commit 07fad47
Show file tree
Hide file tree
Showing 11 changed files with 123 additions and 123 deletions.
2 changes: 1 addition & 1 deletion examples/anontxt/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ git checkout v2.1.3

**Setup AnonTXT**

Edit `anontxt/config/settings.js` and set your database, user & password.
Edit `anontxt/config/settings.js` to set your database, user & password.

```bash
cd examples/anontxt
Expand Down
12 changes: 6 additions & 6 deletions examples/anontxt/app/controllers/_helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ module.exports = {
var errors = {};
var a, e;

for(a = 0; a < errorsIn.length; a++) {
e = errorsIn[a];
for(a = 0; a < errorsIn.length; a++) {
e = errorsIn[a];

errors[e.property] = errors[e.property] || [];
errors[e.property].push(e.msg);
}
return errors;
errors[e.property] = errors[e.property] || [];
errors[e.property].push(e.msg);
}
return errors;
}
};
4 changes: 2 additions & 2 deletions examples/anontxt/app/controllers/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

module.exports = {
home : require('./home_controller'),
messages : require('./messages_controller'),
comments : require('./comments_controller')
messages : require('./messages_controller'),
comments : require('./comments_controller')
};
46 changes: 23 additions & 23 deletions examples/anontxt/app/models/comment.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
var moment = require('moment');

module.exports = function (orm, db) {
var Comment = db.define('comment', {
body : { type: 'text', required: true },
createdAt : { type: 'date', required: true, time: true }
},
{
hooks: {
beforeValidation: function () {
this.createdAt = new Date();
}
},
validations: {
body : orm.enforce.ranges.length(1, 1024)
},
methods: {
serialize: function () {
return {
body : this.body,
createdAt : moment(this.createdAt).fromNow()
}
}
}
});
var Comment = db.define('comment', {
body : { type: 'text', required: true },
createdAt : { type: 'date', required: true, time: true }
},
{
hooks: {
beforeValidation: function () {
this.createdAt = new Date();
}
},
validations: {
body : orm.enforce.ranges.length(1, 1024)
},
methods: {
serialize: function () {
return {
body : this.body,
createdAt : moment(this.createdAt).fromNow()
}
}
}
});

Comment.hasOne('message', db.models.message, { required: true, reverse: 'comments', autoFetch: true });
Comment.hasOne('message', db.models.message, { required: true, reverse: 'comments', autoFetch: true });
};
18 changes: 9 additions & 9 deletions examples/anontxt/app/models/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@ var settings = require('../../config/settings');
var connection = null;

function setup(db, cb) {
require('./message')(orm, db);
require('./comment')(orm, db);
require('./message')(orm, db);
require('./comment')(orm, db);

return cb(null, db);
return cb(null, db);
}

module.exports = function (cb) {
if (connection) return cb(null, connection);
if (connection) return cb(null, connection);

orm.connect(settings.database, function (err, db) {
if (err) return cb(err);
orm.connect(settings.database, function (err, db) {
if (err) return cb(err);

db.settings.set('instance.returnAllErrors', true);
setup(db, cb);
});
db.settings.set('instance.returnAllErrors', true);
setup(db, cb);
});
};
78 changes: 39 additions & 39 deletions examples/anontxt/app/models/message.js
Original file line number Diff line number Diff line change
@@ -1,45 +1,45 @@
var moment = require('moment');

module.exports = function (orm, db) {
var Message = db.define('message', {
title : { type: 'text', required: true },
body : { type: 'text', required: true, big: true },
createdAt : { type: 'date', required: true, time: true }
},
{
hooks: {
beforeValidation: function () {
this.createdAt = new Date();
}
},
validations: {
title: [
orm.enforce.ranges.length(1, undefined, "must be atleast 1 letter long"),
orm.enforce.ranges.length(undefined, 96, "cannot be longer than 96 letters")
],
body: [
orm.enforce.ranges.length(1, undefined, "must be atleast 1 letter long"),
orm.enforce.ranges.length(undefined, 32768, "cannot be longer than 32768 letters")
]
},
methods: {
serialize: function () {
var comments;
var Message = db.define('message', {
title : { type: 'text', required: true },
body : { type: 'text', required: true, big: true },
createdAt : { type: 'date', required: true, time: true }
},
{
hooks: {
beforeValidation: function () {
this.createdAt = new Date();
}
},
validations: {
title: [
orm.enforce.ranges.length(1, undefined, "must be atleast 1 letter long"),
orm.enforce.ranges.length(undefined, 96, "cannot be longer than 96 letters")
],
body: [
orm.enforce.ranges.length(1, undefined, "must be atleast 1 letter long"),
orm.enforce.ranges.length(undefined, 32768, "cannot be longer than 32768 letters")
]
},
methods: {
serialize: function () {
var comments;

if (this.comments) {
comments = this.comments.map(function (c) { return c.serialize(); });
} else {
comments = [];
}
if (this.comments) {
comments = this.comments.map(function (c) { return c.serialize(); });
} else {
comments = [];
}

return {
id : this.id,
title : this.title,
body : this.body,
createdAt : moment(this.createdAt).fromNow(),
comments : comments
};
}
}
});
return {
id : this.id,
title : this.title,
body : this.body,
createdAt : moment(this.createdAt).fromNow(),
comments : comments
};
}
}
});
};
8 changes: 4 additions & 4 deletions examples/anontxt/config/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ var controllers = require('../app/controllers')

module.exports = function (app) {
app.get( '/' , controllers.home);
app.get( '/messages' , controllers.messages.list);
app.post('/messages' , controllers.messages.create);
app.get( '/message/:id' , controllers.messages.get);
app.post('/message/:messageId/comments', controllers.comments.create);
app.get( '/messages' , controllers.messages.list);
app.post('/messages' , controllers.messages.create);
app.get( '/message/:id' , controllers.messages.get);
app.post('/message/:messageId/comments', controllers.comments.create);
};
20 changes: 10 additions & 10 deletions examples/anontxt/config/settings.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
var path = require('path');

var settings = {
path : path.normalize(path.join(__dirname, '..')),
port : process.env.NODE_PORT || 3000,
database : {
protocol : "postgresql", // or "mysql"
query : { pool: true },
host : "127.0.0.1",
database : "anontxt_dev",
user : "anontxt",
password : "apassword"
}
path : path.normalize(path.join(__dirname, '..')),
port : process.env.NODE_PORT || 3000,
database : {
protocol : "postgresql", // or "mysql"
query : { pool: true },
host : "127.0.0.1",
database : "anontxt_dev",
user : "anontxt",
password : "apassword"
}
};

module.exports = settings;
6 changes: 3 additions & 3 deletions examples/anontxt/public/app.css
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@

*, *:before, *:after {
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
}

body {
Expand Down
18 changes: 9 additions & 9 deletions examples/anontxt/public/app.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@

var entityMap = {
"&": "&amp;",
"<": "&lt;",
">": "&gt;",
'"': '&quot;',
"'": '&#39;',
"/": '&#x2F;'
"&": "&amp;",
"<": "&lt;",
">": "&gt;",
'"': '&quot;',
"'": '&#39;',
"/": '&#x2F;'
};

function escapeHtml(string) {
return String(string).replace(/[&<>"'\/]/g, function (s) {
return entityMap[s];
});
return String(string).replace(/[&<>"'\/]/g, function (s) {
return entityMap[s];
});
}

$(document).ready(function () {
Expand Down
34 changes: 17 additions & 17 deletions examples/anontxt/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,28 @@ var routes = require('./config/routes');
var models = require('./app/models/');

module.exports.start = function (done) {
var app = express();
var app = express();

environment(app);
routes(app);
environment(app);
routes(app);

app.listen(settings.port, function () {
console.log( ("Listening on port " + settings.port).green );
app.listen(settings.port, function () {
console.log( ("Listening on port " + settings.port).green );

if (done) {
return done(null, app, server);
}
}).on('error', function (e) {
if (e.code == 'EADDRINUSE') {
console.log('Address in use. Is the server already running?'.red);
}
if (done) {
return done(e);
}
});
if (done) {
return done(null, app, server);
}
}).on('error', function (e) {
if (e.code == 'EADDRINUSE') {
console.log('Address in use. Is the server already running?'.red);
}
if (done) {
return done(e);
}
});
}

// If someone ran: "node server.js" then automatically start the server
if (path.basename(process.argv[1],'.js') == path.basename(__filename,'.js')) {
module.exports.start()
module.exports.start()
}

0 comments on commit 07fad47

Please sign in to comment.