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

来自Arcaea中文维基
(mode)
(try)
标签替换
 
(未显示同一用户的20个中间版本)
第1行: 第1行:
local p={}
local p = {}
p.filter={text=mw.text.encode,json=mw.text.jsonEncode,no=function(x)return x end}
function p.len(frame)
function p.label_text(text)
return #frame.args.a
   return tostring(mw.html.create('span'):addClass('label-text'):wikitext(text))
end
end
function p.song_cell(frame)
function p.explode(frame)
local suf=frame.args['后缀'] and ' '..frame.args['后缀'] or ''
return mw.dumpObject({mw.ustring.byte(frame.args.a,1,-1)})
return mw.text.jsonEncode({
class=frame.args['色彩'],
tab=frame.args['标签'],
content=string.format('[[文件:Songs %%s%s.jpg|256px|none]]%s%s',suf,p.label_text('画师'),frame.args['画师']),
active=suf==''
},mw.text.JSON_PRESERVE_KEYS)
end
function p.tab_img(id, config, pos)
local container = mw.html.create('div'):addClass('container')
if #config==1 then
container:wikitext(config[1].content)
else
local img_tab,figure=container:tag('div'):addClass('img-tab'):attr('id','tab-'..pos),{}
for _, tab in ipairs(config) do
img_tab:tag('div'):addClass('img-tab-part'):addClass(tab.class):wikitext(tab.tab)
table.insert(figure,container:tag('div'):addClass('tab-text-'..pos):wikitext(tab.content))
end
figure[id]:addClass('active')
end
return tostring(container)
-- return '[[文件:Songs '..tostring(id) .. '.jpg|点此上传图片]]'
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
item.content=item.content:format(frame.args['id'])
table.insert(config,item)
if item.active then main=i end
end
return p.tab_img(main,config,frame.args['mode']or'b')
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
end
return p
return p

2024年2月27日 (二) 03:17的最新版本

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

local p = {}
function p.len(frame)
	return #frame.args.a
end
function p.explode(frame)
	return mw.dumpObject({mw.ustring.byte(frame.args.a,1,-1)})
end
return p