From 6f6bea9c4444979f564f7e2242dbd3504895a22e Mon Sep 17 00:00:00 2001 From: Justin Wind Date: Fri, 6 May 2022 11:01:03 -0700 Subject: [PATCH] add indention helper --- lib/template-helper.js | 12 ++++++++++++ test/lib/template-helper.js | 7 +++++++ 2 files changed, 19 insertions(+) diff --git a/lib/template-helper.js b/lib/template-helper.js index a20d1ae..16a14cc 100644 --- a/lib/template-helper.js +++ b/lib/template-helper.js @@ -93,6 +93,17 @@ const secondsToPeriod = (seconds) => { }; +/** + * Return array of strings prefixed with tabs. + * @param {Number} indent + * @param {String[]} list + */ +const indented = (indent, list) => { + const spacer = '\t'.repeat(indent); + return list.map((l) => `${spacer}${l}`); +}; + + /** * Render the preamble for an HTML page. * @param {Number} pagePathLevel number of paths below root this page is @@ -363,6 +374,7 @@ module.exports = { htmlHeader, htmlFooter, htmlMessages, + indented, renderNavLink, LI, UL, diff --git a/test/lib/template-helper.js b/test/lib/template-helper.js index a21b141..ab5533f 100644 --- a/test/lib/template-helper.js +++ b/test/lib/template-helper.js @@ -171,6 +171,13 @@ describe('Template Helper', function () { }); }); // LI + describe('indented', function () { + it('covers', function () { + const result = th.indented(2, ['foo', 'bar']); + result.forEach((r) => assert(r.startsWith('\t\t'))); + }); + }); // indented + describe('htmlBody', function () { it('covers no main', function () { const result = th.htmlBody(pagePathLevel, ctx, options); -- 2.45.2