Module:Yesno/doc: Difference between revisions
Appearance
Content deleted Content added
m rm {{Shared Template Warning}}. |
Marked this version for translation |
||
| (3 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
<languages/> |
|||
| ⚫ | |||
| ⚫ | |||
<noinclude><!-- |
<noinclude><!-- |
||
-->{{#ifeq:{{SUBPAGENAME}}|doc||{{Documentation subpage}}}}<!-- |
-->{{#ifeq:{{SUBPAGENAME}}|doc||{{Documentation subpage}}}}<!-- |
||
-- |
--><!-- |
||
--></noinclude>{{#switch: |
--></noinclude>{{#switch: |
||
| = |
| = |
||
<includeonly> |
<includeonly></includeonly> |
||
<!-- Add categories where indicated at the bottom of this page and interwikis at Wikidata --> |
<!-- Add categories where indicated at the bottom of this page and interwikis at Wikidata --> |
||
| ⚫ | |||
{{high-risk}} |
{{high-risk}} |
||
{{used in system}} |
{{used in system}} |
||
{{Module rating|release}} |
{{Module rating|release}} |
||
{{Module rating|protected}} |
{{Module rating|protected}} |
||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
<translate> |
<translate> |
||
<!--T:36--> |
|||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
</translate> |
</translate> |
||
{{ModuleQuality}} |
{{ModuleQuality}} |
||
<translate> |
<translate> |
||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
<syntaxhighlight lang="lua"> |
<syntaxhighlight lang="lua"> |
||
yesno(value, default) |
yesno(value, default) |
||
</syntaxhighlight> |
</syntaxhighlight> |
||
<!--T:40--> |
|||
<code>value</code> is the value to be tested. |
|||
Boolean input or boolean-style input (see below) always evaluates to either <code>true</code> or <code>false</code>, and <code>nil</code> always evaluates to <code>nil</code>. |
|||
Other values evaluate to <code>default</code>. |
|||
| ⚫ | |||
| ⚫ | |||
== Usage == <!--T:41--> |
|||
| ⚫ | |||
| ⚫ | |||
<!--T:42--> |
|||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
<!--T:43--> |
|||
<syntaxhighlight lang="lua"> |
<syntaxhighlight lang="lua"> |
||
local yesno = require('Module:Yesno') |
local yesno = require('Module:Yesno') |
||
</syntaxhighlight> |
</syntaxhighlight> |
||
<!--T:44--> |
|||
<translate><!--T:13--> Some input values always return <tvar name=1><code>true</code></tvar>, and some always return <tvar name=2><code>false</code></tvar>.</translate> |
|||
Some input values always return <code>true</code>, and some always return <code>false</code>. |
|||
<code>nil</code> values always return <code>nil</code>. |
|||
<!--T:45--> |
|||
<syntaxhighlight lang="lua"> |
<syntaxhighlight lang="lua"> |
||
-- |
-- These always return true: |
||
yesno('yes') |
yesno('yes') |
||
yesno('y') |
yesno('y') |
||
| Line 53: | Line 67: | ||
yesno(true) |
yesno(true) |
||
<!--T:46--> |
|||
-- <translate nowrap><!--T:16--> These always return <tvar name=1>false</tvar>:</translate> |
|||
-- These always return false: |
|||
yesno('no') |
yesno('no') |
||
yesno('n') |
yesno('n') |
||
| Line 62: | Line 77: | ||
yesno(false) |
yesno(false) |
||
<!--T:47--> |
|||
-- <translate nowrap><!--T:17--> A <tvar name=1>nil</tvar> value always returns <tvar name=1>nil</tvar>:</translate> |
|||
-- A nil value always returns nil: |
|||
yesno(nil) |
yesno(nil) |
||
</syntaxhighlight> |
</syntaxhighlight> |
||
| ⚫ | |||
| ⚫ | |||
String values are converted to lower case before they are matched: |
String values are converted to lower case before they are matched: |
||
| ⚫ | |||
<syntaxhighlight lang="lua"> |
<syntaxhighlight lang="lua"> |
||
-- |
-- These always return true: |
||
yesno('Yes') |
yesno('Yes') |
||
yesno('YES') |
yesno('YES') |
||
| Line 77: | Line 90: | ||
yesno('tRuE') |
yesno('tRuE') |
||
<!--T:48--> |
|||
-- <translate nowrap><!--T:20--> These always return <tvar name=1>false</tvar>:</translate> |
|||
-- These always return false: |
|||
yesno('No') |
yesno('No') |
||
yesno('NO') |
yesno('NO') |
||
| Line 85: | Line 99: | ||
</syntaxhighlight> |
</syntaxhighlight> |
||
<!--T:49--> |
|||
You can specify a default value if <code>yesno</code> receives input other than that listed above. |
|||
If you don't supply a default, the module will return <code>nil</code> for these inputs. |
|||
<!--T:50--> |
|||
<syntaxhighlight lang="lua"> |
<syntaxhighlight lang="lua"> |
||
-- |
-- These return nil: |
||
yesno('foo') |
yesno('foo') |
||
yesno({}) |
yesno({}) |
||
| Line 95: | Line 111: | ||
yesno(function() return 'This is a function.' end) |
yesno(function() return 'This is a function.' end) |
||
<!--T:51--> |
|||
-- <translate nowrap><!--T:24--> These return <tvar name=1>true</tvar>:</translate> |
|||
-- These return true: |
|||
yesno('foo', true) |
yesno('foo', true) |
||
yesno({}, true) |
yesno({}, true) |
||
| Line 101: | Line 118: | ||
yesno(function() return 'This is a function.' end, true) |
yesno(function() return 'This is a function.' end, true) |
||
<!--T:52--> |
|||
-- <translate nowrap><!--T:25--> These return <tvar name=1>"bar"</tvar>:</translate> |
|||
-- These return "bar": |
|||
yesno('foo', 'bar') |
yesno('foo', 'bar') |
||
yesno({}, 'bar') |
yesno({}, 'bar') |
||
| Line 107: | Line 125: | ||
yesno(function() return 'This is a function.' end, 'bar') |
yesno(function() return 'This is a function.' end, 'bar') |
||
</syntaxhighlight> |
</syntaxhighlight> |
||
<translate> |
|||
| ⚫ | |||
Note that the blank string also functions this way: |
Note that the blank string also functions this way: |
||
</translate> |
|||
<syntaxhighlight lang="lua"> |
<syntaxhighlight lang="lua"> |
||
yesno('') -- |
yesno('') -- Returns nil. |
||
yesno('', true) -- |
yesno('', true) -- Returns true. |
||
yesno('', 'bar') -- |
yesno('', 'bar') -- Returns "bar". |
||
</syntaxhighlight> |
</syntaxhighlight> |
||
<!--T:53--> |
|||
Although the blank string usually evaluates to <code>false</code> in wikitext, it evaluates to <code>true</code> in Lua. |
|||
This module prefers the Lua behaviour over the wikitext behaviour. |
|||
If treating the blank string as <code>false</code> is important for your module, you will need to remove blank arguments at an earlier stage of processing. |
|||
<includeonly>{{Sandbox other|| |
<includeonly>{{Sandbox other|| |
||
<!-- Categories below this line; interwikis at Wikidata --> |
<!-- Categories below this line; interwikis at Wikidata --> |
||
| ⚫ | |||
[[Category:Modules]] |
[[Category:Modules]] |
||
}}</includeonly><noinclude> |
}}</includeonly><noinclude> |
||
[[Category:Module documentation pages{{#translation:}}]] |
[[Category:Module documentation pages{{#translation:}}{{#translation:}}]] |
||
| ⚫ | |||
<!--T:54--> |
|||
</noinclude> |
</noinclude> |
||
| #default= |
| #default= |
||
{{#invoke:Template translation|renderTranslatedTemplate|template=Module:Yesno/doc|noshift=1|uselang={{int:lang}}}} |
{{#invoke:Template translation|renderTranslatedTemplate|template=Module:Yesno/doc|noshift=1|uselang={{int:lang}}}} |
||
}} |
}} |
||
| ⚫ | |||