Modul:Dokumentáció

A Wikipédiából, a szabad enciklopédiából

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

require('strict')

local p = {}

local function box(title, args, header, purgelink, preload)
	local frame = mw.getCurrentFrame()
	local text, cat
	if title == mw.title.getCurrentTitle() then
		text = '<strong class="error">Hibás paraméter: A sablon saját magára hivatkozik! Az első paraméter nem egyezhet meg a sablon nevével.</strong>'
		cat = 'Hibásan használt sablonok'
	elseif title.exists then
		text = frame:expandTemplate{ title = title, args = args or {} }
		cat = 'Sablonok dokumentációval'
	else
		local link = title:fullUrl{
			action = 'edit',
			preload = preload
		}
		text = string.format('Amiben segíthetsz: [%s dokumentációs allap létrehozása]', link)
		cat = 'Leírás nélküli sablonok'
	end
	local styles = frame:extensionTag('templatestyles', nil, { src = 'Modul:Dokumentáció/style.css' })
	local padlock = require('Modul:Lapvédelem').autoTemplate{ small = true } or ''
	if header then
		header = header .. '\n'
	else
		header = ''
	end
	local purge = ''
	if purgelink then
		purge = string.format('<div class="template-documentation-purgelink">%s</div>\n', frame:expandTemplate{ title = 'Purge' })
	end
	text = string.format('<div class="template-documentation">\n%s\n%s\n%s%s\n%s</div>', styles, padlock, header, text, purge)
	return text, cat
end

function p.template(frame)
	local preload = 'Sablon:Sablondokumentáció/docpreload'
	local args = {}
	local title
	local function processTable(tbl)
		if tbl[1] then
			title = tbl[1]
		end
		local max = #tbl > 7 and #tbl or 7
		for i = 2, max do
			args[i-1] = tbl[i] or args[i-1] or ''
		end
	end
	if type(frame) == 'table' then
		if frame.getParent then
			processTable(frame:getParent().args) 
		end
		if frame.args then
			processTable(frame.args)
		else
			processTable(frame)
		end
	end
	title = title and mw.title.new(title, 10) or mw.title.getCurrentTitle():subPageTitle('doc')
	local titleText = '[[Fájl:Template-info.svg|50px]] <span class="mw-headline">Használati útmutató</span>'
	local titleLinksText = '<ul class="template-documentation-titlelinks plainlinks">\n' ..
		'<li class="template-documentation-titlelinks-help">[[Wikipédia:Sablondokumentáció|sablondok. infó]]</li>\n' ..
		'<li class="template-documentation-titlelinks-edit">[' .. title:fullUrl{ action = 'edit', preload = preload } .. ' szerkesztés]</li>\n' ..
		(title.exists and ('<li class="template-documentation-titlelinks-history">[' .. title:fullUrl{ action = 'history' } .. ' történet]</li>\n') or '') ..
		'</ul>'
	local header = string.format('<div class="template-documentation-title">%s %s</div>', titleText, titleLinksText)
	local div, cat = box(title, args, header, true, preload)
	return div .. '[[Kategória:' .. cat .. ']]'
end

function p.module(frame)
	local title = mw.title.getCurrentTitle()
	local isTests = title.subpageText == 'tests'
	title = title:subPageTitle('doc')
	local header = mw.getCurrentFrame():expandTemplate{ title = isTests and 'Modul teszt fejléc' or 'Modul fejléc' }
	local body = ''
	if title.exists then
		body = box(title)
	end
	return header .. body
end

return p