Module:Sandbox/Ahecht: Difference between revisions

Content deleted Content added
clear
Tag: Replaced
test
Line 31:
end
 
function p.infoboxattraction(frame)
 
local output = {"{{Infobox attraction/section/sandbox"}
local args = {[0]={}}
for k,v in pairs(frame:getParent().args) do
local val = mw.text.trim(v)
if val or "" ~= "" then
-- val exists and isn't blank
local loc = tonumber(mw.ustring.sub(k,-1))
if loc and (loc > 0) and (loc <= 10) and (not mw.ustring.match(k, "location_%d+")) then
-- last character is a number 1-10, and it's not "location_#""
if not args[loc] then
args[loc] = {}
end
-- strip "location_" and number from key
local key = mw.ustring.gsub(mw.ustring.gsub(k, "_?%d+$", ""), "^location_", "")
args[loc][key] = val
else
args[0][k] = val
end
end
end
for k, v in pairs(args[0]) do
table.insert(output, "| " .. k .. " = " .. v)
end
for i, a in ipairs(args) do
if not args[0]["location_" .. i] then
-- ___location subtemplate isn't defined
table.insert(output, "| location_" .. i .. " = {{Infobox attraction/section/sandbox|child=yes")
for k, v in pairs(a) do
table.insert(output, "| " .. k .. " = " .. v)
end
table.insert(output,"}}")
end
end
table.insert(output, "}}")
return table.concat(output, "\n")
end
 
return p