Módulo:Spreadsheet
Apariencia
A continuación se muestra la documentación transcluida desde la subpágina /doc. [salta a la caja de código]
Este módulo sirve para crear tablas con celdas calculadas a partir de otras celdas.
Esta documentación está transcluida desde Módulo:Spreadsheet/doc.
Por favor, añade las categorías en la subpágina de documentación y los interwikis en Wikidata. Subpáginas de este módulo.
Por favor, añade las categorías en la subpágina de documentación y los interwikis en Wikidata. Subpáginas de este módulo.
local p = {}
-- Dump and die debug function
function dd( data )
local message = mw.dumpObject( data )
error( message, 0 )
end
-- Recursively replace all occurences of "{1}" for the value in row 1
-- and so on for every row, while keeping an eye for loops
function expand( value, key )
if ( mw.ustring.match( '{' .. value .. '}', '{' .. key .. '}' ) ) then
error( 'circular reference detected', 0 )
end
local rows = mw.getCurrentFrame():getParent().args
for rowKey, rowValue in ipairs( rows ) do
local rowValue = rows[ rowKey ]
if rowValue and rowValue ~= '' and mw.ustring.match( '{' .. value .. '}', '{' .. rowKey .. '}' ) then
value = mw.ustring.gsub( value, '{' .. rowKey .. '}', rowValue )
value = expand( value, rowKey )
end
end
return value
end
function p.row( frame )
local data = {}
local rows = frame:getParent().args
for rowKey, rowValue in ipairs( rows ) do
if mw.ustring.match( rowValue, '{%d%d?}' ) then
rowValue = expand( rowValue, rowKey )
rowValue = frame:callParserFunction( 'formatnum', rowValue, 'R' )
rowValue = frame:callParserFunction( '#expr', rowValue )
rowValue = frame:callParserFunction( 'formatnum', rowValue )
end
data[ rowKey ] = rowValue
end
local html = mw.html.create( "tr" )
for key, value in ipairs( data ) do
html:tag( "td" ):wikitext( data[ key ] )
end
return html
end
return p