Модуль:GetField: различия между версиями
Pok (обсуждение | вклад) Нет описания правки |
Pok (обсуждение | вклад) Нет описания правки |
||
| Строка 448: | Строка 448: | ||
end | end | ||
local function build_tpl(id, pagePath, tplPath, data) | local function normalize_template_args(raw) | ||
raw = mw.text.unstripNoWiki(raw or "") | |||
if raw == "" then | |||
return "" | |||
end | |||
if string.sub(raw, 1, 1) == "|" then | |||
return string.sub(raw, 2) | |||
end | |||
return raw | |||
end | |||
local function build_tpl(id, pagePath, tplPath, data, tplArgs) | |||
if id == "" or pagePath == "" or tplPath == "" then | if id == "" or pagePath == "" or tplPath == "" then | ||
return "" | return "" | ||
| Строка 461: | Строка 474: | ||
local entry = resolve_entry(data, id) | local entry = resolve_entry(data, id) | ||
local extra = flatten_entry(entry) | local extra = flatten_entry(entry) | ||
local extraTplArgs = normalize_template_args(tplArgs) | |||
local templatePath = resolve_template_path(tplPath) | local templatePath = resolve_template_path(tplPath) | ||
local tplStr = "{{Шаблон:" .. templatePath .. "|id=" .. tostring(id) | local tplStr = "{{Шаблон:" .. templatePath | ||
if extraTplArgs ~= "" then | |||
tplStr = tplStr .. "|" .. extraTplArgs | |||
end | |||
tplStr = tplStr .. "|id=" .. tostring(id) | |||
if extra ~= "" then | if extra ~= "" then | ||
tplStr = tplStr .. "|" .. extra | tplStr = tplStr .. "|" .. extra | ||
| Строка 666: | Строка 684: | ||
local keyPath = args[3] or "" | local keyPath = args[3] or "" | ||
local tplPath = mw.text.unstripNoWiki(args[4] or "") | local tplPath = mw.text.unstripNoWiki(args[4] or "") | ||
local tplArgs = args.tplArgs or args.templateArgs or "" | |||
local searchType = (args.searchType or ""):lower() | local searchType = (args.searchType or ""):lower() | ||
| Строка 677: | Строка 696: | ||
keyPath = args[2] or "" | keyPath = args[2] or "" | ||
tplPath = mw.text.unstripNoWiki(args[3] or "") | tplPath = mw.text.unstripNoWiki(args[3] or "") | ||
tplArgs = args[4] or args.tplArgs or args.templateArgs or "" | |||
end | end | ||
| Строка 772: | Строка 792: | ||
local out = {} | local out = {} | ||
for _, idKey in ipairs(matches) do | for _, idKey in ipairs(matches) do | ||
local tpl = build_tpl(idKey, pagePath, tplPath, data) | local tpl = build_tpl(idKey, pagePath, tplPath, data, tplArgs) | ||
if tpl ~= "" then | if tpl ~= "" then | ||
out[#out + 1] = tpl | out[#out + 1] = tpl | ||
| Строка 791: | Строка 811: | ||
local pagePath = args[2] or "" | local pagePath = args[2] or "" | ||
local tplPath = mw.text.unstripNoWiki(args[3] or "") | local tplPath = mw.text.unstripNoWiki(args[3] or "") | ||
local tplArgs = args[4] or args.tplArgs or args.templateArgs or "" | |||
if id == "" or pagePath == "" or tplPath == "" then | if id == "" or pagePath == "" or tplPath == "" then | ||
| Строка 805: | Строка 826: | ||
end | end | ||
local tplStr = build_tpl(id, pagePath, tplPath, data) | local tplStr = build_tpl(id, pagePath, tplPath, data, tplArgs) | ||
return preprocess_or_return(frame, tplStr) | return preprocess_or_return(frame, tplStr) | ||
end | end | ||
| Строка 815: | Строка 836: | ||
local generatorId = args[3] or "" | local generatorId = args[3] or "" | ||
local tplPath = mw.text.unstripNoWiki(args[4] or "") | local tplPath = mw.text.unstripNoWiki(args[4] or "") | ||
local tplArgs = args[5] or args.tplArgs or args.templateArgs or "" | |||
if searchId == "" or generatorId == "" or tplPath == "" then | if searchId == "" or generatorId == "" or tplPath == "" then | ||
| Строка 840: | Строка 862: | ||
local out = {} | local out = {} | ||
for _, id in ipairs(ids) do | for _, id in ipairs(ids) do | ||
local tpl = build_tpl(id, pagePath, tplPath, data) | local tpl = build_tpl(id, pagePath, tplPath, data, tplArgs) | ||
if tpl ~= "" then | if tpl ~= "" then | ||
out[#out + 1] = tpl | out[#out + 1] = tpl | ||
| Строка 969: | Строка 991: | ||
local pagePath = args[1] or "" | local pagePath = args[1] or "" | ||
local tplPath = args[2] or "" | local tplPath = args[2] or "" | ||
local tplArgs = args[3] or args.tplArgs or args.templateArgs or "" | |||
if pagePath == "" or tplPath == "" then | if pagePath == "" or tplPath == "" then | ||
| Строка 988: | Строка 1011: | ||
for idKey in pairs(idsTable) do | for idKey in pairs(idsTable) do | ||
local tpl = build_tpl(idKey, pagePath, tplPath, data) | local tpl = build_tpl(idKey, pagePath, tplPath, data, tplArgs) | ||
if tpl ~= "" then | if tpl ~= "" then | ||
out[#out + 1] = tpl | out[#out + 1] = tpl | ||
| Строка 1004: | Строка 1027: | ||
local jsonStr = mw.text.unstripNoWiki(args[1] or args.json or "") | local jsonStr = mw.text.unstripNoWiki(args[1] or args.json or "") | ||
local tplPath = mw.text.unstripNoWiki(args[2] or args.template or "") | local tplPath = mw.text.unstripNoWiki(args[2] or args.template or "") | ||
local tplArgs = normalize_template_args(args[3] or args.tplArgs or args.templateArgs or "") | |||
if jsonStr == "" or tplPath == "" then | if jsonStr == "" or tplPath == "" then | ||
| Строка 1025: | Строка 1049: | ||
end | end | ||
local parts = { makeTemplatePrefix() | local parts = { makeTemplatePrefix() } | ||
if tplArgs ~= "" then | |||
parts[#parts + 1] = tplArgs | |||
end | |||
parts[#parts + 1] = "id=" .. id | |||
if type(obj) == "table" then | if type(obj) == "table" then | ||