X-Git-Url: https://git.archive.openwrt.org/?p=project%2Fluci.git;a=blobdiff_plain;f=libs%2Fweb%2Fluasrc%2Fdispatcher.lua;h=b1ed62b82fc246e11b30249008f936f092dcadc5;hp=c1e8d990f7ec70c7238f60c88cff75b342f0abff;hb=e12b8dbc1f8d4a0d820d89ab8ade4bc6f740bb63;hpb=8c9aef1b2de7df6838b939c9eb314ad613bab3d9 diff --git a/libs/web/luasrc/dispatcher.lua b/libs/web/luasrc/dispatcher.lua index c1e8d990f..b1ed62b82 100644 --- a/libs/web/luasrc/dispatcher.lua +++ b/libs/web/luasrc/dispatcher.lua @@ -281,6 +281,20 @@ function dispatch(request) assert(media, "No valid theme found") end + local function ifattr(cond, key, val) + if cond then + local env = getfenv(1) + return string.format( + ' %s="%s"', tostring(key), + luci.util.pcdata(tostring( val + or (type(env[key]) ~= "function" and env[key]) + or "" )) + ) + else + return '' + end + end + tpl.context.viewns = setmetatable({ write = luci.http.write; include = function(name) tpl.Template(name):render(getfenv(2)) end; @@ -290,7 +304,9 @@ function dispatch(request) pcdata = util.pcdata; media = media; theme = fs.basename(media); - resource = luci.config.main.resourcebase + resource = luci.config.main.resourcebase; + ifattr = ifattr; + attr = function(...) return ifattr(true, ...) end }, {__index=function(table, key) if key == "controller" then return build_url()