dev

This module was made as a sandbox for the Luadocs module. This documentation is kept to prevent redlinks.


--<nowiki> Shows modules links in the list of global modules
-- Syntax :{{#invoke:Luadocs|main|<modulename>|notests=1}}

local p = {}
local getArgs = require("Dev:Arguments").getArgs
local isMod = require("Dev:Existsmod").module_exists
local link = require("Dev:Links").link

function p.create_links(modName, external, noTests)
    if not modName then
        return
    end
    
    local headerText = modName
    local modLinks = {
        "[[Global Lua Modules/" .. modName .. "|Docs]]",
        "[[Module:" .. modName .. "|Source]]"
    }

    if external then
        headerText = link(external, modName)

        local icons = {
            wikipedia = "Wp icon 16x16",
            github = "GitHub icon 16x16"
        }

        for substring, icon in pairs(icons) do
            if external:lower():find(substring) then
                headerText = "[[File:" .. icon .. ".png]] " .. headerText
            end
        end
    end

    local headerDiv = mw.html.create("div")
        :css("font-size", "18px")
        :css("line-height", "26px")
        :wikitext(headerText)

    if not noTests then
        local testPage = "Module:" .. modName .. "/testcases"
        local testLink = "[[" .. testPage .. "|Tests]]"

        if not isMod(testPage, true) then
            local url = mw.uri.fullUrl(testPage):extend{
                action = "edit",
                preload = "Template:Moduletestcases"
            }

            testLink = testLink .. "<sup>([" .. tostring(url) .. " add])</sup>"
        end

        modLinks[3] = testLink
    end

    return tostring(headerDiv) .. table.concat(modLinks, " · ")
end

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

    if args[1] then
        return p.create_links(args[1], args["external"], args["notests"])
    end
end

return p