Module:Iteration/doc: Difference between revisions
More actions
mNo edit summary |
m +link |
||
| Line 31: | Line 31: | ||
''This'' problem is solved differently, for the function "attribs" with a primitive workaround. | ''This'' problem is solved differently, for the function "attribs" with a primitive workaround. | ||
== Namespace lists == | |||
There are special lists for some namespaces | |||
* {{T\|Filelist|08}} - for items of the [[#Filelist|namespace 6]] | |||
* {{T\|Userlist|08}} - for items of the [[#Userlist|namespace 2]] | |||
* {{T\|Linklist|08}} - for items of the namespace <s>0</s>{{0|00}} (not yet) | |||
* {{T\|Templist|08}} - for items of the namespace <s>10</s>{{0}} (not yet) | |||
* {{T\|Cat-list|08}} - for items of the namespace <s>14</s>{{0}} (not yet) | |||
* {{T\|Mod-list|08}} - for items of the namespace <s>828</s> (not yet) | |||
=== File list templates === | |||
=== {{T\|Filelist|08}} === | |||
==== File list templates ==== | |||
The three "Ifim " templates avoid to display the file itself as an 'other version'. <br> | The three "Ifim " templates avoid to display the file itself as an 'other version'. <br> | ||
There are currently five templates creating file lists with the <code>function:filelist</code> | There are currently five templates creating file lists with the <code>function:filelist</code> | ||
| Line 42: | Line 52: | ||
All these templates are {{C|Autoreferencing templates|autoreferencing}}, and the support also the "gallery" option. | All these templates are {{C|Autoreferencing templates|autoreferencing}}, and the support also the "gallery" option. | ||
=== Other file lists === | ==== Other file lists ==== | ||
The <code>function:svglang</code> creates a list of just file_names and language_codes, for | The <code>function:svglang</code> creates a list of just file_names and language_codes, for | ||
#<li value="6"> {{T0|Svg lang}} | #<li value="6"> {{T0|Svg lang}} | ||
| Line 57: | Line 67: | ||
The template displays a line of SVG emojis; Unicode characters/emojis can be displayed with the function {{T0|Emoji|Emodis}}. | The template displays a line of SVG emojis; Unicode characters/emojis can be displayed with the function {{T0|Emoji|Emodis}}. | ||
=== Variable iterations === | ==== Variable iterations ==== | ||
A very simple iteration, useable for everything, is performed by <code>function:iterate</code> | A very simple iteration, useable for everything, is performed by <code>function:iterate</code> | ||
:used by e.g. {{T|Image extracted}}, {{T|Image translated}}, <br> | :used by e.g. {{T|Image extracted}}, {{T|Image translated}}, <br> | ||
| Line 66: | Line 76: | ||
The <code>function:loop</code> is used by {{T|Repeat}}. | The <code>function:loop</code> is used by {{T|Repeat}}. | ||
=== | ==== "samefile" function ==== | ||
When the ''name'' of one of the files is the ''same'' as the first one, it is enough to reference it with its ''extension'' after a dot, | |||
e.g. just ".jpeg".<br>The ''most standard'' extensions can be abbreviated, e.g. ".j" will be sufficient for ".jpg" (only for lower case!). | |||
The function "'''incrhx'''" increments a hexadecimal number (parm 1) by a decimal number (parm 2).<br> | |||
Valid numbers are assumed, no checking occurs !<br> | |||
When parameter 2 is preceded by a minus, the first number is ''de''cremented by the second one | |||
=== {{T\|Userlist|08}} === | |||
* {{T\|Userlist|08}}: {{T0|Userlist}} with many formatting parameters | * {{T\|Userlist|08}}: {{T0|Userlist}} with many formatting parameters | ||
=== {{T\|Linklist|08}} === | |||
=== {{T\|Templist|08}} === | |||
== Other iterations == | |||
* {{T\|Langlist|08}}: | |||
* {{T\|Colorbox|08}}: {{T0|ColorString}} and other color box templates | * {{T\|Colorbox|08}}: {{T0|ColorString}} and other color box templates | ||
* {{T\|Legends |08}}: {{T0|Legtab}} combines single {{T0|Legend}}s | * {{T\|Legends |08}}: {{T0|Legtab}} combines single {{T0|Legend}}s | ||
* {{T\|Tleparms|08}}: the metatemplate {{T0|Tle}} displays the parameter usage of a template | * {{T\|Tleparms|08}}: the metatemplate {{T0|Tle}} displays the parameter usage of a template | ||
* {{T\|Navigate|08}}: {{T0|Navcat}} navigates through color categories | * {{T\|Navigate|08}}: {{T0|Navcat}} navigates through color categories | ||
* {{T\|Showname|08}}: {{T0|Showname}} helper template, for parameter tests | |||
* {{T\|Emodis {{0}}|08}}: {{T0|Emoji}} displays (one or many) Unicode characters | * {{T\|Emodis {{0}}|08}}: {{T0|Emoji}} displays (one or many) Unicode characters | ||
:The function "{{T\|emodis|08}}" <u>dis</u>plays Unicode characters / <u>emo</u>jis; it can care for newlines, while | :The function "{{T\|emodis|08}}" <u>dis</u>plays Unicode characters / <u>emo</u>jis; it can care for newlines, while | ||
:The function "{{T\|emotab|08}}" displays a <u>tab</u>le of files / <u>emo</u>jis. | :The function "{{T\|emotab|08}}" displays a <u>tab</u>le of files / <u>emo</u>jis. | ||
Revision as of 02:50, 8 March 2023
The module uses frequently the template {{=}} for title = "="
This module contains the functions for different templates, solving their iteration problem
- The Wikipedia template coding does not support the repetitive processing of a parameter set,
- which leads often to a very primitive and long chain of parameter checks in the kind of
{{#if:{{{1|}}} | perform an action with parameter 1 }} {{#if:{{{2|}}} | perform an action with parameter 2 }} {{#if:{{{3|}}} | perform an action with parameter 3 }} {{#if:{{{4|}}} | perform an action with parameter 4 }} ••• ••• {{#if:{{{33|}}} perform an action with parameter 33 }}
with the disadvantage that such a construct will fail as soon as there comes a 34nd parm.
I always thought that with Lua and its for loops this iterations should be possible, somehow.
After long searching without any success and without an idea how to perform it, I asked at several forums
and got finally from User:Trappist the monk the helping hint to solve it with a control structure like
local out = {}
for i, v in ipairs (args) do
table.insert (out, frame:expandTemplate{ title = title, args = v })
end
return table.concat (out)
The functions contained therein are from very simple, just one parameter to pass,
to more complicated ones, where e.g. a pair of parameters needs kind of a flip-flop switch
when always a tuple of e.g. an item and its correlated text needs to be passed.
When there are tuples, triples etc., the table.insert occurs, when the last element is processed;
this performs problems when the last group is incomplete – it should be finished with empty values
to trigger the table.insert. The check with table.maxn seems not to work correctly ?
This problem is solved differently, for the function "attribs" with a primitive workaround.
Namespace lists
There are special lists for some namespaces
- Filelist - for items of the namespace 6
- Userlist - for items of the namespace 2
- Linklist - for items of the namespace
0(not yet) - Templist - for items of the namespace
10(not yet) - Cat-list - for items of the namespace
14(not yet) - Mod-list - for items of the namespace
828(not yet)
Filelist
File list templates
The three "Ifim " templates avoid to display the file itself as an 'other version'.
There are currently five templates creating file lists with the function:filelist
- Other versions a vertical list (without initial)
- Filelist a horizontal list (without initial)
- Derivative versions a vertical list
- Derived from a vertical list
- File a horizontal list
All these templates are autoreferencing, and the support also the "gallery" option.
Other file lists
The function:svglang creates a list of just file_names and language_codes, for
Much more is created by the function:ownbased for the template
which will handle in the majority of cases just one file, but can serve an unlimited number.
This list can be controlled by the user to be displayed either horizontally or vertically.
The template works, whether there is a user assigned for a file, or one filename follows another.
The template displays a line of SVG emojis; Unicode characters/emojis can be displayed with the function Emodis.
Variable iterations
A very simple iteration, useable for everything, is performed by function:iterate
- used by e.g. {{Image extracted}}, {{Image translated}},
More useable is the function:iteration for transclusions of a template with
- a number of positional parameters which can change at each transclusion, and
- a number of positional parameters which are the same for all transclusions.
See template {{Iterate}}.
The function:loop is used by {{Repeat}}.
"samefile" function
When the name of one of the files is the same as the first one, it is enough to reference it with its extension after a dot,
e.g. just ".jpeg".
The most standard extensions can be abbreviated, e.g. ".j" will be sufficient for ".jpg" (only for lower case!).
The function "incrhx" increments a hexadecimal number (parm 1) by a decimal number (parm 2).
Valid numbers are assumed, no checking occurs !
When parameter 2 is preceded by a minus, the first number is decremented by the second one
Userlist
- Userlist: Userlist with many formatting parameters
Linklist
Templist
Other iterations
- Langlist:
- Colorbox: ColorString and other color box templates
- Legends : Legtab combines single Legends
- Tleparms: the metatemplate Tle displays the parameter usage of a template
- Navigate: Navcat navigates through color categories
- Showname: Showname helper template, for parameter tests
- Emodis : Emoji displays (one or many) Unicode characters
- The function "emodis" displays Unicode characters / emojis; it can care for newlines, while
- The function "emotab" displays a table of files / emojis.