From 0624de93654b515fdf14b6aeb313a40f24ebee95 Mon Sep 17 00:00:00 2001 From: Annwan Date: Tue, 13 Aug 2024 00:25:45 +0200 Subject: [PATCH] [Dispatch] convert to template --- main.lua | 40 +++++++++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/main.lua b/main.lua index 7e7f02b..85defa3 100755 --- a/main.lua +++ b/main.lua @@ -1,10 +1,31 @@ #!/usr/bin/env lua local fcgi = require"fcgi" +local etlua = require"etlua" apps = { yqtemplate = require"yqtemplate" } +local template = etlua.compile[[ + + + + Annwan's CGI scripts + + + <% if app and app ~= nil then %> +

No such application: <%= app -%>

+ <% end %> +

Available Applications

+ + + +]] + while fcgi.accept() do app = fcgi.getenv("DOCUMENT_URI"):sub(6) appfn = apps[app] @@ -12,20 +33,9 @@ while fcgi.accept() do appfn.run(fcgi) else fcgi.print"Content-Type: text/html; charset=utf-8\r\n\r\n" - fcgi.print[[ - -Annwan's CGI scripts -]] - if app and app ~= "" then - fcgi.print("

No such application: " .. app .. "\n") - end - fcgi.print("

Available applications:

- -]] + fcgi.print(template{ + app = app, + apps = apps + }) end end