Documents: restructure Documents/ directory
This commit is contained in:
35
Elwig/Helpers/Printing/Html.cs
Normal file
35
Elwig/Helpers/Printing/Html.cs
Normal file
@ -0,0 +1,35 @@
|
||||
using RazorLight;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Elwig.Helpers.Printing {
|
||||
public static class Html {
|
||||
|
||||
private static RazorLightEngine? Engine = null;
|
||||
public static bool IsReady => Engine != null;
|
||||
|
||||
public static async Task Init(Action evtHandler) {
|
||||
var e = new RazorLightEngineBuilder()
|
||||
.UseFileSystemProject(App.DataPath + "resources")
|
||||
.UseMemoryCachingProvider()
|
||||
.Build();
|
||||
|
||||
await e.CompileTemplateAsync("Document");
|
||||
await e.CompileTemplateAsync("BusinessDocument");
|
||||
await e.CompileTemplateAsync("BusinessLetter");
|
||||
await e.CompileTemplateAsync("DeliveryNote");
|
||||
await e.CompileTemplateAsync("CreditNote");
|
||||
await e.CompileTemplateAsync("DeliveryJournal");
|
||||
await e.CompileTemplateAsync("Letterhead");
|
||||
await e.CompileTemplateAsync("DeliveryConfirmation");
|
||||
|
||||
Engine = e;
|
||||
evtHandler();
|
||||
}
|
||||
|
||||
public static async Task<string> CompileRenderAsync(string key, object model) {
|
||||
if (Engine == null) throw new InvalidOperationException("The razor engine has not been initialized yet");
|
||||
return await Engine.CompileRenderAsync(key, model);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user