Модуль:Сущность: различия между версиями
Pok (обсуждение | вклад) мНет описания правки |
Pok (обсуждение | вклад) мНет описания правки |
||
| Строка 487: | Строка 487: | ||
return "" | return "" | ||
end | end | ||
local outputType = (args.type or "list"):lower() | |||
local bullet = mw.text.unstripNoWiki(args.prefix or "* ") | local bullet = mw.text.unstripNoWiki(args.prefix or "* ") | ||
| Строка 500: | Строка 502: | ||
for _, v in ipairs(data) do | for _, v in ipairs(data) do | ||
local text = "" | local text = "" | ||
if type(v) == "table" then | if type(v) == "table" then | ||
if is_array(v) then | if is_array(v) then | ||
text = table.concat(v, ", ") | |||
else | else | ||
local okJson, jsonVal = pcall(mw.text.jsonEncode, v) | local okJson, jsonVal = pcall(mw.text.jsonEncode, v) | ||
| Строка 520: | Строка 515: | ||
text = tostring(v) | text = tostring(v) | ||
end | end | ||
if text ~= "" then | if text ~= "" then | ||
local patt = valuePattern ~= "" and valuePattern or keyPattern | local patt = valuePattern ~= "" and valuePattern or keyPattern | ||
local repl = valueReplace ~= "" and valueReplace or keyReplace | local repl = valueReplace ~= "" and valueReplace or keyReplace | ||
text = apply_pattern(text, patt, repl) | text = apply_pattern(text, patt, repl) | ||
table.insert(out, bullet .. text) | |||
if outputType == "enum" then | |||
table.insert(out, text) | |||
else | |||
table.insert(out, bullet .. text) | |||
end | |||
end | end | ||
end | end | ||
| Строка 537: | Строка 538: | ||
local v = data[k] | local v = data[k] | ||
local vStr | local vStr | ||
if type(v) == "table" then | if type(v) == "table" then | ||
local okJson, jsonVal = pcall(mw.text.jsonEncode, v) | local okJson, jsonVal = pcall(mw.text.jsonEncode, v) | ||
| Строка 547: | Строка 549: | ||
vStr = tostring(v) | vStr = tostring(v) | ||
end | end | ||
local keyStr = tostring(k) | local keyStr = tostring(k) | ||
keyStr = apply_pattern(keyStr, keyPattern, keyReplace) | keyStr = apply_pattern(keyStr, keyPattern, keyReplace) | ||
vStr = apply_pattern(vStr, valuePattern, valueReplace) | vStr = apply_pattern(vStr, valuePattern, valueReplace) | ||
if vStr ~= "" then | if vStr ~= "" then | ||
table.insert(out, bullet .. keyStr .. sep .. vStr) | local pair = keyStr .. " " .. vStr | ||
if outputType == "enum" then | |||
table.insert(out, pair) | |||
else | |||
table.insert(out, bullet .. keyStr .. sep .. vStr) | |||
end | |||
end | end | ||
end | end | ||
end | end | ||
return frame:preprocess(table.concat(out, "\n")) | if outputType == "enum" then | ||
return frame:preprocess(table.concat(out, ", ")) | |||
else | |||
return frame:preprocess(table.concat(out, "\n")) | |||
end | |||
end | end | ||
return p | return p | ||