summaryrefslogtreecommitdiffstats
path: root/api/WhatApi/Templates/TemplateFulfiller.cs
blob: e24e77d9d2e11a68e6a20626714dbc88220e66c1 (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
30
31
32
33
34
35
36
37
38
39
40
41
using Fluid;

namespace WhatApi.Templates;

public class TemplateFulfiller
{
    private static readonly FluidParser Parser = new();
    private static readonly TemplateContext EmptyContext = 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"));
    private static string WebTermsTemplate => File.ReadAllText(Path.Combine(TemplateDirectory, "web_terms.liquid"));


    public static string WebMapPage() {
        Parser.TryParse(WebMapTemplate, out var template);
        return template.Render(EmptyContext);
    }

    public static string WebUploadPage() {
        Parser.TryParse(WebUploadTemplate, out var template);
        return template.Render(EmptyContext);
    }

    public class WebLoginModel
    {
        public string Error { get; set; } = string.Empty;
    }

    public static string WebLoginPage(WebLoginModel model) {
        Parser.TryParse(WebLoginTemplate, out var template);
        var context = new TemplateContext(model);
        return template.Render(context);
    }

    public static string WebTermsPage() {
        Parser.TryParse(WebTermsTemplate, out var template);
        return template.Render(EmptyContext);
    }
}