Module:Mbox: Difference between revisions

From Ato Wiki
starcitizen>Alistair3149
No edit summary
m (1 revision imported)
Line 1: Line 1:
local libraryUtil = require( 'libraryUtil' )
-- This Module is used for making templates based in the Lua language.
local checkType = libraryUtil.checkType
-- See more details about Lua in [[w:Help:Lua]].
local mArguments -- lazily initialise [[Module:Arguments]]
-- The Fandom Developer's Wiki hosts Global Lua Modules that can be imported and locally overridden.
local mError -- lazily initialise [[Module:Error]]
-- The next line imports the Mbox module from the [[w:c:dev:Global Lua Modules]].
local Mbox = require('Dev:Mbox')
-- See more details about this module at [[w:c:dev:Global_Lua_Modules/Mbox]]


local p = {}
-- The imported Module is overwritten locally to include default styling.
-- For a more flexible Mbox experience, delete the function below and import
-- https://dev.fandom.com/wiki/MediaWiki:Global_Lua_Modules/Mbox.css
-- or paste (and modify as you like) its contents in your wiki's
-- [[MediaWiki:Wikia.css]] (see [[w:Help:Including_additional_CSS_and_JS]])
-- or look at https://dev.fandom.com/wiki/Global_Lua_Modules/Mbox
-- for more customization inspiration


--- Helper function to throw error
--  
-- BEGIN DELETION HERE
--
--
-- @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 )
local getArgs = require('Dev:Arguments').getArgs
local args = getArgs( frame )
local localCSS = mw.loadData('Module:Mbox/data').localStyle
local title = args[1] or args[ 'title' ]
 
local text = args[2] or args[ 'text' ]
function Mbox.main(frame)
if not s then
    local args = getArgs(frame)
return p.makeWikitextError(
 
'no text specified',
    -- styles
'Template:Mbox#Errors',
    local styles = {}
args.category
    if args.bordercolor then
)
        styles['border-left-color'] = args.bordercolor
end
    elseif args.type then
return p._mbox( title, text, {
        styles['border-left-color'] = 'var(--type-' .. args.type .. ')'
extraclasses = args.extraclasses,
    end
icon = args.icon
 
} )
    if args.bgcolor then
end
        styles['background-color'] = args.bgcolor
    end
 
    -- images
    local image = args.image or ''
    local imagewidth = args.imagewidth or '80px'
    local imagelink = ''
    if args.imagelink then
        imagelink = '|link=' .. args.imagelink
    end
 
    local imagewikitext = ('%sFile:%s|%s%s' .. ']]'):format('[[', image, imagewidth, imagelink)
 
    -- id for closure
    local id = args.id or 'mbox'
 
    local container = mw.html.create('div')
        :addClass('mbox')
        :addClass(args.class)
        :css(styles)
        :css(localCSS['mbox'])
        :cssText(args.style)
 
    local content = container:tag('div')
        :addClass('mbox__content')
        :css(localCSS['mbox__content'])
 
    if args.image then
        local image = content:tag('div')
            :addClass('mbox__content__image')
            :addClass('mw-collapsible')
            :attr('id', 'mw-customcollapsible-' .. id)
        :css(localCSS['mbox__content__image'])
            :wikitext(imagewikitext)
            if args.collapsed then
                image:addClass('mw-collapsed')
            end
    end
 
    local contentwrapper = content:tag('div')
        :addClass('mbox__content__wrapper')
        :css(localCSS['mbox__content__wrapper'])


function p._mbox( title, text, options )
    if args.header then
checkType( '_mbox', 1, title, 'string' )
        contentwrapper:tag('div')
checkType( '_mbox', 2, text, 'string' )
            :addClass('mbox__content__header')
checkType( '_mbox', 3, options, 'table', true )
            :css(localCSS['mbox__content__header'])
            :wikitext(args.header)
    end


options = options or {}
    if args.text then
local mbox = mw.html.create( 'div' )
        local text = contentwrapper:tag('div')
local extraclasses
            :addClass('mbox__content__text')
if type( options.extraclasses ) == 'string' then
            :addClass('mw-collapsible')
extraclasses = options.extraclasses
            :attr('id', 'mw-customcollapsible-' .. id)
end
            :css(localCSS['mbox__content__text'])
            :wikitext(args.text)
            if args.collapsed then
                text:addClass('mw-collapsed')
            end


mbox
        if args.comment then
:attr( 'role', 'presentation' )
            text:tag('div')
:addClass( 'mbox' )
                :addClass('mbox__content__text__comment')
:addClass( extraclasses )
                :css(localCSS['mbox__content__text__comment'])
                :wikitext(args.comment)
        end
    end


local mboxTitle = mbox:tag( 'div' ):addClass( 'mbox-title' )
    contentwrapper:tag('span')
        :addClass('mbox__close')
if options.icon and type( options.icon ) == 'string' then
        :addClass('mw-customtoggle-' .. id)
mboxTitle:tag( 'div' )
        :css(localCSS['mbox__close'])
:addClass( 'mbox-icon metadata' )
        :attr('title', 'Dismiss')
:wikitext( '[[File:' .. options.icon .. '|14px|link=]]' )
:done()
:tag( 'div' )
:wikitext( title )
else
mboxTitle:wikitext( title )
end


mbox:tag( 'div' )
    if args.aside then
:addClass( 'mbox-text' )
        local aside = content:tag('div')
:wikitext( text )
            :addClass('mbox__content__aside')
            :addClass('mw-collapsible')
            :attr('id', 'mw-customcollapsible-' .. id)
            :css(localCSS['mbox__content__aside'])
            :wikitext(args.aside)
            if args.collapsed then
                aside:addClass('mw-collapsed')
            end
    end


return mw.getCurrentFrame():extensionTag{
    return container
name = 'templatestyles', args = { src = 'Module:Mbox/styles.css' }
} .. tostring(mbox)
end
end


return p
--
-- END DELETION HERE
--
 
-- The last line produces the output for the template
return Mbox

Revision as of 22:48, 6 November 2023

Lua error in package.lua at line 80: module 'Dev:Mbox' not found.


-- This Module is used for making templates based in the Lua language.
-- See more details about Lua in [[w:Help:Lua]].
-- The Fandom Developer's Wiki hosts Global Lua Modules that can be imported and locally overridden.
-- The next line imports the Mbox module from the [[w:c:dev:Global Lua Modules]].
local Mbox = require('Dev:Mbox')
-- See more details about this module at [[w:c:dev:Global_Lua_Modules/Mbox]]

-- The imported Module is overwritten locally to include default styling.
-- For a more flexible Mbox experience, delete the function below and import 
-- https://dev.fandom.com/wiki/MediaWiki:Global_Lua_Modules/Mbox.css
-- or paste (and modify as you like) its contents in your wiki's 
-- [[MediaWiki:Wikia.css]] (see [[w:Help:Including_additional_CSS_and_JS]])
-- or look at https://dev.fandom.com/wiki/Global_Lua_Modules/Mbox
-- for more customization inspiration

-- 
-- BEGIN DELETION HERE
--

local getArgs = require('Dev:Arguments').getArgs
local localCSS = mw.loadData('Module:Mbox/data').localStyle

function Mbox.main(frame)
    local args = getArgs(frame)

    -- styles
    local styles = {}
    if args.bordercolor then
        styles['border-left-color'] = args.bordercolor
    elseif args.type then
        styles['border-left-color'] = 'var(--type-' .. args.type .. ')'
    end

    if args.bgcolor then
        styles['background-color'] = args.bgcolor
    end

    -- images
    local image = args.image or ''
    local imagewidth = args.imagewidth or '80px'
    local imagelink = ''
    if args.imagelink then
        imagelink = '|link=' .. args.imagelink
    end

    local imagewikitext = ('%sFile:%s|%s%s' .. ']]'):format('[[', image, imagewidth, imagelink)

    -- id for closure
    local id = args.id or 'mbox'

    local container = mw.html.create('div')
        :addClass('mbox')
        :addClass(args.class)
        :css(styles)
        :css(localCSS['mbox'])
        :cssText(args.style)

    local content = container:tag('div')
        :addClass('mbox__content')
        :css(localCSS['mbox__content'])

    if args.image then
        local image = content:tag('div')
            :addClass('mbox__content__image')
            :addClass('mw-collapsible')
            :attr('id', 'mw-customcollapsible-' .. id)
        :css(localCSS['mbox__content__image'])
            :wikitext(imagewikitext)
            if args.collapsed then
                image:addClass('mw-collapsed')
            end
    end

    local contentwrapper = content:tag('div')
        :addClass('mbox__content__wrapper')
        :css(localCSS['mbox__content__wrapper'])

    if args.header then
        contentwrapper:tag('div')
            :addClass('mbox__content__header')
            :css(localCSS['mbox__content__header'])
            :wikitext(args.header)
    end

    if args.text then
        local text = contentwrapper:tag('div')
            :addClass('mbox__content__text')
            :addClass('mw-collapsible')
            :attr('id', 'mw-customcollapsible-' .. id)
            :css(localCSS['mbox__content__text'])
            :wikitext(args.text)
            if args.collapsed then
                text:addClass('mw-collapsed')
            end

        if args.comment then
            text:tag('div')
                :addClass('mbox__content__text__comment')
                :css(localCSS['mbox__content__text__comment'])
                :wikitext(args.comment)
        end
    end

    contentwrapper:tag('span')
        :addClass('mbox__close')
        :addClass('mw-customtoggle-' .. id)
        :css(localCSS['mbox__close'])
        :attr('title', 'Dismiss')

    if args.aside then
        local aside = content:tag('div')
            :addClass('mbox__content__aside')
            :addClass('mw-collapsible')
            :attr('id', 'mw-customcollapsible-' .. id)
            :css(localCSS['mbox__content__aside'])
            :wikitext(args.aside)
            if args.collapsed then
                aside:addClass('mw-collapsed')
            end
    end

    return container
end

-- 
-- END DELETION HERE
--

-- The last line produces the output for the template
return Mbox