From 5a9d4f89c2212c83f05f910b6f2a176f21048ba6 Mon Sep 17 00:00:00 2001 From: FakeTruth Date: Mon, 29 Jul 2013 02:37:59 +0200 Subject: WebAdmin templates can use Lua New WebAdmin templates can use Lua to completely compose the pages themselves. This should allow infinite WebAdmin design possibilities. --- MCServer/webadmin/template.lua | 453 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 453 insertions(+) create mode 100644 MCServer/webadmin/template.lua (limited to 'MCServer') diff --git a/MCServer/webadmin/template.lua b/MCServer/webadmin/template.lua new file mode 100644 index 000000000..f508ad5aa --- /dev/null +++ b/MCServer/webadmin/template.lua @@ -0,0 +1,453 @@ +-- Use a table for fast concatenation of strings +local SiteContent = {} +function Output(String) + table.insert(SiteContent, String) +end + +function GetTableSize(Table) + local Size = 0 + for key,value in pairs(Table) do + Size = Size + 1 + end + return Size +end + +function GetDefaultPage() + local PM = cRoot:Get():GetPluginManager() + + local SubTitle = "Current Game" + local Content = "" + + Content = Content .. "

Server Name:

" + Content = Content .. "

" .. cRoot:Get():GetServer():GetServerID() .. "

" + + Content = Content .. "

Plugins:

" + Content = Content .. "

Players:


"; + + return Content, SubTitle +end + +function ShowPage(WebAdmin, TemplateRequest) + SiteContent = {} + local BaseURL = WebAdmin:GetBaseURL(TemplateRequest.Request.Path) + local Title = "MCServer" + local MemoryUsage = WebAdmin:GetMemoryUsage() + local NumChunks = cRoot:Get():GetTotalChunkCount() + local PluginPage = WebAdmin:GetPage(TemplateRequest.Request) + local PageContent = PluginPage.Content + local SubTitle = PluginPage.PluginName + if (PluginPage.TabName ~= "") then + SubTitle = PluginPage.PluginName .. " - " .. PluginPage.TabName + end + if (PageContent == "") then + PageContent, SubTitle = GetDefaultPage() + end + + Output([[ + + + + +]] .. Title .. [[ + + + + + + +
+ +

+ MCServer +

+
+
+ + + +

Welcome ]] .. TemplateRequest.Request.Username .. [[

+
+

]] .. SubTitle .. [[

+ ]] .. PageContent .. [[ +
+ + +
+ +
+ +
+ + + +
+ + + + ]]) + + return table.concat(SiteContent) +end \ No newline at end of file -- cgit v1.2.3