Модуль:Песочница/Pok: различия между версиями

мНет описания правки
мНет описания правки
Строка 19: Строка 19:
if not content then return {} end
if not content then return {} end
local keys = {}
local keys = {}
local titlePos = string.find(content, "|%s*title%s*=")
local lower = content:lower()
local titlePos = lower:find("|%s*title%s*=")
if not titlePos then
if not titlePos then
return keys
return keys
end
end
local substr = content:sub(titlePos)
local endPos = substr:find("}}")
local startBrace = content:find("{{", titlePos)
local region = substr
local region = nil
if endPos then
if startBrace then
region = substr:sub(1, endPos)
local len = #content
local i = startBrace
local depth = 0
while i <= len - 1 do
local two = content:sub(i, i+1)
if two == "{{" then
depth = depth + 1
i = i + 2
elseif two == "}}" then
depth = depth - 1
i = i + 2
if depth == 0 then
region = content:sub(startBrace, i-1)
break
end
else
i = i + 1
end
end
end
if not region then
local substr = content:sub(titlePos)
local endPos = substr:find("}}")
if endPos then
region = substr:sub(1, endPos)
else
region = substr
end
end
end
for key in string.gmatch(region, "|%s*([^=|%}]-)%s*=") do
for key in string.gmatch(region, "|%s*([^=|%}]-)%s*=") do
Строка 67: Строка 95:
local foundComponents = {}
local foundComponents = {}
local foundPrototypes = {}
local foundPrototypes = {}
-- If the component.json contains a list for this id, use it (entity -> components)
local compList = componentDefs[id]
local compList = componentDefs[id]
if type(compList) == "table" then
if type(compList) == "table" then
Строка 77: Строка 104:
end
end


-- If the prototype.json contains a list for this id, use it (entity -> prototypes)
local protoList = prototypeDefs[id]
local protoList = prototypeDefs[id]
if type(protoList) == "table" then
if type(protoList) == "table" then
Строка 87: Строка 113:
end
end


-- Also support passing comma-separated component/prototype names directly
for name in string.gmatch(id, "[^,]+") do
for name in string.gmatch(id, "[^,]+") do
local n = trim(name)
local n = trim(name)
if n ~= "" then
if n ~= "" then
-- if it's a known component/prototype name, include it
if componentDefs[n] ~= nil then
if componentDefs[n] ~= nil then
foundComponents[n] = true
foundComponents[n] = true
Строка 98: Строка 122:
foundPrototypes[n] = true
foundPrototypes[n] = true
end
end
-- also allow using the name directly even if not present in defs
-- treat it as a component name
if componentDefs[n] == nil and prototypeDefs[n] == nil then
if componentDefs[n] == nil and prototypeDefs[n] == nil then
foundComponents[n] = true
foundComponents[n] = true
Строка 152: Строка 174:
end
end


-- Append errors first
for _, e in ipairs(errors) do
for _, e in ipairs(errors) do
table.insert(out, "<div class=\"error\">" .. mw.text.encode(e) .. "</div>")
table.insert(out, "<div class=\"error\">" .. mw.text.encode(e) .. "</div>")
end
end


-- Then for each key output header and all template invocations for that key
for _, key in ipairs(keyOrder) do
for _, key in ipairs(keyOrder) do
table.insert(out, "<h2>" .. mw.text.encode(key) .. "</h2>")
table.insert(out, "<h2>" .. mw.text.encode(key) .. "</h2>")