Module:Locations: Difference between revisions

From Candypedia
Modularising locations too
 
No edit summary
 
(6 intermediate revisions by one other user not shown)
Line 2: Line 2:
local p = {}
local p = {}


-- 1) Define your ordered groups & items
p.groups = {
p.groups = {
   {
   {
Line 54: Line 53:
}
}


-- 2a) Render the navbox (with proper re-parsing)
function p.renderNav(frame)
function p.renderNav(frame)
   local args = {
   local args = {
     "{{Navbox",
     "{{Navbox",
     "| name      = Locations and concepts",
     "| name      = Locations",
     "| title    = Locations and concepts",
     "| title    = Locations and concepts",
     "| listclass = hlist",
     "| listclass = hlist",
     "| 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
       -- allow piped sublinks
       -- Use ** for anything with a section (#), otherwise *
      local star = entry:find("#") and "** " or "* "
      local target, label
       if entry:find("|") then
       if entry:find("|") then
         local target, label = mw.text.split(entry, "|", true)
         local parts = mw.text.split(entry, "|", true)
         table.insert(items, "* [[" .. target .. "|" .. label .. "]]")
         target = parts[1]
        label  = parts[2] or parts[1]
       else
       else
         table.insert(items, "* [[" .. entry .. "]]")
         target = entry
        label  = entry
       end
       end
      table.insert(items, star .. "[[" .. 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


-- 2b) Render a plain “List of locations and concepts” page
function p.renderList(frame)
function p.renderList(frame)
   local out = {"= List of locations and concepts =\n"}
   local out = {""}
 
   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, "<div style=\"column-count:2; column-gap:2em;\">\n")
     table.insert(out, '<div style="column-count:3; 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 target, label = mw.text.split(entry, "|", true)
         local parts = mw.text.split(entry, "|", true)
         table.insert(out, "* [[" .. target .. "|" .. label .. "]]\n")
         target = parts[1]
        label  = parts[2] or parts[1]
       else
       else
         table.insert(out, "* [[" .. entry .. "]]\n")
         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

Latest revision as of 06:42, 24 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",
    "| 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
      -- Use ** for anything with a section (#), otherwise *
      local star = entry:find("#") and "** " or "* "
      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, star .. "[[" .. 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 = {""}

  for _, grp in ipairs(p.groups) do
    table.insert(out, "== " .. grp.name .. " ==\n")
    table.insert(out, '<div style="column-count:3; 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