Template talk:Mf-adr

Page contents not supported in other languages.
From Wikipedia, the free encyclopedia

Lua Module[edit]

I don't want to implement this myself, but if you feel like it, here is a conversion of this template into a Lua module.

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

local function isnotempty(s)
    return s and s:match( '^%s*(.-)%s*$' ) ~= ''
end

function p.main(frame)
    local args = frame:getArgs()
    local inadr = args.inadr or "+"
    local street = args.street
    local city = args.city
    local region = args.region
    local pocode = args.pocode
    local nation = args.nation

    local span_class = "adr"
    if inadr == "-" then
        span_class = ""
    end

    local output = mw.html.create("span")
    if span_class ~= "" then
        output:addClass(span_class)
    else
        output:attr("style", "display:none")
    end

    if isnotempty(street) then
        output:wikitext(mw.html.create("span")
            :addClass("street-address")
            :wikitext(street)
            :done()
            :text(", "))
    end

    if isnotempty(city) then
        output:wikitext(mw.html.create("span")
            :addClass("locality")
            :wikitext(city)
            :done()
            :text(", "))
    end

    if isnotempty(region) then
        output:wikitext(mw.html.create("span")
            :addClass("region")
            :wikitext(region)
            :done()
            :text(", "))
    end

    if isnotempty(pocode) then
        output:wikitext(mw.html.create("span")
            :addClass("postal-code")
            :wikitext(pocode)
            :done()
            :text(", "))
    end

    if isnotempty(nation) then
        output:wikitext(mw.html.create("span")
            :addClass("country-name")
            :wikitext(nation)
            :done())
    end

    return tostring(output) .. frame:expandTemplate({title = "Documentation"})
end

return p

BoonDock (talk) 02:24, 26 April 2023 (UTC)[reply]