mirror of
https://github.com/lxsang/antd-web-apps
synced 2024-12-26 01:18:21 +01:00
the info page now use the silk framework
This commit is contained in:
parent
5f5c165f0b
commit
dc9e9a85d6
@ -1,6 +1,6 @@
|
||||
BUILDDIR = ../build/info
|
||||
|
||||
copyfiles = index.ls style.css router.lua models views controllers
|
||||
copyfiles = index.ls style.css router.lua models views controllers logs
|
||||
|
||||
main:
|
||||
- mkdir $(BUILDDIR)
|
||||
|
@ -1,10 +1,47 @@
|
||||
IndexController = BaseController:extends{
|
||||
class = "IndexController",
|
||||
registry = {},
|
||||
models = { "sections", "user", "category" }
|
||||
models = { "sections", "category" }
|
||||
}
|
||||
|
||||
local sectionsByCid = function(db, id)
|
||||
local cond = { exp = { ["="] = { cid = id } } , order = { start = "DESC" } }
|
||||
local data, a = db:find(cond)
|
||||
return data,a
|
||||
end
|
||||
|
||||
function IndexController:index(...)
|
||||
local args = {...}
|
||||
-- now read all the data
|
||||
-- get all root sections as the toc
|
||||
local cond = { exp = { ["="] = { pid = 0 } }, order = { name = "ASC" } }
|
||||
local data, a = self.category:find(cond)
|
||||
local toc = {}
|
||||
if not data then
|
||||
return self:error("Cannot query the ToC")
|
||||
end
|
||||
-- find all children category of the toc
|
||||
for key,cat in pairs(data) do
|
||||
cat.name = cat.name:gsub("^%d+%.","")
|
||||
table.insert( toc, {cat.name, cat.id} )
|
||||
cond = { exp = { ["="] = { pid = cat.id } }, order = { name = "ASC" } }
|
||||
local children, b = self.category:find(cond)
|
||||
if children and #children > 0 then
|
||||
for k,v in pairs(children) do
|
||||
v.sections = sectionsByCid(self.sections,v.id)
|
||||
end
|
||||
cat.children = children
|
||||
else
|
||||
cat.sections = sectionsByCid(self.sections,cat.id)
|
||||
end
|
||||
end
|
||||
self.template:set("data", data)
|
||||
self.template:set("toc", toc)
|
||||
return true
|
||||
end
|
||||
|
||||
function IndexController:notoc(...)
|
||||
self.template:setView("index")
|
||||
return self:index(table.unpack({...}))
|
||||
end
|
||||
|
||||
|
7
info/controllers/TocController.lua
Normal file
7
info/controllers/TocController.lua
Normal file
@ -0,0 +1,7 @@
|
||||
TocController = BaseController:extends{
|
||||
class = "TocController"
|
||||
}
|
||||
|
||||
function TocController:index(...)
|
||||
return true
|
||||
end
|
14
info/controllers/UserController.lua
Normal file
14
info/controllers/UserController.lua
Normal file
@ -0,0 +1,14 @@
|
||||
UserController = BaseController:extends{
|
||||
class = "UserController",
|
||||
models = {"user"}
|
||||
}
|
||||
|
||||
function UserController:index(...)
|
||||
local args = {...}
|
||||
local data = self.user:findAll()
|
||||
if not data or not data[1] then
|
||||
self:error("Cannot fetch user info")
|
||||
end
|
||||
self.template:set("data", data[1])
|
||||
return true
|
||||
end
|
@ -5,7 +5,7 @@
|
||||
-- some global variables
|
||||
DIR_SEP = "/"
|
||||
WWW_ROOT = "/opt/www/htdocs/info"
|
||||
HTTP_ROOT = "https://apps.localhost:9195/"
|
||||
HTTP_ROOT = "https://info.localhost:9195/"
|
||||
-- class path: path.to.class
|
||||
BASE_FRW = ""
|
||||
-- class path: path.to.class
|
||||
@ -34,19 +34,19 @@ router:setPath(CONTROLLER_ROOT)
|
||||
-- example of depedencies to the current main route
|
||||
-- each layout may have different dependencies
|
||||
local default_routes_dependencies = {
|
||||
edit = {
|
||||
url = "post/edit",
|
||||
user = {
|
||||
url = "user/index",
|
||||
visibility = "ALL"
|
||||
},
|
||||
toc = {
|
||||
url = "toc/index",
|
||||
visibility = {
|
||||
shown = true,
|
||||
routes = {
|
||||
["post/index"] = true
|
||||
["index/index"] = true
|
||||
}
|
||||
}
|
||||
},
|
||||
--category = {
|
||||
-- url = "cat/index",
|
||||
-- visibility = "ALL"
|
||||
--}
|
||||
}
|
||||
}
|
||||
router:route('default', default_routes_dependencies )
|
||||
router:delegate()
|
||||
|
@ -1,3 +1,92 @@
|
||||
<?lua
|
||||
echo("main page")
|
||||
local args = {...}
|
||||
local data = args[1].data
|
||||
if not data then return end
|
||||
|
||||
for k,v in pairs(data) do
|
||||
if v.children then
|
||||
?>
|
||||
<div class="container" id =<?='"toc'..v.id..'"'?>>
|
||||
<h1><?=v.name:gsub("^%d+%.","")?></h1>
|
||||
<?lua
|
||||
for l,child in pairs(v.children) do
|
||||
?>
|
||||
<div class="sub-container">
|
||||
<h2><?=child.name:gsub("^%d+%.","")?></h2>
|
||||
<?lua
|
||||
if child.sections then
|
||||
for m, entry in pairs(child.sections) do
|
||||
?>
|
||||
<div class= "entry">
|
||||
<p>
|
||||
<?lua if entry.title ~= "" then ?>
|
||||
<span class= "fa fa-bookmark"></span>
|
||||
<span class= "title"><?=entry.title?></span>
|
||||
<?lua end ?>
|
||||
<span class= "title-optional"></span>
|
||||
<span class="location"><?=entry.location?></span>
|
||||
</p>
|
||||
<div class="entry-short-des">
|
||||
<span><?=entry.subtitle?></span>
|
||||
<span class="date">
|
||||
<?lua
|
||||
if entry["start"]:match("^20%d.*") and entry['end']:match("^20%d.*") then
|
||||
echo(entry.start.."-"..entry['end'])
|
||||
end
|
||||
?>
|
||||
</span>
|
||||
</div>
|
||||
<div class="entry-description">
|
||||
<?=entry.content?>
|
||||
</div>
|
||||
</div>
|
||||
<?lua
|
||||
end
|
||||
end
|
||||
?>
|
||||
</div>
|
||||
<?lua
|
||||
end
|
||||
?>
|
||||
</div>
|
||||
<?lua
|
||||
else
|
||||
?>
|
||||
<div class="container" id =<?='"toc'..v.id..'"'?>>
|
||||
<h1><?=v.name?></h1>
|
||||
<?lua
|
||||
if v.sections then
|
||||
for m, entry in pairs(v.sections) do
|
||||
?>
|
||||
<div class= "entry">
|
||||
<p>
|
||||
<?lua if entry.title ~= "" then ?>
|
||||
<span class= "fa fa-bookmark"></span>
|
||||
<span class= "title"><?=entry.title?></span>
|
||||
<?lua end ?>
|
||||
<span class= "title-optional"></span>
|
||||
<span class="location"><?=entry.location?></span>
|
||||
</p>
|
||||
<div class="entry-short-des">
|
||||
<span><?=entry.subtitle?></span>
|
||||
<span class="date">
|
||||
<?lua
|
||||
if entry["start"]:match("^20%d.*") and entry['end']:match("^20%d.*") then
|
||||
echo(entry.start.."-"..entry['end'])
|
||||
end
|
||||
?>
|
||||
</span>
|
||||
</div>
|
||||
<div class="entry-description">
|
||||
<?=entry.content?>
|
||||
</div>
|
||||
</div>
|
||||
<?lua
|
||||
end
|
||||
end
|
||||
?>
|
||||
</div>
|
||||
<?lua
|
||||
end
|
||||
end
|
||||
?>
|
@ -1,9 +1,51 @@
|
||||
<?lua
|
||||
echo("<h1>Default page</h1>")
|
||||
|
||||
local args = {...}
|
||||
local views = args[1]
|
||||
if views.__main__ then
|
||||
views.__main__:render()
|
||||
end
|
||||
?>
|
||||
?>
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<script type="text/javascript" src="<?=HTTP_ROOT?>/asset/get/rst/gscripts/showdown.min.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="<?=HTTP_ROOT?>/asset/get/style.css" />
|
||||
<link rel="stylesheet" type="text/css" href="<?=HTTP_ROOT?>/asset/get/rst/font-awesome.css" />
|
||||
<title>Porfolio</title>
|
||||
</head>
|
||||
<body>
|
||||
<div class="layout">
|
||||
<div class = "cv-content">
|
||||
<?lua
|
||||
if views.user then
|
||||
views.user:render()
|
||||
end
|
||||
if views.__main__ then
|
||||
views.__main__:render()
|
||||
end
|
||||
?>
|
||||
<div class = "container">
|
||||
<h1 style="margin:0;"></h1>
|
||||
<p style="text-align:right; padding:0; margin:0;color:#878887;">Powered by antd server, (C) 2017-2018 Xuan Sang LE</p>
|
||||
</div>
|
||||
</div>
|
||||
<?lua
|
||||
if views.toc then
|
||||
views.toc:set("data", views.__main__:get("toc"))
|
||||
views.toc:render()
|
||||
end
|
||||
?>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
window.onload = function()
|
||||
{
|
||||
var els = document.getElementsByClassName("entry-description");
|
||||
var converter = new showdown.Converter();
|
||||
for(var i in els)
|
||||
{
|
||||
var text = els[i].innerHTML;
|
||||
var html = converter.makeHtml(text);
|
||||
els[i].innerHTML = html;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
17
info/views/default/toc/index.ls
Normal file
17
info/views/default/toc/index.ls
Normal file
@ -0,0 +1,17 @@
|
||||
<?lua
|
||||
if HEADER.mobile then return end
|
||||
local args = {...}
|
||||
local data = args[1].data
|
||||
if not data then return end
|
||||
?>
|
||||
<div class = "cv-toc">
|
||||
<ul>
|
||||
<?lua
|
||||
for k, v in pairs(data) do
|
||||
?>
|
||||
<li><a href=<?='"#toc'..v[2]..'"'?>><?=v[1]?></a></li>
|
||||
<?lua
|
||||
end
|
||||
?>
|
||||
</ul>
|
||||
</div>
|
24
info/views/default/user/index.ls
Normal file
24
info/views/default/user/index.ls
Normal file
@ -0,0 +1,24 @@
|
||||
<?lua
|
||||
local args = {...}
|
||||
local data = args[1].data
|
||||
?>
|
||||
|
||||
<h1>
|
||||
<span class="name"><?=data.fullname?></span>
|
||||
<span class="cv">Curriculum Vitae</span>
|
||||
</h1>
|
||||
<p class="coordination">
|
||||
<span class="fa fa-home"></span><?=data.address?></p>
|
||||
<p class="coordination">
|
||||
<span class="fa fa-phone"></span>
|
||||
<span class="text"><?=data.Phone?></span>
|
||||
<span class="fa fa-envelope-o"></span>
|
||||
<span class="text"><?=data.email?></span>
|
||||
<span class="fa fa-globe"></span>
|
||||
<span class="text"><a href ="<?=data.url?>"><?=data.url?></a></span>
|
||||
</p>
|
||||
<p class="shortbio">
|
||||
<span class="fa fa-quote-left"></span>
|
||||
<span><?=data.shortbiblio?></span>
|
||||
<span class="fa fa-quote-right"></span>
|
||||
</p>
|
@ -68,7 +68,8 @@ NotfoundController = BaseController:extends{ registry = {}, models = {} }
|
||||
|
||||
function NotfoundController:index(...)
|
||||
local args = {...}
|
||||
self:error("404: Controller "..args[1].." not found")
|
||||
local error = args[2] or ""
|
||||
self:error("404: Controller "..args[1].." not found : "..error)
|
||||
return false
|
||||
end
|
||||
|
||||
@ -86,9 +87,9 @@ function AssetController:get(...)
|
||||
if POLICY.mimes[mime] then
|
||||
std.header(mime)
|
||||
if std.isBinary(path) then
|
||||
std.f(path)
|
||||
else
|
||||
std.fb(path)
|
||||
else
|
||||
std.f(path)
|
||||
end
|
||||
end
|
||||
return false
|
||||
|
@ -22,4 +22,5 @@ function BaseObject:error(msg, trace)
|
||||
else
|
||||
error(msg)
|
||||
end
|
||||
return false
|
||||
end
|
@ -44,11 +44,11 @@ function Router:infer(url)
|
||||
local controller_path = self.path.."."..controller_name
|
||||
-- require the controller module
|
||||
-- ignore the error
|
||||
pcall(require, controller_path)
|
||||
local r,e = pcall(require, controller_path)
|
||||
--require(controller_path)
|
||||
if not _G[controller_name] then
|
||||
data.controller = NotfoundController:new{ registry = self.registry }
|
||||
data.args = {controller_name}
|
||||
data.args = {controller_name, e}
|
||||
data.action = "index"
|
||||
data.name = "notfound"
|
||||
else
|
||||
@ -113,9 +113,9 @@ function Router:dependencies(url)
|
||||
end
|
||||
|
||||
function Router:call(data)
|
||||
data.controller.template:setView(data.action, data.name)
|
||||
local obj = data.controller[data.action](data.controller,table.unpack(data.args))
|
||||
if obj then
|
||||
data.controller.template:setView(data.action, data.name)
|
||||
return data.controller.template
|
||||
else
|
||||
return false
|
||||
|
@ -11,21 +11,32 @@ function Template:set(k, v, ow)
|
||||
end
|
||||
end
|
||||
|
||||
function Template:get(k)
|
||||
return self.vars[k]
|
||||
end
|
||||
|
||||
function Template:remove(k)
|
||||
self.vars[k] = nil
|
||||
end
|
||||
|
||||
-- infer view path
|
||||
function Template:setView(name, controller)
|
||||
self.path = VIEW_ROOT..DIR_SEP..self.registry.layout..DIR_SEP..controller..DIR_SEP..name..".ls"
|
||||
if ulib.exists(self.path) then
|
||||
self.name = name
|
||||
if controller then
|
||||
self.controller = controller
|
||||
end
|
||||
end
|
||||
function Template:path()
|
||||
local path = VIEW_ROOT..DIR_SEP..self.registry.layout..DIR_SEP..self.controller..DIR_SEP..self.name..".ls"
|
||||
if ulib.exists(path) then
|
||||
return path
|
||||
else
|
||||
self:error("View not found: "..self.path)
|
||||
self:error("View not found: "..path)
|
||||
end
|
||||
end
|
||||
-- render the page
|
||||
function Template:render()
|
||||
local fn, e = loadscript(self.path)
|
||||
local fn, e = loadscript(self:path())
|
||||
if fn then
|
||||
local r,o = pcall(fn, self.vars)
|
||||
if not r then
|
||||
|
Loading…
Reference in New Issue
Block a user