Module:沙盒/盐棋/Sandbox1:修订间差异
小 (back) |
小 (wrap) |
||
第1行: | 第1行: | ||
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)) | |||
end | end | ||
function p.tab_img(id, config) | |||
function p.tab_img(id, config | |||
local container = mw.html.create('div'):addClass('container') | local container = mw.html.create('div'):addClass('container') | ||
if #config==1 then | if #config == 1 then | ||
container:wikitext(config[1].content) | container:wikitext(config[1].content) | ||
else | else | ||
local img_tab, | local img_tab, tab_text = container:tag('div'):addClass('img-tab'), {} | ||
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) | ||
table.insert( | table.insert(tab_text, container:tag('div'):addClass('tab-text-a'):wikitext(tab.content)) | ||
end | end | ||
tab_text[id]:addClass('active') | |||
end | end | ||
return tostring(container) | return tostring(container) | ||
-- return '[[文件:Songs '..tostring(id) .. '.jpg|点此上传图片]]' | -- 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 | end | ||
function p.song(frame) | function p.song(frame) | ||
local config,main={},1 | local config, main = {}, 1 | ||
for i, v in ipairs(frame.args) do | for i, v in ipairs(frame.args) do | ||
local item=mw.text.jsonDecode(v)--use json. what about use in module | local item = mw.text.jsonDecode(v) -- use json. what about use in module | ||
item.content= | local suf = item['后缀'] and ' ' .. item['后缀'] or '' | ||
table.insert(config, { | |||
if | class = item['色彩'], | ||
tab = item['标签'], | |||
content = p.file_song(frame.args['id'], suf, item['画师']), | |||
}) | |||
if suf == '' then main = i end | |||
end | end | ||
return p.tab_img(main,config | return p.tab_img(main, config) | ||
end | end | ||
function p.direct(frame) | function p.direct(frame) | ||
return p.filter[frame.args[3] or 'no'](p.tab_img(frame.args[1],frame.args[2])) | return p.filter[frame.args[3] or 'no'](p.tab_img(frame.args[1], frame.args[2])) | ||
end | end | ||
function p.jsonmode(frame) | function p.jsonmode(frame) | ||
return p.filter[frame.args[3] or 'no'](p.tab_img(frame.args[1],mw.text.jsonDecode(frame.args[2]))) | 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 |
2022年8月1日 (一) 10:42的版本
可在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