mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-04 18:41:51 +00:00
optimize gui.template
This commit is contained in:
parent
1e90115a26
commit
f944dfb51d
1 changed files with 10 additions and 8 deletions
|
|
@ -226,15 +226,17 @@ end
|
|||
|
||||
function gui.template(name, params)
|
||||
local text = file.read(file.find("layouts/templates/"..name..".xml"))
|
||||
for k,v in pairs(params) do
|
||||
local arg = tostring(v):gsub("'", "\\'"):gsub('"', '\\"')
|
||||
text = text:gsub("(%%{"..k.."})", arg)
|
||||
end
|
||||
text = text:gsub("if%s*=%s*'%%{%w+}'", "if=''")
|
||||
text = text:gsub("if%s*=%s*\"%%{%w+}\"", "if=\"\"")
|
||||
text = text:gsub("%%{([^}]+)}", function(n)
|
||||
local s = params[n]
|
||||
if not s or #s == 0 then
|
||||
return
|
||||
end
|
||||
local e = string.escape(s)
|
||||
return e:sub(2, #e-1)
|
||||
end)
|
||||
text = text:gsub('if%s*=%s*[\'"]%%{%w+}[\'"]', "if=\"\"")
|
||||
-- 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
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue