Module:沙盒/盐棋/Sandbox1:修订间差异

来自Arcaea中文维基
(img)
(try?)
第1行: 第1行:
-- text.jsonEncode({sp=W.site.namespaces},W.text.JSON_PRETTY)
-- text.jsonEncode({sp=W.site.namespaces},W.text.JSON_PRETTY)
local p={}
local p={}
p.filter={text=mw.text.encode,json=mw.text.jsonEncode,no=function (x)return x end}
p.filter={text=mw.text.encode,json=mw.text.jsonEncode,no=function(x)return x end}
function p.label_text(text)
function p.label_text(text)
    return tostring(mw.html.create('span'):addClass('label-text'):wikitext(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
end
function p.tab_img(id, config)
function p.tab_img(id, config)
if id then
local container = mw.html.create('div'):addClass('container')
local container = mw.html.create('div'):addClass('container')
if #config==1 then
if type(config)=="string" then
container:wikitext(config[1].content)
container:wikitext('[[文件:Songs '..id..'.jpg|256px|none]]',p.label_text('画师'),config)
else
elseif type(config)=="table" then
local img_tab=container:tag('div'):addClass('img-tab'):attr('id', 'tab-a')
local img_tab=container:tag('div'):addClass('img-tab'):attr('id', 'tab-a')
for _, tab in ipairs(config) do
for _, tab in ipairs(config) do
img_tab:tag('div'):addClass('img-tab-part'):addClass(tab.class):wikitext(tab.tab)
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)
local figure=container:tag('div'):addClass('tab-text-a'):wikitext('[[文件:Songs '..id..(tab.suffix~='' and ' ' or '')..tab.suffix..'.jpg|256px|none]]',p.label_text('画师'),tab.illust)
if _==id then figure:addClass('active') end
if tab.suffix=="" then figure:addClass('active') end
end
end
end
return tostring(container)
end
end
return tostring(container)
-- return '[[文件:Songs '..tostring(id) .. '.jpg|点此上传图片]]'
-- 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
end
function p.direct(frame)
function p.direct(frame)

2022年7月30日 (六) 11:05的版本

可在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