Module:Inventory slot/Aliases/Table

From Modded Wiki
Revision as of 00:06, 13 February 2015 by minecraft>Majr (Since the aliases table now contains actual code, it's not going to cut it to display what aliases are available.)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Documentation for this module may be created at Module:Inventory slot/Aliases/Table/doc

local p = {}
p.table = function()
	local grid = require( [[Module:Grid]] ).cell
	local aliases = mw.loadData( [[Module:Grid/Aliases]] )
	
	local keys = {}
	for i, v in pairs( aliases ) do
		-- Skip the banner aliases, as there are so many of them it causes the
		-- page to be too slow. Maybe once we use sprites it will be fast enough.
		if not i:find( 'Banner$' ) then
			table.insert( keys, i )
		end
	end
	table.sort( keys )
	
	local tableRows = {
		' {| class="wikitable collapsible collapsed"',
		'! Alias !! class="collapse-button" | Output'
	}
	for _, key in ipairs( keys ) do
		local alias = aliases[key]
		
		local displayCell = {}
		for name in mw.text.gsplit( alias, '%s*;%s*' ) do
			-- Aliases are disabled in output for accuracy
			-- (as sub-aliases aren't meant to work) and performance
			table.insert( displayCell, grid{ name, noalias = true } )
		end
		
		table.insert( tableRows, '|' .. key .. '||' .. table.concat( displayCell ) )
	end
	table.insert( tableRows, '|}' )
	
	return table.concat( tableRows, '\n|-\n' )
end
return p