模块:Infobox/item/multidata:修订间差异

来自Cookie☆Wiki
无编辑摘要
无编辑摘要
第4行: 第4行:
local parent = frame:getParent()
local parent = frame:getParent()
local itemsPerRow = tonumber(parent.args['row-items'])
local itemsPerRow = tonumber(parent.args['row-items'])
if true then
return itemsPerRow
end
if itemsPerRow == nil then
if itemsPerRow == nil then
error('"row-items" is not a number')
error('"row-items" is not a number')
第19行: 第22行:


local result = ''
local result = ''

if true then
return 'test:' .. parent.args['row-items']
end



local widthPercent = string.format('%.2f', 100/itemsPerRow) .. '%'
local widthPercent = string.format('%.2f', 100/itemsPerRow) .. '%'

2019年1月13日 (日) 02:23的版本

可在模块:Infobox/item/multidata/doc创建此模块的帮助文档

local p = {}

function p.make()
    local parent = frame:getParent()
    local itemsPerRow = tonumber(parent.args['row-items'])
    if true then
        return itemsPerRow
    end
    if itemsPerRow == nil then
        error('"row-items" is not a number')
    end
    
    local count = 0
    local unnamed = {}
    for k, v in pairs(parent.args) do
        if tonumber(k) ~= nil then
            table.insert(unnamed, v)
            count = count + 1

        end
    end

    local result = ''

    local widthPercent = string.format('%.2f', 100/itemsPerRow) .. '%'
    local majorPart = math.floor(count / itemsPerRow) * itemsPerRow
    local i = 1
    while (true) do
        if i > majorPart then break end
        result = result .. frame:expandTemplate{ title = 'Infobox/item/data', args = {
            width = widthPercent, data = unnamed[i]
        } }
        i = i + 1
    end

    local remain = count - majorPart
    if remain ~= 0 then
        widthPercent = string.format('%.2f', 100/(remain)) .. '%'
        while (true) do
            if i > count then break end
            result = result .. frame:expandTemplate{ title = 'Infobox/item/data', args = {
                width = widthPercent, data = unnamed[i]
            } }
            i = i + 1
        end
    end

    return result
end

return p