This commit is contained in:
@@ -94,7 +94,7 @@ namespace AyaNova.Api.Controllers
|
||||
await new BrowserFetcher().DownloadAsync(BrowserFetcher.DefaultRevision);
|
||||
|
||||
//sample CSS
|
||||
var templateCSS = @"
|
||||
var reportCSS = @"
|
||||
@page {
|
||||
margin: 1cm;
|
||||
}
|
||||
@@ -104,11 +104,9 @@ namespace AyaNova.Api.Controllers
|
||||
}";
|
||||
|
||||
//sample template
|
||||
var templateHtml = "'<div>{{#with person}}{{firstname}} {{lastname}}{{/with}}</div>'";
|
||||
|
||||
//data object
|
||||
var jsonData = "{person: {firstname: \"Yehuda\",lastname: \"Katz\",}}";
|
||||
var dat="{ person: { firstname: 'Yehuda', lastname: 'Katz' } }";
|
||||
var reportTemplate = "'<div>{{#with person}}{{firstname}} {{lastname}}{{/with}}</div>'";
|
||||
//data object
|
||||
var reportData = "{ person: { firstname: 'Yehuda', lastname: 'Katz' } }";
|
||||
|
||||
using (var browser = await Puppeteer.LaunchAsync(new LaunchOptions { Headless = true }))
|
||||
using (var page = await browser.NewPageAsync())
|
||||
@@ -116,20 +114,23 @@ namespace AyaNova.Api.Controllers
|
||||
//Add handlebars JS for compiling and presenting
|
||||
await page.AddScriptTagAsync(new AddTagOptions() { Path = hbspath });
|
||||
|
||||
//script
|
||||
//var theScript = $"let fun=Handlebars.compile({templateHtml});fun({dat})";
|
||||
var theScript = $"let fun=Handlebars.compile({templateHtml});fun({dat});";
|
||||
//script
|
||||
//this works and returns the template properly
|
||||
// var theScript = $"let fun=Handlebars.compile({templateHtml});fun({dat});";
|
||||
|
||||
//COMPILE into function
|
||||
|
||||
var f3 = await page.EvaluateExpressionAsync<string>(theScript);
|
||||
|
||||
//get result by running hb function against data
|
||||
// string html = await page.EvaluateExpressionAsync<string>(sfunc);
|
||||
//cleanest way here
|
||||
var compileScript = $"Handlebars.compile({reportTemplate})({reportData});";
|
||||
|
||||
//this properly returns the function, but it doesn't work later
|
||||
// var theScript = $"''+Handlebars.compile({templateHtml});";
|
||||
|
||||
//COMPILE into function and call against data object
|
||||
var resultHTML = await page.EvaluateExpressionAsync<string>(compileScript);
|
||||
|
||||
|
||||
//open page with result
|
||||
// await page.AddStyleTagAsync(new AddTagOptions { Content = templateCSS });
|
||||
// await page.SetContentAsync(templateHtml);
|
||||
await page.AddStyleTagAsync(new AddTagOptions { Content = reportCSS });
|
||||
await page.SetContentAsync(resultHTML);
|
||||
|
||||
//pdf-ize and return
|
||||
var pdfBuffer = await page.PdfDataAsync();
|
||||
|
||||
29
server/AyaNova/resource/reportjs/ayhandlebars.js
Normal file
29
server/AyaNova/resource/reportjs/ayhandlebars.js
Normal file
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user