Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
MediaWiki help
Creopedia
Search
Search
Appearance
Log in
Personal tools
Log in
View source for Module:Location/Components/Table
Module
Discussion
English
Read
View source
View history
Tools
Tools
move to sidebar
hide
Actions
Read
View source
View history
General
What links here
Related changes
Special pages
Page information
Appearance
move to sidebar
hide
←
Module:Location/Components/Table
require( 'strict' ) local tableLua = require( 'Module:TableLua' ) local p = { MAX_WIKITEXT_LOCATIONS = 50 } --- Process the wikitext args --- --- @param args table --- @return table local function processArgs( args ) local data = {} for i = 1, p.MAX_WIKITEXT_LOCATIONS do local name = args[ 'name' .. i ] local link = args[ 'link' .. i ] local rate = args[ 'rate' .. i ] local note = args[ 'note' .. i ] if name then table.insert( data, { name = name, link = link, rate = rate, note = note } ) end end return data end --- Whether any location carries an encounter rate. The Rate column is only --- rendered when at least one does, so tables without rate data are unchanged. --- --- @param data table --- @return boolean local function hasRate( data ) for _, location in ipairs( data ) do if location.rate then return true end end return false end --- @param showRate boolean --- @return TableColumn[] local function getColumns( showRate ) local columns = { { id = 'location', label = 'Location' } } if showRate then table.insert( columns, { id = 'rate', label = 'Rate', textAlign = 'number' } ) end table.insert( columns, { id = 'note', label = 'Note' } ) return columns end --- @param data table --- @param showRate boolean --- @return TableRow[] local function getRows( data, showRate ) local rows = {} for _, location in ipairs( data ) do local row = { string.format( '[[%s|%s]]', location.link or location.name, location.name ) } if showRate then table.insert( row, location.rate or '' ) end table.insert( row, location.note or '' ) table.insert( rows, row ) end return rows end --- @param data table --- @return TableProps local function getTableProps( data ) local showRate = hasRate( data ) return { caption = 'Locations', hideCaption = true, columns = getColumns( showRate ), data = getRows( data, showRate ), class = table.concat( { 't-location-table', 'wikitable--fluid' -- Citizen built-in class for broad tables }, ' ' ) } end --- Wikitext entry point for the module --- --- @param frame mw.frame --- @return string function p.main( frame ) local getArgs = require( 'Module:Arguments' ).getArgs return p._main( processArgs( getArgs( frame ) ) ) end --- Lua entry point for the module --- --- @param data table --- @return string function p._main( data ) return tableLua.render( getTableProps( data ) ) end return p
Templates used on this page:
Template:Documentation
(
view source
)
Module:Location/Components/Table/doc
(
view source
)
Return to
Module:Location/Components/Table
.