From e30f943428d0695c28a091bab4a9b7f26d4f55a0 Mon Sep 17 00:00:00 2001 From: Niedziolka Michal Date: Sun, 20 Nov 2022 22:30:39 +0100 Subject: [PATCH 1/3] Remove "%example-css-src%" when no path to CSS --- lib/tabbedPageBuilder.js | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/lib/tabbedPageBuilder.js b/lib/tabbedPageBuilder.js index a7948cc9e..98c568f57 100644 --- a/lib/tabbedPageBuilder.js +++ b/lib/tabbedPageBuilder.js @@ -10,15 +10,13 @@ import * as processor from "./processor.js"; */ function addCSS(currentPage, tmpl) { if (currentPage.cssExampleSrc) { - tmpl = tmpl.replace( + return tmpl.replace( "%example-css-src%", fse.readFileSync(currentPage.cssExampleSrc, "utf8") ); } else { - tmpl.replace("%example-css-src%", ""); + return tmpl.replace("%example-css-src%", ""); } - - return tmpl; } /** @@ -41,15 +39,13 @@ function addHTML(currentPage, tmpl) { */ function addJS(currentPage, tmpl) { if (currentPage.jsExampleSrc) { - tmpl = tmpl.replace( + return tmpl.replace( "%example-js-src%", fse.readFileSync(currentPage.jsExampleSrc, "utf8") ); } else { - tmpl = tmpl.replace("%example-js-src%", ""); + return tmpl.replace("%example-js-src%", ""); } - - return tmpl; } /** From 02bb8a2f35ebc2a1faa17072f5e831835c0bc588 Mon Sep 17 00:00:00 2001 From: Niedziolka Michal Date: Thu, 24 Nov 2022 18:52:13 +0100 Subject: [PATCH 2/3] Change to ternary --- lib/tabbedPageBuilder.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/tabbedPageBuilder.js b/lib/tabbedPageBuilder.js index 98c568f57..003bd3ea3 100644 --- a/lib/tabbedPageBuilder.js +++ b/lib/tabbedPageBuilder.js @@ -38,14 +38,14 @@ function addHTML(currentPage, tmpl) { * @returns the processed template string */ function addJS(currentPage, tmpl) { - if (currentPage.jsExampleSrc) { - return tmpl.replace( + tmpl = tmpl.replace( "%example-js-src%", - fse.readFileSync(currentPage.jsExampleSrc, "utf8") - ); - } else { - return tmpl.replace("%example-js-src%", ""); - } + currentPage.jsExampleSrc + ? fse.readFileSync(currentPage.jsExampleSrc, "utf8") + : "" + ); + + return tmpl; } /** From a028602be0f90c55b49e4e6ca4f4d938373b2f8b Mon Sep 17 00:00:00 2001 From: Niedziolka Michal Date: Thu, 24 Nov 2022 18:56:05 +0100 Subject: [PATCH 3/3] Change to ternary in addCSS --- lib/tabbedPageBuilder.js | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/lib/tabbedPageBuilder.js b/lib/tabbedPageBuilder.js index 003bd3ea3..2b17481d1 100644 --- a/lib/tabbedPageBuilder.js +++ b/lib/tabbedPageBuilder.js @@ -9,14 +9,12 @@ import * as processor from "./processor.js"; * @returns the processed template string */ function addCSS(currentPage, tmpl) { - if (currentPage.cssExampleSrc) { - return tmpl.replace( - "%example-css-src%", - fse.readFileSync(currentPage.cssExampleSrc, "utf8") - ); - } else { - return tmpl.replace("%example-css-src%", ""); - } + return tmpl.replace( + "%example-css-src%", + currentPage.cssExampleSrc + ? fse.readFileSync(currentPage.cssExampleSrc, "utf8") + : "" + ); } /** @@ -39,10 +37,10 @@ function addHTML(currentPage, tmpl) { */ function addJS(currentPage, tmpl) { tmpl = tmpl.replace( - "%example-js-src%", - currentPage.jsExampleSrc - ? fse.readFileSync(currentPage.jsExampleSrc, "utf8") - : "" + "%example-js-src%", + currentPage.jsExampleSrc + ? fse.readFileSync(currentPage.jsExampleSrc, "utf8") + : "" ); return tmpl;