optimize gui.template
This commit is contained in:
parent
1e90115a26
commit
f944dfb51d
@ -226,15 +226,17 @@ end
|
|||||||
|
|
||||||
function gui.template(name, params)
|
function gui.template(name, params)
|
||||||
local text = file.read(file.find("layouts/templates/"..name..".xml"))
|
local text = file.read(file.find("layouts/templates/"..name..".xml"))
|
||||||
for k,v in pairs(params) do
|
text = text:gsub("%%{([^}]+)}", function(n)
|
||||||
local arg = tostring(v):gsub("'", "\\'"):gsub('"', '\\"')
|
local s = params[n]
|
||||||
text = text:gsub("(%%{"..k.."})", arg)
|
if not s or #s == 0 then
|
||||||
|
return
|
||||||
end
|
end
|
||||||
text = text:gsub("if%s*=%s*'%%{%w+}'", "if=''")
|
local e = string.escape(s)
|
||||||
text = text:gsub("if%s*=%s*\"%%{%w+}\"", "if=\"\"")
|
return e:sub(2, #e-1)
|
||||||
|
end)
|
||||||
|
text = text:gsub('if%s*=%s*[\'"]%%{%w+}[\'"]', "if=\"\"")
|
||||||
-- remove unsolved properties: attr='%{var}'
|
-- remove unsolved properties: attr='%{var}'
|
||||||
text = text:gsub("%s*%S+='%%{[^}]+}'%s*", " ")
|
text = text:gsub('%s*%S+=[\'"]%%{[^}]+}[\'"]%s*', " ")
|
||||||
text = text:gsub('%s*%S+="%%{[^}]+}"%s*', " ")
|
|
||||||
return text
|
return text
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user