Skip to content

Commit

Permalink
start of big refactor to break it down into pieces
Browse files Browse the repository at this point in the history
  • Loading branch information
ianstormtaylor committed Mar 29, 2015
1 parent 0d62d13 commit 674fd7a
Show file tree
Hide file tree
Showing 20 changed files with 604 additions and 384 deletions.
25 changes: 15 additions & 10 deletions Makefile
@@ -1,20 +1,25 @@

# Clean non-checked-in files.
clean:
@rm -rf node_modules
# Binaries.
mocha = ./node_modules/.bin/mocha \
--require gnode \
--require co-mocha \
--reporter spec \
--slow 500 \
--bail

# Install dependencies from npm.
node_modules: package.json
@npm install
@touch node_modules

# Run the tests.
test: node_modules
@node_modules/.bin/mocha \
test/index \
--reporter spec \
--timeout 10000 \
--bail
@$(mocha)

# Run the tests in debug mode.
test-debug: node_modules
@$(mocha) debug

# Phony targets.
.PHONY: clean
.PHONY: test
.PHONY: test
.PHONY: test-debug
12 changes: 12 additions & 0 deletions index.js
@@ -0,0 +1,12 @@

/**
* Add backwards compatibility for Node 0.10.
*/

require('gnode');

/**
* Export `Khaos`.
*/

module.exports = require('./lib');
29 changes: 14 additions & 15 deletions lib/helpers.js
@@ -1,42 +1,41 @@

var handlebars = require('handlebars');
var Case = require('case');
var moment = require('moment');

/**
* Register a helper for each case.
* Cases.
*/

Object.keys(Case.cases).forEach(function(key){
handlebars.registerHelper(key + 'case', function(str){
exports[key + 'case'] = function(str){
return Case[key](str);
});
};
});

/**
* Add a default helper.
* Default.
*/

handlebars.registerHelper('default', function(value, def){
exports.default = function(value, def){
return value ? value : def;
});
};

/**
* Add a date helper.
* Date.
*/

handlebars.registerHelper('date', function(date, format){
exports.date = function(date, format){
return moment(date).format(format);
});
};

/**
* Add `is` and `isnt` helper.
* Is and isnt.
*/

handlebars.registerHelper('is', function(value, match){
exports.is = function(value, match){
return value === match;
});
};

handlebars.registerHelper('isnt', function(value, match){
exports.isnt = function(value, match){
return value !== match;
});
};

0 comments on commit 674fd7a

Please sign in to comment.