Zum Inhalt springen

Modul:SimpleLinkList

aus Wikipedia, der freien Enzyklopädie
Dies ist eine alte Version dieser Seite, zuletzt bearbeitet am 10. Februar 2022 um 19:53 Uhr durch Vollbracht (Diskussion | Beiträge). 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 = {}

p.culled = function(frame)
	if frame.args[1] == nil then
		return frame:preprocess('[[Modul:SimpleLinkList]]')
	end
	local Param = mw.text.split(frame.args[1], ',')
	local result = ""
	local title = frame:getTitle()
	mw.log(title)
	for _, v in ipairs(Param) do
		if v ~= title then
			result = result .. ' - ' .. frame:preprocess('[[' .. 
				string.gsub(v, '^%s*(.-)%s*$', '%1') .. ']]')
		end
	end
	return mw.ustring.sub(result, 4)
end

p.stacked = function(frame)
	if frame.args[1] == nil then
		return frame:preprocess('[[Modul:SimpleLinkList]]')
	end
	local Param = mw.text.split(frame.args[1], ',')
	local result = ""
	local title = frame:getTitle()
	mw.log(title)
	for _, v in ipairs(Param) do
		if v ~=  title then
			result = result .. '<br />' .. frame:preprocess('[[' .. 
				string.gsub(v, '^%s*(.-)%s*$', '%1') .. ']]')
		end
	end
	return mw.ustring.sub(result, 7)
end

p.highlighted = function(frame)
	if frame.args[1] == nil then
		return frame:preprocess('[[Modul:SimpleLinkList]]')
	end
	local Param = mw.text.split(frame.args[1], ',')
	local result = ""
	local title = frame:getTitle()
	mw.log(title)
	for _, v in ipairs(Param) do
		if v ==  title then
			result = result .. ' - ' .. 
			         '<span class="highlighted">' .. v .. '</span>'
		else
			result = result .. ' - ' .. frame:preprocess('[[' .. 
				string.gsub(v, '^%s*(.-)%s*$', '%1') .. ']]')
		end
	end
	return mw.ustring.sub(result, 4)
end

p.stackedHL = function(frame)
	if frame.args[1] == nil then
		return frame:preprocess('[[Modul:SimpleLinkList]]')
	end
	local Param = mw.text.split(frame.args[1], ',')
	local result = ""
	local title = frame:getTitle()
	mw.log(title)
	for _, v in ipairs(Param) do
		if v ==  title then
			result = result .. '<br />' .. 
			         '<span class="highlighted">' .. v .. '</span>'
		else
			result = result .. '<br />' .. frame:preprocess('[[' .. 
				string.gsub(v, '^%s*(.-)%s*$', '%1') .. ']]')
		end
	end
	return mw.ustring.sub(result, 7)
end

return p