summaryrefslogtreecommitdiffstats
path: root/api/WhatApi/Templates/TemplateFulfiller.cs
blob: 34337018588dddddde08ebf32ebc5c4fd8c45381 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
using Fluid;

namespace WhatApi.Templates;

public class TemplateFulfiller
{
    private static readonly FluidParser Parser = new();
    private static readonly string TemplateDirectory = Path.Combine(Directory.GetCurrentDirectory(), "Templates");
    private static string WebMapTemplate => File.ReadAllText(Path.Combine(TemplateDirectory, "web_map.liquid"));
    private static string WebUploadTemplate => File.ReadAllText(Path.Combine(TemplateDirectory, "web_upload.liquid"));
    private static string WebLoginTemplate => File.ReadAllText(Path.Combine(TemplateDirectory, "web_login.liquid"));

    public static string WebMapPage(object? data = null) {
        Parser.TryParse(WebMapTemplate, out var template);
        var context = data is null ? new TemplateContext() : new TemplateContext(data);
        return template.Render(context);
    }

    public static string WebUploadPage(object? data = null) {
        Parser.TryParse(WebUploadTemplate, out var template);
        var context = data is null ? new TemplateContext() : new TemplateContext(data);
        return template.Render(context);
    }
    public static string WebLoginPage(object? data = null) {
        Parser.TryParse(WebLoginTemplate, out var template);
        var context = data is null ? new TemplateContext() : new TemplateContext(data);
        return template.Render(context);
    }
}