https://pt.touhouwiki.net/index.php?title=M%C3%B3dulo:Infobox&feed=atom&action=history
Módulo:Infobox - Histórico de revisões
2024-03-29T13:17:55Z
Histórico de edições para esta página nesta wiki
MediaWiki 1.39.3
https://pt.touhouwiki.net/index.php?title=M%C3%B3dulo:Infobox&diff=1939&oldid=prev
Kim Belacqua the Fox: uma edição
2013-12-16T14:33:56Z
<p>uma edição</p>
<table style="background-color: #fff; color: #202122;" data-mw="interface">
<col class="diff-marker" />
<col class="diff-content" />
<col class="diff-marker" />
<col class="diff-content" />
<tr class="diff-title" lang="pt">
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">← Revisão anterior</td>
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">Revisão das 14h33min de 16 de dezembro de 2013</td>
</tr>
<!-- diff cache key touhouwiki-thwikiPT_:diff::1.12:old-1938:rev-1939 -->
</table>
Kim Belacqua the Fox
https://pt.touhouwiki.net/index.php?title=M%C3%B3dulo:Infobox&diff=1938&oldid=prev
DennouNeko: 1 revision: updates for most recent version of Scribunto
2013-08-08T16:10:47Z
<p>1 revision: updates for most recent version of Scribunto</p>
<p><b>Página nova</b></p><div>-- Lua port of [[Template:Infobox]]<br />
-- by DennouNeko<br />
<br />
local common = require("Module:Common")<br />
local style = require("Module:Styles")<br />
<br />
local colors = style.main_colors<br />
<br />
<br />
-- == Helper functions ==<br />
<br />
-- retrieve param list from arguments<br />
-- builds a table of objects with 'header', 'label', 'data', 'class', 'rclass' fields<br />
local function scan_data_rows(frame, ttype)<br />
local idx = {}<br />
local header = {}<br />
local label = {}<br />
local data = {}<br />
local class = {}<br />
local rclass = {}<br />
<br />
local ret = {}<br />
<br />
local s,e,t<br />
<br />
for k,v in frame:argumentPairs() do<br />
-- accept only parameters without leading zeros<br />
s,e,t = string.find(k, '^header([1-9]%d*)$')<br />
if s ~= nil then<br />
header[tonumber(t)] = v<br />
idx[#idx+1] = tonumber(t)<br />
end<br />
<br />
s,e,t = string.find(k, '^label([1-9]%d*)$')<br />
if s ~= nil then<br />
label[tonumber(t)] = v<br />
end<br />
<br />
s,e,t = string.find(k, '^data([1-9]%d*)$')<br />
if s ~= nil then<br />
data[tonumber(t)] = v<br />
idx[#idx+1] = tonumber(t)<br />
end<br />
<br />
s,e,t = string.find(k, '^class([1-9]%d*)$')<br />
if s ~= nil then<br />
class[tonumber(t)] = v<br />
end<br />
<br />
s,e,t = string.find(k, '^rowclass([1-9]%d*)$')<br />
if s ~= nil then<br />
rclass[tonumber(t)] = v<br />
end<br />
end<br />
<br />
common.trunkTable(idx)<br />
<br />
for k,v in pairs(idx) do<br />
local tmp = {}<br />
tmp['index'] = v<br />
if common.isset(header[v]) then tmp['header'] = header[v] end<br />
if common.isset(label[v]) then tmp['label'] = label[v] end<br />
if common.isset(data[v]) then tmp['data'] = data[v] end<br />
if common.isset(class[v]) then tmp['class'] = class[v] end<br />
if common.isset(rclass[v]) then tmp['rclass'] = rclass[v] end<br />
ret[#ret+1] = tmp<br />
end<br />
<br />
return ret<br />
end<br />
<br />
-- builds a single header row for table<br />
local function build_header_row(ttype, class, rclass, header, hstyle)<br />
local ret = {''}<br />
<br />
if common.isset(header) then<br />
if common.isset(colors[ttype]) then<br />
hstyle = 'background-color:' .. colors[ttype]['title'] .. ';' .. common.cv(common.isset(hstyle), hstyle, '')<br />
end<br />
<br />
ret[#ret+1] = '<tr><th colspan="2"'<br />
<br />
if common.isset(class) then ret[#ret+1] = ' class="' .. class .. '"' end<br />
<br />
ret[#ret+1] = ' style="text-align:center;'<br />
style.add(ret, hstyle)<br />
ret[#ret+1] = '">'<br />
<br />
ret[#ret+1] = header<br />
<br />
ret[#ret+1] = '</th></tr>'<br />
end<br />
<br />
return table.concat(ret)<br />
end<br />
<br />
-- builds a single regular row for table<br />
local function build_row(ttype, class, rclass, label, lstyle, data, dstyle)<br />
local ret = {''}<br />
<br />
if common.isset(data) then<br />
ret[#ret+1] = '<tr'<br />
if common.isset(rclass) then ret[#ret+1] = ' class="' .. rclass .. '"' end<br />
ret[#ret+1] = '>'<br />
<br />
if common.isset(label) then<br />
<br />
ret[#ret+1] = '<th scope="row"'<br />
<br />
if common.isset(class) then ret[#ret+1] = ' class="' .. class .. '"' end<br />
<br />
ret[#ret+1] = ' style="text-align:left;'<br />
style.add(ret, lstyle)<br />
ret[#ret+1] = '">'<br />
<br />
ret[#ret+1] = label<br />
<br />
ret[#ret+1] = '</th><td'<br />
else<br />
ret[#ret+1] = '<td colspan="2"'<br />
<br />
dstyle = 'text-align:center;' .. common.cv(common.isset(dstyle), dstyle, '')<br />
end<br />
<br />
if common.isset(class) then ret[#ret+1] = ' class="' .. class .. '"' end<br />
if common.isset(dstyle) then ret[#ret+1] = ' style="' .. dstyle .. '"' end<br />
<br />
ret[#ret+1] = '>'<br />
<br />
ret[#ret+1] = '\n' .. data<br />
<br />
ret[#ret+1] = '</td></tr>'<br />
end<br />
<br />
return table.concat(ret)<br />
end<br />
<br />
<br />
-- == Functions generating the table body ==<br />
<br />
-- starts the infobox<br />
local function build_start(frame, ttype)<br />
local ret = {}<br />
<br />
if frame.args['child'] ~= 'yes' then<br />
-- if it's not a child infobox, start a table<br />
<br />
ret[#ret+1] = '<table'<br />
<br />
ret[#ret+1] = ' class="infobox'<br />
if common.isset(frame.args['bodyclass']) then ret[#ret+1] = ' ' .. frame.args['bodyclass'] end<br />
ret[#ret+1] = '"'<br />
<br />
ret[#ret+1] = ' cellspacing="5"'<br />
<br />
ret[#ret+1] = ' style="width:22em; text-align:left; font-size:88%; line-height:1.5em;'<br />
if common.isset(colors[ttype]) then<br />
ret[#ret+1] = 'border-color:' .. colors[ttype]['border'] .. ';'<br />
ret[#ret+1] = 'background-color:' .. colors[ttype]['background'] .. ';'<br />
end<br />
style.add(ret, frame.args['bodystyle'])<br />
ret[#ret+1] = '"'<br />
<br />
ret[#ret+1] = '>'<br />
<br />
-- Caption<br />
if common.isset(frame.args['title']) then<br />
ret[#ret+1] = '<caption'<br />
if common.isset(frame.args['titleclass']) then ret[#ret+1] = ' class="' .. frame.args['titleclass'] .. '"' end<br />
<br />
ret[#ret+1] = ' style="font-size:125%; font-weight:bold;'<br />
style.add(ret, frame.args['titlestyle'])<br />
ret[#ret+1] = '"'<br />
<br />
ret[#ret+1] = '>'<br />
<br />
ret[#ret+1] = frame.args['title']<br />
<br />
ret[#ret+1] = '</caption>'<br />
end<br />
<br />
-- Header<br />
if common.isset(frame.args['above']) then<br />
local class = frame.args['aboveclass']<br />
local rclass = frame.args['aboverowclass']<br />
local text = frame.args['above']<br />
local style = 'text-align:center; font-size:125%; font-weight:bold;'<br />
if common.isset(frame.args['abovestyle']) then style = style .. ' ' .. frame.args['abovestyle'] end<br />
<br />
ret[#ret+1] = build_header_row(ttype, class, rclass, text, style)<br />
end<br />
<br />
else<br />
-- for child infobox add simple header<br />
if common.isset(frame.args['title']) then<br />
ret[#ret+1] = "'''" .. frame.args['title'] .. "'''"<br />
end<br />
end<br />
<br />
return table.concat(ret)<br />
end<br />
<br />
-- build the header part (subheaders and images)<br />
local function build_headers(frame, ttype)<br />
local ret = {}<br />
<br />
-- Subheader1<br />
if common.isset(frame.args['subheader']) or common.isset(frame.args['subheader1']) then<br />
local text = common.cv(common.isset(frame.args['subheader']), frame.args['subheader'], frame.args['subheader1'])<br />
local style = frame.args['subheaderstyle']<br />
local class = frame.args['subheaderclass']<br />
local rclass = common.cv(common.isset(frame.args['subheaderrowclass']), frame.args['subheaderrowclass'], frame.args['subheaderrowclass1'])<br />
<br />
ret[#ret+1] = build_row(ttype, class, rclass, '', '', text, style)<br />
end<br />
<br />
-- Subheader2<br />
if common.isset(frame.args['subheader2']) then<br />
local text = frame.args['subheader2']<br />
local style = frame.args['subheaderstyle']<br />
local class = frame.args['subheaderclass']<br />
local rclass = frame.args['subheaderrowclass2']<br />
<br />
ret[#ret+1] = build_row(ttype, class, rclass, '', '', text, style)<br />
end<br />
<br />
-- Image1<br />
if common.isset(frame.args['image']) or common.isset(frame.args['image1']) then<br />
local text = {}<br />
text[#text+1] = common.cv(common.isset(frame.args['image']), frame.args['image'], frame.args['image1'])<br />
<br />
if common.isset(frame.args['caption']) or common.isset(frame.args['caption1']) then<br />
text[#text+1] = '<br/><span'<br />
if common.isset(frame.args['captionstyle']) then text[#text+1] = ' style="' .. frame.args['captionstyle'] .. '"' end<br />
text[#text+1] = '>'<br />
text[#text+1] = common.cv(common.isset(frame.args['caption']), frame.args['caption'], frame.args['caption1'])<br />
text[#text+1] = '</span>'<br />
end<br />
<br />
text = table.concat(text)<br />
<br />
local class = frame.args['imageclass']<br />
local dstyle = frame.args['imagestyle']<br />
local rclass = frame.args['imagerowclass1']<br />
<br />
ret[#ret+1] = build_row(ttype, class, rclass, '', '', text, dstyle)<br />
end<br />
<br />
-- Image2<br />
if common.isset(frame.args['image2']) then<br />
local text = {}<br />
text[#text+1] = frame.args['image2']<br />
<br />
if common.isset(frame.args['caption2']) then<br />
text[#text+1] = '<br/><span'<br />
if common.isset(frame.args['captionstyle']) then text[#text+1] = ' style="' .. frame.args['captionstyle'] .. '"' end<br />
text[#text+1] = '>'<br />
text[#text+1] = frame.args['caption2']<br />
text[#text+1] = '</span>'<br />
end<br />
<br />
text = table.concat(text)<br />
<br />
local class = frame.args['imageclass']<br />
local dstyle = frame.args['imagestyle']<br />
local rclass = frame.args['imagerowclass2']<br />
<br />
ret[#ret+1] = build_row(ttype, class, rclass, '', '', text, dstyle)<br />
end<br />
<br />
return table.concat(ret)<br />
end<br />
<br />
-- build the main part (all the headers and data rows below images)<br />
local function build_body(frame, ttype, tbl)<br />
local ret = {''}<br />
<br />
local hstyle = frame.args['headerstyle']<br />
local lstyle = frame.args['labelstyle']<br />
local dstyle = frame.args['datastyle']<br />
<br />
for k,v in pairs(tbl) do<br />
-- not using common.cv, because both functions would be called<br />
if common.isset(v['header']) then<br />
ret[#ret+1] = build_header_row(ttype, v['class'], v['rclass'], v['header'], hstyle)<br />
else<br />
ret[#ret+1] = build_row(ttype, v['class'], v['rclass'], v['label'], lstyle, v['data'], dstyle)<br />
end<br />
end<br />
<br />
return table.concat(ret)<br />
end<br />
<br />
-- finalize the infobox<br />
local function build_end(frame, ttype)<br />
local ret = {''}<br />
<br />
if frame.args['child'] ~= 'yes' then<br />
ret[#ret+1] = '</table>'<br />
end<br />
<br />
return table.concat(ret)<br />
end<br />
<br />
<br />
-- == Exported functions ==<br />
<br />
-- the basic infobox<br />
local function build_infobox(frame)<br />
local ret = {}<br />
<br />
-- prepare data<br />
local drows = scan_data_rows(frame)<br />
local ttype = frame.args['type']<br />
if ttype == nil then ttype = '' end<br />
<br />
-- build infobox<br />
ret[#ret+1] = build_start(frame, ttype)<br />
ret[#ret+1] = build_headers(frame, ttype)<br />
ret[#ret+1] = build_body(frame, ttype, drows)<br />
ret[#ret+1] = build_end(frame, ttype)<br />
<br />
return table.concat(ret)<br />
end<br />
<br />
return {<br />
['BuildInfobox'] = build_infobox,<br />
['BuildInfoboxTemplate'] = function(frame) return build_infobox(frame:getParent()) end,<br />
}<br />
<br />
-- [[Category:Lua Scripts|{{PAGENAME}}]]</div>
DennouNeko