Difference between revisions of "Module:Yesno"

From CryGaia Wiki
Jump to: navigation, search
(+support for on/off)
m (1 revision imported)
Line 1: Line 1:
-- Function allowing for consistent treatment of boolean-like wikitext input.
+
{{<includeonly>safesubst:</includeonly>#switch: {{<includeonly>safesubst:</includeonly>lc: {{{1|¬}}} }}
-- It works similarly to the template {{yesno}}.
+
|no
 
+
|n
return function (val, default)
+
|false
-- If your wiki uses non-ascii characters for any of "yes", "no", etc., you
+
|off
-- should replace "val:lower()" with "mw.ustring.lower(val)" in the
+
|0        = {{{no|<!-- null -->}}}
-- following line.
+
|        = {{{blank|{{{no|<!-- null -->}}}}}}
val = type(val) == 'string' and val:lower() or val
+
|¬        = {{{¬|}}}
if val == nil then
+
|yes
return nil
+
|y
elseif val == true
+
|true
or val == 'yes'
+
|on
or val == 'y'
+
|1       = {{{yes|yes}}}
or val == 'true'
+
|#default = {{{def|{{{yes|yes}}}}}}
or val == 't'
+
}}<noinclude>
or val == 'on'
+
{{Documentation}}
or tonumber(val) == 1
+
</noinclude>
then
 
return true
 
elseif val == false
 
or val == 'no'
 
or val == 'n'
 
or val == 'false'
 
or val == 'f'
 
or val == 'off'
 
or tonumber(val) == 0
 
then
 
return false
 
else
 
return default
 
end
 
end
 

Revision as of 06:52, 30 April 2018

[create] Documentation