Модуль:GetField: различия между версиями
Pok (обсуждение | вклад) Нет описания правки |
Pok (обсуждение | вклад) Нет описания правки |
||
| Строка 4: | Строка 4: | ||
local getArgs = require('Module:Arguments').getArgs | local getArgs = require('Module:Arguments').getArgs | ||
local function load_cached_data | local function load_cached_data(pagePath) | ||
local titleName = JsonPaths.get(pagePath) | |||
local titleName = JsonPaths. | |||
if not titleName or titleName == "" then | if not titleName or titleName == "" then | ||
return nil | return nil | ||
end | end | ||
local ok, data = pcall(mw. | local ok, data = pcall(mw.loadData, titleName) | ||
if not ok or type(data) ~= "table" then | if not ok or type(data) ~= "table" then | ||
return nil | return nil | ||
| Строка 195: | Строка 187: | ||
local function load_entry(id, pagePath, data) | local function load_entry(id, pagePath, data) | ||
data = data or load_cached_data | data = data or load_cached_data(pagePath) | ||
return resolve_entry_from_data(data, id) | return resolve_entry_from_data(data, id) | ||
end | end | ||
| Строка 474: | Строка 466: | ||
local storeName = (kind == "prototype") and "prototype_store.json" or "component_store.json" | local storeName = (kind == "prototype") and "prototype_store.json" or "component_store.json" | ||
local data = | local data = load_cached_data(storeName) | ||
if not data then | if not data then | ||
return "" | return "" | ||
| Строка 711: | Строка 703: | ||
end | end | ||
local data = | local data = load_cached_data(pagePath) | ||
if not data then | if not data then | ||
return "[]" | return "[]" | ||
| Строка 769: | Строка 761: | ||
end | end | ||
local data = | local data = load_cached_data(pagePath) | ||
if not data or type(data) ~= "table" then | if not data or type(data) ~= "table" then | ||
return "[]" | return "[]" | ||
| Строка 885: | Строка 877: | ||
end | end | ||
local data = | local data = load_cached_data(pagePath) | ||
if not data then | if not data then | ||
return "" | return "" | ||
| Строка 984: | Строка 976: | ||
end | end | ||
local data = | local data = load_cached_data(pagePath) | ||
if not data then | if not data then | ||
return "" | return "" | ||
| Строка 1044: | Строка 1036: | ||
end | end | ||
local | local data = load_cached_data("component.json") | ||
if not data then | if not data then | ||
return "false" | return "false" | ||
| Строка 1076: | Строка 1067: | ||
end | end | ||
local | local data = load_cached_data("component.json") | ||
if not data or type(data) ~= "table" then | if not data or type(data) ~= "table" then | ||
return "[]" | return "[]" | ||
| Строка 1112: | Строка 1102: | ||
end | end | ||
local data = | local data = load_cached_data(pagePath) | ||
if not data then | if not data then | ||
return "" | return "" | ||
| Строка 1162: | Строка 1152: | ||
end | end | ||
local data = | local data = load_cached_data(pagePath) | ||
if not data then | if not data then | ||
return "" | return "" | ||