Module:沙盒/盐棋/Sandbox1

来自Arcaea中文维基
< Module:沙盒
盐棋讨论 | 贡献2022年7月30日 (六) 11:05的版本 (try?)

可在Module:沙盒/盐棋/Sandbox1/doc创建此模块的帮助文档

-- text.jsonEncode({sp=W.site.namespaces},W.text.JSON_PRETTY)
local p={}
p.filter={text=mw.text.encode,json=mw.text.jsonEncode,no=function(x)return x end}
function p.label_text(text)
    return tostring(mw.html.create('span'):addClass('label-text'):wikitext(text))
end
function p.song_cell(frame)
	return mw.text.jsonEncode({
		class=frame.args['色彩'],
		tab=frame.args['标签'],
		content=string.format('[[文件:Songs %%s%s.jpg|256px|none]]%s%s',frame.args['后缀']or'',p.label_text('画师'),frame.args['画师']),
		active=frame.args['后缀']==nil
	},mw.text.JSON_PRESERVE_KEYS)
end
function p.tab_img(id, config)
	local container = mw.html.create('div'):addClass('container')
	if #config==1 then
		container:wikitext(config[1].content)
	else
		local img_tab=container:tag('div'):addClass('img-tab'):attr('id', 'tab-a')
		for _, tab in ipairs(config) do
			img_tab:tag('div'):addClass('img-tab-part'):addClass(tab.class):wikitext(tab.tab)
			local figure=container:tag('div'):addClass('tab-text-a'):wikitext(tab.content)
			if _==id then figure:addClass('active') end
		end
	end
	return tostring(container)
	-- return '[[文件:Songs '..tostring(id) .. '.jpg|点此上传图片]]'
end
function p.song(frame)
	local config,main={},1
	for i, v in ipairs(frame) do
		local item=mw.text.jsonDecode(v)
		item.content=item.content:format(frame.args['id'])
		config:insert(item)
		if item.active then main=i end
	end
	return p.tab_img(main,config)
end
function p.direct(frame)
	return p.filter[frame.args[3] or 'no'](p.tab_img(frame.args[1],frame.args[2]))
end
function p.jsonmode(frame)
	return p.filter[frame.args[3] or 'no'](p.tab_img(frame.args[1],mw.text.jsonDecode(frame.args[2])))
end
return p