Module:Locations: Difference between revisions
Modularising locations too |
m bugfix |
||
| Line 2: | Line 2: | ||
local p = {} | local p = {} | ||
p.groups = { | p.groups = { | ||
{ | { | ||
| Line 54: | Line 53: | ||
} | } | ||
function p.renderNav(frame) | function p.renderNav(frame) | ||
local args = { | local args = { | ||
| Line 63: | Line 61: | ||
"| state = " .. (frame.args.state or "autocollapse") | "| state = " .. (frame.args.state or "autocollapse") | ||
} | } | ||
for i, grp in ipairs(p.groups) do | for i, grp in ipairs(p.groups) do | ||
table.insert(args, "| group" .. i .. " = " .. grp.name) | table.insert(args, "| group" .. i .. " = " .. grp.name) | ||
local items = {} | local items = {} | ||
for _, entry in ipairs(grp.list) do | for _, entry in ipairs(grp.list) do | ||
local target, label | |||
if entry:find("|") then | if entry:find("|") then | ||
local | local parts = mw.text.split(entry, "|", true) | ||
target = parts[1] | |||
label = parts[2] or parts[1] | |||
else | else | ||
target = entry | |||
label = entry | |||
end | end | ||
table.insert(items, "* [[" .. target .. "|" .. label .. "]]") | |||
end | end | ||
table.insert(args, "| list" .. i .. " =\n" .. table.concat(items, "\n")) | table.insert(args, "| list" .. i .. " =\n" .. table.concat(items, "\n")) | ||
end | end | ||
table.insert(args, "}}") | table.insert(args, "}}") | ||
return frame:preprocess(table.concat(args, "\n")) | return frame:preprocess(table.concat(args, "\n")) | ||
end | end | ||
function p.renderList(frame) | function p.renderList(frame) | ||
local out = {"= List of locations and concepts =\n"} | local out = {"= List of locations and concepts =\n"} | ||
for _, grp in ipairs(p.groups) do | for _, grp in ipairs(p.groups) do | ||
table.insert(out, "== " .. grp.name .. " ==\n") | table.insert(out, "== " .. grp.name .. " ==\n") | ||
table.insert(out, | table.insert(out, '<div style="column-count:2; column-gap:2em;">\n') | ||
for _, entry in ipairs(grp.list) do | for _, entry in ipairs(grp.list) do | ||
local target, label | |||
if entry:find("|") then | if entry:find("|") then | ||
local | local parts = mw.text.split(entry, "|", true) | ||
target = parts[1] | |||
label = parts[2] or parts[1] | |||
else | else | ||
target = entry | |||
label = entry | |||
end | end | ||
table.insert(out, "* [[" .. target .. "|" .. label .. "]]\n") | |||
end | end | ||
table.insert(out, "</div>\n") | table.insert(out, "</div>\n") | ||
end | end | ||
return table.concat(out, "\n") | return table.concat(out, "\n") | ||
end | end | ||
return p | return p | ||
Revision as of 23:33, 23 April 2025
Documentation for this module may be created at Module:Locations/doc
-- Module:Locations
local p = {}
p.groups = {
{
name = "Schools",
list = {
"Roseville Elementary School",
"Roseville Middle School",
"Roseville High School",
"Roseville High School#Auditorium|<small>Auditorium</small>",
"Roseville High School#Bus stop|<small>Bus stop</small>",
"Roseville High School#Cafeteria|<small>Cafeteria</small>",
"Roseville High School#Gymnasium|<small>Gymnasium</small>",
"Roseville High School#Library|<small>Library</small>",
"Roseville High School#Oval|<small>Oval</small>"
}
},
{
name = "Homes",
list = {
"Mike's house","Lucy's house","Paulo's house","Daisy's house",
"David's house","Augustus's house","Abbey's house","Rachel's house",
"Sandy's house","Tess's house"
}
},
{
name = "Businesses",
list = {
"Airport","Aquarium","Bowling alley","Burger-Tron","Carnival",
"Convention center","Drive-in theater","Maraschino mall",
"Modeling agency","Psychiatrist's office","Roseville cinema",
"Roseville shopping mall"
}
},
{
name = "Concepts",
list = {
"Blasto","Roseville High Hornets","SwordsVale"
}
},
{
name = "Other locations",
list = {
"Abandoned warehouse rooftop","Abbey's childhood house",
"Alejandro's apartment","Cinder Station area",
"East Rutledge High School","Hospital","Maraschino City",
"Matt's aunt's beachhouse","Museum",
"Neighborhood sidewalks and streets","Northern Highway",
"Park","Prom Venue","Silvershore Islands"
}
}
}
function p.renderNav(frame)
local args = {
"{{Navbox",
"| name = Locations and concepts",
"| title = Locations and concepts",
"| listclass = hlist",
"| state = " .. (frame.args.state or "autocollapse")
}
for i, grp in ipairs(p.groups) do
table.insert(args, "| group" .. i .. " = " .. grp.name)
local items = {}
for _, entry in ipairs(grp.list) do
local target, label
if entry:find("|") then
local parts = mw.text.split(entry, "|", true)
target = parts[1]
label = parts[2] or parts[1]
else
target = entry
label = entry
end
table.insert(items, "* [[" .. target .. "|" .. label .. "]]")
end
table.insert(args, "| list" .. i .. " =\n" .. table.concat(items, "\n"))
end
table.insert(args, "}}")
return frame:preprocess(table.concat(args, "\n"))
end
function p.renderList(frame)
local out = {"= List of locations and concepts =\n"}
for _, grp in ipairs(p.groups) do
table.insert(out, "== " .. grp.name .. " ==\n")
table.insert(out, '<div style="column-count:2; column-gap:2em;">\n')
for _, entry in ipairs(grp.list) do
local target, label
if entry:find("|") then
local parts = mw.text.split(entry, "|", true)
target = parts[1]
label = parts[2] or parts[1]
else
target = entry
label = entry
end
table.insert(out, "* [[" .. target .. "|" .. label .. "]]\n")
end
table.insert(out, "</div>\n")
end
return table.concat(out, "\n")
end
return p