Module:Infocard: Difference between revisions

From Path of Exile 2 Wiki
Jump to navigation Jump to search
No edit summary
m (9 revisions imported)
 
(7 intermediate revisions by 2 users not shown)
Line 1: Line 1:
-------------------------------------------------------------------------------
--
--                            Module:Infocard
--
-- This module implements Template:Infocard and is used by a number of other
-- modules to display info cards.
-------------------------------------------------------------------------------
require('Module:No globals')
local m_util = require('Module:Util')
-- Should we use the sandbox version of our submodules?
local use_sandbox = m_util.misc.maybe_sandbox('Infocard')
-- The cfg table contains all localisable strings and configuration, to make it
-- easier to port this module to another wiki.
local cfg = use_sandbox and mw.loadData('Module:Infocard/config/sandbox') or mw.loadData('Module:Infocard/config')
local i18n = cfg.i18n
-- ----------------------------------------------------------------------------
-- Main function
-- ----------------------------------------------------------------------------
local function _main(args)
    args.heading = args.heading or args.header
    args.subheading = args.subheading or args.subheader
    local html = mw.html.create('div')
        :addClass('info-card')
    if args.class then
        html:addClass(args.class)
    end
    if args.above then
        html
            :tag('div')
                :addClass('info-card__above')
                :node(args.above)
    end
    local card = mw.html.create('div')
        :addClass('info-card__card')
    local header = mw.html.create('div')
        :addClass('info-card__header')
    header
        :tag('div')
            :addClass('left')
            :wikitext(args.headerleft or '')
    local middle = mw.html.create('div')
        :addClass('middle')
    middle
        :tag('div')
            :addClass('heading')
            :wikitext(args.heading)
    if args.subheading then
        middle
            :tag('div')
                :addClass('subheading')
                :wikitext(args.subheading)
    end
    header
        :node(middle)
    header
        :tag('div')
            :addClass('right')
            :wikitext(args.headerright or '')
    card:node(header)
    local body = mw.html.create('div')
        :addClass('info-card__body')
    local block
    for i=1, math.huge do -- repeat until no more blocks are found
        if args[i] == nil then
            break
        end
        block = mw.html.create('div')
            :addClass('block')
        if args[i .. 'class'] then
            block:addClass(args[i .. 'class'])
        end
        block:node(args[i])
        body:node(block)
    end
    card:node(body)
    html:node(card)
    if args.below then
        html
            :tag('div')
                :addClass('info-card__below')
                :node(args.below)
    end
    return tostring(html)
end
-- ----------------------------------------------------------------------------
-- Exported functions
-- ----------------------------------------------------------------------------
local p = {}
local p = {}
local getArgs


function p.main(frame)
p.main = m_util.misc.invoker_factory(_main, {
if not getArgs then
    wrappers = cfg.wrappers,
getArgs = require('Module:Arguments').getArgs
})
end
local args = getArgs(frame, {
wrappers = 'Template:Infocard'
})
return p._main(args)
end


function p._main(args)
p.infocard = p.main
local container = mw.html.create('div')
p._main = p.main -- Contingency for modules that are still calling p._main()
:attr( 'class', 'infocard ' .. (args.class or '') )
local topbar = mw.html.create('div')
:attr('class', 'topbar')
topbar:tag('div')
:attr('class', 'left')
:wikitext(args.headerleft)
:done()
local middle = mw.html.create('div')
:attr('class', 'middle')
middle:tag('div')
:attr('class', 'header')
:wikitext(args.header)
:done()
if args.subheader then
middle:tag('div')
:attr('class', 'subheader')
:wikitext(args.subheader)
:done()
end
topbar:node(middle)
topbar:tag('div')
:attr('class', 'right')
:wikitext(args.headerright)
:done()
container:node(topbar)
local inner = mw.html.create('div')
:attr('class', 'inner')
local i = 1
while args[i] do
inner:tag('div')
:attr('class', 'block')
:wikitext(args[i])
:done()
i = i + 1
end
container:node(inner)
return tostring(container)
end


return p
return p

Latest revision as of 10:46, 27 September 2024

Module documentation[view] [edit] [history] [purge]


Lua logo

This module depends on the following other modules:

This module implements {{infocard}}.

-------------------------------------------------------------------------------
-- 
--                            Module:Infocard
-- 
-- This module implements Template:Infocard and is used by a number of other
-- modules to display info cards.
-------------------------------------------------------------------------------

require('Module:No globals')
local m_util = require('Module:Util')

-- Should we use the sandbox version of our submodules?
local use_sandbox = m_util.misc.maybe_sandbox('Infocard')

-- The cfg table contains all localisable strings and configuration, to make it
-- easier to port this module to another wiki.
local cfg = use_sandbox and mw.loadData('Module:Infocard/config/sandbox') or mw.loadData('Module:Infocard/config')

local i18n = cfg.i18n

-- ----------------------------------------------------------------------------
-- Main function
-- ----------------------------------------------------------------------------

local function _main(args)
    args.heading = args.heading or args.header
    args.subheading = args.subheading or args.subheader
    local html = mw.html.create('div')
        :addClass('info-card')
    if args.class then
        html:addClass(args.class)
    end
    if args.above then
        html
            :tag('div')
                :addClass('info-card__above')
                :node(args.above)
    end
    local card = mw.html.create('div')
        :addClass('info-card__card')
    local header = mw.html.create('div')
        :addClass('info-card__header')
    header
        :tag('div')
            :addClass('left')
            :wikitext(args.headerleft or '')
    local middle = mw.html.create('div')
        :addClass('middle')
    middle
        :tag('div')
            :addClass('heading')
            :wikitext(args.heading)
    if args.subheading then
        middle
            :tag('div')
                :addClass('subheading')
                :wikitext(args.subheading)
    end
    header
        :node(middle)
    header
        :tag('div')
            :addClass('right')
            :wikitext(args.headerright or '')
    card:node(header)
    local body = mw.html.create('div')
        :addClass('info-card__body')
    local block
    for i=1, math.huge do -- repeat until no more blocks are found
        if args[i] == nil then
            break
        end
        block = mw.html.create('div')
            :addClass('block')
        if args[i .. 'class'] then
            block:addClass(args[i .. 'class'])
        end
        block:node(args[i])
        body:node(block)
    end
    card:node(body)
    html:node(card)
    if args.below then
        html
            :tag('div')
                :addClass('info-card__below')
                :node(args.below)
    end
    return tostring(html)
end

-- ----------------------------------------------------------------------------
-- Exported functions
-- ----------------------------------------------------------------------------

local p = {}

p.main = m_util.misc.invoker_factory(_main, {
    wrappers = cfg.wrappers,
})

p.infocard = p.main
p._main = p.main -- Contingency for modules that are still calling p._main()

return p