This commit is contained in:
@@ -94,7 +94,7 @@ namespace AyaNova.Api.Controllers
|
|||||||
await new BrowserFetcher().DownloadAsync(BrowserFetcher.DefaultRevision);
|
await new BrowserFetcher().DownloadAsync(BrowserFetcher.DefaultRevision);
|
||||||
|
|
||||||
//sample CSS
|
//sample CSS
|
||||||
var templateCSS = @"
|
var reportCSS = @"
|
||||||
@page {
|
@page {
|
||||||
margin: 1cm;
|
margin: 1cm;
|
||||||
}
|
}
|
||||||
@@ -104,11 +104,9 @@ namespace AyaNova.Api.Controllers
|
|||||||
}";
|
}";
|
||||||
|
|
||||||
//sample template
|
//sample template
|
||||||
var templateHtml = "'<div>{{#with person}}{{firstname}} {{lastname}}{{/with}}</div>'";
|
var reportTemplate = "'<div>{{#with person}}{{firstname}} {{lastname}}{{/with}}</div>'";
|
||||||
|
|
||||||
//data object
|
//data object
|
||||||
var jsonData = "{person: {firstname: \"Yehuda\",lastname: \"Katz\",}}";
|
var reportData = "{ person: { firstname: 'Yehuda', lastname: 'Katz' } }";
|
||||||
var dat="{ person: { firstname: 'Yehuda', lastname: 'Katz' } }";
|
|
||||||
|
|
||||||
using (var browser = await Puppeteer.LaunchAsync(new LaunchOptions { Headless = true }))
|
using (var browser = await Puppeteer.LaunchAsync(new LaunchOptions { Headless = true }))
|
||||||
using (var page = await browser.NewPageAsync())
|
using (var page = await browser.NewPageAsync())
|
||||||
@@ -117,19 +115,22 @@ namespace AyaNova.Api.Controllers
|
|||||||
await page.AddScriptTagAsync(new AddTagOptions() { Path = hbspath });
|
await page.AddScriptTagAsync(new AddTagOptions() { Path = hbspath });
|
||||||
|
|
||||||
//script
|
//script
|
||||||
//var theScript = $"let fun=Handlebars.compile({templateHtml});fun({dat})";
|
//this works and returns the template properly
|
||||||
var theScript = $"let fun=Handlebars.compile({templateHtml});fun({dat});";
|
// var theScript = $"let fun=Handlebars.compile({templateHtml});fun({dat});";
|
||||||
|
|
||||||
//COMPILE into function
|
//cleanest way here
|
||||||
|
var compileScript = $"Handlebars.compile({reportTemplate})({reportData});";
|
||||||
|
|
||||||
var f3 = await page.EvaluateExpressionAsync<string>(theScript);
|
//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);
|
||||||
|
|
||||||
//get result by running hb function against data
|
|
||||||
// string html = await page.EvaluateExpressionAsync<string>(sfunc);
|
|
||||||
|
|
||||||
//open page with result
|
//open page with result
|
||||||
// await page.AddStyleTagAsync(new AddTagOptions { Content = templateCSS });
|
await page.AddStyleTagAsync(new AddTagOptions { Content = reportCSS });
|
||||||
// await page.SetContentAsync(templateHtml);
|
await page.SetContentAsync(resultHTML);
|
||||||
|
|
||||||
//pdf-ize and return
|
//pdf-ize and return
|
||||||
var pdfBuffer = await page.PdfDataAsync();
|
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