Module:StateMap
From Architecture
More actions
Documentation for this module may be created at Module:StateMap/doc
-- Save this code as Module:StateMap on your wiki
local p = {}
-- A private helper table to map common abbreviations (CA, Tex.) to full names
local stateAlias = {
["AL"] = "Alabama", ["AK"] = "Alaska", ["AZ"] = "Arizona", ["AR"] = "Arkansas",
["CA"] = "California", ["CO"] = "Colorado", ["CT"] = "Connecticut", ["DE"] = "Delaware",
["FL"] = "Florida", ["GA"] = "Georgia", ["HI"] = "Hawaii", ["ID"] = "Idaho",
["IL"] = "Illinois", ["IN"] = "Indiana", ["IA"] = "Iowa", ["KS"] = "Kansas",
["KY"] = "Kentucky", ["LA"] = "Louisiana", ["ME"] = "Maine", ["MD"] = "Maryland",
["MA"] = "Massachusetts", ["MI"] = "Michigan", ["MN"] = "Minnesota", ["MS"] = "Mississippi",
["MO"] = "Missouri", ["MT"] = "Montana", ["NE"] = "Nebraska", ["NV"] = "Nevada",
["NH"] = "New Hampshire", ["NJ"] = "New Jersey", ["NM"] = "New Mexico", ["NY"] = "New York",
["NC"] = "North Carolina", ["ND"] = "North Dakota", ["OH"] = "Ohio", ["OK"] = "Oklahoma",
["OR"] = "Oregon", ["PA"] = "Pennsylvania", ["RI"] = "Rhode Island", ["SC"] = "South Carolina",
["SD"] = "South Dakota", ["TN"] = "Tennessee", ["TX"] = "Texas", ["UT"] = "Utah",
["VT"] = "Vermont", ["VA"] = "Virginia", ["WA"] = "Washington", ["WV"] = "West Virginia",
["WI"] = "Wisconsin", ["WY"] = "Wyoming", ["DC"] = "District of Columbia"
}
-- The main function called by the template
function p.highlight(frame)
-- 1. Get the raw input argument (e.g., {{StateMap|texas}})
local input = frame.args[1] or frame:getParent().args[1]
-- 2. Basic cleanup: trim whitespace, capitalize the first letter, lowercase the rest.
if not input or input == "" then return "[[File:USA_Base_Map.png|300px|center]]" end
input = mw.text.trim(input)
-- Check aliases (e.g., 'CA' -> 'California')
local standardizedName = stateAlias[string.upper(input)]
-- If no abbreviation alias, try to standardize the full name casing (e.g., 'new york' -> 'New York')
if not standardizedName then
-- This basic function just capitalizes the first character;
-- a production system needs robust multi-word capitalization logic.
standardizedName = input:gsub("^%l", string.upper)
end
-- 3. Construct the filename based on our convention.
-- We are assuming these images EXIST on the wiki.
local filename = "USA_Map_with_" .. standardizedName .. "_Highlighted.png"
-- 4. Construct the MediaWiki image syntax to return.
-- Example Output: [[File:USA_Map_with_California_Highlighted.png|300px|center]]
local wikiSyntax = "[[File:" .. filename .. "|300px|center|Map highlighting " .. standardizedName .. "]]"
return wikiSyntax
end
return p