Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit a45a309
Showing
9 changed files
with
343 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
* text=auto |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
node_modules | ||
|
||
# Coverage directory used by tools like istanbul | ||
coverage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
sudo: false | ||
language: node_js | ||
node_js: | ||
- 'iojs' | ||
- '0.12' | ||
- '0.10' | ||
after_success: | ||
- npm run coveralls |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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()); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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": "*" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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')); | ||
} | ||
); | ||
} | ||
); |