local research = { }
local umatch = mw.ustring.match
local uformat = mw.ustring.format
local match="(.+)(%d+)"
local procMap =
{
profile =
{
uAlias = 'p',
fallback = [[''~该角色调查资料待补充~'']],
},
image =
{
uAlias = 'i',
fallback = [['''未指定该调查资料的立绘图像''']],
},
affiliation=
{
uAlias = 'a',
fallback = [[???]]
}
}
procMap.info = procMap.profile
procMap.img = procMap.image
procMap.aff = procMap.affiliation
function TryGet(s,f)
if s == nil or s == [[]] then return f
else return s end
end
function EmptyOrNil(s)
return s == nil or s == [[]]
end
function RepackArgs(t)
if t == nil then return nil end
local pack = { contents = {} }
pack.aff = t.affiliation or t.aff or procMap.affiliation.fallback
for k,v in pairs(t) do
local typ,ind = string.match(k,match)
mw.log(typ,ind)
if typ and ind then
ind = tonumber(ind) or 0
typ = string.lower(typ)
if procMap[typ] then
if not pack.contents[ ind ] then pack.contents[ ind ] = { } end
pack.contents[ ind ][ procMap[typ].uAlias ] = v
else
mw.log("UNKNOWN TYPE=" .. typ)
end
end
end
mw.logObject(pack)
return pack
end
function ImageBlock(imgsrc)
local root =
mw.html.create("div")
:addClass("image")
if EmptyOrNil(imgsrc) then
root:wikitext(procMap.image.fallback)
else
root:wikitext(uformat("[[File:%s|450x312px]]",imgsrc))
end
root:done()
return root
end
function ProfileBlock(profile)
local root =
mw.html.create("div")
:addClass("info")
if EmptyOrNil(profile) then
root:wikitext(procMap.profile.fallback)
else
root:wikitext(profile)
end
root:done()
return root
end
function AffiliationBlock(aff)
local root =
mw.html.create("div")
:addClass("affiliation")
:css{width="fit-content"}
if EmptyOrNil(aff) then
root:wikitext("隶属:" .. procMap.aff.fallback)
else
root:wikitext("隶属:" .. aff)
end
root:done()
return root
end
--[[Test with:
=p.Main(
mw.getCurrentFrame()
: newChild{
args=
{
profile1="a",image1="b",
info2="aaaa",img2="s"
}
}
: newChild{ }
)
=p.Main(mw.getCurrentFrame():newChild{args={aff="affff",profile1="a",image1="b",aff1="cccc",info2="aaaa"}}:newChild())
--]]
function research.Main(frame)
local args = RepackArgs(frame:getParent().args or frame.args)
if not args then return [[]] end
local root =
mw.html.create("div")
:addClass("research-wrapper")
local html =
mw.html.create("div")
:addClass("Tabs")
:addClass("blue")
:attr( {
["data-label-side"]="top",
["data-label-color-side-reverse"]="",
["data-divider-size"]="",
["data-text-background-color"]="#e6f5ff",
["data-auto-width"]="yes",
} )
for k,v in pairs(args.contents) do
local blkImg = ImageBlock(v.i)
local blkPrf = ProfileBlock(v.p)
local blkAff = AffiliationBlock(v.a or args.aff or procMap.affiliation.fallback)
local grid =
mw.html.create("div")
:addClass("research-grid"):newline()
:node(blkImg):done():newline()
:node(blkPrf):done():newline()
:allDone()
local label =
mw.html.create("div")
:addClass("TabLabelText"):wikitext(uformat("调查资料%d",k)):done()
local content =
mw.html.create("div"):addClass("TabContentText"):newline()
:node(blkAff):done():newline()
:node(grid):done()
:allDone()
local tab =
mw.html.create("div")
:addClass("Tab"):newline()
:node(label):newline()
:node(content):newline()
:allDone()
html:node(tab)
end
root:node(html):allDone()
return frame:extensionTag{ name="templatestyles", args={ src = 'Template:东放调查资料/style.css' } }
..'\n' .. tostring(root:allDone())
end
return research