Module:MapLocation: Difference between revisions

From HOPE Wiki
Lexicon (talk | contribs)
getting ready to add a map
 
Lexicon (talk | contribs)
mNo edit summary
 
Line 1: Line 1:
local p = {}
local p = {}


local function esc(s)
local function clean(value)
if s == nil then return "" end
if value == nil then
s = tostring(s)
return ""
s = s:gsub("\\", "\\\\")
end
s = s:gsub('"', '\\"')
return mw.text.trim(tostring(value))
s = s:gsub("\n", " ")
return s
end
end


function p.infobox(frame)
function p.infobox(frame)
local a = frame:getParent().args
local args = frame:getParent().args
local name = a.name or mw.title.getCurrentTitle().text
 
local lat = a.lat or ""
local name = clean(args.name)
local lon = a.lon or ""
if name == "" then
local category = a.category or "Other"
name = mw.title.getCurrentTitle().text
local description = a.description or ""
end
local hours = a.hours or ""
 
local url = a.url or ""
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 = {}
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,
'<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, "'''" .. name .. "'''<br />")
table.insert(out, "'''Category:''' " .. category .. "<br />")
table.insert(out, "'''Category:''' " .. category .. "<br />")
table.insert(out, "'''Coordinates:''' " .. lat .. ", " .. lon .. "<br />")
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 .. " Link]<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


function p.geojson(frame)
if lat ~= "" and lon ~= "" then
local a = frame:getParent().args
table.insert(out,
local name = a.name or mw.title.getCurrentTitle().text
"'''Coordinates:''' " .. lat .. ", " .. lon .. "<br />"
local lat = a.lat or ""
)
local lon = a.lon or ""
else
local category = a.category or "Other"
table.insert(out, "'''Coordinates:''' Missing<br />")
local description = a.description or ""
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


if lat == "" or lon == "" then return "" end
table.insert(out, "</div>")
table.insert(out, "[[Category:HOPE 26 Map Locations]]")
table.insert(out, "[[Category:HOPE 26 " .. category .. "]]")


return string.format([[
return table.concat(out, "\n")
{
  "type": "Feature",
  "properties": {
    "title": "%s",
    "description": "%s",
    "marker-symbol": "marker",
    "marker-color": "%s"
  },
  "geometry": {
    "type": "Point",
    "coordinates": [%s, %s]
  }
}]], esc(name), esc(description), esc(category), lon, lat)
end
end


return p
return p

Latest revision as of 22:36, 9 July 2026

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