Модуль:Песочница/Knkd/Test01

Материал из Википедии — свободной энциклопедии
Перейти к навигации Перейти к поиску
Документация

Хеллоуворд.

local p = {}

local template = [[<div style="float:right; clear:right; border:solid black 1px; margin:1px;">
	<table style="width:238px; background:%s;" cellspacing="0">
		<tr>
			<td style="width:45px; height:45px; background:%s; text-align:center; font-size:12pt; font-weight:bold;">%s</td>
			<td style="font-size:8pt; padding:4pt; line-height:1.25em; color:black;">%s</td>
		</tr>
	</table>
</div>]]

local function strip(str)
	return str:gsub('^[ \n\t]+', ''):gsub('[ \n\t]+$', '')
end

function p.hello(frame)
	local title       = strip(frame.args["title"]       or frame.args[1] or "")
	local title_color = strip(frame.args["title_color"] or frame.args[2] or "")
	local icon        = strip(frame.args["icon"]        or frame.args[3] or "")
	local icon_color  = strip(frame.args["icon_color"]  or frame.args[4] or "")
	
	return template:format(title_color, icon_color, icon, title)
	-- local bf = ""
	-- for k, v in pairs(frame.args) do
	-- 	bf = bf .. ("%s => %s\n\n"):format(k, v)
	-- end
	-- return bf
end

return p