TehCupcakes (talk | contribs) m (1 revision imported) |
TehCupcakes (talk | contribs) m (1 revision imported) |
||
(4 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
local libraryUtil = require( 'libraryUtil' ) | |||
local checkType = libraryUtil.checkType | |||
local mArguments -- lazily initialise [[Module:Arguments]] | |||
-- | local mError -- lazily initialise [[Module:Error]] | ||
local | |||
-- | |||
local p = {} | |||
-- | --- Helper function to throw error | ||
- | |||
-- | -- | ||
-- @param msg string - Error message | |||
-- | |||
-- @return string - Formatted error message in wikitext | |||
local function makeWikitextError( msg ) | |||
mError = require( 'Module:Error' ) | |||
return mError.error { | |||
message = 'Error: ' .. msg .. '.' | |||
} | |||
end | |||
function p.mbox( frame ) | |||
mArguments = require( 'Module:Arguments' ) | |||
local args = mArguments.getArgs( frame ) | |||
local title = args[ 1 ] or args[ 'title' ] | |||
local text = args[ 2 ] or args[ 'text' ] | |||
if not title or not text then | |||
return makeWikitextError( | |||
'no title or text specified' | |||
) | |||
end | |||
return p._mbox( title, text, { | |||
extraclasses = args.extraclasses, | |||
icon = args.icon | |||
} ) | |||
end | |||
function p._mbox( title, text, options ) | |||
checkType( '_mbox', 1, title, 'string' ) | |||
checkType( '_mbox', 2, text, 'string' ) | |||
checkType( '_mbox', 3, options, 'table', true ) | |||
options = options or {} | |||
local mbox = mw.html.create( 'div' ) | |||
local extraclasses | |||
if type( options.extraclasses ) == 'string' then | |||
extraclasses = options.extraclasses | |||
end | |||
mbox | |||
:attr( 'role', 'presentation' ) | |||
:addClass( 'mbox' ) | |||
:addClass( extraclasses ) | |||
local mboxTitle = mbox:tag( 'div' ):addClass( 'mbox-title' ) | |||
if options.icon and type( options.icon ) == 'string' then | |||
mboxTitle:tag( 'div' ) | |||
:addClass( 'mbox-icon metadata' ) | |||
:wikitext( '[[File:' .. options.icon .. '|14px|link=]]' ) | |||
:done() | |||
:tag( 'div' ) | |||
:wikitext( title ) | |||
else | |||
mboxTitle:wikitext( title ) | |||
end | |||
mbox:tag( 'div' ) | |||
:addClass( 'mbox-text' ) | |||
:wikitext( text ) | |||
return mw.getCurrentFrame():extensionTag { | |||
name = 'templatestyles', args = { src = 'Module:Mbox/styles.css' } | |||
} .. tostring( mbox ) | |||
end | end | ||
return p | |||
return |
Latest revision as of 09:39, 1 May 2024
This documentation is transcluded from Module:Mbox/doc. Changes can be proposed in the talk page.
This module is unused.
This module is neither invoked by a template nor required/loaded by another module. If this is in error, make sure to add
{{Documentation}}
/{{No documentation}}
to the calling template's or parent's module documentation.Function list |
---|
L 13 — makeWikitextError L 20 — p.mbox L 36 — p._mbox |
local libraryUtil = require( 'libraryUtil' )
local checkType = libraryUtil.checkType
local mArguments -- lazily initialise [[Module:Arguments]]
local mError -- lazily initialise [[Module:Error]]
local p = {}
--- Helper function to throw error
--
-- @param msg string - Error message
--
-- @return string - Formatted error message in wikitext
local function makeWikitextError( msg )
mError = require( 'Module:Error' )
return mError.error {
message = 'Error: ' .. msg .. '.'
}
end
function p.mbox( frame )
mArguments = require( 'Module:Arguments' )
local args = mArguments.getArgs( frame )
local title = args[ 1 ] or args[ 'title' ]
local text = args[ 2 ] or args[ 'text' ]
if not title or not text then
return makeWikitextError(
'no title or text specified'
)
end
return p._mbox( title, text, {
extraclasses = args.extraclasses,
icon = args.icon
} )
end
function p._mbox( title, text, options )
checkType( '_mbox', 1, title, 'string' )
checkType( '_mbox', 2, text, 'string' )
checkType( '_mbox', 3, options, 'table', true )
options = options or {}
local mbox = mw.html.create( 'div' )
local extraclasses
if type( options.extraclasses ) == 'string' then
extraclasses = options.extraclasses
end
mbox
:attr( 'role', 'presentation' )
:addClass( 'mbox' )
:addClass( extraclasses )
local mboxTitle = mbox:tag( 'div' ):addClass( 'mbox-title' )
if options.icon and type( options.icon ) == 'string' then
mboxTitle:tag( 'div' )
:addClass( 'mbox-icon metadata' )
:wikitext( '[[File:' .. options.icon .. '|14px|link=]]' )
:done()
:tag( 'div' )
:wikitext( title )
else
mboxTitle:wikitext( title )
end
mbox:tag( 'div' )
:addClass( 'mbox-text' )
:wikitext( text )
return mw.getCurrentFrame():extensionTag {
name = 'templatestyles', args = { src = 'Module:Mbox/styles.css' }
} .. tostring( mbox )
end
return p