{{Documentation}}
/{{No documentation}}
to the calling template's or parent's module documentation.Function list |
---|
L 18 — t L 23 — restoreUnderscore L 28 — formatNumber L 46 — getDetailsHTML L 65 — methodtable.tableToCommaList L 74 — methodtable.formatRange L 98 — methodtable.addUnitIfExists L 107 — methodtable.renderMessage L 124 — methodtable.renderImage L 166 — methodtable.renderIndicator |
|type = website |description = Module:InfoboxNeue is a template page used on the TCG Card Shop Simulator Wiki. Templates are pages that are embedded (transcluded) into other pages to allow for the repetition of information. |site_name = TCG Card Shop Simulator Wiki |locale = en }}
This module is used by Lua modules to build infobox.
Components
Lua error in Module:InfoboxNeue/example at line 2: attempt to call method 'new' (a nil value).
Image
infobox:renderImage( 'TCG Cards.jpg' )
Indicator
Parameter | Description | Type | Status |
---|---|---|---|
data |
Data of the indicator | string | required |
desc |
Description of the indicator | string | optional |
class |
HTML classes to be added to the indicator | string | optional |
infobox:renderIndicator( { data = 'Indicator' } )
Header
Parameter | Description | Type | Status |
---|---|---|---|
title |
Title of the infobox | string | required |
subtitle |
Subtitle of the infobox | string | optional |
infobox:renderHeader( { title = 'Title', subtitle = 'Subtitle' } )
Message
This is a shortcut way to create a message wrapped in a section.
Parameter | Description | Type | Status |
---|---|---|---|
title |
Title of the message | string | required |
desc |
Description of the message | string | optional |
infobox:renderMessage( { title = 'Message title', desc = 'Message description' } )
Item
Parameter | Description | Type | Status |
---|---|---|---|
data |
Data of the item | string | required |
label |
Label of the item | string | optional |
desc |
Description of the item | string | optional |
row |
Whether to display the item in a row | boolean | optional |
spacebetween |
Whether to put space between elements in the item | boolean | optional |
colspan |
Number of columns that the item spans | int | optional |
infobox:renderItem( { label = 'Item label', data = 'Item data' } )
Section
This is used to wrap items into a section.
Parameter | Description | Type | Status |
---|---|---|---|
content |
Content of the section | string | required |
title |
Title of the section | string | optional |
subtitle |
Subtitle of the section | string | optional |
col |
Number of columns in the section | int | optional |
class |
HTML classes to be added to the section | string | optional |
infobox:renderSection( { title = 'Section title', content = table.concat( sectionTable ), col = 3 } )
Layout
Row
Lua error in Module:InfoboxNeue/example at line 2: attempt to call method 'new' (a nil value).
-- Create items sectionTable = { infobox:renderItem( { label = 'Bacon', data = 'Good', row = true, spacebetween = true } ), infobox:renderItem( { label = 'Pancetta', data = 'Great', row = true, spacebetween = true } ), infobox:renderItem( { label = 'Prosciutto', data = 'Wonderful', row = true, spacebetween = true } ) } -- Create section with items infobox:renderSection( { title = 'Row layout', subtitle = 'This is an example of the row layout.', content = table.concat( sectionTable ) } )
List
Lua error in Module:InfoboxNeue/example at line 2: attempt to call method 'new' (a nil value).
-- Create items sectionTable = { infobox:renderItem( { data = 'Bacon is good', desc = 'Bacon ipsum dolor amet burgdoggen boudin spare ribs pork pork chop drumstick beef. Jowl turkey pork, kevin shankle shank shoulder. ', } ), infobox:renderItem( { data = 'Pancetta is great', desc = 'Kevin pig fatback, alcatra pancetta sirloin venison tri-tip shankle kielbasa meatloaf spare ribs beef. Corned beef salami kielbasa tenderloin swine spare ribs andouille.', } ), infobox:renderItem( { data = 'Prosciutto is wonderful', desc = 'Venison chicken meatloaf, ground round swine short ribs shankle short loin tenderloin jerky capicola. Prosciutto venison sirloin beef brisket pancetta.', } ) } -- Create section with items infobox:renderSection( { title = 'List layout', subtitle = 'This is an example of the list layout.', content = table.concat( sectionTable ) } )
Grid
Lua error in Module:InfoboxNeue/example at line 2: attempt to call method 'new' (a nil value).
-- Create items sectionTable = { infobox:renderItem( { label = 'Bacon', data = 'Good' } ), infobox:renderItem( { label = 'Pancetta', data = 'Great' } ), infobox:renderItem( { label = 'Prosciutto', data = 'Wonderful' } ), infobox:renderItem( { label = 'Capicola', data = 'Delightful' } ) } -- Create section with items infobox:renderSection( { title = '2 col grid layout', subtitle = 'This is an example of the two column grid layout.', content = table.concat( sectionTable ), col = 2 } ) infobox:renderSection( { title = '3 col grid layout', subtitle = 'This is an example of the three column grid layout.', content = table.concat( sectionTable ), col = 3 } ) infobox:renderSection( { title = '4 col grid layout', subtitle = 'This is an example of the four column grid layout.', content = table.concat( sectionTable ), col = 4 } )
local InfoboxNeue = {}
local metatable = {}
local methodtable = {}
local libraryUtil = require( 'libraryUtil' )
local checkType = libraryUtil.checkType
local checkTypeMulti = libraryUtil.checkTypeMulti
local i18n = require( 'Module:i18n' ):new()
metatable.__index = methodtable
metatable.__tostring = function ( self )
return tostring( self:renderInfobox() )
end
--- Wrapper function for Module:i18n.translate
local function t( key )
return i18n:translate( key )
end
--- Helper function to restore underscore from space
local function restoreUnderscore( s )
return s:gsub( ' ', '%%5F' )
end
--- Helper function to format string to number with separators
local function formatNumber( s )
local lang = mw.getContentLanguage()
if s == nil then
return
end
if type( s ) ~= 'number' then
s = tonumber( s )
end
if type( s ) == 'number' then
return lang:formatNum( s )
end
return s
end
--- Updated function to manually render <details> and <summary>
local function getDetailsHTML( data, frame )
local summary = mw.html.create( 'summary' )
:addClass( data.summary.class )
:wikitext( data.summary.content )
local details = mw.html.create( 'details' )
:addClass( data.details.class )
if data.details.open then
details:attr( 'open', 'open' )
end
details:node( summary )
:wikitext( data.details.content )
return tostring( details )
end
--- Put table values into a comma-separated list
function methodtable.tableToCommaList( data )
if type( data ) == 'table' then
return table.concat( data, ', ' )
else
return data
end
end
--- Show range if value1 and value2 are different
function methodtable.formatRange( s1, s2, formatNum )
if s1 == nil and s2 == nil then
return
end
formatNum = formatNum or false
if formatNum then
if s1 then
s1 = formatNumber( s1 )
end
if s2 then
s2 = formatNumber( s2 )
end
end
if s1 and s2 and s1 ~= s2 then
return s1 .. ' – ' .. s2
end
return s1 or s2
end
--- Append unit to the value if exists
function methodtable.addUnitIfExists( s, unit )
if s == nil then
return
end
return s .. ' ' .. unit
end
--- Shortcut to return the HTML of the infobox message component as string
function methodtable.renderMessage( self, data, noInsert )
checkType( 'Module:InfoboxNeue.renderMessage', 1, self, 'table' )
checkType( 'Module:InfoboxNeue.renderMessage', 2, data, 'table' )
checkType( 'Module:InfoboxNeue.renderMessage', 3, noInsert, 'boolean', true )
noInsert = noInsert or false
local item = self:renderSection( { content = self:renderItem( { data = data.title, desc = data.desc } ) }, noInsert )
if not noInsert then
table.insert( self.entries, item )
end
return item
end
--- Return the HTML of the infobox image component as string
function methodtable.renderImage( self, filename )
checkType( 'Module:InfoboxNeue.renderImage', 1, self, 'table' )
local hasPlaceholderImage = false
if type( filename ) ~= 'string' and self.config.displayPlaceholder == true then
hasPlaceholderImage = true
filename = self.config.placeholderImage
table.insert( self.categories,
string.format( '[[Category:%s]]', t( 'category_infobox_using_placeholder_image' ) )
)
end
if type( filename ) ~= 'string' then
return ''
end
local parts = mw.text.split( filename, ':', true )
if #parts > 1 then
table.remove( parts, 1 )
filename = table.concat( parts, ':' )
end
local html = mw.html.create( 'div' )
:addClass( 'infobox__image' )
:wikitext( string.format( '[[File:%s|400px]]', filename ) )
if hasPlaceholderImage == true then
local icon = mw.html.create( 'span' ):addClass( 'citizen-ui-icon mw-ui-icon-wikimedia-upload' )
html:tag( 'div' ):addClass( 'infobox__image-upload' )
:wikitext( string.format( '[[%s|%s]]', 'Special:UploadWizard',
tostring( icon ) .. t( 'label_upload_image' ) ) )
end
local item = tostring( html )
table.insert( self.entries, item )
return item
end
--- Return the HTML of the infobox indicator component as string
function methodtable.renderIndicator( self, data )
checkType( 'Module:InfoboxNeue.renderIndicator', 1, self, 'table' )
checkType( 'Module:InfoboxNeue.renderIndicator', 2, data, 'table' )
if data == nil or data[ 'data' ] == nil or data[ 'data' ] == '' then return '' end
local html = mw.html.create( 'div' ):addClass( 'infobox__indicators' )
local htmlClasses = {
'infobox__indicator'
}
if data[ 'class' ] then
table.insert( htmlClasses, data[ 'class' ] )
end
if data[ 'color' ] then
table.insert( htmlClasses, 'infobox__indicator--' .. data[ 'color' ] )
end
if data[ 'nopadding' ] == true then
table.insert( htmlClasses, 'infobox__indicator--nopadding' )
end
html:wikitext(
self:renderItem(
{
[ 'data' ] = data[ 'data' ],
[ 'class' ] = table.concat( htmlClasses, ' ' ),
row = true,
spacebetween = true
}
)
)
local item = tostring( html )
table.insert( self.entries, item )
return item
end
--- Remaining methods are unchanged ---
--- RenderHeader, RenderFooter, and other helper functions remain exactly the same.
--- Copy and paste the remaining sections of your code here as needed.
return InfoboxNeue