Module:Unsubst-infobox: Difference between revisions

NeonWabbit changed the content model of the page Module:Unsubst-infobox from "wikitext" to "Scribunto"
No edit summary
 
Line 77: Line 77:


-- Pull information from parameter aliases
-- Pull information from parameter aliases
local aliases = {}
local aliases, extra = {}, {}
if frame.args['$aliases'] then
if frame.args['$aliases'] then
local list = mw.text.split( frame.args['$aliases'], '%s*,%s*' )
local list = mw.text.split( frame.args['$aliases'], '%s*,%s*' )
for k, v in ipairs( list ) do
for k, v in ipairs( list ) do
local tmp = mw.text.split( v, '%s*>%s*' )
local tmp = mw.text.split( v, '%s*>%s*' )
aliases[(tonumber(mw.ustring.match(tmp[1], '^[1-9][0-9]*$'))) or tmp[1]] = ((tonumber(mw.ustring.match(tmp[2], '^[1-9][0-9]*$'))) or tmp[2])
local alias = (tonumber(mw.ustring.match(tmp[1], '^[1-9][0-9]*$'))) or tmp[1]
aliases[alias] = ((tonumber(mw.ustring.match(tmp[2], '^[1-9][0-9]*$'))) or tmp[2])
extra[alias] = true
end
end
end
end
Line 96: Line 98:
break
break
end
end
if not aliases[k] then
ret = ret .. '|' .. v
ret = ret .. '|' .. v
args[k] = nil
args[k] = nil
end
end
end


-- Pull lists from special parameters
-- Pull lists from special parameters
local discard = {}
local params = mw.text.split( frame.args['$params'], '%s*,%s*' )
local params = mw.text.split( frame.args['$params'], '%s*,%s*' )
for k, v in ipairs( params ) do
for k, v in ipairs( params ) do
params[k] = (tonumber(mw.ustring.match(v, '^[1-9][0-9]*$'))) or v
-- Numbered args don't go here
if mw.ustring.match(v, '^[1-9][0-9]*$') then
table.insert( discard, 1, k )
end
end
end
local sets, setparams, extra = {{}, {}, {}}, {}, {}
for k, v in ipairs( discard ) do table.remove( params, v ) end
local sets, setparams = {{}, {}, {}}, {}
for k = 1, 3 do
for k = 1, 3 do
local v = frame.args['$set' .. k]
local v = frame.args['$set' .. k]
if v then
if v then
setparams[k] = mw.text.split( v, '%s*,%s*' )
setparams[k] = mw.text.split( v, '%s*,%s*' )
discard = {}
for x, y in ipairs( setparams[k] ) do
for x, y in ipairs( setparams[k] ) do
setparams[k][x] = (tonumber(mw.ustring.match(y, '^[1-9][0-9]*$'))) or y
sets[k][setparams[k][x]] = true
sets[k][setparams[k][x]] = true
-- Numbered args don't go here
if mw.ustring.match(y, '^[1-9][0-9]*$') then
table.insert( discard, 1, x )
end
end
end
    for x, y in ipairs( discard ) do table.remove( setparams[k], y ) end
end
end
end
end
Line 139: Line 149:
-- Align parameters correctly and remove extra ones
-- Align parameters correctly and remove extra ones
local maxlength = 0
local maxlength = 0
local discard = {}
discard = {}
for k, v in ipairs( params ) do
for k, v in ipairs( params ) do
if (not extra[v]) or args[v] then
if (not extra[v]) or args[v] then
Line 149: Line 159:
end
end
for k, v in ipairs( discard ) do table.remove( params, v ) end
for k, v in ipairs( discard ) do table.remove( params, v ) end
local indent = string.rep(' ', (tonumber(frame.args['$indent']) or 0))
local indent = mw.ustring.rep(' ', (tonumber(frame.args['$indent']) or 0))
-- Numbered args after discontinuity continue first
discard = {}
for k, v in pairs( args ) do
if mw.ustring.match(k, '^[1-9][0-9]*$') then table.insert ( discard, 1, k ) end
end
for k, v in ipairs( discard ) do table.insert( params, 1, v ) end
 
local space, newline = ' ', '\n'
local space, newline = ' ', '\n'
if not next(params) then space, newline = '', '' end
if not next(params) then space, newline = '', '' end