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

来自Cookie☆Wiki
(先看看直接这么返回的效果吧…)
(local p = {} function p.make() local frame = mw.getCurrentFrame() local parent = frame:getParent() local arg = parent.args['image'] if arg != nil then --< 单张图片 if string.byte(arg, 1) == 127 then return '<s)
第5行: 第5行:
local parent = frame:getParent()
local parent = frame:getParent()
local arg = parent.args['image']
local arg = parent.args['image']
if string.byte(arg, 1) == 127 then --< 参数可能是 <gallery>…</gallery>
if arg ~= nil then --< 单张图片
return arg
if string.byte(arg, 1) == 127 then
return '<span style="font-size: 24px; color: red">\
-- arg = string.sub(arg, 2, -1)
-- pattern = '^%s*<gallery>.*</gallery>%s*$'
不支持<nowiki><gallery></nowiki>语法</span>\
[[Category: 含有在信息框中使用了旧的画廊语法的页面]]'
-- old_arg = arg
end
-- arg = string.match(arg, pattern)
-- if arg == nil then
-- error('The image argument of this template (module) must be a file name in plain text or a <gallery> element. Test:' .. mw.text.unstrip(parent.args['image']))
-- end
-- images = {}
-- for image_line in arg:gmatch('[^\r\n]+') do
-- -- table.insert(lines, line)
-- local sep = image_line:find('|')
-- table.insert(images, {
-- file = string.sub(image_line, 1, sep-1),
-- title = string.sub(image_line, sep+1, -1)
-- })
-- end
-- return mw.dumpObject(images) --< debug
else --< 参数是图片名
return frame:expandTemplate{ title = 'Infobox/item/single image', args = {
return frame:expandTemplate{ title = 'Infobox/item/single image', args = {
image = arg, caption = parent.args['caption']
image = arg, caption = parent.args['caption']
} }
} }
end
end

arg = parent.args['gallery']
if arg == nil then --< 根本没有图片
return ''
end

for image_line in arg:gmatch('[^\r\n]+') do
-- table.insert(lines, line)
local sep = image_line:find(':')
table.insert(images, {
file = string.sub(image_line, 1, sep-1),
title = string.sub(image_line, sep+1, -1)
})
end
return mw.dumpObject(images) --< debug
end
end



2019年1月15日 (二) 02:19的版本

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

local p = {}

function p.make()
    local frame = mw.getCurrentFrame()
    local parent = frame:getParent()
    local arg = parent.args['image']
    if arg ~= nil then --< 单张图片
        if string.byte(arg, 1) == 127 then
            return '<span style="font-size: 24px; color: red">\
            不支持<nowiki><gallery></nowiki>语法</span>\
            [[Category: 含有在信息框中使用了旧的画廊语法的页面]]'
        end
        return frame:expandTemplate{ title = 'Infobox/item/single image', args = {
            image = arg, caption = parent.args['caption']
        } }
    end

    arg = parent.args['gallery']
    if arg == nil then --< 根本没有图片
        return ''
    end

    for image_line in arg:gmatch('[^\r\n]+') do
        -- table.insert(lines, line)
        local sep = image_line:find(':')
        table.insert(images, {
            file = string.sub(image_line, 1, sep-1),
            title = string.sub(image_line, sep+1, -1)
        })
    end
    return mw.dumpObject(images) --< debug
end

return p