-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
37 lines (30 loc) · 1.09 KB
/
Program.cs
File metadata and controls
37 lines (30 loc) · 1.09 KB
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
using System.Runtime.InteropServices;
using System.Text.Json.Serialization;
using Extism;
using Mustachio;
using System.Dynamic;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
namespace MustachioPlugin;
public class Program
{
public static void Main()
{
// Note: a `Main` method is required for the app to compile
}
[UnmanagedCallersOnly(EntryPoint = "combine")]
public static int MustachioCombine() {
var parameters = Pdk.GetInputJson(SourceGenerationContext.Default.MustachioInput);
var input = new MustachioInput(parameters.template, parameters.model_json);
// Parse the template
var template = Mustachio.Parser.Parse(input.template);
// Build the ExpandoObject
dynamic? model = JsonConvert.DeserializeObject<ExpandoObject>(input.model_json);
var content = template(model);
Pdk.SetOutput(content);
return 0;
}
}
[JsonSerializable(typeof(MustachioInput))]
public partial class SourceGenerationContext : JsonSerializerContext {}
public record MustachioInput(string template, string model_json);