Template:FunctionDeclaration: Difference between revisions
No edit summary |
Use question marks (?, a la TypeScript) instead of brackets for optional parameters. Brackets have a different meaning in ASH (maps), so using them for optional parameters was confusing. |
||
(13 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
<includeonly><kbd><b>{{{return_type}}} {{{name}}}({{ | <includeonly>{{ | ||
#if: {{data|{{{name}}}|function{{{func}}}.return_type}} | |||
| <kbd><b>{{type|{{data|{{{name}}}|function{{{func}}}.return_type}}}} [[{{data|{{{name}}}|name}}]]({{ | |||
#if: {{data|{{{name}}}|function{{{func}}}.param1.type}} | |||
| {{param2|name={{{name}}}|func={{{func}}}|param=1|format={{{format}}}}} | |||
}}{{ | }}{{ | ||
#if: {{data|{{{name}}}|function{{{func}}}.param2.type}} | |||
|, {{param2|name={{{name}}}|func={{{func}}}|param=2|format={{{format}}}}} | |||
}}{{ | |||
#if: {{data|{{{name}}}|function{{{func}}}.param3.type}} | |||
}}{{ | |, {{param2|name={{{name}}}|func={{{func}}}|param=3|format={{{format}}}}} | ||
}}{{ | |||
#if: {{data|{{{name}}}|function{{{func}}}.param4.type}} | |||
|, {{param2|name={{{name}}}|func={{{func}}}|param=4|format={{{format}}}}} | |||
}}{{ | |||
}} | #if: {{data|{{{name}}}|function{{{func}}}.param5.type}} | ||
|, {{param2|name={{{name}}}|func={{{func}}}|param=5|format={{{format}}}}} | |||
}}{{ | |||
#if: {{data|{{{name}}}|function{{{func}}}.param1.type}} | |||
| }})</b></kbd>{{ | |||
}}{{ | #if: {{{desc|}}} | ||
| :{{data|{{{name}}}|function{{{func}}}.description}}}}{{ | |||
#if: {{{param_desc|}}} | |||
|{{ | |||
#if: {{data|{{{name}}}|function{{{func}}}.param1.type}} | |||
}}{{ | | :* {{pspan|{{data|{{{name}}}|function{{{func}}}.param1}}}}: {{data|{{{name}}}|function{{{func}}}.param1.description}}}}{{ | ||
#if: {{data|{{{name}}}|function{{{func}}}.param2.type}} | |||
|& | | :* {{pspan|{{data|{{{name}}}|function{{{func}}}.param2}}}}: {{data|{{{name}}}|function{{{func}}}.param2.description}}}}{{ | ||
}}) | #if: {{data|{{{name}}}|function{{{func}}}.param3.type}} | ||
| :* {{pspan|{{data|{{{name}}}|function{{{func}}}.param3}}}}: {{data|{{{name}}}|function{{{func}}}.param3.description}}}}{{ | |||
#if: {{data|{{{name}}}|function{{{func}}}.param4.type}} | |||
| :* {{pspan|{{data|{{{name}}}|function{{{func}}}.param4}}}}: {{data|{{{name}}}|function{{{func}}}.param4.description}}}}{{ | |||
#if: {{data|{{{name}}}|function{{{func}}}.param5.type}} | |||
| :* {{pspan|{{data|{{{name}}}|function{{{func}}}.param5}}}}: {{data|{{{name}}}|function{{{func}}}.param5.description}}}} | |||
}} | |||
| {{error|Invalid function number (func = "{{{func|}}}") in Template:FunctionDeclaration}}}}</includeonly><noinclude> | |||
<templatedata> | <templatedata> | ||
{ | { | ||
"description": "Displays an ASH function's declaration. This is meant to be transcluded by other templates, rather than | "description": "Displays an ASH function's declaration. This is meant to be transcluded by other templates, rather than regular pages.", | ||
"params": { | "params": { | ||
" | "name": { | ||
"label": " | "label": "Function page name", | ||
"description": "Name of parameter 1 ( | "description": "Name of a function page. '''This must be a data page.'''", | ||
"type": "wiki-page-name", | |||
"required": true | |||
}, | |||
"func": { | |||
"label": "Overloaded function number", | |||
"description": "A function page may describe multiple overloaded functions under the same name. This parameter allows you to select one. Allowed values are 1-5, inclusive.", | |||
"type": "number", | |||
"required": true | |||
}, | |||
"format": { | |||
"label": "Rendering format", | |||
"description": "\"\" (empty string) = show everything, \"signature\" = only show parameter types (i.e. function signature). Default value is empty string (show everything).", | |||
"type": "line" | "type": "line" | ||
}, | }, | ||
" | "desc": { | ||
"label": " | "label": "Show descriptions?", | ||
"description": " | "description": "If set to \"yes\", also show the description of each function and its parameters below the declaration. Technically, any non-empty string works, but please use \"yes\" for ease of maintenance.", | ||
"type": "line" | |||
" | |||
}, | }, | ||
" | "param_desc": { | ||
"label": " | "label": "Show parameter descriptions?", | ||
"description": "\"yes\" | "description": "If set to \"yes\", also show the description of each function's parameters below the declaration. Technically, any non-empty string works, but please use \"yes\" for ease of maintenance.", | ||
"type": "line" | "type": "line" | ||
} | } | ||
Line 60: | Line 72: | ||
==Examples== | ==Examples== | ||
=== | {| class="wikitable" | ||
<pre>{{ | ! style="width: 50%" | Wiki markup | ||
|name= | ! Result | ||
| | |- | ||
}}</pre> | ! colspan="2" | Normal format | ||
|- | |||
{{ | | <pre>{{FunctionDeclaration|name=visit_url|func=1}}</pre> | ||
|name= | | {{FunctionDeclaration|name=visit_url|func=1}} | ||
| | |- | ||
}} | | <pre>{{FunctionDeclaration|name=visit_url|func=2}}</pre> | ||
| {{FunctionDeclaration|name=visit_url|func=2}} | |||
|- | |||
<pre>{{ | ! colspan="2" | Normal format with description | ||
|name= | |- | ||
| <pre>{{FunctionDeclaration|name=visit_url|func=1|desc=yes}}</pre> | |||
| | | {{FunctionDeclaration|name=visit_url|func=1|desc=yes}} | ||
|- | |||
}}</pre> | | <pre>{{FunctionDeclaration|name=visit_url|func=2|desc=yes}}</pre> | ||
| {{FunctionDeclaration|name=visit_url|func=2|desc=yes}} | |||
{{ | |- | ||
|name= | ! colspan="2" | Normal format with description + parameter description | ||
| | |- | ||
| | | <pre>{{FunctionDeclaration|name=visit_url|func=1|desc=yes|param_desc=yes}}</pre> | ||
| | | {{FunctionDeclaration|name=visit_url|func=1|desc=yes|param_desc=yes}} | ||
|- | |||
| <pre>{{FunctionDeclaration|name=visit_url|func=2|desc=yes|param_desc=yes}}</pre> | |||
| {{FunctionDeclaration|name=visit_url|func=2|desc=yes|param_desc=yes}} | |||
<pre>{{ | |- | ||
|name= | ! colspan="2" | Signature format | ||
| | |- | ||
| | |<pre>{{FunctionDeclaration|name=visit_url|func=2|format=signature}}</pre> | ||
| | | {{FunctionDeclaration|name=visit_url|func=2|format=signature}} | ||
| | |- | ||
| | ! colspan="2" | Invalid or missing function number | ||
| | |- | ||
| | | <pre>{{FunctionDeclaration|name=visit_url|func=4}}</pre> | ||
| | | {{FunctionDeclaration|name=visit_url|func=4}} | ||
| | |- | ||
| | | <pre>{{FunctionDeclaration|name=visit_url|func=0}}</pre> | ||
| | | {{FunctionDeclaration|name=visit_url|func=0}} | ||
}}</pre> | |- | ||
| <pre>{{FunctionDeclaration|name=visit_url}}</pre> | |||
{{ | | {{FunctionDeclaration|name=visit_url}} | ||
|name= | |} | ||
| | |||
| | |||
| | |||
| | |||
| | |||
| | |||
| | |||
| | |||
| | |||
| | |||
}} | |||
<pre>{{ | |||
|name= | |||
| | |||
| | |||
| | |||
| | |||
| | |||
| | |||
| | |||
| | |||
| | |||
}}</pre> | |||
{{ | |||
|name= | |||
| | |||
| | |||
| | |||
| | |||
| | |||
| | |||
| | |||
| | |||
| | |||
}} | |||
<pre>{{ | |||
|name=visit_url | |||
| | |||
| | |||
| | |||
| | |||
| | |||
| | |||
| | |||
| | |||
}}</pre> | |||
{{ | |||
|name=visit_url | |||
| | |||
| | |||
| | |||
| | |||
| | |||
| | |||
| | |||
| | |||
| | |||
| | |||
| | |||
| | |||
| | |||
| | |||
[[Category:Basic Templates]] | |||
</noinclude> | </noinclude> |
Latest revision as of 14:22, 31 December 2020
Displays an ASH function's declaration. This is meant to be transcluded by other templates, rather than regular pages.
Parameter | Description | Type | Status | |
---|---|---|---|---|
Function page name | name | Name of a function page. '''This must be a data page.''' | Page name | required |
Overloaded function number | func | A function page may describe multiple overloaded functions under the same name. This parameter allows you to select one. Allowed values are 1-5, inclusive. | Number | required |
Rendering format | format | "" (empty string) = show everything, "signature" = only show parameter types (i.e. function signature). Default value is empty string (show everything). | Line | optional |
Show descriptions? | desc | If set to "yes", also show the description of each function and its parameters below the declaration. Technically, any non-empty string works, but please use "yes" for ease of maintenance. | Line | optional |
Show parameter descriptions? | param_desc | If set to "yes", also show the description of each function's parameters below the declaration. Technically, any non-empty string works, but please use "yes" for ease of maintenance. | Line | optional |
Examples
Wiki markup | Result |
---|---|
Normal format | |
{{FunctionDeclaration|name=visit_url|func=1}} |
buffer visit_url() |
{{FunctionDeclaration|name=visit_url|func=2}} |
buffer visit_url( string url, boolean? use_POST = true, boolean? encoded = false ) |
Normal format with description | |
{{FunctionDeclaration|name=visit_url|func=1|desc=yes}} |
buffer visit_url()
|
{{FunctionDeclaration|name=visit_url|func=2|desc=yes}} |
buffer visit_url( string url, boolean? use_POST = true, boolean? encoded = false )
|
Normal format with description + parameter description | |
{{FunctionDeclaration|name=visit_url|func=1|desc=yes|param_desc=yes}} |
buffer visit_url()
|
{{FunctionDeclaration|name=visit_url|func=2|desc=yes|param_desc=yes}} |
buffer visit_url( string url, boolean? use_POST = true, boolean? encoded = false )
|
Signature format | |
{{FunctionDeclaration|name=visit_url|func=2|format=signature}} |
buffer visit_url( string, boolean?, boolean? ) |
Invalid or missing function number | |
{{FunctionDeclaration|name=visit_url|func=4}} |
Invalid function number (func = "4") in Template:FunctionDeclaration |
{{FunctionDeclaration|name=visit_url|func=0}} |
Invalid function number (func = "0") in Template:FunctionDeclaration |
{{FunctionDeclaration|name=visit_url}} |
Invalid function number (func = "") in Template:FunctionDeclaration |