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:CardLua
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:CardLua
require( 'strict' ) --- Simplified Lua interface for building a card. --- Using similar approach to the Codex Card component. --- @class CardProps --- @field title ?string --- @field description ?string --- @field url ?string --- @field page ?string --- @field icon ?string --- @field class ?string --- @field thumbnail ?string --- @field thumbnailSize ?string local p = {} --- @param file string --- @param size string --- @return string local function getFileWikitext( file, size ) -- `metadata` class is needed to be excluded from MultimediaViewer. -- `link=` is needed make sure the image is not clickable. return string.format( '[[File:%s|%s|class=metadata|link=]]', file, size ) end --- @param root mw.html --- @param thumbnail string --- @param thumbnailSize string local function renderThumbnail( root, thumbnail, thumbnailSize ) local html = mw.html.create( 'div' ) html :addClass( 't-card__thumbnail' ) :wikitext( getFileWikitext( thumbnail, thumbnailSize or '48px' ) ) root:node( html ) end --- @param root mw.html --- @param icon string local function renderIcon( root, icon ) local html = mw.html.create( 'div' ) html :addClass( 't-card__icon' ) :wikitext( getFileWikitext( icon, '20px' ) ) root:node( html ) end --- @param root mw.html --- @param title ?string --- @param description ?string local function renderText( root, title, description ) local html = mw.html.create( 'div' ) html:addClass( 't-card__text' ) if type( title ) == 'string' then html:tag( 'div' ):addClass( 't-card__title' ):wikitext( title ) end if type( description ) == 'string' then html:tag( 'div' ):addClass( 't-card__description' ):wikitext( description ) end root:node( html ) end --- @param root mw.html --- @param link string local function renderInternalLink( root, link ) local html = mw.html.create( 'div' ) html :addClass( 't-card__link' ) :wikitext( string.format( '[[%s]]', link ) ) root:node( html ) root:addClass( 't-card--is-link' ) end --- @param root mw.html --- @param link string local function renderExternalLink( root, link ) local html = mw.html.create( 'div' ) html :addClass( 't-card__link' ) :wikitext( string.format( '[%s]', link ) ) root:node( html ) root:addClass( 't-card--is-link' ) end --- @param props CardProps --- @return string function p.render( props ) local root = mw.html.create( 'div' ):addClass( 't-card' ) if type( props.class ) == 'string' then root:addClass( props.class ) end if type( props.thumbnail ) == 'string' then renderThumbnail( root, props.thumbnail, props.thumbnailSize ) elseif type( props.icon ) == 'string' then renderIcon( root, props.icon ) end renderText( root, props.title, props.description ) if type( props.page ) == 'string' then renderInternalLink( root, props.page ) elseif type( props.url ) == 'string' then renderExternalLink( root, props.url ) end return mw.getCurrentFrame():extensionTag { name = 'templatestyles', args = { src = 'Module:CardLua/styles.css' } } .. tostring( root ) 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.render( getArgs( frame ) ) end return p
Templates used on this page:
Template:Documentation
(
view source
)
Module:CardLua/doc
(
view source
)
Return to
Module:CardLua
.