跳转到内容

模組:Bulletin/sandbox

维基百科,自由的百科全书
local p = {}

function p._getClass( classname )
	local classlist = {
		["公告"] = "success",
		["人事"] = "warning",
		["投票"] = "warning",
		["编辑"] = "progressive",
		["編輯"] = "progressive",
		["讨论"] = "progressive",
		["討論"] = "progressive",
		["請求"] = "warning",
		["请求"] = "warning",
		["通知"] = "notice",
		["调查"] = "subtle",
		["調查"] = "subtle",
		["聚會"] = "subtle",
		["聚会"] = "subtle",
		["獎勵"] = "subtle",
		["奖励"] = "subtle",
		["解任"] = "error",
		["離任"] = "error",
		["离任"] = "error",
		["广告"] = "subtle",
		["廣告"] = "subtle",
		["評選"] = "progressive",
		["评选"] = "progressive",
		["分享"] = "subtle",
		["提醒"] = "warning",
		["協作"] = "progressive",
		["协作"] = "progressive",
		["建議"] = "notice",
		["建议"] = "notice"
	}
	if classlist[classname] == nil then
		return "subtle"
	end
	return classlist[classname]
end

function p.item( frame )
	local args = frame:getParent().args
	prefix = args["prefix"]
	if prefix == nil then
		prefix = ""
	end
		
	suffix = args["suffix"]
	if suffix == nil then
		suffix = ""
	end
		
	separator = args["separator"]
	if separator == nil then
		separator = "、"
	end
	
	conjunction = args["conjunction"]
	if conjunction == nil then
		conjunction = "及"
	end
	
	type = args[1]
	if type == nil then
		type = "公告"
	end
	type = mw.text.trim(type)
	
	local items = {}
	local i = 2
	local value
	while args[i] ~= nil do
		value = mw.text.trim( args[i] )
		if value ~= "" then
			table.insert( items, value )
		end
		i = i + 1
	end
	return mw.getCurrentFrame():extensionTag{ name = 'templatestyles', args = { src = 'Module:Bulletin/sandbox/styles.css' } } ..
	'<span class="bulletin-type cdx-info-chip cdx-info-chip--' .. p._getClass(type) .. '"><span class="cdx-info-chip__text">\'\'\'' .. type .. '\'\'\'</span></span> ' ..
		'<span class="bulletin-prefix">' .. prefix .. "</span>" ..
		'<span class="bulletin-item">' .. mw.text.listToText(
			items,
			'</span><span class="bulletin-separator">' .. separator .. '</span><span class="bulletin-item">',
			'</span><span class="bulletin-conjunction">' .. conjunction .. '</span><span class="bulletin-item">'
		) .. '</span>' ..
		'<span class="bulletin-suffix">' .. suffix .. '</span>'
end

return p