Модуль:GetField: различия между версиями
Pok (обсуждение | вклад) Нет описания правки Метка: ручная отмена |
Pok (обсуждение | вклад) Нет описания правки |
||
| Строка 152: | Строка 152: | ||
end | end | ||
local function resolve_entry_from_data(data, id) | local function resolve_entry_from_data(data, id, allowDefault) | ||
if type(data) ~= "table" then | if type(data) ~= "table" then | ||
return nil | return nil | ||
| Строка 176: | Строка 176: | ||
end | end | ||
end | end | ||
end | |||
if allowDefault == false then | |||
return nil | |||
end | end | ||
| Строка 186: | Строка 190: | ||
end | end | ||
local function load_entry(id, pagePath, data) | local function load_entry(id, pagePath, data, allowDefault) | ||
data = data or load_cached_data(pagePath) | data = data or load_cached_data(pagePath) | ||
return resolve_entry_from_data(data, id) | if allowDefault == nil then | ||
allowDefault = true | |||
end | |||
return resolve_entry_from_data(data, id, allowDefault) | |||
end | end | ||
| Строка 424: | Строка 431: | ||
end | end | ||
local function build_tpl(id, pagePath, tplPath, data, tplArgs, preEntry) | local function build_tpl(id, pagePath, tplPath, data, tplArgs, preEntry, strictExact) | ||
if id == "" or pagePath == "" or tplPath == "" then | if id == "" or pagePath == "" or tplPath == "" then | ||
return "" | return "" | ||
end | end | ||
local entry = preEntry or load_entry(id, pagePath, data) | local entry | ||
if strictExact then | |||
entry = load_entry(id, pagePath, data, false) | |||
else | |||
entry = preEntry or load_entry(id, pagePath, data) | |||
end | |||
if entry == nil then | if entry == nil then | ||
return "" | return "" | ||
| Строка 722: | Строка 735: | ||
for _, idKey in ipairs(ids) do | for _, idKey in ipairs(ids) do | ||
local entry = resolve_entry_from_data(data, idKey) | local entry = resolve_entry_from_data(data, idKey, true) | ||
if type(entry) == "table" and entry_matches_path(entry, parsedPath, target, searchType) then | if type(entry) == "table" and entry_matches_path(entry, parsedPath, target, searchType) then | ||
matches[#matches + 1] = idKey | matches[#matches + 1] = idKey | ||
| Строка 827: | Строка 840: | ||
for _, idKey in ipairs(ids) do | for _, idKey in ipairs(ids) do | ||
local entry = resolve_entry_from_data(data, idKey) | local entry = resolve_entry_from_data(data, idKey, true) | ||
if mode == "component" then | if mode == "component" then | ||
if entry_has_all_targets_component(entry, targets) then | if entry_has_all_targets_component(entry, targets) then | ||
| Строка 897: | Строка 910: | ||
if searchType == "path" then | if searchType == "path" then | ||
for _, idKey in ipairs(ids) do | for _, idKey in ipairs(ids) do | ||
local entry = resolve_entry_from_data(data, idKey) | local entry = resolve_entry_from_data(data, idKey, true) | ||
entryCache[idKey] = entry | entryCache[idKey] = entry | ||
if type(entry) == "table" and entry_has_any_nonempty_path(entry, parsedPath) then | if type(entry) == "table" and entry_has_any_nonempty_path(entry, parsedPath) then | ||
| Строка 906: | Строка 919: | ||
local target = tostring(searchValue) | local target = tostring(searchValue) | ||
for _, idKey in ipairs(ids) do | for _, idKey in ipairs(ids) do | ||
local entry = resolve_entry_from_data(data, idKey) | local entry = resolve_entry_from_data(data, idKey, true) | ||
entryCache[idKey] = entry | entryCache[idKey] = entry | ||
if type(entry) == "table" and entry_matches_path(entry, parsedPath, target, searchType) then | if type(entry) == "table" and entry_matches_path(entry, parsedPath, target, searchType) then | ||
| Строка 920: | Строка 933: | ||
local out = {} | local out = {} | ||
for _, idKey in ipairs(matches) do | for _, idKey in ipairs(matches) do | ||
local tpl = build_tpl(idKey, pagePath, tplPath, data, tplArgs, entryCache[idKey]) | local tpl = build_tpl(idKey, pagePath, tplPath, data, tplArgs, entryCache[idKey], false) | ||
if tpl ~= "" then | if tpl ~= "" then | ||
out[#out + 1] = tpl | out[#out + 1] = tpl | ||
| Строка 947: | Строка 960: | ||
local data = frame.data | local data = frame.data | ||
local tplStr = build_tpl(id, pagePath, tplPath, data, tplArgs) | local tplStr = build_tpl(id, pagePath, tplPath, data, tplArgs, nil, true) | ||
return preprocess_or_return(frame, tplStr) | return preprocess_or_return(frame, tplStr) | ||
end | end | ||
| Строка 983: | Строка 996: | ||
local out = {} | local out = {} | ||
for _, id in ipairs(ids) do | for _, id in ipairs(ids) do | ||
local entry = resolve_entry_from_data(data, id) | local entry = resolve_entry_from_data(data, id, true) | ||
if entry ~= nil then | if entry ~= nil then | ||
local tpl = build_tpl(id, pagePath, tplPath, data, tplArgs, entry) | local tpl = build_tpl(id, pagePath, tplPath, data, tplArgs, entry, true) | ||
if tpl ~= "" then | if tpl ~= "" then | ||
out[#out + 1] = tpl | out[#out + 1] = tpl | ||
| Строка 1165: | Строка 1178: | ||
for idKey in pairs(idsTable) do | for idKey in pairs(idsTable) do | ||
local entry = resolve_entry_from_data(data, idKey) | local entry = resolve_entry_from_data(data, idKey, true) | ||
if entry ~= nil then | if entry ~= nil then | ||
local tpl = build_tpl(idKey, pagePath, tplPath, data, tplArgs, entry) | local tpl = build_tpl(idKey, pagePath, tplPath, data, tplArgs, entry, true) | ||
if tpl ~= "" then | if tpl ~= "" then | ||
out[#out + 1] = tpl | out[#out + 1] = tpl | ||