-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: fixed templates in test and bundle
- Loading branch information
1 parent
265f3f9
commit 2e4c00b
Showing
11 changed files
with
63 additions
and
90 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,23 @@ | ||
import fs from 'fs/promises'; | ||
import Mustache from 'mustache'; | ||
import * as footer from '../templates/footer.mustache'; | ||
import * as header from '../templates/header.mustache'; | ||
|
||
/** | ||
* Render data in a mustache template | ||
* | ||
* @param {object} data An object of data to use in the template | ||
* @param {string} templatePath the path to the mustache template | ||
* @param {string} template the main mustache template as a string | ||
* @param {{[key:string] : string} | undefined} partials name and template string | ||
* @returns string | ||
*/ | ||
export default async (data: any, templatePath: string, partials: any) => { | ||
const template = await fs.readFile(templatePath, 'utf8'); | ||
let partialTemplates: {[key: string]: string } = {}; | ||
if (partials) { | ||
const keys = Object.keys(partials); | ||
for (let i = 0; i < keys.length; i++) { | ||
const key = keys[i]; | ||
const partial = await fs.readFile(partials[key], 'utf8'); | ||
partialTemplates[key] = partial; | ||
} | ||
} | ||
export default async (data: any, template: string, partials?: {[key: string]: string }) => { | ||
const fullPartials = { | ||
header: header.default, | ||
footer: footer.default, | ||
...partials, | ||
}; | ||
|
||
data.name = 'IRMA'; // TODO later veranderen bij naam switch | ||
|
||
return Mustache.render(template.toString(), data, partialTemplates); | ||
return Mustache.render(template, data, fullPartials); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.