Module:Infobox

-- -- Infobox template module for w:c:dev documentation. -- @module     infobox -- @version    1.0.1 -- @usage -- @author     Speedit -- @see        Template:Infobox JavaScript; Template:Infobox CSS -- @release    unstable

-- Module package. local infobox = {}

-- Module variables and utilities. -- @section utils local yesno = require('Dev:Yesno') local title = mw.title.getCurrentTitle

-- Module message data. -- @see        Module:Infobox/i18n local i18n = require('Module:I18n').loadMessages('Infobox', 'Common', 'Testharness')

-- Module categories data. -- @see        Module:Infobox/data local data = mw.loadData('Module:Infobox/data')

-- Date formatter utility. -- @param      {string} d Unprocessed date. -- @param      {string} f Date format to use. -- @see        Template:FormatDate -- @return     {string} Formatted, localised date. function dtfm(d, f)   return mw.getCurrentFrame:expandTemplate{ title = 'FormatDate', args = { d, dateformat = f, uselang = i18n:getLang } } end

-- Installation exports. -- @section exps

-- Infobox data argument handler. -- Substitutes $n arguments with version numbers. -- @param      {table} frame Frame invocation object. -- @param      {string} frame.args[1] Infobox data input. -- @param      {string} frame.args.ucfirst Capitalization boolean. -- @raise      'missing argument in infobox.data' -- @usage -- @return     {string} Argument-substituted infobox data. function infobox.data(frame) -- Throw error if incorrectly configured. if not ((frame or {}).args or {})[1] then error('missing argument in infobox.data') end -- Template arguments & variables. local args = frame:getParent.args local ret = frame.args[1] -- Replacement handler. local function repl(d) local rsub = d == '1' and (args.Submodule or i18n:msg('original')) or (args['Submodule' .. d] or i18n:msg('version', d)) return yesno(mw.text.trim(frame.args.ucfirst or '')) and rsub:gsub('^%l', mw.ustring.upper) or rsub end -- Argument substitution. return string.find(ret, '$') and ret:gsub('%$(%w+)', repl) or ret end

-- Infobox date list generator with version numbers. -- @param      {table} frame Frame invocation object. -- @param      {string} frame.args Invocation arguments. -- @param      {string} frame.args.ext Code type. -- @param      {table} frame:getParent.args Template arguments. -- @usage -- @return     {string} Formatted multi-line date string. function infobox.date(frame) -- Template arguments & variables. local args = frame:getParent.args local dateformat = args.dateformat or '' local ret = '' -- Formatted date field. if args.Updated then -- Generated first formatted date. ret = dtfm(args.Updated, dateformat) if args.Submodule or args.Updated2 then -- Append first version tag. local sub1 = args.Submodule or i18n:msg('original') if sub1 ~= '' then ret = ret .. ' (' .. sub1 .. ')' end end -- Handle further versions. for d = 2, math.huge do           local p = args['Updated' .. d]           if not p then break end local s = args['Submodule' .. d] or i18n:msg('version', d)           ret = ret .. ' '               .. dtfm(p, dateformat) .. ' (' .. s ..')' end -- Default date field. elseif args.Code then -- @todo Use DPL template to extract main code page? local ext = frame.args.ext or 'js' local suffix = '.' .. ext if ext ~= 'css' then suffix = '/code' .. suffix end local u = frame:expandTemplate{ title = 'Updated', args = { 'MediaWiki:' .. title.baseText .. suffix }       }        ret = dtfm(u, dateformat) end return ret end

-- Documentation to do function infobox.categories(frame) local ret = '' local typ = frame.args[1] local args = frame:getParent.args if (args.Status and mw.ustring.lower(args.Status) == 'archive') or not typ or not data.categories[typ] then return '' end local sortkey = args.Title or title.prefixedText ret = ret .. ''   if args.Type then for v in mw.text.gsplit(mw.text.trim(mw.ustring.lower(args.Type)), ',', true) do           local cat = data.categories[typ][mw.text.trim(v)] if cat then ret = ret .. ''           end end end return ret end

-- Documentation to do. function infobox.luatype(frame) local args = frame:getParent.args local typ = args.Type or args.type if typ then return data.luatypes[typ:lower] end return '' end

-- Test suite status. -- @param      {table} frame Frame invocation object. -- @return     {string} Test suite status badge. function infobox.luasuite(frame) -- Function variables. local page = mw.language.fetchLanguageName(title.subpageText) == '' and title.subpageText or title.baseText:match('/*([^/]+)$') -- DPL query for categories local query = -- Fetch category data. local cats = mw.text.split(frame:preprocess(query), ',') local status = data.luastatus[cats[1] or ''] or {} local badge = mw.html.create('div') :addClass('plainlinks') :wikitext('[' .. mw.site.server .. mw.uri.fullUrl('Module talk:' .. page .. '/testcases').path .. ' ') :tag('span') :addClass('wds-button') :css({               ['background']  = '#' .. status.background,                ['border']      = 'none',                ['color']       = '#' .. (status.color or 'ffffff'),                ['cursor']      = 'inherit',                ['font-weight'] = 'bold'            }) :wikitext(i18n:msg(status.i18n_key)) :done :wikitext(']') return tostring(badge) end

return infobox --