Edge Rewrite
// HTMLRewriter · presentation

This page was redesigned at the edge.

Cloudflare fetched the original article and streamed it through HTMLRewriter to apply an entirely new visual system without rebuilding the source page.

Jump to content

Template talk:Mf-adr

Page contents not supported in other languages.
Add topic
From Wikipedia, the free encyclopedia
Latest comment: 3 years ago by BoonDock in topic Lua Module

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