Skip to content

Commit

Permalink
Coding style tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
vesln committed May 9, 2012
1 parent 1a0a85b commit 4cf3815
Show file tree
Hide file tree
Showing 13 changed files with 49 additions and 28 deletions.
8 changes: 4 additions & 4 deletions lib/app.js
Expand Up @@ -6,10 +6,9 @@
*/ */


/** /**
* Module dependencies. * Dependencies.
*/ */
var flatiron = require('flatiron'); var flatiron = require('flatiron');
var path = require('path');


/** /**
* The application object. * The application object.
Expand All @@ -35,6 +34,7 @@ app.use(flatiron.plugins.cli, {
' todo version - Lib version.', ' todo version - Lib version.',
' todo write - Write items to file.', ' todo write - Write items to file.',
'', '',
'Author: Veselin Todorov <hi@vesln.com>' 'Author: Veselin Todorov <hi@vesln.com>',
''
] ]
}); });
2 changes: 1 addition & 1 deletion lib/cli.js
Expand Up @@ -41,4 +41,4 @@ app.cmd(/rm (.+)/, commands.destroy);
app.cmd(/write (.+)/, commands.write); app.cmd(/write (.+)/, commands.write);


// Adds new todo item. // Adds new todo item.
app.cmd(/(.+)/, commands.add); app.cmd(/(.+)/, commands.add);
2 changes: 1 addition & 1 deletion lib/commands.js
Expand Up @@ -147,4 +147,4 @@ commands.write = function(filename) {
if (err) return commands.print(err); if (err) return commands.print(err);
}); });
}); });
}; };
10 changes: 5 additions & 5 deletions lib/formatter.js
@@ -1,6 +1,6 @@
/*! /*!
* todo - Todos in the CLI like what. * todo - Todos in the CLI like what.
* *
* Veselin Todorov <hi@vesln.com> * Veselin Todorov <hi@vesln.com>
* MIT License. * MIT License.
*/ */
Expand All @@ -12,24 +12,24 @@ var colors = require('colors');


/** /**
* Formatter namespace. * Formatter namespace.
* *
* @type {Object} * @type {Object}
*/ */
var formatter = module.exports; var formatter = module.exports;


/** /**
* Formats an item. * Formats an item.
* *
* @param {Object} Todo item. * @param {Object} Todo item.
* @param {Number} Item number. * @param {Number} Item number.
* @returns {String} * @returns {String}
* @api public * @api public
*/ */
formatter.format = function(item, num) { formatter.format = function(item, num) {
var state = (item.done) ? '√'.green : '✖'.red; var state = (item.done) ? '√'.green : '✖'.red;

return ' ' return ' '
+ '#' + (num + 1) + ' ' + '#' + (num + 1) + ' '
+ state + ' ' + state + ' '
+ item.text; + item.text;
}; };
8 changes: 4 additions & 4 deletions lib/storage.js
@@ -1,6 +1,6 @@
/*! /*!
* todo - Todos in the CLI like what. * todo - Todos in the CLI like what.
* *
* Veselin Todorov <hi@vesln.com> * Veselin Todorov <hi@vesln.com>
* MIT License. * MIT License.
*/ */
Expand All @@ -13,14 +13,14 @@ var path = require('path');


/** /**
* Database path. * Database path.
* *
* @type {String} * @type {String}
*/ */
var db = path.join(__dirname, '..', 'data', 'db.json'); var db = path.join(__dirname, '..', 'data', 'db.json');


/** /**
* Storage object. * Storage object.
* *
* @type {Object} * @type {Object}
*/ */
var storage = module.exports = new Storr(db); var storage = module.exports = new Storr(db);
7 changes: 7 additions & 0 deletions lib/todos.js
@@ -1,3 +1,10 @@
/*!
* todo - Todos in the CLI like what.
*
* Veselin Todorov <hi@vesln.com>
* MIT License.
*/

var Todos = module.exports = function(storage) { var Todos = module.exports = function(storage) {
this.storage = storage; this.storage = storage;
}; };
Expand Down
8 changes: 4 additions & 4 deletions test/app.test.js
@@ -1,6 +1,6 @@
/*! /*!
* todo - Todos in the CLI like what. * todo - Todos in the CLI like what.
* *
* Veselin Todorov <hi@vesln.com> * Veselin Todorov <hi@vesln.com>
* MIT License. * MIT License.
*/ */
Expand All @@ -12,13 +12,13 @@ var flatiron = require('flatiron');


/** /**
* The tests object. * The tests object.
* *
* @type {Object} * @type {Object}
*/ */
var app = require('../lib/app'); var app = require('../lib/app');


describe('app', function() { describe('app', function() {
it('should be flatiron app', function() { it('is flatiron app', function() {
app.should.eql(flatiron.app); app.should.eql(flatiron.app);
}); });
}); });
6 changes: 3 additions & 3 deletions test/cli.test.js
Expand Up @@ -25,11 +25,11 @@ var storage = require('../lib/storage');
var commands = require('../lib/commands'); var commands = require('../lib/commands');


describe('cli', function() { describe('cli', function() {
it('should expose flatiron app', function() { it('exposes flatiron app', function() {
cli.should.eql(flatiron.app); cli.should.eql(flatiron.app);
}); });


it('should register routes', function() { it('registers routes', function() {
cli.router.routes.version.on.should.eql(commands.version); cli.router.routes.version.on.should.eql(commands.version);
cli.router.routes.ls.on.should.eql(commands.list); cli.router.routes.ls.on.should.eql(commands.list);
cli.router.routes.clear.on.should.eql(commands.clear); cli.router.routes.clear.on.should.eql(commands.clear);
Expand All @@ -38,4 +38,4 @@ describe('cli', function() {
cli.router.routes.undo['(.+)'].on.should.eql(commands.undo); cli.router.routes.undo['(.+)'].on.should.eql(commands.undo);
cli.router.routes['(.+)'].on.should.eql(commands.add); cli.router.routes['(.+)'].on.should.eql(commands.add);
}); });
}); });
2 changes: 1 addition & 1 deletion test/commands.test.js
Expand Up @@ -87,4 +87,4 @@ describe('commands', function() {
storage.items.should.eql([]); storage.items.should.eql([]);
}); });
}); });
}); });
4 changes: 2 additions & 2 deletions test/formatter.test.js
Expand Up @@ -14,11 +14,11 @@ var formatter = require('../lib/formatter');


describe('formatter', function() { describe('formatter', function() {
describe('.format()', function() { describe('.format()', function() {
it('should format done items properly', function() { it('formats finished items', function() {
formatter.format({ text: 'Foo', done: true }, 0).should.eql(' #1 \u001b[32m√\u001b[39m Foo'); formatter.format({ text: 'Foo', done: true }, 0).should.eql(' #1 \u001b[32m√\u001b[39m Foo');
}); });


it('should format unfinished items properly', function() { it('formats not finished items', function() {
formatter.format({ text: 'Foo', done: false }, 0).should.eql(' #1 \u001b[31m✖\u001b[39m Foo'); formatter.format({ text: 'Foo', done: false }, 0).should.eql(' #1 \u001b[31m✖\u001b[39m Foo');
}); });
}); });
Expand Down
2 changes: 1 addition & 1 deletion test/storage.test.js
Expand Up @@ -18,7 +18,7 @@ var Storr = require('storr');
var storage = require('../lib/storage'); var storage = require('../lib/storage');


describe('storage', function() { describe('storage', function() {
it('should be Storr object', function() { it('is Storr object', function() {
storage.constructor.should.eql(Storr); storage.constructor.should.eql(Storr);
}); });
}); });
9 changes: 8 additions & 1 deletion test/support/fake_storage.js
@@ -1,3 +1,10 @@
/*!
* todo - Todos in the CLI like what.
*
* Veselin Todorov <hi@vesln.com>
* MIT License.
*/

var Storage = module.exports = function() {}; var Storage = module.exports = function() {};


Storage.prototype.get = function(type, callback) { Storage.prototype.get = function(type, callback) {
Expand All @@ -22,4 +29,4 @@ Storage.prototype.save = function(callback) {
this.items = this._items; this.items = this._items;
delete this._items; delete this._items;
callback(null); callback(null);
}; };
9 changes: 8 additions & 1 deletion test/todos.test.js
@@ -1,3 +1,10 @@
/*!
* todo - Todos in the CLI like what.
*
* Veselin Todorov <hi@vesln.com>
* MIT License.
*/

var Todos = require('../lib/todos'), var Todos = require('../lib/todos'),
Storage = require('./support/fake_storage'); Storage = require('./support/fake_storage');


Expand Down Expand Up @@ -90,4 +97,4 @@ describe("todos", function() {
items('undone').should.eql([undone, undone]); items('undone').should.eql([undone, undone]);
}); });
}); });
}); });

0 comments on commit 4cf3815

Please sign in to comment.