mirror of
https://github.com/lxsang/antd-web-apps
synced 2024-11-20 02:18:20 +01:00
Silk can now handle the asset file directly in url
This commit is contained in:
parent
48ad3a30da
commit
8e8139e709
@ -1,6 +1,6 @@
|
|||||||
BUILDDIR = ../build/blog
|
BUILDDIR = ../build/blog
|
||||||
|
|
||||||
copyfiles = *.html assets *.lua view
|
copyfiles = *.html assets *.lua view robot.txt
|
||||||
|
|
||||||
main:
|
main:
|
||||||
- mkdir $(BUILDDIR)
|
- mkdir $(BUILDDIR)
|
||||||
|
2
blog/robot.txt
Normal file
2
blog/robot.txt
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
User-agent: *
|
||||||
|
Allow: /
|
@ -1,6 +1,6 @@
|
|||||||
BUILDDIR = ../build/info
|
BUILDDIR = ../build/info
|
||||||
|
|
||||||
copyfiles = index.ls style.css router.lua models views controllers logs
|
copyfiles = index.ls style.css router.lua models views controllers logs robot.txt
|
||||||
|
|
||||||
main:
|
main:
|
||||||
- mkdir $(BUILDDIR)
|
- mkdir $(BUILDDIR)
|
||||||
|
2
info/robot.txt
Normal file
2
info/robot.txt
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
User-agent: *
|
||||||
|
Allow: /
|
@ -5,9 +5,9 @@
|
|||||||
|
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<script type="text/javascript" src="<?=HTTP_ROOT?>/asset/get/rst/gscripts/showdown.min.js"></script>
|
<script type="text/javascript" src="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="style.css" />
|
||||||
<link rel="stylesheet" type="text/css" href="<?=HTTP_ROOT?>/asset/get/rst/font-awesome.css" />
|
<link rel="stylesheet" type="text/css" href="rst/font-awesome.css" />
|
||||||
<title>Porfolio</title>
|
<title>Porfolio</title>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
@ -90,13 +90,19 @@ function AssetController:get(...)
|
|||||||
local path = WWW_ROOT..DIR_SEP..implode({...}, DIR_SEP)
|
local path = WWW_ROOT..DIR_SEP..implode({...}, DIR_SEP)
|
||||||
local mime = std.mimeOf(path)
|
local mime = std.mimeOf(path)
|
||||||
|
|
||||||
if POLICY.mimes[mime] then
|
if ulib.exists(path) then
|
||||||
std.header(mime)
|
if POLICY.mimes[mime] then
|
||||||
if std.isBinary(path) then
|
std.header(mime)
|
||||||
std.fb(path)
|
if std.isBinary(path) then
|
||||||
else
|
std.fb(path)
|
||||||
std.f(path)
|
else
|
||||||
|
std.f(path)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
self:error("Access fobiden: "..path)
|
||||||
end
|
end
|
||||||
|
else
|
||||||
|
self:error("Assset file not found: "..path)
|
||||||
end
|
end
|
||||||
return false
|
return false
|
||||||
end
|
end
|
@ -1,6 +1,5 @@
|
|||||||
|
|
||||||
--define the class
|
--define the class
|
||||||
BaseObject:subclass ("Router",{registry = {}})
|
BaseObject:subclass("Router", {registry = {}})
|
||||||
function Router:setPath(path)
|
function Router:setPath(path)
|
||||||
self.path = path
|
self.path = path
|
||||||
end
|
end
|
||||||
@ -25,76 +24,95 @@ function Router:infer(url)
|
|||||||
-- if user dont provice the url, try to infer it
|
-- if user dont provice the url, try to infer it
|
||||||
-- from the REQUEST
|
-- from the REQUEST
|
||||||
url = url or REQUEST.query.r
|
url = url or REQUEST.query.r
|
||||||
url = std.trim(url,"/")
|
url = std.trim(url, "/")
|
||||||
local args = explode(url,"/")
|
local args = explode(url, "/")
|
||||||
local data = {
|
local data = {
|
||||||
name = 'index',
|
name = "index",
|
||||||
action = 'index',
|
action = "index",
|
||||||
args = {}
|
args = {}
|
||||||
}
|
}
|
||||||
if args and #args > 0 and args[1] ~= "" then
|
if args and #args > 0 and args[1] ~= "" then
|
||||||
data.name = args[1]
|
data.name = args[1]
|
||||||
if args[2] then data.action = args[2] end
|
if args[2] then
|
||||||
for i = 3, #args do table.insert( data.args, args[i] ) end
|
data.action = args[2]
|
||||||
|
end
|
||||||
|
for i = 3, #args do
|
||||||
|
table.insert(data.args, args[i])
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
self:log('Controller: '..JSON.encode(data))
|
|
||||||
-- find the controller class and init it
|
-- find the controller class and init it
|
||||||
local controller_name = firstToUpper(data.name).."Controller"
|
local controller_name = firstToUpper(data.name) .. "Controller"
|
||||||
local controller_path = self.path.."."..controller_name
|
local controller_path = self.path .. "." .. controller_name
|
||||||
-- require the controller module
|
-- require the controller module
|
||||||
-- ignore the error
|
-- ignore the error
|
||||||
local r,e = pcall(require, controller_path)
|
local r, e = pcall(require, controller_path)
|
||||||
--require(controller_path)
|
--require(controller_path)
|
||||||
if not _G[controller_name] then
|
if not _G[controller_name] then
|
||||||
data.controller = NotfoundController:new{ registry = self.registry }
|
-- verify if it is an asset
|
||||||
data.args = {controller_name, e}
|
url = url:gsub("/", DIR_SEP)
|
||||||
data.action = "index"
|
if ulib.exists(WWW_ROOT..DIR_SEP..url) then
|
||||||
data.name = "notfound"
|
data.controller = AssetController:new {registry = self.registry}
|
||||||
|
data.action = "get"
|
||||||
|
data.name = "asset"
|
||||||
|
data.args ={url}
|
||||||
|
else
|
||||||
|
-- let the notfound controller handle the error
|
||||||
|
data.controller = NotfoundController:new {registry = self.registry}
|
||||||
|
data.args = {controller_name, e}
|
||||||
|
data.action = "index"
|
||||||
|
data.name = "notfound"
|
||||||
|
end
|
||||||
else
|
else
|
||||||
data.controller = _G[controller_name]:new{ registry = self.registry }
|
-- create the coresponding controller
|
||||||
if not data.controller[data.action] then
|
data.controller = _G[controller_name]:new {registry = self.registry}
|
||||||
|
if not data.controller[data.action] then
|
||||||
data.args = {data.action}
|
data.args = {data.action}
|
||||||
data.action = "actionnotfound"
|
data.action = "actionnotfound"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
self:log("Controller: " .. data.controller.class .. ", action: "..data.action..", args: ".. JSON.encode(data.args))
|
||||||
return data
|
return data
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
function Router:delegate()
|
function Router:delegate()
|
||||||
local views = {}
|
local views = {}
|
||||||
local data = self:infer()
|
local data = self:infer()
|
||||||
-- set the controller to the main controller
|
-- set the controller to the main controller
|
||||||
data.controller.main = true
|
data.controller.main = true
|
||||||
views.__main__ = self:call(data)
|
views.__main__ = self:call(data)
|
||||||
if not views.__main__ then return end
|
if not views.__main__ then
|
||||||
|
return
|
||||||
|
end
|
||||||
-- get all visible routes
|
-- get all visible routes
|
||||||
local routes = self:dependencies(data.name.."/"..data.action)
|
local routes = self:dependencies(data.name .. "/" .. data.action)
|
||||||
for k, v in pairs(routes) do
|
for k, v in pairs(routes) do
|
||||||
data = self:infer(v)
|
data = self:infer(v)
|
||||||
views[k] = self:call(data)
|
views[k] = self:call(data)
|
||||||
end
|
end
|
||||||
-- now require the main page to put the view
|
-- now require the main page to put the view
|
||||||
|
|
||||||
local fn, e = loadscript(VIEW_ROOT..DIR_SEP..self.registry.layout..DIR_SEP.."layout.ls")
|
local fn, e = loadscript(VIEW_ROOT .. DIR_SEP .. self.registry.layout .. DIR_SEP .. "layout.ls")
|
||||||
html()
|
html()
|
||||||
if fn then
|
if fn then
|
||||||
local r,o = pcall(fn, views)
|
local r, o = pcall(fn, views)
|
||||||
if not r then
|
if not r then
|
||||||
self:error(o)
|
self:error(o)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
self:error("The index page is not found for layout: "..self.registry.layout)
|
self:error("The index page is not found for layout: " .. self.registry.layout)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function Router:dependencies(url)
|
function Router:dependencies(url)
|
||||||
if not self.routes[self.registry.layout] then return {} end
|
if not self.routes[self.registry.layout] then
|
||||||
|
return {}
|
||||||
|
end
|
||||||
local list = {}
|
local list = {}
|
||||||
--self:log("comparing "..url)
|
--self:log("comparing "..url)
|
||||||
for k,v in pairs(self.routes[self.registry.layout]) do
|
for k, v in pairs(self.routes[self.registry.layout]) do
|
||||||
v.url = std.trim(v.url,"/")
|
v.url = std.trim(v.url, "/")
|
||||||
if v.visibility == "ALL" then
|
if v.visibility == "ALL" then
|
||||||
list[k] = v.url
|
list[k] = v.url
|
||||||
elseif v.visibility.routes then
|
elseif v.visibility.routes then
|
||||||
@ -114,7 +132,7 @@ end
|
|||||||
|
|
||||||
function Router:call(data)
|
function Router:call(data)
|
||||||
data.controller.template:setView(data.action, data.name)
|
data.controller.template:setView(data.action, data.name)
|
||||||
local obj = data.controller[data.action](data.controller,table.unpack(data.args))
|
local obj = data.controller[data.action](data.controller, table.unpack(data.args))
|
||||||
if obj then
|
if obj then
|
||||||
return data.controller.template
|
return data.controller.template
|
||||||
else
|
else
|
||||||
@ -124,4 +142,4 @@ end
|
|||||||
|
|
||||||
function Router:route(layout, dependencies)
|
function Router:route(layout, dependencies)
|
||||||
self.routes[layout] = dependencies
|
self.routes[layout] = dependencies
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user