Modul:Text: Unterschied zwischen den Versionen
K
export concatParams and allow format string
w>Umherirrender K (fix listToText - local var args was never used) |
w>Umherirrender K (export concatParams and allow format string) |
||
| Zeile 12: | Zeile 12: | ||
Text.concatParams = function ( args, apply ) | Text.concatParams = function ( args, apply, adapt ) | ||
-- Concat list items into one string | -- Concat list items into one string | ||
-- Parameter: | -- Parameter: | ||
-- args -- table (sequence) with numKey=string | -- args -- table (sequence) with numKey=string | ||
-- apply -- string (optional); separator (default: "|") | -- apply -- string (optional); separator (default: "|") | ||
-- adapt -- string (optional); format including "%s" | |||
-- Returns: string | -- Returns: string | ||
local collect = { } | local collect = { } | ||
| Zeile 23: | Zeile 24: | ||
v = mw.text.trim( v ) | v = mw.text.trim( v ) | ||
if v ~= "" then | if v ~= "" then | ||
if adapt then | |||
v = mw.ustring.format( adapt, v ) | |||
end | |||
table.insert( collect, v ) | table.insert( collect, v ) | ||
end | end | ||
| Zeile 180: | Zeile 184: | ||
-- Export | -- Export | ||
local p = { } | local p = { } | ||
function p.concatParams( frame ) | |||
local args | |||
local template = frame.args.template | |||
if type( template ) == "string" then | |||
template = mw.text.trim( template ) | |||
template = ( template == "1" ) | |||
end | |||
if template then | |||
args = frame:getParent().args | |||
else | |||
args = frame.args | |||
end | |||
return Text.concatParams( args, frame.args.separator, frame.args.format ) | |||
end | |||
function p.containsCJK( frame ) | function p.containsCJK( frame ) | ||