Ugrás a tartalomhoz

Modul:Portál

Ellenőrzött
A Wikipédiából, a szabad enciklopédiából

Portál[mi ez?] • [dokumentáció: mutat, szerkeszt] • [tesztek: létrehozás]

local getArgs = require('Modul:Arguments').getArgs
local p = {}

local function prepareArgs(args)
	local prepared, other = {}, {}
	for _, v in ipairs( args ) do
		if mw.title.new( 'Portál:' .. v ) and mw.title.new( 'Portál:' .. v ).exists then
			table.insert( prepared, { mw.text.trim( v ) } )
		-- ne pakoljon a prepared[0]-ba, gyakori {{portál|X|-|}} paramétermegadás
		-- javítása (kategorizálandó?)
		elseif #prepared > 0 and prepared[#prepared][2] == nil then
			prepared[#prepared][2] = v
		end
	end
	for n, v in pairs( args ) do
		if type(n) ~= 'number' and v ~= '' then
			other[ n ] = v
		end
	end
	if #prepared == 0 then
		prepared = nil
	end
	return prepared, other
end

local function text(name, extra, css, desc)
	local frame = mw.getCurrentFrame()
	local function ucfirst(t)
		return mw.language.getContentLanguage():ucfirst(t)
	end
	local function special(prop)
		return frame:expandTemplate{ title = 'Portál/speciális', args = { name, prop } }
	end
	local file, txt
	local specialImg = special('ikon')
	local subpage = mw.title.new( 'Portál:' .. name .. '/ikon' )
	if specialImg and specialImg ~= '' then
		file = specialImg
	elseif subpage.exists then
		file = frame:expandTemplate{ title = subpage }
	elseif mw.title.new( 'Media:Portál ' .. name .. '.png' ).exists then
		file = 'Portál ' .. name .. '.png'
	else
		file = 'Portal.svg'
	end
	file = '[[Fájl:' .. file .. '|25x25px|' .. name .. ']]'
	local specialTxt = special('név')
	if specialTxt and specialTxt ~= '' then
		txt = specialTxt
	else
		txt = ucfirst(name) .. (extra or '') .. 'portál'
	end
	txt = string.format( "%s '''[[Portál:%s|%s]]'''", file, name, txt )
	if desc then
		txt = txt .. ' ' .. frame:expandTemplate{ title = 'Portál/leírások', args = { name } }
	end
	local li = mw.html.create( 'li' )
	li
		:css(css)
		:wikitext(txt)
	return tostring(li)
end

local function getUl(args)
	local desc = (#args == 1)
	local function one(n, baseCss, moreCss)
		baseCss['float']	= moreCss.float
		baseCss['width']	= moreCss.width
		baseCss['margin-left']	= moreCss.mleft
		baseCss['margin-right']	= moreCss.mright
		return text(args[n][1], args[n][2], baseCss, desc)
	end
	local ul = mw.html.create( 'ul' )
	local css = {
		['display']	= 'block',
		['clear']	= 'both',
		['list-style-type']	= 'none',
		['list-style-image']	= 'none',
		['width']	= '100%',
		['vertical-align']	= 'middle',
		['margin']	= '0 0 1em',
		['padding']	= '0',
		['min-height'] = '27px'
	}
	ul:css(css)
	local liCss = {
		['min-height']	= '27px',
		['line-height']	= '25px',
		['margin-bottom']	= '0',
		['margin-top']	= '0.5em',
		['padding'] = '0',
		['border']	= '1px solid #ccf',
		['background-color']	= '#f0eeff'
	}
	for n, v in pairs(args) do
		local pos = n % 3
		local moreCss = {}
		if pos == 1 then
			moreCss.float	= 'left'
			if args[n+2] then
				moreCss.width	= '33%'
				moreCss.mleft	= '-4px'
				moreCss.mright	= '1%'
			elseif args[n+1] then
				moreCss.width	= '49%'
				moreCss.mleft	= '-3px'
				moreCss.mright	= '1%'
			else
				moreCss.width	= '100%'
				moreCss.mleft	= '0'
				moreCss.mright	= '0'
			end
		elseif pos == 2 then
			if args[n+1] then
				moreCss.float	= 'left'
				moreCss.width	= '32%'
				moreCss.mleft	= '0'
				moreCss.mright	= '1%'
			else
				moreCss.float	= 'right'
				moreCss.width	= '49%'
				moreCss.mleft	= '1%'
				moreCss.mright	= '-3px'
			end
		else
			moreCss.float	= 'right'
			moreCss.width	= '33%'
			moreCss.mleft	= '0'
			moreCss.mright	= '-4px'
		end
		ul:wikitext( one(n, liCss, moreCss) )
	end
	return tostring(ul)
end

function p.main(frame)
	local args = getArgs( frame, { trim = false, removeBlanks = false } )
	local configs
	args, configs = prepareArgs(args)
	local div = mw.html.create( 'div' )
	local divCss = {
		['margin-left']  = '0',
		['margin-right'] = '2px'
	}
	if args then
		div:wikitext( getUl(args) )
		if args[3] then
			divCss['margin-left']  = '4px'
			divCss['margin-right'] = '4px'
		elseif args[2] then
			divCss['margin-left']  = '3px'
			divCss['margin-right'] = '3px'
		end
	else
		-- ha a usernek baja van
		local errDiv = mw.html.create( 'div' )
		errDiv
			:addClass( 'error' )
			:css( 'font-size', 'larger' )
			:wikitext( 'A {{portál}} sablon számára legalább egy paramétert meg kell adnod!' )
		div:wikitext( tostring( errDiv ) )
	end
	div
		:addClass( 'portalbox noprint noviewer' )
		:css(divCss)
	return tostring( div )
end

return p
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy