Модуль:Example

Материал из in.wiki
Версия от 19:35, 15 января 2016; t>WindEwriX (для начала)
(разн.) ← Предыдущая версия | Текущая версия (разн.) | Следующая версия → (разн.)
Перейти к навигации Перейти к поиску

Для документации этого модуля может быть создана страница Модуль:Example/doc

local p = {}

local function copy(other)
	local res = {}
	for k,v in pairs(other) do 
		res[k] = v
	end
	return res
end

function expand(frame, tname, args)
	local success, result = pcall(
		frame.expandTemplate,
		frame,
		{title = template, args = targs}
	)
	if success then
		return result
	else
		return ''
	end
end	


function p.main(frame)
	local args = copy(frame.args)
	tag =  args._tag or 'code'
	sep =  args._sep or '→'
	nwt = mw.html.create(tag):tag(tag)

	content = '{{'

	if args._template then
		tname = args._template
	else
		tname = args[1]
		table.remove(args,1)
		args[1] = nil
	end

	content = content .. tname
	
	local targs = {}
	
	for k, v in pairs(args) do
		if type(k) == 'number' then
			targs[k] = v
			content = content .. '|' .. v
		elseif not k:find('^_') then
			targs[k] = v
			content = content .. '|' .. k .. '=' .. v
		end
	end

	content = content .. '}}'
	nwt:wikitext(content):done()

	return tostring(nwt) .. sep .. tostring(expand(frame, tname, targs))
end

return p