From 31e0bb69cca401e195274da90091d2d601c8057b Mon Sep 17 00:00:00 2001 From: hacksalot Date: Thu, 11 Feb 2016 22:02:50 -0500 Subject: [PATCH] Introduce "pad()" helper. Introduce a helper to emit padded strings / arrays of strings. --- dist/helpers/generic-helpers.js | 15 +++++++++++++++ src/helpers/generic-helpers.coffee | 15 +++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/dist/helpers/generic-helpers.js b/dist/helpers/generic-helpers.js index 9529463..74c1073 100644 --- a/dist/helpers/generic-helpers.js +++ b/dist/helpers/generic-helpers.js @@ -522,6 +522,21 @@ Generic template helper definitions for HackMyResume / FluentCV. } else { return options.inverse(this); } + }, + pad: function(stringOrArray, padAmount, unused) { + var PAD, ret; + stringOrArray = stringOrArray || ''; + padAmount = padAmount || 0; + ret = ''; + PAD = require('string-padding'); + if (!String.is(stringOrArray)) { + ret = stringOrArray.map(function(line) { + return PAD(line, line.length + Math.abs(padAmount), null, padAmount < 0 ? PAD.LEFT : PAD.RIGHT); + }).join('\n'); + } else { + ret = PAD(stringOrArray, stringOrArray.length + Math.abs(padAmount), null, padAmount < 0 ? PAD.LEFT : PAD.RIGHT); + } + return ret; } }; diff --git a/src/helpers/generic-helpers.coffee b/src/helpers/generic-helpers.coffee index ba273bf..15529e4 100644 --- a/src/helpers/generic-helpers.coffee +++ b/src/helpers/generic-helpers.coffee @@ -487,6 +487,21 @@ GenericHelpers = module.exports = + pad: (stringOrArray, padAmount, unused ) -> + stringOrArray = stringOrArray || '' + padAmount = padAmount || 0 + ret = '' + PAD = require 'string-padding' + if !String.is stringOrArray + ret = stringOrArray + .map (line) -> PAD line, line.length + Math.abs(padAmount), null, if padAmount < 0 then PAD.LEFT else PAD.RIGHT + .join '\n' + else + ret = PAD stringOrArray, stringOrArray.length + Math.abs(padAmount), null, if padAmount < 0 then PAD.LEFT else PAD.RIGHT + ret + + + ###* Report an error to the outside world without throwing an exception. Currently relies on kludging the running verb into. opts.