summaryrefslogtreecommitdiffhomepage
path: root/src/ffluci/dispatcher.lua
diff options
context:
space:
mode:
authorSteven Barth <steven@midlink.org>2008-03-17 18:06:41 +0000
committerSteven Barth <steven@midlink.org>2008-03-17 18:06:41 +0000
commitcfe8fc894fb2e51885b7a992ea685c71baf6b769 (patch)
treefe4edccaa8985d4567cd1ba3be202478c520ecd7 /src/ffluci/dispatcher.lua
parent38d279e4eaf840ef014e0a76e4f1857d284d36b2 (diff)
* Added class support to template engine
* Cleaned up dispatcher * Added 404 error page * Cleaned up properties
Diffstat (limited to 'src/ffluci/dispatcher.lua')
-rw-r--r--src/ffluci/dispatcher.lua27
1 files changed, 16 insertions, 11 deletions
diff --git a/src/ffluci/dispatcher.lua b/src/ffluci/dispatcher.lua
index f43d7f5a9d..bf2ac511e4 100644
--- a/src/ffluci/dispatcher.lua
+++ b/src/ffluci/dispatcher.lua
@@ -100,16 +100,17 @@ function dispatch(req)
end
end
-
-- Sends a 404 error code and renders the "error404" template if available
function error404(message)
message = message or "Not Found"
- ffluci.http.status(404, "Not Found")
+ local s, t = pcall(ffluci.template.Template, "error404")
- if not pcall(ffluci.template.render, "error404") then
+ if not s then
ffluci.http.textheader()
- print(message)
+ print(message)
+ else
+ t:render()
end
return false
end
@@ -118,9 +119,13 @@ end
function error500(message)
ffluci.http.status(500, "Internal Server Error")
- if not pcall(ffluci.template.render, "error500") then
+ local s, t = pcall(ffluci.template.Template, "error500")
+
+ if not s then
ffluci.http.textheader()
print(message)
+ else
+ t:render()
end
return false
end
@@ -147,14 +152,15 @@ end
function simpleview(request)
local i18n = require("ffluci.i18n")
local tmpl = require("ffluci.template")
- local conf = require("ffluci.config")
local disp = require("ffluci.dispatcher")
- pcall(i18n.load, request.module .. "." .. conf.lang)
- if not pcall(tmpl.get, request.module .. "/" .. request.action) then
+ i18n.loadc(request.module)
+ local s, t = pcall(tmpl.Template, request.module .. "/" .. request.action)
+
+ if not s then
disp.error404()
else
- tmpl.render(request.module .. "/" .. request.action)
+ t:render()
end
end
@@ -162,10 +168,9 @@ end
-- action_"request.action" and calls it
function action(request)
local i18n = require("ffluci.i18n")
- local conf = require("ffluci.config")
local disp = require("ffluci.dispatcher")
- pcall(i18n.load, request.module .. "." .. conf.lang)
+ i18n.loadc(request.module)
local action = getfenv()["action_" .. request.action:gsub("-", "_")]
if action then
action()