1
0
mirror of https://github.com/JuanCanham/HackMyResume.git synced 2024-11-05 01:56:21 +00:00

Promote console helpers has to console-helpers.js.

This commit is contained in:
hacksalot 2016-01-09 22:11:06 -05:00
parent 311030474d
commit d7cfc76636
2 changed files with 68 additions and 47 deletions

View File

@ -133,7 +133,7 @@ Output routines for HackMyResume.
case HME.afterAnalyze:
var info = evt.info;
var rawTpl = FS.readFileSync( PATH.join( __dirname, 'analyze.hbs' ), 'utf8');
HANDLEBARS.registerHelper( consoleFormatHelpers );
HANDLEBARS.registerHelper( require('../helpers/console-helpers') );
var template = HANDLEBARS.compile(rawTpl, { strict: false, assumeObjects: false });
var tot = 0;
info.keywords.forEach(function(g) {
@ -159,50 +159,4 @@ Output routines for HackMyResume.
});
var consoleFormatHelpers = {
v: function( val, defaultVal, padding, style ) {
retVal = ( val === null || val === undefined ) ? defaultVal : val;
var spaces = 0;
if( String.is(padding) ) {
spaces = parseInt( padding, 10 );
if( isNaN(spaces) ) spaces = 0;
}
else if( _.isNumber(padding) ) {
spaces = padding;
}
if( spaces !== 0 )
retVal = pad( retVal, Math.abs(spaces), null, spaces > 0 ? pad.LEFT : pad.RIGHT );
if( style && String.is( style )) {
retVal = LO.get( chalk, style )( retVal );
}
return retVal;
},
heat: function(val) {
if( val < 35 )
return chalk.green.bold(val);
else if( val < 95 )
return chalk.yellow.bold(val);
else
return chalk.red.bold(val);
},
style: function( val, style ) {
return LO.get( chalk, style )( val );
},
isPlural: function( val, options ) {
if( val > 1 )
return options.fn(this);
},
pad: function( val, spaces ) {
return pad(val, Math.abs(spaces), null, spaces > 0 ? pad.LEFT : pad.RIGHT );
}
};
}());

View File

@ -0,0 +1,67 @@
/**
Generic template helper definitions for command-line output.
@module console-helpers.js
@license MIT. See LICENSE.md for details.
*/
(function() {
var PAD = require('string-padding')
, LO = require('lodash')
, CHALK = require('chalk')
, _ = require('underscore');
require('../utils/string');
var consoleFormatHelpers = module.exports = {
v: function( val, defaultVal, padding, style ) {
retVal = ( val === null || val === undefined ) ? defaultVal : val;
var spaces = 0;
if( String.is(padding) ) {
spaces = parseInt( padding, 10 );
if( isNaN(spaces) ) spaces = 0;
}
else if( _.isNumber(padding) ) {
spaces = padding;
}
if( spaces !== 0 )
retVal = PAD( retVal, Math.abs(spaces), null, spaces > 0 ? PAD.LEFT : PAD.RIGHT );
if( style && String.is( style )) {
retVal = LO.get( CHALK, style )( retVal );
}
return retVal;
},
gapLength: function(val) {
if( val < 35 )
return CHALK.green.bold(val);
else if( val < 95 )
return CHALK.yellow.bold(val);
else
return CHALK.red.bold(val);
},
style: function( val, style ) {
return LO.get( CHALK, style )( val );
},
isPlural: function( val, options ) {
if( val > 1 )
return options.fn(this);
},
pad: function( val, spaces ) {
return PAD(val, Math.abs(spaces), null, spaces > 0 ? PAD.LEFT : PAD.RIGHT );
}
};
}());