Модуль:Песочница/Pok: различия между версиями
Pok (обсуждение | вклад) мНет описания правки |
Pok (обсуждение | вклад) Нет описания правки |
||
| Строка 47: | Строка 47: | ||
local function load_template_content(path) | local function load_template_content(path) | ||
local title = mw.title.new(" | local title = mw.title.new("Template:" .. path) | ||
if not title then return nil end | if not title then return nil end | ||
local ok, content = pcall(function() return title:getContent() end) | local ok, content = pcall(function() return title:getContent() end) | ||
| Строка 86: | Строка 86: | ||
local out = {} | local out = {} | ||
local errors = {} | |||
local keyOrder = {} | |||
local keyToTemplates = {} | |||
local function lcfirst(s) | |||
if not s or s == "" then return s end | |||
return string.lower(s:sub(1,1)) .. (s:sub(2) or "") | |||
end | |||
for compName,_ in pairs(foundComponents) do | for compName,_ in pairs(foundComponents) do | ||
local tplPath = " | local compPathName = lcfirst(compName) | ||
local tplPath = "component/" .. compPathName | |||
local content = load_template_content(tplPath) | local content = load_template_content(tplPath) | ||
if not content then | if not content then | ||
table.insert( | table.insert(errors, "Ошибка: не найден шаблон component/" .. compPathName) | ||
else | else | ||
local keys = parse_keys_from_template(content) | local keys = parse_keys_from_template(content) | ||
for _, key in ipairs(keys) do | for _, key in ipairs(keys) do | ||
table.insert( | if not keyToTemplates[key] then | ||
table.insert( | keyToTemplates[key] = {} | ||
table.insert(keyOrder, key) | |||
end | |||
table.insert(keyToTemplates[key], "{{" .. tplPath .. "|title|" .. key .. "}}") | |||
end | end | ||
end | end | ||
| Строка 103: | Строка 114: | ||
for protoName,_ in pairs(foundPrototypes) do | for protoName,_ in pairs(foundPrototypes) do | ||
local tplPath = "prototype/" .. | local protoPathName = lcfirst(protoName) | ||
local tplPath = "prototype/" .. protoPathName | |||
local content = load_template_content(tplPath) | local content = load_template_content(tplPath) | ||
if not content then | if not content then | ||
table.insert( | table.insert(errors, "Ошибка: не найден шаблон prototype/" .. protoPathName) | ||
else | else | ||
local keys = parse_keys_from_template(content) | local keys = parse_keys_from_template(content) | ||
for _, key in ipairs(keys) do | for _, key in ipairs(keys) do | ||
table.insert( | if not keyToTemplates[key] then | ||
table.insert( | keyToTemplates[key] = {} | ||
table.insert(keyOrder, key) | |||
end | |||
table.insert(keyToTemplates[key], "{{" .. tplPath .. "|title|" .. key .. "}}") | |||
end | end | ||
end | |||
end | |||
-- Append errors first | |||
for _, e in ipairs(errors) do | |||
table.insert(out, "<div class=\"error\">" .. mw.text.encode(e) .. "</div>") | |||
end | |||
-- Then for each key output header and all template invocations for that key | |||
for _, key in ipairs(keyOrder) do | |||
table.insert(out, "<h2>" .. mw.text.encode(key) .. "</h2>") | |||
for _, tplCall in ipairs(keyToTemplates[key]) do | |||
table.insert(out, tplCall) | |||
end | end | ||
end | end | ||