forked from PPolza/XServer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRenderer.cs
48 lines (39 loc) · 1.2 KB
/
Renderer.cs
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
42
43
44
45
46
47
48
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace XServer
{
public class Renderer
{
public static string TemplateDirectory = "";
public static string Render(string templateName, Dictionary<string, string> values)
{
if (File.Exists(TemplateDirectory + templateName + ".html"))
{
var sR = new StreamReader(File.OpenRead(TemplateDirectory + templateName + ".html"));
string fileContent = sR.ReadToEnd();
foreach (var d in values)
{
fileContent = fileContent.Replace("{"+d.Key+"}",d.Value);
}
sR.Close();
sR.Dispose();
return fileContent;
}
else
{
Logger.LogError("Can't find template " + templateName);
}
return "";
}
public static string RenderMain(string template, string body)
{
var d = new Dictionary<string, string>();
d["BODY"] = body;
return Render(template, d);
}
}
}