From 00d14adcf1b5e01bdb5e98fabcededdb62845178 Mon Sep 17 00:00:00 2001 From: "Frank A. Krueger" Date: Wed, 21 Feb 2018 16:32:12 -0800 Subject: [PATCH] Add HeadHtml, BodyHeaderHtml, and BodyFooterHtml to UI Fixes #78 --- Ooui/UI.cs | 56 ++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 37 insertions(+), 19 deletions(-) diff --git a/Ooui/UI.cs b/Ooui/UI.cs index 540f74c..5445e51 100644 --- a/Ooui/UI.cs +++ b/Ooui/UI.cs @@ -34,24 +34,9 @@ namespace Ooui public static byte[] ClientJsBytes => clientJsBytes; public static string ClientJsEtag => clientJsEtag; - public static string Template { get; set; } = $@" - - - @Title - - - - - - -
-@InitialHtml -
- - - - -"; + public static string HeadHtml { get; set; } = @""; + public static string BodyHeaderHtml { get; set; } = @""; + public static string BodyFooterHtml { get; set; } = @""; static string host = "*"; public static string Host { @@ -392,7 +377,40 @@ namespace Ooui public static string RenderTemplate (string webSocketPath, string title = "", string initialHtml = "") { - return Template.Replace ("@WebSocketPath", webSocketPath).Replace ("@Styles", rules.ToString ()).Replace ("@Title", title).Replace ("@InitialHtml", initialHtml); + using (var w = new System.IO.StringWriter ()) { + RenderTemplate (w, webSocketPath, title, initialHtml); + return w.ToString (); + } + } + + public static void RenderTemplate (TextWriter writer, string webSocketPath, string title, string initialHtml) + { + writer.Write (@" + + + "); + writer.Write (title.Replace ("&", "&").Replace ("<", "<")); + writer.Write (@" + + "); + writer.WriteLine (HeadHtml); + writer.WriteLine (@" + +"); + writer.WriteLine (BodyHeaderHtml); + writer.WriteLine (@"
"); + writer.WriteLine (initialHtml); + writer.Write (@"
+ + +"); + writer.WriteLine (BodyFooterHtml); + writer.WriteLine (@" +"); } class DataHandler : RequestHandler