-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Page.cs
64 lines (56 loc) · 2.12 KB
/
Page.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
namespace Datasilk
{
public class Page: Request
{
public string title = "Datasilk";
public string description = "";
public string headCss = "";
public string favicon = "/images/favicon.png";
public string svgIcons = "";
public string scripts = "";
public bool useTapestry = true;
public Page(Core DatasilkCore): base (DatasilkCore)
{
svgIcons = DatasilkCore.Server.LoadFileFromCache("/content/themes/default/icons.svg");
}
public virtual string Render(string[] path, string body = "", object metadata = null)
{
//renders HTML layout
var scaffold = new Scaffold(S.Server.MapPath("/layout.html"), "", S.Server.Scaffold);
scaffold.Data["title"] = title;
scaffold.Data["description"] = description;
scaffold.Data["head-css"] = headCss;
scaffold.Data["favicon"] = favicon;
scaffold.Data["svg-icons"] = svgIcons;
scaffold.Data["body"] = body;
//add initialization script
scaffold.Data["scripts"] = scripts;
return scaffold.Render();
}
public string AccessDenied(bool htmlOutput = true, Page login = null)
{
if (htmlOutput == true)
{
if (!CheckSecurity() && login != null)
{
return login.Render(new string[] { });
}
var scaffold = new Scaffold(S.Server.MapPath("/access-denied.html"), "", S.Server.Scaffold);
return scaffold.Render();
}
return "Access Denied";
}
public string Redirect(string url)
{
return "<script language=\"javascript\">window.location.href = '" + url + "';</script>";
}
public void AddScript(string url)
{
scripts += "<script language=\"javascript\" src=\"" + url + "\"></script>";
}
public void AddCSS(string url)
{
headCss += "<link rel=\"stylesheet\" type=\"text/css\" href=\"" + url + "\"></link>";
}
}
}