Модуль:Сущность/data: различия между версиями
Pok (обсуждение | вклад) Нет описания правки |
Pok (обсуждение | вклад) Отмена версии 315901, сделанной Pok (обсуждение) Метка: отмена |
||
| (не показаны 3 промежуточные версии этого же участника) | |||
| Строка 239: | Строка 239: | ||
return table.concat(out, "\n") | return table.concat(out, "\n") | ||
end | |||
local function normalizeFilterKey(s) | |||
s = trim(s or "") | |||
s = s:gsub("%s*_%s*", "_") | |||
return s | |||
end | end | ||
| Строка 245: | Строка 251: | ||
return false | return false | ||
end | end | ||
callKey = normalizeFilterKey(callKey) | |||
compositeKey = normalizeFilterKey(compositeKey) | |||
return list[callKey] or list[compositeKey] or false | return list[callKey] or list[compositeKey] or false | ||
end | end | ||
| Строка 512: | Строка 520: | ||
if not str or str == "" then return res end | if not str or str == "" then return res end | ||
for item in string.gmatch(str, "[^,]+") do | for item in string.gmatch(str, "[^,]+") do | ||
local s = | local s = normalizeFilterKey(item) | ||
if s ~= "" then | if s ~= "" then | ||
local a, b = s:match("^([^_]+)_(.+)$") | local a, b = s:match("^([^_]+)_(.+)$") | ||
| Строка 697: | Строка 705: | ||
end | end | ||
local function | local function extract_whitelist_search_strings(keyFilter) | ||
if not | if not keyFilter or not keyFilter.hasWhitelist then | ||
return | return nil | ||
end | |||
local strings = {} | |||
for sw, keys in pairs(keyFilter.whitelist) do | |||
if type(keys) == "table" then | |||
for key in pairs(keys) do | |||
strings[#strings + 1] = key | |||
end | |||
end | |||
end | end | ||
if | if #strings == 0 then | ||
return | return nil | ||
end | end | ||
return strings | |||
end | |||
local function content_matches_whitelist(content, searchStrings) | |||
if not searchStrings then | |||
return true | |||
end | |||
if not content then | |||
return false | |||
end | end | ||
for _, s in ipairs(searchStrings) do | |||
if | if string.find(content, s, 1, true) then | ||
return true | return true | ||
end | end | ||
| Строка 756: | Строка 766: | ||
local protoHasWhitelist = next(protoWhitelistSet) ~= nil | local protoHasWhitelist = next(protoWhitelistSet) ~= nil | ||
local anyEntityWhitelist = compHasWhitelist or protoHasWhitelist | local anyEntityWhitelist = compHasWhitelist or protoHasWhitelist | ||
local whitelistSearchStrings = extract_whitelist_search_strings(keyFilter) | |||
local function processEntity(kind, name, isStore) | local function processEntity(kind, name, isStore) | ||
| Строка 769: | Строка 781: | ||
onMissing(kind, name, isStore, tplPath) | onMissing(kind, name, isStore, tplPath) | ||
end | end | ||
return | |||
end | |||
if not content_matches_whitelist(content, whitelistSearchStrings) then | |||
return | return | ||
end | end | ||
| Строка 777: | Строка 793: | ||
end | end | ||
local extra = "" | local extra = "" | ||
local paramNames = get_template_params(tplPath, content) | |||
if dp then | |||
local dataPage = tplPath .. ".json" | local dataPage = tplPath .. ".json" | ||
extra = get_selective_extra(id, dataPage, paramNames) | extra = get_selective_extra(id, dataPage, paramNames) | ||