Модуль:Сущность: различия между версиями
Pok (обсуждение | вклад) мНет описания правки |
Pok (обсуждение | вклад) Нет описания правки |
||
| (не показаны 4 промежуточные версии этого же участника) | |||
| Строка 283: | Строка 283: | ||
end | end | ||
end | end | ||
for name in string.gmatch(id, "[^,]+") do | for name in string.gmatch(id, "[^,]+") do | ||
local n = trim(name) | local n = trim(name) | ||
if n ~= "" then | if n ~= "" and n ~= id then | ||
if componentDefs[n] ~= nil then foundComponents[n] = true | if componentDefs[n] ~= nil then | ||
foundComponents[n] = true | |||
elseif prototypeDefs[n] ~= nil then | |||
foundPrototypes[n] = true | |||
end | |||
end | end | ||
end | end | ||
| Строка 487: | Строка 491: | ||
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: | Строка 506: | ||
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: | Строка 519: | ||
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: | Строка 542: | ||
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: | Строка 553: | ||
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) | if outputType == "enum" then | ||
table.insert(out, vStr .. " " .. keyStr) | |||
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 | ||