Module:For: Difference between revisions

From The Satanic Wiki
Jump to navigation Jump to search
m (1 revision imported)
No edit summary
 
Line 2: Line 2:
local p = {}
local p = {}


local i18n = require('Dev:I18n').loadMessages('For')
local i18n = require('Module:I18n').loadMessages('For')
local title = mw.title.getCurrentTitle()
local title = mw.title.getCurrentTitle()



Latest revision as of 05:29, 2 May 2021

Documentation for this module may be created at Module:For/doc

-- <nowiki>
local p = {}

local i18n = require('Module:I18n').loadMessages('For')
local title = mw.title.getCurrentTitle()

-- @param {*} val
-- @returns {(string|nil)}
local function sanitize(val)
    if type(val) == 'string' and mw.text.trim(val) ~= '' then
        return val
    end
    return nil
end

-- @param {table} args
-- @returns {string}
function p._main(args)
    local html = mw.html.create('dl')
    for i = 3, math.huge, 3 do
        local thing = sanitize(args[i - 2])
        local link = sanitize(args[i - 1])
        local link2 = sanitize(args[i])
        if not (thing or link or link2) then
            break
        end
        local message = i18n:msg(
            link2 and 'for-2' or 'for-1',
            thing or i18n:msg('other'),
            link or i18n:inUserLang():msg('disambiguation', title.text),
            link2
        )
        html:tag('dd')
            :tag('span')
                :addClass('dablink')
                :tag('i')
                    :wikitext(message)
                    :allDone()
    end
    return tostring(html)
end

-- @param {table} frame
-- @returns {string}
function p.main(frame)
    local args = frame:getParent().args
    return p._main(args)
end

return p