Module:Yesno and Template:Tag: Difference between pages

From Frontierpedia, the Microsoft Agent encyclopedia
(Difference between pages)
en>Mr. Stradivarius
(fix logic for the case where the first positional parameter is "¬")
 
en>Happy-melon
(fix)
 
Line 1: Line 1:
local p = {}
<tt>{{#switch:{{{3|pair}}
 
|close
function p.yesno(frame)
|single   = <!--nothing-->
 
|open
    -- defaults
|pair
    local retvals = {
|#default = <nowiki><</nowiki>{{{1|tag}}}{{#if:{{{params|}}}|&#32;{{{params}}}}}<nowiki>></nowiki>
        yes   = "yes",
}}{{#switch:{{{3|pair}}}
        no    = "",
|open
        ["¬"] = ""
|close
    }
|single  =
 
|pair
    -- Allow arguments to override defaults.
|#default = {{{2|}}}
    -- 'any' tracks the presence of any arguments at all.
}}{{#switch:{{{3|pair}}}
    local args = frame.args
|open
    local any = false
|single  = <!--nothing-->
    for k,v in pairs(args) do
  |close
        any = true
|pair
        retvals[k] = v
|#default = <nowiki></</nowiki>{{{1|tag}}}<nowiki>></nowiki>
    end
}}{{#switch:{{{3|pair}}}
    -- If there are no arguments, try and get them from the parent frame.
  |single  = <nowiki></</nowiki>{{{1|tag}}}{{#if:{{{params|}}}|&#32;{{{params}}}}}<nowiki> /></nowiki>
    if any == false then
}}</tt><noinclude>
        local pframe = frame:getParent()
{{documentation}}
        args = pframe.args
</noinclude>
        for k,v in pairs(args) do
            any = true
            retvals[k] = v
        end
    end   
 
    val = args[1]
 
    -- First deal with the case if val is nil or "¬", then deal with other cases.
    if val == nil or val == '¬' then
        return retvals['¬']
    end
 
    val = val:lower()          -- Coerce to blank if nil; make lowercase.
    val = val:match'^%s*(.*%S)' or '' -- Trim whitespace.
 
    if val == '' then
        return retvals['blank'] or retvals['no']
    elseif val == 'n' or val == 'no' or val == '0' then
        return retvals['no']
    elseif val == 'y' or val == 'yes' or val == '1' or retvals['def'] == nil then
        return retvals['yes']
    else
        return retvals['def']
    end
end
 
return p

Revision as of 15:06, 31 January 2009

<tag></tag>