Модуль:Сущность: различия между версиями
Pok (обсуждение | вклад) мНет описания правки |
Pok (обсуждение | вклад) мНет описания правки |
||
| Строка 119: | Строка 119: | ||
local id = args[1] or "" | local id = args[1] or "" | ||
if id == "" then return "" end | if id == "" then return "" end | ||
local function parseListArg(str) | |||
local res = {} | |||
if not str or str == "" then return res end | |||
for item in string.gmatch(str, "[^,]+") do | |||
local s = trim(item) | |||
if s ~= "" then | |||
local a, b = s:match("^([^_]+)_(.+)$") | |||
if a and b then | |||
res[a] = res[a] or {} | |||
res[a][b] = true | |||
end | |||
end | |||
end | |||
return res | |||
end | |||
local blacklist = parseListArg(args.blacklist or "") | |||
local whitelist = parseListArg(args.whitelist or "") | |||
local componentDefs = load_module_data("component.json") | local componentDefs = load_module_data("component.json") | ||
| Строка 161: | Строка 178: | ||
local keys = parsed[sw] or {} | local keys = parsed[sw] or {} | ||
for _, key in ipairs(keys) do | for _, key in ipairs(keys) do | ||
if not | local skip = false | ||
if next(whitelist) ~= nil then | |||
if not (whitelist[sw] and whitelist[sw][key]) then skip = true end | |||
else | |||
if blacklist[sw] and blacklist[sw][key] then skip = true end | |||
end | end | ||
local extra = "" | if not skip then | ||
if not switchKeyToTemplates[sw][key] then | |||
switchKeyToTemplates[sw][key] = {} | |||
table.insert(switchKeyOrder[sw], key) | |||
end | |||
local extra = "" | |||
if ok and dp and dp.flattenField then | |||
local dataPage = tplPath .. ".json" | |||
extra = dp.flattenField({ args = { id, dataPage } }) | |||
end | |||
local tplStr = makeTplCall(tplPath, sw, key, id, extra) | |||
local priority = 1 | |||
if parsed and parsed.priority ~= nil then | |||
if type(parsed.priority) == "number" then | |||
priority = parsed.priority | |||
else | |||
local pnum = tonumber(parsed.priority) | |||
if pnum then priority = pnum end | |||
end | |||
end | end | ||
local entry = { | |||
tpl = tplStr, | |||
source = { kind = kind, name = name, pathName = pathName, tplPath = tplPath }, | |||
priority = priority, | |||
idx = #switchKeyToTemplates[sw][key] + 1 | |||
} | |||
table.insert(switchKeyToTemplates[sw][key], entry) | |||
end | end | ||
end | end | ||
end | end | ||