Zum Inhalt springen

Modul:SimpleLinkList

aus Wikipedia, der freien Enzyklopädie
Dies ist eine alte Version dieser Seite, zuletzt bearbeitet am 25. Juni 2022 um 14:08 Uhr durch Vollbracht (Diskussion | Beiträge) (ergänzt: tabuliert). Sie kann sich erheblich von der aktuellen Version unterscheiden.
Vorlagenprogrammierung Diskussionen Lua Unterseiten
Modul Deutsch English

Modul: Dokumentation

Diese Seite enthält Code in der Programmiersprache Lua. Einbindungszahl Cirrus


--[=[ SimpleLinkList 2022-02-10
simple link list generators for navigation in simmilar pages
Param for all methods: lemmas, comma separated
* culled: links to lemmas, hyphen separated, current page culled
* highlighted: links to lemmas, hyphen separated, current page highlighted
* stacked: links to lemmas, line break separated, current page culled
* stackedHL: links to lemmas, line break separated, current page highlighted
]=]

p = {service = {}}

p.service.list = function(frame, formatPassive, formatActive)
	if frame.args[1] == nil then
		return frame:preprocess('[[Modul:SimpleLinkList]]')
	end
	local Param = mw.text.split(frame.args[1], ',')
	local result = ""
	local title = mw.title.getCurrentTitle()
	for _, v in ipairs(Param) do
		local elm = string.gsub(v, '^%s*(.-)%s*$', '%1')
		if elm ~= "" then
			if elm == title.fullText or elm == title.text then
				result = result .. string.format(formatActive, elm)
			else
				result = result .. string.format(formatPassive,
				         frame:preprocess('[[' .. elm .. ']]'))
			end
		end
	end
	return mw.ustring.sub(result, len)
end

p.culled = function(frame)
	return p.service.list(frame, ' - %s', ' - %s')
end

p.stacked = function(frame)
	return p.service.list(frame, '<br />%s','<br />%s')
end

p.highlighted = function(frame)
	return p.service.list(frame, ' - %s',
	                      ' - <span class="highlight">%s</span>')
end

p.stackedHL = function(frame)
	return p.service.list(frame, '<br />%s',
	                      '<br /><span class="highlight">%s</span>')
end

p.tabulated = function(frame)
	local result = '<table style="border:none;margin:0;padding:0"><tr>'
	local result = result .. '<td style="border-left:none; border-top:none;">&nbsp;</td>'
	local result = result .. p.service.list(frame, '<td>%s</td><td style="border-right:none; border-top:none;">&nbsp;</td>',
	                    			  '<td style="border-bottom:none;">%s</td><td style="border-right:none; border-top:none;">&nbsp;</td>')
	return '<table '
end

p.tabulatedTH = function(frame)
	local result = '<table style="border:none;margin:0;padding:0"><tr>'
	local result = result .. '<td style="border-left:none; border-top:none;">&nbsp;</td>'
	local result = result .. p.service.list(frame, '<td>%s</td><td style="border-right:none; border-top:none;">&nbsp;</td>',
	                                  '<th style="border-bottom:none;">%s</th><td style="border-right:none; border-top:none;">&nbsp;</td>')
	return result .. '</tr></table>'
end

p.tabulatedHL = function(frame)
	local result = '<table style="border:none;margin:0;padding:0"><tr>'
	local result = result .. '<td style="border-left:none; border-top:none;">&nbsp;</td>'
	local result = result .. p.service.list(frame, '<td>%s</td><td style="border-right:none; border-top:none;">&nbsp;</td>',
	                '<td class="highlight" style="border-bottom:none;">%s</td><td style="border-right:none; border-top:none;">&nbsp;</td>')
	return result .. '</tr></table>'
end

return p