Module:Mbox

来自Bejeweled Wiki
跳转到导航 跳转到搜索

This module is used by most of the basic Notice templates and is invoked by {{MessageBox}}.


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


function p.main(frame)
	return p._main(getArgs(frame))
end


function p._main(args)
	local mbox = mw.html.create("div"):addClass("mbox")
	if args.tiny then mbox:addClass("mbox-tiny") end
	
	if args.tiny == nil and args.header then
		mbox:tag("div"):addClass("mbox-header"):wikitext(args.header):done()
	end
	mbox = mbox:tag("div"):addClass("mbox-row")
	
	local image = mw.title.makeTitle("File", args.image or "")
	if image then
		image = "[[File:" .. image.text
		local width = math.floor(tonumber(args.imagewidth) or 60)
		if args.tiny or width < 30 then width = 30
		elseif width > 100 then width = 100 end
		image = image .. "|" .. width .. "px"
		if args.imagelink then image = image .. "|link=" .. args.imagelink end
		image = image .. "]]"
		mbox:tag("div"):addClass("mbox-image"):wikitext(image):done()
	end
	
	mbox:tag("div"):addClass("mbox-content"):wikitext("\n" .. args.text .. "\n"):done()
	if args.tiny == nil and args.aside then
		mbox:tag("div"):addClass("mbox-aside"):wikitext("\n" .. args.aside .. "\n"):done()
	end
	
	return tostring(mbox:allDone())
end


return p