Diferencia entre revisiones de «Módulo:Ficha»
Sin resumen de edición |
Sin resumen de edición |
||
| Línea 5: | Línea 5: | ||
local p = {} | local p = {} | ||
local HtmlBuilder = require(' | local HtmlBuilder = require('Module:HtmlBuilder') | ||
local args | local args | ||
| Línea 11: | Línea 11: | ||
function union(t1, t2) | function union(t1, t2) | ||
-- | -- return the union of the values of two tables, as a sequence | ||
local vals = {} | local vals = {} | ||
for k, v in pairs(t1) do | for k, v in pairs(t1) do | ||
| Línea 159: | Línea 159: | ||
local function renderRows() | local function renderRows() | ||
local rownums = union(getArgNums(' | local rownums = union(getArgNums('header'), getArgNums('data')) | ||
table.sort(rownums) | table.sort(rownums) | ||
for k, num in ipairs(rownums) do | for k, num in ipairs(rownums) do | ||
addRow({ | addRow({ | ||
header = args[' | header = args['header' .. num], | ||
label = args[' | label = args['label' .. num], | ||
data = args[' | data = args['data' .. num], | ||
datastyle = args.datastyle, | datastyle = args.datastyle, | ||
class = args['class' .. num], | class = args['class' .. num], | ||
| Línea 196: | Línea 196: | ||
local function renderTrackingCategories() | local function renderTrackingCategories() | ||
if args.decat ~= 'yes' and #(getArgNums('data')) == 0 and mw.title.getCurrentTitle().namespace == 0 then | if args.decat ~= 'yes' and #(getArgNums('data')) == 0 and mw.title.getCurrentTitle().namespace == 0 then | ||
root.wikitext('[[ | root.wikitext('[[Category:Articles which use infobox templates with no data rows]]') | ||
end | end | ||
end | end | ||
| Línea 204: | Línea 204: | ||
root = HtmlBuilder.create('table') | root = HtmlBuilder.create('table') | ||
root | root | ||
.addClass(' | .addClass('infobox') | ||
.addClass(args.bodyclass) | .addClass(args.bodyclass) | ||
.attr('cellspacing', 3) | .attr('cellspacing', 3) | ||
| Línea 235: | Línea 235: | ||
function p.infobox(frame) | function p.infobox(frame) | ||
local origArgs | local origArgs | ||
-- | -- If called via #invoke, use the args passed into the invoking template. | ||
-- | -- Otherwise, for testing purposes, assume args are being passed directly in. | ||
if frame == mw.getCurrentFrame() then | if frame == mw.getCurrentFrame() then | ||
origArgs = frame:getParent().args | origArgs = frame:getParent().args | ||
| Línea 243: | Línea 243: | ||
end | end | ||
-- ParserFunctions | -- ParserFunctions considers the empty string to be false, so to preserve the previous | ||
-- | -- behavior of {{infobox}}, change any empty arguments to nil, so Lua will consider | ||
-- | -- them false too. (Except the 'italic title' param, which specifies different behavior | ||
-- | -- depending on whether it's absent or empty) | ||
args = {} | args = {} | ||
for k, v in pairs(origArgs) do | for k, v in pairs(origArgs) do | ||