Module:Indicator

Module documentation[view][edit][history][purge]
This documentation is transcluded from Module:Indicator/doc. Changes can be proposed in the talk page.
An icon from the Wikimedia Codex library.
Module:Indicator loads configuration from Module:Indicator/config.json.
This module can be configured from the config.json subpage.
An icon from the Wikimedia Codex library.
Module:Indicator loads styles from Module:Indicator/styles.css.
Function list
L 4 — p.main
L 9 — p._main

local getArgs = require('Module:Arguments').getArgs
local p = {}

function p.main(frame)
    local args = getArgs(frame, { parentOnly = true })
    return p._main(frame, args)
end

function p._main(frame, args)
    local config = mw.loadJsonData( 'Module:Indicator/config.json' )
    local namespace = mw.title.getCurrentTitle().namespace

    local indicator, image, text, link

    if args[1] then
        text = string.lower(args[1])
        indicator = config.indicators[text]
    elseif config.indicators[config.namespaces[namespace]] then
        indicator = config.indicators[config.namespaces[namespace]]
    else
        return
    end

    image = indicator.image
    text = indicator.text
    link = indicator.link or text

    local html = mw.html.create( nil )
            :tag('div')
            :addClass('indicator__container')
            :tag('div')
            :addClass('indicator__image')
            :wikitext(string.format("[[File:%s|40px|link=%s]]", image, link))
            :done()
            :tag('div')
            :addClass('indicator__text')
            :wikitext(string.format("[[%s|%s]]", link, text))
            :done()
            :done()

    return frame:extensionTag {
        name = 'templatestyles', args = { src = "Module:Indicator/styles.css" }
    } .. tostring(html)
end

return p