{{Documentation}}
/{{No documentation}}
to the calling template's or parent's module documentation.Function list |
---|
L 21 — t L 29 — restoreUnderscore L 35 — formatNumber L 56 — getDetailsHTML L 87 — methodtable.renderInfobox L 97 — renderContent L 104 — renderSnippet L 145 — InfoboxNeue.new |
|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 7: attempt to call method 'renderImage' (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 50: attempt to call method 'renderItem' (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 83: attempt to call method 'renderItem' (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 110: attempt to call method 'renderItem' (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
---
--- @param key string The translation key
--- @return string If the key was not found, the key is returned
local function t( key )
return i18n:translate( key )
end
--- Helper function to restore underscore from space
--- so that it does not screw up the external link wikitext syntax
--- For some reason SMW property converts underscore into space
--- mw.uri.encode can't be used on full URL
local function restoreUnderscore( s )
return s:gsub( ' ', '%%5F' )
end
--- Helper function to format string to number with separators
--- It is usually used to re-format raw numbers from SMW into a more readable format
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
--- Helper function to generate <details> and <summary> tags
---
--- @param data table {details = {class, content, open}, summary = {class, content}}
--- @return string HTML of the <details> component
local function getDetailsHTML( data )
-- Check if data is provided and valid
if not data or not data.details or not data.summary then
return ''
end
-- Create the <summary> tag
local summary = mw.html.create( 'summary' )
:addClass( data.summary.class or '' ) -- Default to empty if no class
:wikitext( data.summary.content or '' ) -- Default to empty if no content
-- Create the <details> tag
local details = mw.html.create( 'details' )
:addClass( data.details.class or '' ) -- Default to empty if no class
:node( summary ) -- Add the summary as a child
:wikitext( data.details.content or '' ) -- Default to empty if no content
-- Add the 'open' attribute if specified
if data.details.open then
details:attr( 'open', nil ) -- Adds the attribute without a value
end
return tostring( details )
end
--- Example method: Render a full infobox
---
--- @param self table
--- @param innerHtml string Inner HTML of the infobox
--- @param snippetText string Optional snippet for mobile view
--- @return string Full infobox HTML
function methodtable.renderInfobox( self, innerHtml, snippetText )
checkType( 'Module:InfoboxNeue.renderInfobox', 1, self, 'table' )
checkTypeMulti( 'Module:InfoboxNeue.renderInfobox', 2, innerHtml, { 'table', 'string', 'nil' } )
checkType( 'Module:InfoboxNeue.renderInfobox', 3, snippetText, 'string', true )
innerHtml = innerHtml or self.entries
if type( innerHtml ) == 'table' then
innerHtml = table.concat( self.entries )
end
local function renderContent()
local html = mw.html.create( 'div' )
:addClass( 'infobox__content' )
:wikitext( innerHtml )
return tostring( html )
end
local function renderSnippet()
if snippetText == nil then snippetText = mw.title.getCurrentTitle().text end
local html = mw.html.create()
html:tag( 'div' )
:addClass( 'citizen-ui-icon mw-ui-icon-wikimedia-collapse' )
:done()
:tag( 'div' )
:addClass( 'infobox__data' )
:wikitext( string.format( '%s:', t( 'label_quick_facts' ) ) )
:done()
:tag( 'div' )
:addClass( 'infobox__desc' )
:wikitext( snippetText )
return tostring( html )
end
local frame = mw.getCurrentFrame()
local output = getDetailsHTML( {
details = {
class = 'infobox floatright',
content = renderContent(),
open = true
},
summary = {
class = 'infobox__snippet',
content = renderSnippet()
}
} )
return output .. frame:extensionTag {
name = 'templatestyles', args = { src = 'Module:InfoboxNeue/styles.css' }
} .. table.concat( self.categories )
end
--- New Instance
---
--- @param config table Optional configuration
--- @return table InfoboxNeue instance
function InfoboxNeue.new( self, config )
local baseConfig = {
-- Flag to discard empty rows
removeEmpty = false,
-- Optional string which is valued as empty
emptyString = nil,
-- Display a placeholder image if addImage does not find an image
displayPlaceholder = true,
-- Placeholder Image
placeholderImage = 'Platzhalter.webp',
}
for k, v in pairs( config or {} ) do
baseConfig[ k ] = v
end
local instance = {
categories = {},
config = baseConfig,
entries = {}
}
setmetatable( instance, metatable )
return instance
end
return InfoboxNeue