Module:Hatnote inline: Difference between revisions
enwiki>Ankush.srg m 1 revision imported |
No edit summary |
||
| (One intermediate revision by the same user not shown) | |||
| Line 9: | Line 9: | ||
local mHatnote = require('Module:Hatnote') | local mHatnote = require('Module:Hatnote') | ||
local mArguments = require('Module:Arguments') | local mArguments = require('Module:Arguments') | ||
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 20: | Line 62: | ||
['</div>$'] = '</span>' | ['</div>$'] = '</span>' | ||
} | } | ||
for k, v in pairs(subs) do hatnote = string.gsub(hatnote, k, v, 1) end | for k, v in pairs(subs) do | ||
hatnote = string.gsub(hatnote, k, v, 1) | |||
end | |||
end | end | ||
return hatnote | return hatnote | ||