Module:沙盒/盐棋/Sandbox1

来自Arcaea中文维基
< Module:沙盒
盐棋讨论 | 贡献2022年8月1日 (一) 10:42的版本 (wrap)

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

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.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, tab_text = container:tag('div'):addClass('img-tab'), {}
		for _, tab in ipairs(config) do
			img_tab:tag('div'):addClass('img-tab-part'):addClass(tab.class):wikitext(tab.tab)
			table.insert(tab_text, container:tag('div'):addClass('tab-text-a'):wikitext(tab.content))
		end
		tab_text[id]:addClass('active')
	end
	return tostring(container)
	-- return '[[文件:Songs '..tostring(id) .. '.jpg|点此上传图片]]'
end
function p.wrap(frame)
	return mw.text.jsonEncode(frame.args, mw.text.JSON_PRESERVE_KEYS)
end
function p.file_song(id, suf, illust)
	return string.format('[[文件:Songs %s%s.jpg|256px|none]]%s%s', id, suf, p.label_text('画师'), illust)
end
function p.song(frame)
	local config, main = {}, 1
	for i, v in ipairs(frame.args) do
		local item = mw.text.jsonDecode(v) -- use json. what about use in module
		local suf = item['后缀'] and ' ' .. item['后缀'] or ''
		table.insert(config, {
			class = item['色彩'],
			tab = item['标签'],
			content = p.file_song(frame.args['id'], suf, item['画师']),
		})
		if suf == '' 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