Zum Inhalt springen

Modul:Flusssymbole

aus Wikipedia, der freien Enzyklopädie


Dieses Modul gehört zu einem Set von Vorlagen, mit dem Flüsse dargestellt werden können. Zum Set gehören:
Vorlage:Fluss-Header Kopfzeile der Darstellung. Wird zusammen mit Fluss-Footer benutzt.
Vorlage:Fluss-Footer Endzeile der Darstellung. Wird zusammen mit Fluss-Header benutzt.
Vorlage:Fluss-Klappheader Kopfzeile der Darstellung (ausklappbar). Wird zusammen mit Fluss-Klappfooter benutzt.
Vorlage:Fluss-Klappfooter Endzeile der Darstellung (ausklappbar). Wird zusammen mit Fluss-Klappheader benutzt.
Vorlage:Fluss-Zeile Einfache Zeile

local d = mw.loadJsonData( 'Modul:Flusssymbole.json' )
local p = {}

-- resolves a symbol code to a filename via lookup table in Flusssymbole.json
local function datei(c)
	local t = d[string.gsub(c,' ','')] or {}
	return (t.g0 or 'RiverIcon-')..(t.g or 'None')..(t.g9 or '.svg')
end

-- reads symbol codes from a; replies wikitext with files
local function syms(a)
	local r = {}
	for _, c in ipairs(a) do
		table.insert(r, '[[Datei:')
		table.insert(r, datei(c))
		table.insert(r, '|x20px|alt=]]')
	end
	return #r>0 and table.concat(r, "")
end

local function zeile(a)
	local bc = function (c) return
		c and c~="" and "background-color:"..c..";" or ""
	end
	local inv = function (z) return
		(z:find("Sinnbild",1,true) or z == "Burg.svg") and "|klasse=skin-invert" or ""
	end
	local zus = function (z) return
		z and z~="" and "[[Datei:"..z.."|28x14px|alt="..inv(z).."]]" or ""
	end
	local tele = function (p, bt) p = syms(p) return p and
		'<div style="position:relative; z-index:1;"><div style="position:absolute; '
		..bt..':0px; width:100%;">'..p..'</div></div>' or ""
	end
	local ico = function (p) p = syms(p) return p and
		'<div style="position:relative; z-index:2;">'..p..'</div>' or ""
	end
	local m = tonumber(a.P) or 1 -- max positional args interpreted as sym code
	local To, Tu, P, x = { a.T or a.To }, { a.T or a.Tu }, {}
	for i = 1, 12 do
		table.insert(P, i<=m and a[i] or a['P'..i])
		x = a['T'..i] or a['To'..i]
		while x and #To < #P do table.insert(To, x) end -- auto-fills tele gaps
		x = a['T'..i] or a['Tu'..i]                     -- by repeating x for
		while x and #Tu < #P do table.insert(Tu, x) end -- missing T*= args
	end
	local rc = bc(a.rc)
	local lc = bc(a.lc)
	local to = tele(To, 'bottom')
	local tu = tele(Tu, 'top')
	local ps = ico(P)
	local r = { '<tr>',
		'\n<td style="', rc, 'padding:0 0 0 1em;">', zus(a.zr), (a.wr or ''), '</td>',
		'\n<td style="', rc, 'padding:0 1em; min-width:100px; text-align:right;">', (a[m+1] or ''), '</td>',
		'\n<td style="padding:0; overflow:hidden; text-align:center; width:30px;">', to, ps, tu, '</td>',
		'\n<td style="', lc, 'padding:0 1em; min-width:100px;">', (a[m+2] or ''), '</td>',
		'\n<td style="', lc, 'padding:0 1em 0 0; text-align:right;">', (a.wl or ''), zus(a.zl), '</td>',
		'\n</tr>'
	}
	return table.concat(r, "")
end

function p.datei(frame)
	return datei(frame.args[1])
end

function p.zeile(frame)
	return zeile(frame:getParent().args)
end

function p.uebersicht(frame)
	local t = { table.concat({
		"{| class=\"wikitable sortable\" style=\"text-align:center\"",
		"|-", "! Nr.", "! <var>ID</var>", "! Bild",
		"! Feature<br />orographisch", "! Symbolisiert"
	}, "\n") }
	local _d = {}
	for k, v in pairs(d) do
		table.insert(_d, { id=v.id, k=k, g=v.g, de=v.de, o=v.o, a=v.a })
	end
	table.sort(_d, function (a, b) return a.id < b.id end)
	for _, v in ipairs(_d) do
		local b = v.de or "»Beschreibung fehlt«"
		local o = (v.o or ''):gsub('.',{ L="links",R="rechts",B="beidseitig" })
		if v.a then b = "[["..v.a.."|"..b.."]]" end
		table.insert(t, "-")
		table.insert(t, v.id)
		table.insert(t, v.k)
		table.insert(t, "[[Datei:"..datei(v.k).."|25px]]")
		table.insert(t, o)
		table.insert(t, "style=\"text-align:left\"|"..b)
	end
	table.insert(t, "}")
	return table.concat(t, "\n|")
end

return p