Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
natecavanaugh committed Aug 20, 2015
0 parents commit a45a309
Show file tree
Hide file tree
Showing 9 changed files with 343 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitattributes
@@ -0,0 +1 @@
* text=auto
4 changes: 4 additions & 0 deletions .gitignore
@@ -0,0 +1,4 @@
node_modules

# Coverage directory used by tools like istanbul
coverage
8 changes: 8 additions & 0 deletions .travis.yml
@@ -0,0 +1,8 @@
sudo: false
language: node_js
node_js:
- 'iojs'
- '0.12'
- '0.10'
after_success:
- npm run coveralls
21 changes: 21 additions & 0 deletions LICENSE
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) Nate Cavanaugh <nate@shift22.com> (alterform.com)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
56 changes: 56 additions & 0 deletions README.md
@@ -0,0 +1,56 @@
# content-logger-handlebars-helpers
[![NPM version][npm-image]][npm-url]
[![build status][travis-image]][travis-url]
[![Test coverage][coveralls-image]][coveralls-url]

> My mathematical module

## Install

```
$ npm install --save content-logger-handlebars-helpers
```


## Usage

```js
var contentLoggerHandlebarsHelpers = require('content-logger-handlebars-helpers');

contentLoggerHandlebarsHelpers('unicorns');
//=> unicorns & rainbows
```


## API

### contentLoggerHandlebarsHelpers(input, [options])

#### input

*Required*
Type: `string`

Lorem ipsum.

#### options

##### foo

Type: `boolean`
Default: `false`

Lorem ipsum.


## License

MIT © [Nate Cavanaugh](http://alterform.com)

[npm-image]: https://img.shields.io/npm/v/content-logger-handlebars-helpers.svg?style=flat-square
[npm-url]: https://npmjs.org/package/content-logger-handlebars-helpers
[travis-image]: https://img.shields.io/travis/natecavanaugh/content-logger-handlebars-helpers/master.svg?style=flat-square
[travis-url]: https://travis-ci.org/natecavanaugh/content-logger-handlebars-helpers
[coveralls-image]: https://img.shields.io/coveralls/natecavanaugh/content-logger-handlebars-helpers/master.svg?style=flat-square
[coveralls-url]: https://coveralls.io/r/natecavanaugh/content-logger-handlebars-helpers?branch=master
29 changes: 29 additions & 0 deletions gulpfile.js
@@ -0,0 +1,29 @@
var gulp = require('gulp-help')(require('gulp'));
var plugins = require('gulp-load-plugins')();
var runSequence = require('run-sequence');

gulp.task('coveralls', function () {
gulp.src('coverage/**/lcov.info')
.pipe(plugins.coveralls());
});

gulp.task('test', function(done) {
return runSequence('test-unit', done);
});

gulp.task('test-unit', function() {
return gulp.src(['test/**/*.js', '!test/fixture/*.js'])
.pipe(plugins.mocha());
});

gulp.task('test-cover', function() {
return gulp.src(['./*.js'])
.pipe(plugins.istanbul())
.pipe(plugins.istanbul.hookRequire());
});

gulp.task('test-coverage', ['test-cover'], function() {
return gulp.src(['test/**/*.js', '!test/fixture/*.js'])
.pipe(plugins.mocha())
.pipe(plugins.istanbul.writeReports());
});
81 changes: 81 additions & 0 deletions index.js
@@ -0,0 +1,81 @@
var _ = require('lodash');

var colors = require('cli-color-keywords')();

module.exports = function(hb) {
hb = hb || require('handlebars');

Object.keys(colors.styles).forEach(
function(item, index) {
hb.registerHelper(
item,
function(options) {
return colors[item](options.fn(this));
}
);
}
);

hb.registerHelper(
'color',
function(options) {
var colorStyle = this.type;

if (!_.isFunction(colors[colorStyle])) {
colorStyle = 'warn';
}

return colors[colorStyle](options.fn(this));
}
);

hb.registerHelper(
'line',
function(options) {
var line = this.line;
var text = 'Line';

if (Array.isArray(line)) {
line = line.join('-');
text = 'Lines';
}

if (this.column && options.data.root.showColumns) {
line += ', Column ' + this.column;
}

return text + ' ' + line;
}
);

hb.registerHelper(
'and',
function(a, b, options) {
var retVal;

if (a && b) {
retVal = options.fn(this);
}
else {
retVal = options.inverse(this);
}

return retVal;
}
);

hb.registerHelper(
'banner',
function(options) {
var content = options.fn(this);

if (!this.showBanner) {
content = '';
}

return content;
}
);

return hb;
};
42 changes: 42 additions & 0 deletions package.json
@@ -0,0 +1,42 @@
{
"name": "content-logger-handlebars-helpers",
"version": "0.0.1",
"description": "My mathematical module",
"license": "MIT",
"repository": "natecavanaugh/content-logger-handlebars-helpers",
"author": {
"name": "Nate Cavanaugh",
"email": "nate@shift22.com",
"url": "alterform.com"
},
"engines": {
"node": ">=0.10.0"
},
"scripts": {
"test": "gulp test-coverage",
"coveralls": "gulp coveralls"
},
"keywords": [
""
],
"dependencies": {
"cli-color-keywords": "0.0.1",
"handlebars": "^3.0.3",
"lodash": "^3.10.1"
},
"devDependencies": {
"mocha": "*",
"chai": "*",
"chai-string": "*",
"coveralls": "*",
"gulp-coveralls": "*",
"gulp-istanbul": "*",
"istanbul": "*",
"sinon": "*",
"gulp": "*",
"gulp-load-plugins": "*",
"gulp-help": "*",
"run-sequence": "*",
"gulp-mocha": "*"
}
}
101 changes: 101 additions & 0 deletions test/test.js
@@ -0,0 +1,101 @@
'use strict';
var Handlebars = require('../')();

var colors = require('cli-color-keywords')();

var sinon = require('sinon');
var chai = require('chai');

chai.use(require('chai-string'));

var assert = chai.assert;

var colorStyles = Object.keys(colors.styles);

it(
'should have explicitly defined helpers available',
function() {
'banner and line color'.split(' ').forEach(
function(item, index) {
assert.isTrue(item in Handlebars.helpers);
}
);
}
);

it(
'should have dynamically defined helpers available',
function() {
colorStyles.forEach(
function(item, index) {
assert.isTrue(item in Handlebars.helpers);
}
);
}
);

it(
'handle banner',
function() {
var banner = '{{#banner}}Hello{{/banner}}';

var tpl = Handlebars.compile(banner);

assert.equal(tpl({showBanner: true}), 'Hello');
assert.equal(tpl({showBanner: false}), '');
}
);

it(
'handle and',
function() {
var and = '{{#and foo bar}}Hello{{/and}}';

var tpl = Handlebars.compile(and);

assert.equal(tpl({bar: true, foo: true}), 'Hello');
assert.equal(tpl({bar: false, foo: true}), '');
assert.equal(tpl({bar: true, foo: false}), '');
}
);

it(
'handle line',
function() {
var line = '{{line}}';

var tpl = Handlebars.compile(line);

assert.equal(tpl({line: 1}), 'Line 1');
assert.equal(tpl({line: [1, 5]}), 'Lines 1-5');
assert.equal(tpl({line: 1, column: 1, showColumns: true}), 'Line 1, Column 1');
}
);

it(
'handle color',
function() {
var color = '{{#color}}Hello{{/color}}';

var tpl = Handlebars.compile(color);

assert.equal(tpl({type: 'warn'}), colors.warn('Hello'));
assert.equal(tpl({type: 'subtle'}), colors.subtle('Hello'));
assert.equal(tpl({type: 'foo'}), colors.warn('Hello'));
}
);

it(
'handle dynamically defined color',
function() {
colorStyles.forEach(
function(item, index) {
var color = '{{#' + item + '}}Hello{{/' + item + '}}';

var tpl = Handlebars.compile(color);

assert.equal(tpl(), colors[item]('Hello'));
}
);
}
);

0 comments on commit a45a309

Please sign in to comment.