本模塊用於執行{{交叉顏色}}模板,請到模板頁閱讀具體用法。
--協力:User:サンムル
local p = {}
function p._main(args,toggle)
local texts = {}
local colors = {}
for k, v in pairs(args) do
if type(k) == 'string' then --如果是字符串則匹配c開頭
local index = k:match "^c(%d+)$"
if index then colors[tonumber(index)] = v end
else --是數字
texts[k] = v
end
end
colors[0] = colors[#colors] -- 餘數等於0時輸出除數域
--渲染部分
local root = mw.html.create 'span'
for i, v in ipairs(texts) do
root:tag 'span'
:wikitext(v)
:css {color = colors[i%#colors],
["data-color"] = toggle and color}
:addClass(toggle and 'colorToggleBlock')
end
return root
end
function p.main ( frame )
local wrappers = { ['Template:交叉顏色'] = true, ['Template:交叉顏色護眼版'] = true }
local toggle = frame.args["toggle"]
local parent = frame:getParent()
if parent and wrappers[parent:getTitle()] then
frame = parent
end
local args = frame.args
return p._main(args,toggle)
end
return p