Moduł:Lepsze główne: Różnice pomiędzy wersjami

Z Nonsensopedii, polskiej encyklopedii humoru
M (kosmetyczne)
(fix)
Linia 12: Linia 12:
function makeElementTable(args, num)
function makeElementTable(args, num)
local cur = {}
local cur = {}
cur['title'] = removeUnwanted(args['ptytuł' .. num], 'Nie podano tytułu')
cur['title'] = sanitizeOrElse(args['ptytuł' .. num], 'Nie podano tytułu')
cur['text'] = removeUnwanted(args['panel' .. num], '')
cur['text'] = sanitizeOrElse(args['panel' .. num], '')
cur['num'] = num
cur['num'] = num
cur['showstatus'] = removeUnwanted(args['pwarunki' .. num], '')
cur['showstatus'] = sanitizeOrElse(args['pwarunki' .. num], '')
cur['icon'] = removeUnwanted(args['pikona' .. num], '')
cur['icon'] = sanitizeOrElse(args['pikona' .. num], '')
cur['iconlink'] = removeUnwanted(args["pikonalink" .. num], '')
cur['iconlink'] = sanitizeOrElse(args["pikonalink" .. num], '')
return cur
return cur
end
end

Wersja z 13:35, 26 mar 2022

Moduł automatycznie generujący semi-responsywny kolumnowy układ stron głównych. Zobacz też: Szablon:Generator głównych


local tools = require('Moduł:Narzędzia')
local p = {}

function sanitizeOrElse(text, alt)
	if text ~= nil then
		return mw.text.nowiki(text)
	else
		return alt
	end
end

function makeElementTable(args, num)
	local cur = {}
	cur['title'] = sanitizeOrElse(args['ptytuł' .. num], 'Nie podano tytułu')
	cur['text'] = sanitizeOrElse(args['panel' .. num], '')
	cur['num'] = num
	cur['showstatus'] = sanitizeOrElse(args['pwarunki' .. num], '')
	cur['icon'] = sanitizeOrElse(args['pikona' .. num], '')
	cur['iconlink'] = sanitizeOrElse(args["pikonalink" .. num], '')
	return cur
end

-- robi listę elementów wg kolumn, ignoruje - i puste
function makeElementList(args)
	-- kolumny
	local first = {}
	local second = {}
	local curRight = false
	for i = 1, 50 do
		if args['panel' .. i] ~= nil then
			if args['panel' .. i] == '-' or args['panel' .. i] == '' then else
				local cur = makeElementTable(args, i)
				if i % 2 == 1 then
					table.insert(first, cur)
					curRight = false
				else
					cur["showstatus"] = cur["showstatus"] .. " desktoponly"
					table.insert(second, cur)
					local cur2 = makeElementTable(args, i)
					cur2["showstatus"] = cur2["showstatus"] .. " mobileonly"
					table.insert(first, cur2)
					curRight = true
				end
			end
		else break end
	end
	if curRight then
		table.remove(first, table.maxn(first))
		local maxSec = table.maxn(second)
		local ss = second[maxSec]["showstatus"]
		second[maxSec]["showstatus"] = string.gsub(ss, " desktoponly", "")
	end
	return first, second
end


function makePanel(tab)
	local panelname = tab["title"]
	local template = tab["text"]
	local mobiledesktop = tab["showstatus"]
	local icon = tab["icon"]
	local iconlink = tab["iconlink"]
	local id = "panel-" .. tab["num"] .. "-" .. mw.text.encode(panelname)
	local wikitext = "{{User:Polskacafe/panel|" .. panelname .. "|{{" .. template .. "}}|ikona=" .. icon .. "|link=" .. iconlink .. "}}"
	local panel = mw.html.create("div")
		:addClass("glowna-panel")
		:attr("id", id)
		:wikitext(wikitext)
	if (mobiledesktop ~= nil) then
		panel = panel:addClass(mobiledesktop)
	end
	return panel:done()
end
		

function makeColumn(elements)
	column = mw.html.create("div")
		:addClass("glowna-kolumna")
	for k,v in ipairs(elements)
	do
		local elem = makePanel(v)
		column = column:node(elem)
	end
	return column:done()
end

function makeAll(args)
	local first, second = makeElementList(args)
	local mainList = mw.html.create("div")
		:addClass("glowna-lista")
		:node(makeColumn(first))
		:node(makeColumn(second))
		:done()
	return mainList
end

function p.kolumny(frame)
	local args = tools.getArgs(frame) -- argumenty szablonu to jest
	local mainList = makeAll(args)
	return frame:preprocess(tostring(mainList))
end
return p