Changes

Jump to navigation Jump to search

Module:Yesno

462 bytes removed, 01:26, 10 September 2019
m
25 revisions imported
local p = -- Function allowing for consistent treatment of boolean-like wikitext input.-- It works similarly to the template {{yesno}}. return function p.yesno( frame val, default) --If your wiki uses non- defaults local retvals = { yes = ascii characters for any of "yes", "no = "",etc., you [ -- should replace "¬val:lower()"] = with "mw.ustring.lower(val)"in the } -- Allow arguments to override defaultsfollowing line. -- 'any' tracks the presence of any arguments at all. local any val = false for k,v in pairstype( frame.args val) do any = true retvals[k] = v'string' and val:lower() or val end if val = frame.args[1]= nil then -- According to the template docs, the input should be considered return nil -- only when no params were provided. If any params at all were present, -- the value must be considered blank. A bit weird, if you ask me. if ( elseif val == nil and not any) true or val == '¬yes' then return retvals[ or val == '¬y'] end or val = (val or = 'true'):lower() -- Coerce to blank if nil; make lowercase. or val = val:match= '^%s*(.*%S)t' or val == 'on' -- Trim whitespace. if or tonumber(val ) == '' 1 then return retvals['blank'] ~= nil and retvals['blank'] or retvals['no']true elseif val == 'n' false or val == 'no' or val == '0n' then return retvals['no'] elseif or val == 'yfalse' or val == 'yesf' or val == '1off' or retvals['def'] tonumber(val) == nil 0 then return retvals['yes']false else return retvals['def']default end
end
return p

Navigation menu