From 6d8776a8a70126a142664d28b3ef766880503043 Mon Sep 17 00:00:00 2001 From: Ted Trask Date: Thu, 3 Nov 2011 19:43:08 +0000 Subject: Rewrite of snom xml_elem function --- config/templates/snom-template.lua | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/config/templates/snom-template.lua b/config/templates/snom-template.lua index e109c04..cdf830c 100644 --- a/config/templates/snom-template.lua +++ b/config/templates/snom-template.lua @@ -1,25 +1,25 @@ <% local values = ... -local function xml_elem(t,v,p,i) - local elem = t - if i == nil then - if v == true then - io.write('<'..elem..' perm="'..p..'">on\n') - elseif v == false then - io.write('<'..elem..' perm="'..p..'">off\n') - else - io.write('<'..elem..' perm="'..p..'">'..tostring(v)..'\n') - end - else - if v == true then - io.write('<'..elem..' idx="'..i..'" perm="'..p..'">on\n') - elseif v == false then - io.write('<'..elem..' idx="'..i..'" perm="'..p..'">off\n') - else - io.write('<'..elem..' idx="'..i..'" perm="'..p..'">'..tostring(v)..'\n') - end - end +local function onoff ( bool ) + if bool then + return "on" + else + return "off" + end +end + +local function xml_elem(elem,value,permissions,i) + local output = {"<", elem, ' perm="', permissions, '"'} + if i then output[#output+1] = ' idx="'..i..'"' end + output[#output+1] = ">" + if type(value) == "boolean" then + output[#output+1] = onoff(value) + elseif value then + output[#output+1] = value + end + output[#output+1] = "" + io.write(table.concat(output)) end %> -- cgit v1.2.3