1
0
mirror of https://github.com/lxsang/antd-web-apps synced 2025-07-17 06:09:50 +02:00
This commit is contained in:
Xuan Sang LE
2018-08-27 20:10:53 +02:00
parent 30762988cf
commit 48ad3a30da
14 changed files with 43 additions and 34 deletions

View File

@ -1,9 +1,11 @@
-- create class
BaseController = BaseObject:extends{
class="BaseController",
registry = {},
models = {},
main = false }
BaseObject:subclass("BaseController",
{
registry = {},
models = {},
main = false
})
-- set the name here in each subclasses
function BaseController:initialize()
for k, v in pairs(self.models) do
@ -24,6 +26,10 @@ function BaseController:initialize()
self.template = Template:new{registry = self.registry}
end
function BaseController:print(...)
return self:actionnotfound("print")
end
function BaseController:redirect(url)
std.status(301, "Moved Permanently")
std.custom_header("Content-Type","text/html")
@ -64,7 +70,7 @@ function BaseController:modelnotfound(...)
end
-- The not found controller
NotfoundController = BaseController:extends{ registry = {}, models = {} }
BaseController:subclass("NotfoundController",{ registry = {}, models = {} })
function NotfoundController:index(...)
local args = {...}
@ -74,7 +80,7 @@ function NotfoundController:index(...)
end
-- The asset controller for the static file
AssetController = BaseController:extends{name= "AssetController",registry={}, models={}}
BaseController:subclass("AssetController", {registry={}, models={}})
function AssetController:index(...)
local args = {...}
return self:get(table.unpack(args))

View File

@ -1,6 +1,6 @@
-- create class
BaseModel = BaseObject:extends{class="BaseModel",registry = {}}
BaseObject:subclass("BaseModel", {registry = {}})
function BaseModel:initialize()
self.db = self.registry.db

View File

@ -1,5 +1,8 @@
BaseObject = Object:extends{registry = {}, class="BaseObject"}
function BaseObject:subclass(name, args)
_G[name] = self:extends(args)
_G[name].class = name
end
function BaseObject:log(msg, level)
level = level or "INFO"
@ -12,6 +15,10 @@ function BaseObject:debug(msg)
self:log(msg, "DEBUG")
end
function BaseObject:print()
print(self.class)
end
function BaseObject:error(msg, trace)
html()
echo(msg)

View File

@ -2,7 +2,7 @@ sqlite = modules.sqlite()
if sqlite == nil then return 0 end
-- create class
DBHelper = BaseObject:extends{db=nil, class='DBHelper'}
BaseObject:subclass("DBHelper",{db={}})
function DBHelper:createTable(tbl, m)
if self:available(tbl) then return true end

View File

@ -1,6 +1,6 @@
--define the class
Router = BaseObject:extends{class="Router",registry = {}}
BaseObject:subclass ("Router",{registry = {}})
function Router:setPath(path)
self.path = path
end

View File

@ -1,5 +1,5 @@
-- create class
Template = BaseObject:extends{class="Template",registry = {}}
BaseObject:subclass("Template",{registry = {}})
function Template:initialize()
self.vars = {}