Module:Sprite: Difference between revisions

Return a HTMLBuilder rather than a string. Doc shouldn't run through sprite function.
Improve speed by only lowercasing each name once
Line 201: Line 201:
end
end
local nameKeys = {}
local keyedData = {}
for name in pairs( data.ids ) do
for name, idData in pairs( data.ids ) do
table.insert( nameKeys, name )
table.insert( keyedData, {
sortKey = mw.ustring.lower( name ),
name = name,
data = idData
} )
end
end
table.sort( nameKeys, function( a, b )
table.sort( keyedData, function( a, b )
return mw.ustring.lower( a ) < mw.ustring.lower( b )
return a.sortKey < b.sortKey
end )
end )
for _, name in ipairs( nameKeys ) do
for _, data in ipairs( keyedData ) do
local idData = data.ids[name]
local idData = data.data
local pos = idData.pos
local pos = idData.pos
local section = sections[idData.section]
local section = sections[idData.section]
Line 224: Line 228:
local codeElem = names
local codeElem = names
:tag( 'li' ):addClass( 'spritedoc-name' )
:tag( 'li' ):addClass( 'spritedoc-name' )
:tag( 'code' ):wikitext( name )
:tag( 'code' ):wikitext( data.name )
if idData.deprecated then
if idData.deprecated then