Module:MapLocation

From HOPE Wiki
Revision as of 22:36, 9 July 2026 by Lexicon (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Documentation for this module may be created at Module:MapLocation/doc

local p = {}

local function clean(value)
	if value == nil then
		return ""
	end
	return mw.text.trim(tostring(value))
end

function p.infobox(frame)
	local args = frame:getParent().args

	local name = clean(args.name)
	if name == "" then
		name = mw.title.getCurrentTitle().text
	end

	local lat = clean(args.lat)
	local lon = clean(args.lon)
	local category = clean(args.category)
	local description = clean(args.description)
	local hours = clean(args.hours)
	local url = clean(args.url)

	if category == "" then
		category = "Other"
	end

	local out = {}

	table.insert(out,
		'<div class="hope-map-location" ' ..
		'style="border:1px solid #aaa; padding:0.75em; ' ..
		'margin:0.75em 0; max-width:32em;">'
	)

	table.insert(out, "'''" .. name .. "'''<br />")
	table.insert(out, "'''Category:''' " .. category .. "<br />")

	if lat ~= "" and lon ~= "" then
		table.insert(out,
			"'''Coordinates:''' " .. lat .. ", " .. lon .. "<br />"
		)
	else
		table.insert(out, "'''Coordinates:''' Missing<br />")
	end

	if description ~= "" then
		table.insert(out,
			"'''Description:''' " .. description .. "<br />"
		)
	end

	if hours ~= "" then
		table.insert(out,
			"'''Hours:''' " .. hours .. "<br />"
		)
	end

	if url ~= "" then
		table.insert(out,
			"'''Website:''' [" .. url .. " Official website]<br />"
		)
	end

	table.insert(out, "</div>")
	table.insert(out, "[[Category:HOPE 26 Map Locations]]")
	table.insert(out, "[[Category:HOPE 26 " .. category .. "]]")

	return table.concat(out, "\n")
end

return p