Moduł:Stopka portal: Różnice pomiędzy wersjami

Z Nonsensopedii, polskiej encyklopedii humoru
M
M (nooo)
Linia 84: Linia 84:
args = tools.getArgs(frame)
args = tools.getArgs(frame)
local i = 1
local i = 1
local text = ''
while args[tostring(i)] do
while args[tostring(i)] do
makePortalItem(args[tostring(i)])
text = text .. makePortalItem(args[tostring(i)])
i = i + 1
i = i + 1
end
end
return text
end
end



Wersja z 21:22, 30 mar 2022

Generuje linki do portali w szablonie {{Stopka}}. Zobacz też: Moduł:Stopka.


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

-- Portale dodawaj alfabetycznie.
-- Edytuj śmiało, teksty zachęcające do kliknięcia w link są losowane z podanej tu puli
local portals = {
	['Historia'] = {
		letter = 'H',
		color = '#820000',
		text = {
			"Zobacz więcej artykułów w '''[[Portal:Historia|portalu o historii]]'''."
		}
	},
	['Informatyka'] = {
		letter = '',  -- Tux ;)
	 	color = '#235bc1',
		text = {
			"Zobacz więcej artykułów w '''[[Portal:Informatyka|portalu o informatyce]]'''."
		}
	},
	['Polityka'] = {
		letter = 'P',
	 	color = '#090082',
		text = {
			"Zobacz więcej artykułów w '''[[Portal:Polityka|portalu o polityce]]'''."
		}
	},
}

-- extra ordered list for navigation ordering
local portalList = {
	'Historia', 'Informatyka', 'Polityka'
}

-- Appends a portal initial to an HTML builder object
local function makeInitial(builder, name, info)
	return builder:tag('span')
		:addClass('n-portal-initial')
		:addClass('link-kolor')
		:cssText('color: ' .. info.color)
		:node('[[Portal:' .. name .. '|' .. info.letter .. ']]')
		:done()
end

-- Makes a div with a nice link to portal by the given name -> see the LUT above
local function makePortalItem(name)
	local info = portals[name]
	
	if info then
		div = mw.html.create('div')
			:addClass('n-portal-link')
		
		div = makeInitial(div, name, info)
		
		div = div:tag('span')
			:addClass('n-portal-link-text')
			:node(info.text[math.random(#info.text)])
			:done()
		
		return tostring(div)
	else
		return ''
	end
end

-- for {{stopka}}
function p.getText()
	local text = ''
	local title = mw.title.getCurrentTitle()
	local res = mw.smw.getQueryResult{ 
		'[[Zawiera artykuł::' .. title.fullText .. ']]',
		'[[Portal:+]]'
	}
	
	for _, r in ipairs(res.results) do
		text = text .. makePortalItem(mw.ustring.gsub(r.fulltext, 'Portal:', ''))
	end
	
	return text
end

-- for {{KatStopka}}
function p.getKatText(frame, args)
	args = tools.getArgs(frame)
	local i = 1
	local text = ''
	while args[tostring(i)] do
		text = text .. makePortalItem(args[tostring(i)])
		i = i + 1
	end
	return text
end

function p.getNavigation()
	local cont = mw.html.create('div')
		:addClass('n-portal-nav-container')
		
	for _, name in pairs(portalList) do
		info = portals[name]
		cont = cont:tag('div')
			:addClass('n-portal-nav-item')
			
		cont = makeInitial(cont, name, info)
		
		cont = cont:tag('span')
			:addClass('n-portal-nav-text')
			:node('[[Portal:' .. name .. '|' .. name .. ']]')
			:done()
			:done()
	end
	
	return tostring(cont)
end

return p