Модуль:GetField: различия между версиями
Pok (обсуждение | вклад) Нет описания правки |
Pok (обсуждение | вклад) Нет описания правки |
||
| (не показано 16 промежуточных версий этого же участника) | |||
| Строка 1: | Строка 1: | ||
local p = {} | local p = {} | ||
local lang = mw.language.getContentLanguage() | |||
local JsonPaths = require('Module:JsonPaths') | local JsonPaths = require('Module:JsonPaths') | ||
local project = JsonPaths.project() | |||
local getArgs = require('Module:Arguments').getArgs | local getArgs = require('Module:Arguments').getArgs | ||
| Строка 352: | Строка 354: | ||
local moduleName = get_module_name(pagePath) | local moduleName = get_module_name(pagePath) | ||
data = data or load_cached_data(moduleName) | |||
if not data then | if not data then | ||
return "" | return "" | ||
| Строка 362: | Строка 362: | ||
local extra = flatten_entry(entry) | local extra = flatten_entry(entry) | ||
local tplStr = "{{" .. | local templatePath = tplPath | ||
if project ~= nil and project ~= "" then | |||
templatePath = project .. ":" .. lang:ucfirst(tplPath) | |||
templatePath = "{{#ifexist:Шаблон:" .. templatePath .. "|" .. templatePath .. "|" .. tplPath .. "}}" | |||
end | |||
local tplStr = "{{Шаблон:" .. templatePath .. "|id=" .. tostring(id) | |||
if extra ~= "" then | if extra ~= "" then | ||
tplStr = tplStr .. "|" .. extra | tplStr = tplStr .. "|" .. extra | ||
| Строка 415: | Строка 421: | ||
function p.flattenField(frame) | function p.flattenField(frame) | ||
local args = | local args = frame.args or {} | ||
local id = args[1] or "" | local id = args[1] or "" | ||
local pagePath = args[2] or "" | local pagePath = args[2] or "" | ||
| Строка 461: | Строка 467: | ||
end | end | ||
function p. | function p.searchId(frame) | ||
local args = getArgs(frame, { removeBlanks = false }) | local args = getArgs(frame, { removeBlanks = false }) | ||
local searchValue = args[1] or "" | local searchValue = args[1] or "" | ||
| Строка 525: | Строка 531: | ||
end | end | ||
function p. | function p.searchIdTpl(frame) | ||
local args = getArgs(frame, { removeBlanks = false }) | local args = getArgs(frame, { removeBlanks = false }) | ||
local searchValue = args[1] or "" | local searchValue = args[1] or "" | ||
| Строка 643: | Строка 649: | ||
end | end | ||
function p. | function p.searchStoreTpl(frame) | ||
local args = getArgs(frame, { removeBlanks = false }) | local args = getArgs(frame, { removeBlanks = false }) | ||
local searchId = args[1] or "" | local searchId = args[1] or "" | ||
| Строка 688: | Строка 694: | ||
end | end | ||
function p. | function p.searchStore(frame) | ||
local args = getArgs(frame, { removeBlanks = false }) | local args = getArgs(frame, { removeBlanks = false }) | ||
local searchId = args[1] or "" | local searchId = args[1] or "" | ||
| Строка 749: | Строка 755: | ||
end | end | ||
function p. | function p.getAll(frame) | ||
local args = getArgs(frame, { removeBlanks = false }) | local args = getArgs(frame, { removeBlanks = false }) | ||
local pagePath = args[1] or "" | local pagePath = args[1] or "" | ||
| Строка 799: | Строка 805: | ||
end | end | ||
function p. | function p.getAllTpl(frame) | ||
local args = getArgs(frame, { removeBlanks = false }) | local args = getArgs(frame, { removeBlanks = false }) | ||
local pagePath = args[1] or "" | local pagePath = args[1] or "" | ||
| Строка 838: | Строка 844: | ||
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 "") | ||
if jsonStr == "" or tplPath == "" then | if jsonStr == "" or tplPath == "" then | ||
return "" | return "" | ||
| Строка 848: | Строка 855: | ||
local okDp, dp = pcall(require, "Module:GetField") | local okDp, dp = pcall(require, "Module:GetField") | ||
local calls = {} | |||
local projectPath = nil | |||
if project ~= nil and project ~= "" then | |||
projectPath = project .. ":" .. lang:ucfirst(tplPath) | |||
end | |||
local | local function makeTemplatePrefix() | ||
if projectPath then | |||
return "{{Шаблон:{{#ifexist:Шаблон:" .. projectPath .. "|" .. projectPath .. "|" .. tplPath .. "}}" | |||
end | |||
return "{{" .. tplPath | |||
end | |||
local function makeCall(id, obj) | local function makeCall(id, obj) | ||
| Строка 856: | Строка 875: | ||
end | end | ||
local parts = { | local parts = { makeTemplatePrefix(), "id=" .. id } | ||
if type(obj) == "table" then | if type(obj) == "table" then | ||