Switched to handlebars for templateing

ref #5
This commit is contained in:
2021-02-05 20:08:47 +01:00
parent 3af76a53e3
commit 4acf3e39ce
3 changed files with 11 additions and 13 deletions

View File

@@ -2,7 +2,7 @@ import fs from "fs";
import path from 'path';
import puppeteer from "puppeteer";
import { Runner } from './models/Runner';
import Handlebars = require('handlebars');
/**
* This class is responsible for all things pdf creation.
* This uses the html templates from src/templates.
@@ -19,13 +19,10 @@ export class PdfCreator {
//TODO: Accept the runner class
public async generateSponsoringContract(runner: Runner): Promise<any> {
let template = fs.readFileSync(`${this.templateDir}/sponsoring_contract.html`, 'utf8');
template = template
.replace("{{runner_id}}", runner.id.toString())
.replace("{{runner_firstname}}", runner.firstname)
.replace("{{runner_lastname}}", runner.lastname)
.replace("{{runner_groupname}}", runner.group.name);
return await this.renderPdf(template, { format: "A5", landscape: true });
const template_source = fs.readFileSync(`${this.templateDir}/sponsoring_contract.html`, 'utf8');
const template = Handlebars.compile(template_source);
const result = template({ runner: runner })
return await this.renderPdf(result, { format: "A5", landscape: true });
}
/**