luci-base: dispatcher.lua: factor out template class init into own function
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
This commit is contained in:
parent
a6b214f873
commit
1ec6e72106
1 changed files with 79 additions and 72 deletions
|
@ -668,55 +668,10 @@ function menu_json()
|
|||
})
|
||||
end
|
||||
|
||||
function dispatch(request)
|
||||
--context._disable_memtrace = require "luci.debug".trap_memtrace("l")
|
||||
local ctx = context
|
||||
ctx.path = request
|
||||
local function init_template_engine(ctx)
|
||||
local tpl = require "luci.template"
|
||||
local media = luci.config.main.mediaurlbase
|
||||
|
||||
local c = ctx.tree
|
||||
local stat
|
||||
if not c then
|
||||
c = createtree()
|
||||
end
|
||||
|
||||
local track = {}
|
||||
local args = {}
|
||||
ctx.args = args
|
||||
ctx.requestargs = ctx.requestargs or args
|
||||
local n
|
||||
local preq = {}
|
||||
local freq = {}
|
||||
|
||||
for i, s in ipairs(request) do
|
||||
preq[#preq+1] = s
|
||||
freq[#freq+1] = s
|
||||
c = c.nodes[s]
|
||||
n = i
|
||||
if not c then
|
||||
break
|
||||
end
|
||||
|
||||
util.update(track, c)
|
||||
|
||||
if c.leaf then
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
if c and c.leaf then
|
||||
for j=n+1, #request do
|
||||
args[#args+1] = request[j]
|
||||
freq[#freq+1] = request[j]
|
||||
end
|
||||
end
|
||||
|
||||
ctx.requestpath = ctx.requestpath or freq
|
||||
ctx.path = preq
|
||||
|
||||
-- Init template engine
|
||||
if (c and c.index) or not track.notemplate then
|
||||
local tpl = require("luci.template")
|
||||
local media = track.mediaurlbase or luci.config.main.mediaurlbase
|
||||
if not pcall(tpl.Template, "themes/%s/header" % fs.basename(media)) then
|
||||
media = nil
|
||||
for name, theme in pairs(luci.config.themes) do
|
||||
|
@ -787,6 +742,58 @@ function dispatch(request)
|
|||
return rawget(tbl, key) or _G[key]
|
||||
end
|
||||
end})
|
||||
|
||||
return tpl
|
||||
end
|
||||
|
||||
function dispatch(request)
|
||||
--context._disable_memtrace = require "luci.debug".trap_memtrace("l")
|
||||
local ctx = context
|
||||
ctx.path = request
|
||||
|
||||
local c = ctx.tree
|
||||
local stat
|
||||
if not c then
|
||||
c = createtree()
|
||||
end
|
||||
|
||||
local track = {}
|
||||
local args = {}
|
||||
ctx.args = args
|
||||
ctx.requestargs = ctx.requestargs or args
|
||||
local n
|
||||
local preq = {}
|
||||
local freq = {}
|
||||
|
||||
for i, s in ipairs(request) do
|
||||
preq[#preq+1] = s
|
||||
freq[#freq+1] = s
|
||||
c = c.nodes[s]
|
||||
n = i
|
||||
if not c then
|
||||
break
|
||||
end
|
||||
|
||||
util.update(track, c)
|
||||
|
||||
if c.leaf then
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
if c and c.leaf then
|
||||
for j=n+1, #request do
|
||||
args[#args+1] = request[j]
|
||||
freq[#freq+1] = request[j]
|
||||
end
|
||||
end
|
||||
|
||||
ctx.requestpath = ctx.requestpath or freq
|
||||
ctx.path = preq
|
||||
|
||||
-- Init template engine
|
||||
if (c and c.index) or not track.notemplate then
|
||||
init_template_engine(ctx)
|
||||
end
|
||||
|
||||
track.dependent = (track.dependent ~= false)
|
||||
|
|
Loading…
Reference in a new issue