Module:Yesno/doc/pt
More actions
{{#ifeq:pt|doc||{{#ifeq:pt |doc
|
{{#ifeq:show |show
|
File:Edit-copy green.svg | Template:Strong for Template:Terminate sentence It may contain usage information, categories and other content that is not part of the original {{#if: |{{{text2}}} |{{#if: |{{{text1}}} |{{#ifeq:Module |User |module template page |{{#if:Module |module page|article}}}}}}}}. |
}}{{#if: | | {{#ifexist:Module:Yesno/doc | [[Category:{{#switch:Module |Template=Template |Module=Module |User=User |#default=Wikipedia}} documentation pages]] | }} }} | }}}}{{#switch:
| =
Template:Shared Template Warning
Template:High-risk
Template:Used in system
Template:Module rating
Template:Module rating
Este módulo fornece uma interface consistente para o processamento de booliano e da entrada de string ao estilo de boolinao.
Enquanto Lua permite os valores boolianos true
e false
, os modelos do código wiki só podem expressar os valores boolianos através de strings, tais como "1", "0", "yes", "no", etc.
Este módulo processa estes tipos de strings e transforma-as numa entrada booliana para Lua processar.
Este também devolve valores nil
como nil
, para permitir distinções entre nil
e false
.
Este módulo aceita outras estruturas de Lua como entrada, por exemplo, boolianos, números, tabelas, e funções.
Se for passada uma entrada que não reconhece como booliano ou nil
, é possível especificar um valor predefinido para devolver.
Qualidade do Módulo
Sintaxe
<syntaxhighlight lang="lua"> yesno(value, default) </syntaxhighlight>
value
é o valor a ser testado.
A entrada booliana ou entrada no estilo booliano (veja em baixo) aponta sempre para true
ou false
, e nil
aponta sempre para nil
.
Outros valores apontam para default
.
Utilização
Primeiro, carregue o módulo. Note que este só pode ser carregado de outros módulos de Lua, não das páginas wiki normais.
Em vez disso, para as páginas wiki normais pode utilizar {{yesno}}
.
<syntaxhighlight lang="lua"> local yesno = require('Module:Yesno') </syntaxhighlight>
Alguns valores de entrada devolvem sempre true
, e alguns devolvem sempre false
.
Valores nil
devolvem sempre nil
.
<syntaxhighlight lang="lua"> -- Estes devolvem sempre true: yesno('yes') yesno('y') yesno('true') yesno('t') yesno('1') yesno(1) yesno(true)
-- Estes devolvem sempre false: yesno('no') yesno('n') yesno('false') yesno('f') yesno('0') yesno(0) yesno(false)
-- Um valor nil devolve sempre nil: yesno(nil) </syntaxhighlight> Os valores da string são convertidos para letras minúsculas antes de serem correspondidas: <syntaxhighlight lang="lua"> -- Estes devolvem sempre true: yesno('Yes') yesno('YES') yesno('yEs') yesno('Y') yesno('tRuE')
-- Estes devolvem sempre false: yesno('No') yesno('NO') yesno('nO') yesno('N') yesno('fALsE') </syntaxhighlight>
Pode especificar um valor predefinido se yesno
recebe entrada diferente da listada em cima.
Se não fornecer uma predefinição , o módulo devolverá nil
para essas entradas.
<syntaxhighlight lang="lua"> -- Estes devolvem nil: yesno('foo') yesno({}) yesno(5) yesno(function() return 'This is a function.' end)
-- Estes devolvem true: yesno('foo', true) yesno({}, true) yesno(5, true) yesno(function() return 'This is a function.' end, true)
-- Estes devolvem "bar": yesno('foo', 'bar') yesno({}, 'bar') yesno(5, 'bar') yesno(function() return 'This is a function.' end, 'bar') </syntaxhighlight> NOTE que UMA string em branco também funciona desta forma: <syntaxhighlight lang="lua"> yesno() -- Devolve nil. yesno(, true) -- Devolve true. yesno(, 'bar') -- Devolve "bar". </syntaxhighlight>
Embora a string em branco geralmente seja apontada para false
no texto wiki, ela é apontada para true
na Lua.
Este módulo prefere o comportamento de Lua ao comportamento do texto wiki.
Se tratar a string em branco como false
é importante para o seu módulo, terá de remover os argumentos em branco numa fase anterior do processamento.
| #default=
{{#switch:
| =
Template:Languages
Template:Shared Template Warning
Template:High-risk
Template:Used in system
Template:Module rating
Template:Module rating
This module provides a consistent interface for processing boolean or boolean-style string input.
While Lua allows the true
and false
boolean values, wikicode templates can only express boolean values through strings such as "1", "0", "yes", "no", etc.
This module processes these kinds of strings and turns them into boolean input for Lua to process.
It also returns nil
values as nil
, to allow for distinctions between nil
and false
.
The module also accepts other Lua structures as input, i.e. booleans, numbers, tables, and functions.
If it is passed input that it does not recognise as boolean or nil
, it is possible to specify a default value to return.
Module Quality
Syntax
<syntaxhighlight lang="lua"> yesno(value, default) </syntaxhighlight>
value
is the value to be tested.
Boolean input or boolean-style input (see below) always evaluates to either true
or false
, and nil
always evaluates to nil
.
Other values evaluate to default
.
Usage
First, load the module. Note that it can only be loaded from other Lua modules, not from normal wiki pages.
For normal wiki pages you can use {{yesno}}
instead.
<syntaxhighlight lang="lua"> local yesno = require('Module:Yesno') </syntaxhighlight>
Some input values always return true
, and some always return false
.
nil
values always return nil
.
<syntaxhighlight lang="lua"> -- These always return true: yesno('yes') yesno('y') yesno('true') yesno('t') yesno('1') yesno(1) yesno(true)
-- These always return false: yesno('no') yesno('n') yesno('false') yesno('f') yesno('0') yesno(0) yesno(false)
-- A nil value always returns nil: yesno(nil) </syntaxhighlight> String values are converted to lower case before they are matched: <syntaxhighlight lang="lua"> -- These always return true: yesno('Yes') yesno('YES') yesno('yEs') yesno('Y') yesno('tRuE')
-- These always return false: yesno('No') yesno('NO') yesno('nO') yesno('N') yesno('fALsE') </syntaxhighlight>
You can specify a default value if yesno
receives input other than that listed above.
If you don't supply a default, the module will return nil
for these inputs.
<syntaxhighlight lang="lua"> -- These return nil: yesno('foo') yesno({}) yesno(5) yesno(function() return 'This is a function.' end)
-- These return true: yesno('foo', true) yesno({}, true) yesno(5, true) yesno(function() return 'This is a function.' end, true)
-- These return "bar": yesno('foo', 'bar') yesno({}, 'bar') yesno(5, 'bar') yesno(function() return 'This is a function.' end, 'bar') </syntaxhighlight> Note that the blank string also functions this way: <syntaxhighlight lang="lua"> yesno() -- Returns nil. yesno(, true) -- Returns true. yesno(, 'bar') -- Returns "bar". </syntaxhighlight>
Although the blank string usually evaluates to false
in wikitext, it evaluates to true
in Lua.
This module prefers the Lua behaviour over the wikitext behaviour.
If treating the blank string as false
is important for your module, you will need to remove blank arguments at an earlier stage of processing.
{{safesubst:#if:{{safesubst:#ifeq:pt|sandbox|1}}{{safesubst:#ifeq:pt|doc|1}}||
}}
| #default=
Lua error: expandTemplate: template loop detected.
}} }}