توضیحات این پودمان می‌تواند در پودمان:AlborzInfoBox/توضیحات قرار گیرد.

local p = {}
local data = mw.loadData('Module:AlborzInfoBox/Data/Geography')

-------------------------------------------------------
-- NORMALIZE
-------------------------------------------------------

local function norm(s)
    if not s then
        return nil
    end

    s = mw.text.trim(s)
    s = mw.ustring.gsub(s, "[\u200C\u200D]", "")

    return s
end

-------------------------------------------------------
-- GET ARG
-------------------------------------------------------

local function getArg(args, field)

    if not field then
        return nil
    end

    ---------------------------------------------------
    -- حالت جدید (args)
    ---------------------------------------------------

    if field.args then

        for i = 1, #field.args do

            local value = args[norm(field.args[i])]

            if value and value ~= "" then
                return value
            end

        end

    end

    ---------------------------------------------------
    -- سازگاری با نسخه قدیمی
    ---------------------------------------------------

    if field.arg then
        return args[norm(field.arg)]
    end

    return nil

end

-------------------------------------------------------
-- GET ARGS
-------------------------------------------------------

local function getArgs(frame)

    local args = {}

    local function add(tbl)

        if not tbl then
            return
        end

        for k, v in pairs(tbl) do

            if v and v ~= "" then
                args[norm(k)] = mw.text.trim(v)
            end

        end

    end

    add(frame.args)

    local parent = frame:getParent()

    if parent then
        add(parent.args)
    end

    return args

end

-------------------------------------------------------
-- ADD ROW
-------------------------------------------------------

local function addRow(root,label,value)

    if not value or value=="" then
        return
    end

    local tr=root:tag("tr")

    tr:tag("th")
        :wikitext(label)

    tr:tag("td")
        :wikitext(value)

end
-------------------------------------------------------
-- BADGE
-------------------------------------------------------

local badgeMap = {

    city = "شهر",
    village = "روستا",
    county = "شهرستان",
    district = "بخش",
    ruraldistrict = "دهستان",

    mountain = "کوه",
    cave = "غار",
    river = "رودخانه",
    waterfall = "آبشار",
    park = "پارک",

    historic = "بنای تاریخی"

}

local function addBadge(root, rawType)

    if not rawType or rawType == "" then
        return
    end

    local label = badgeMap[rawType] or rawType

    root:tag("tr")
        :tag("td")
            :attr("colspan","2")
            :addClass("infobox-badge")
            :tag("span")
                :addClass("infobox-badge-label")
                :wikitext(label)

end

-------------------------------------------------------
-- IMAGE
-------------------------------------------------------

local function addImage(root,args)

    local image =
        args[norm("تصویر")]
        or args[norm("پرونده")]
        or args.image

    if not image then
        return
    end

    root:tag("tr")
        :tag("td")
            :attr("colspan","2")
            :addClass("infobox-image")
            :wikitext("[[پرونده:" .. image .. "|250px]]")

end

-------------------------------------------------------
-- CAPTION
-------------------------------------------------------

local function addCaption(root,args)

    local caption =
        args[norm("توضیح تصویر")]
        or args[norm("عنوان تصویر")]
        or args[norm("زیرنویس")]

    if not caption then
        return
    end

    root:tag("tr")
        :tag("td")
            :attr("colspan","2")
            :addClass("infobox-caption")
            :wikitext(caption)

end

-------------------------------------------------------
-- TABLE
-------------------------------------------------------

local function newTable(rawType)

    return mw.html.create("table")
        :addClass("infobox")
        :addClass("alborz-infobox")
        :addClass("infobox-type-" .. rawType)

end

-------------------------------------------------------
-- TITLE
-------------------------------------------------------

local function addTitle(root,args)

    local title =
        args[norm("نام")]
        or args[norm("نام رسمی")]
        or args[norm("نام‌رسمی")]
        or mw.title.getCurrentTitle().text

    root:tag("tr")
        :tag("th")
            :attr("colspan","2")
            :addClass("infobox-title")
            :wikitext(title)

end
-------------------------------------------------------
-- ROWS
-------------------------------------------------------

local function addRows(root, args, layout)

    for i = 1, #layout do

        local field = data.fields[layout[i]]

        if field then

            local value = getArg(args, field)

            if (not value or value == "") and field.default then
                value = field.default
            end

            if value and value ~= "" then
                addRow(root, field.label, value)
            end

        end

    end

end

-------------------------------------------------------
-- RENDER
-------------------------------------------------------

local function render(args)

    local rawType = args[norm("نوع")] or "city"

    local layout =
        data.layouts[rawType]
        or data.layouts.city

    local root = newTable(rawType)

    addTitle(root, args)

    addBadge(root, rawType)

    addImage(root, args)

    addCaption(root, args)

    addRows(root, args, layout)

    return tostring(root)

end

-------------------------------------------------------
-- MAIN
-------------------------------------------------------

function p.main(frame)

    local args = getArgs(frame)

    return render(args)

end

return p