Module:Side box: Difference between revisions
m 1 revision imported |
No edit summary |
||
| Line 1: | Line 1: | ||
local yesno = require | -- FIX: Import yesno function correctly | ||
local yesno | |||
local success, result = pcall(require, 'Module:Yesno') | |||
if success and type(result) == "table" then | |||
yesno = result._yesno or result.yesno | |||
if type(yesno) ~= "function" then | |||
yesno = function(val, default) | |||
if val == nil then return default end | |||
if type(val) == "boolean" then return val end | |||
if type(val) == "string" then | |||
val = val:lower():match('^%s*(.-)%s*$') or "" | |||
if val == 'yes' or val == 'y' or val == 'true' or val == 't' or val == 'on' or val == '1' then | |||
return true | |||
elseif val == 'no' or val == 'n' or val == 'false' or val == 'f' or val == 'off' or val == '0' then | |||
return false | |||
end | |||
elseif type(val) == "number" then | |||
if val == 1 then return true | |||
elseif val == 0 then return false end | |||
end | |||
return default | |||
end | |||
end | |||
else | |||
yesno = function(val, default) | |||
if val == nil then return default end | |||
if type(val) == "boolean" then return val end | |||
if type(val) == "string" then | |||
val = val:lower():match('^%s*(.-)%s*$') or "" | |||
if val == 'yes' or val == 'y' or val == 'true' or val == 't' or val == 'on' or val == '1' then | |||
return true | |||
elseif val == 'no' or val == 'n' or val == 'false' or val == 'f' or val == 'off' or val == '0' then | |||
return false | |||
end | |||
elseif type(val) == "number" then | |||
if val == 1 then return true | |||
elseif val == 0 then return false end | |||
end | |||
return default | |||
end | |||
end | |||
local p = {} | local p = {} | ||
| Line 160: | Line 201: | ||
local args = {} | local args = {} | ||
for k, v in pairs(origArgs) do | for k, v in pairs(origArgs) do | ||
v = v:match('%s*(.-)%s*$') | if v then | ||
v = v:match('%s*(.-)%s*$') | |||
if v ~= '' then | |||
args[k] = v | |||
end | |||
end | end | ||
end | end | ||