From: Justin Wind Date: Fri, 6 May 2022 18:01:03 +0000 (-0700) Subject: add indention helper X-Git-Tag: v1.2.0~2 X-Git-Url: https://git.squeep.com/?a=commitdiff_plain;h=6f6bea9c4444979f564f7e2242dbd3504895a22e;p=squeep-html-template-helper add indention helper --- 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);