Modul:SimpleLinkList

aus Wikipedia, der freien Enzyklopädie
--[=[ 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
			local splE = mw.text.split(elm, '{{{!}}}')
			if splE[2] == nil then splE = {elm, elm} end
			if splE[1] == title.fullText or splE[1] == title.text then
				result = result .. string.format(formatActive, splE[2])
			else
				result = result .. string.format(formatPassive,
				         frame:preprocess('[[' .. splE[1] .. '|' .. splE[2] .. ']]'))
			end
		end
	end
	return mw.ustring.sub(result, len)
end

p.spaced = function(frame)
	return p.service.list(frame, ' %s', ' %s')
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

TABS = {}
	TABS.HEADER='<table class="tab"><tr><td class="marginLT">&nbsp;</td>'
	TABS.FOOTER='</tr></table>'
	TABS.SPACING='<td class="spacingTR">&nbsp;</td>'
	TABS.DEFAULT='<td>%s</td>' .. TABS.SPACING
	TABS.ACTIVE='<td class="active">%s</td>' .. TABS.SPACING
	TABS.ACTIVETH='<th class="active">%s</th>' .. TABS.SPACING
	TABS.ACTIVEHL='<td class="active highlight">%s</td>' .. TABS.SPACING

p.tabulated = function(frame)
	local result = TABS.HEADER
	local result = result .. p.service.list(frame, TABS.DEFAULT, TABS.ACTIVE)
	return result .. TABS.FOOTER
end

p.tabulatedTH = function(frame)
	local result = TABS.HEADER
	local result = result .. p.service.list(frame, TABS.DEFAULT, TABS.ACTIVETH)
	return result .. TABS.FOOTER
end

p.tabulatedHL = function(frame)
	local result = TABS.HEADER
	local result = result .. p.service.list(frame, TABS.DEFAULT, TABS.ACTIVEHL)
	return result .. TABS.FOOTER
end

return p