This commit is contained in:
@@ -104,7 +104,7 @@ namespace AyaNova.Api.Controllers
|
||||
}";
|
||||
|
||||
//sample template
|
||||
var reportTemplate = "'<div>{{#with person}}{{firstname}} {{lastname}}{{/with}}</div>'";
|
||||
var reportTemplate = "'<div>{{#with person}}{{firstname}} {{loud lastname}}{{/with}}</div>'";
|
||||
//data object
|
||||
var reportData = "{ person: { firstname: 'Yehuda', lastname: 'Katz' } }";
|
||||
|
||||
@@ -114,13 +114,18 @@ namespace AyaNova.Api.Controllers
|
||||
//Add handlebars JS for compiling and presenting
|
||||
await page.AddScriptTagAsync(new AddTagOptions() { Path = hbspath });
|
||||
|
||||
//test add helpers
|
||||
await page.AddScriptTagAsync(new AddTagOptions() { Path = Path.Combine(ReportJSFolderPath, "ay-hb-helpers.js") });
|
||||
//execute to add to handlebars
|
||||
await page.EvaluateExpressionAsync("ayRegisterHelpers();");
|
||||
|
||||
//compile and run handlebars template
|
||||
var compileScript = $"Handlebars.compile({reportTemplate})({reportData});";
|
||||
var compileScript = $"Handlebars.compile({reportTemplate})({reportData});";
|
||||
var resultHTML = await page.EvaluateExpressionAsync<string>(compileScript);
|
||||
|
||||
|
||||
//render report as HTML
|
||||
await page.AddStyleTagAsync(new AddTagOptions { Content = reportCSS });
|
||||
await page.SetContentAsync(resultHTML);
|
||||
await page.AddStyleTagAsync(new AddTagOptions { Content = reportCSS });
|
||||
await page.SetContentAsync(resultHTML);
|
||||
|
||||
//render to pdf and return
|
||||
var pdfBuffer = await page.PdfDataAsync();
|
||||
|
||||
5
server/AyaNova/resource/reportjs/ay-hb-helpers.js
Normal file
5
server/AyaNova/resource/reportjs/ay-hb-helpers.js
Normal file
@@ -0,0 +1,5 @@
|
||||
function ayRegisterHelpers() {
|
||||
Handlebars.registerHelper("loud", function (aString) {
|
||||
return aString.toUpperCase();
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user