Module:Places: Difference between revisions

From Nguhcraft Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 55: Line 55:
_m.condominia = function(frame)
_m.condominia = function(frame)
out = [=[
out = [=[
<table>
<table class="wikitable sortable">
<th>Common name</th>
<th>Common name</th>
<th>Full name</th>
<th>Full name</th>
Line 82: Line 82:
out = out .. "<td>" .. c.code2 .. "</td>"
out = out .. "<td>" .. c.code2 .. "</td>"
out = out .. "<td>" .. c.code3 .. "</td>"
out = out .. "<td>" .. c.code3 .. "</td>"
out = out .. "<td>" .. (c.ung == "member" and "yes" or "no") .. "</td>"
if not c.notes then out = out .. "<td></td>" else
if not c.notes then out = out .. "<td></td>" else
out = out .. [[<td><div class="mw-collapsible mw-collapsed">]] .. c.notes .. "</div></td>"
out = out .. [[<td><div class="mw-collapsible mw-collapsed">]] .. c.notes .. "</div></td>"

Revision as of 10:42, 19 November 2025

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

local _m = {}
local u = require"Module:Utils"

local data = mw.loadJsonData([[Data:Places]])

_m.countries = function(frame)
	local out = [==[
<table class="wikitable sortable">
<tr>
	<th>Common name</th>
	<th>Full name</th>
	<th>Ruler</th>
	<th>Ruler title</th>
	<th data-sort-type="date">Date founded</th>
	<th>Capital</th>
	<th>Code-2</th>
	<th>Code-3</th>
	<th>UŊ Member</th>
	<th>Notes</th>
</tr>
]==]
	for _, c in ipairs(data.places) do
		if not c.not_ngation and not c.condominium and not c.reason_dissolved and not c.reserved then
			out = out .. "<tr>"
			out = out .. "<td>" .. frame:expandTemplate{title = "Banner", args = {c.code2}}
			          .. " " .. (c.common_name and ("[[" .. c.common_name .. "]]") or "") .. "</td>"
			out = out .. "<td>" .. (c.name or "") .. "</td>"
			if not c.ruler then out = out .. "<td></td>"
			elseif type(c.ruler) == "table" then
				out = out .. "<td>"
				for i, r in ipairs(c.ruler) do out = out .. (i ~= 1 and ", [[" or "[[") .. r .. "]]" end
				out = out .. "</td>"
			elseif c.ruler_link then
				out = out .. "<td>[[" .. c.ruler_link .. "|" .. c.ruler .. "]]</td>"
			else out = out .. "<td>[[" .. c.ruler .. "]]</td>"
			end
			out = out .. "<td>" .. (c.ruler_title or "") .. "</td>"
			if not c.date_founded then out = out .. "<td></td>" else
				out = out .. "<td>" .. u.date(c.date_founded[1], c.date_founded[2], c.date_founded[3], true) .. "</td>"
			end
			out = out .. "<td>" .. (c.capital or "") .. "</td>"
			out = out .. "<td>" .. c.code2 .. "</td>"
			out = out .. "<td>" .. c.code3 .. "</td>"
			out = out .. "<td>" .. (c.ung == "member" and "yes" or "no") .. "</td>"
			if not c.notes then out = out .. "<td></td>" else
				out = out .. [[<td><div class="mw-collapsible mw-collapsed">]] .. c.notes .. "</div></td>"
			end
			out = out .. "</tr>"
		end
	end
	out = out .. [[</table>]]
	return out
end

_m.condominia = function(frame)
	out = [=[
<table  class="wikitable sortable">
	<th>Common name</th>
	<th>Full name</th>
	<th data-sort-type="date">Date founded</th>
	<th>Capital</th>
	<th>Parent Ŋation(s)</th>
	<th>Code-2</th>
	<th>Code-3</th>
	<th>Notes</th>
</tr>
]=]
	for _, c in ipairs(data.places) do
		if c.condominium then
			out = out .. "<tr>"
			out = out .. "<td>" .. frame:expandTemplate{title = "Banner", args = {c.code2}}
			          .. " " .. (c.common_name and ("[[" .. c.common_name .. "]]") or "") .. "</td>"
			out = out .. "<td>" .. (c.name or "") .. "</td>"
			if not c.date_founded then out = out .. "<td></td>" else
				out = out .. "<td>" .. u.date(c.date_founded[1], c.date_founded[2], c.date_founded[3], true) .. "</td>"
			end
			out = out .. "<td>" .. (c.capital or "") .. "</td>"
			for i, p in ipairs(c.condominium) do
				if i ~= 1 then out = out .. ", " end
				out = out .. _m.get_style(p)
			end
			out = out .. "<td>" .. c.code2 .. "</td>"
			out = out .. "<td>" .. c.code3 .. "</td>"
			if not c.notes then out = out .. "<td></td>" else
				out = out .. [[<td><div class="mw-collapsible mw-collapsed">]] .. c.notes .. "</div></td>"
			end
			out = out .. "</tr>"
		end
	end
	out = out .. [[</table>]]
	return out
end

_m.non_countries = function(frame)
	return ""
end
_m.former = function(frame)
	return ""
end

_m.get = function(it) for _, v in ipairs(data.places) do if it == v.code2 then return v end end end
_m.get_style = function(it)
	local c = _m.get(u._a(it))
	local f = mw.getCurrentFrame()
	return f:expandTemplate{title = "Banner", args = {c.code2}} .. "[[" .. c.common_name .. "]]"
end

_m.get_banner = function(frame)
	for _, c in ipairs(data.places) do
		if c.code2 == frame.args[1] then return (c.banner or "???") end
	end
end
return _m