پرش به محتوا

پودمان:AlborzInfoBox: تفاوت میان نسخه‌ها

از ویکی البرز
صفحه‌ای تازه حاوی «-------------------------------------------------------------------------------- -- Module:AlborzInfoBox -- Wiki Alborz -- Version 1.0 -------------------------------------------------------------------------------- local p = {} local data = mw.loadData('Module:AlborzInfoBox/Data/Geography') -------------------------------------------------------------------------------- -- Render ----------------------------------------------------...» ایجاد کرد
 
جزبدون خلاصۀ ویرایش
خط ۱: خط ۱:
local p = {}
local data = mw.loadData('Module:AlborzInfoBox/Data/Geography')
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- Module:AlborzInfoBox
-- DEBUG TOGGLE
-- Wiki Alborz
-- Version 1.0
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
local DEBUG = true


local p = {}
local function log(t)
 
    if DEBUG then
local data = mw.loadData('Module:AlborzInfoBox/Data/Geography')
        mw.logObject(t)
    end
end


--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
خط ۱۵: خط ۲۰:
local function render(args)
local function render(args)


     local layout = data.layouts[args["نوع"] or "city"]
    log(args)
 
     local layoutName = args["نوع"] or "city"
    local layout = data.layouts[layoutName]


     if not layout then
     if not layout then
         layout = data.layouts.city
         layout = data.layouts.city
        log("Fallback to city layout")
    else
        log("Layout: " .. layoutName)
     end
     end


     local root = mw.html.create("table")
     local root = mw.html.create("table")
         :addClass("infobox")
         :addClass("infobox alborz-infobox")
        :addClass("alborz-infobox")


     --------------------------------------------------------------------------
     --------------------------------------------------------------------------
خط ۲۹: خط ۳۹:
     --------------------------------------------------------------------------
     --------------------------------------------------------------------------


     local title = args["نام"]
     local title = args["نام"] or mw.title.getCurrentTitle().text
 
    if not title or title == "" then
        title = mw.title.getCurrentTitle().text
    end


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


     --------------------------------------------------------------------------
     --------------------------------------------------------------------------
خط ۴۸: خط ۵۲:
     if args["تصویر"] and args["تصویر"] ~= "" then
     if args["تصویر"] and args["تصویر"] ~= "" then


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


         if args["توضیح تصویر"] and args["توضیح تصویر"] ~= "" then
         if args["توضیح تصویر"] and args["توضیح تصویر"] ~= "" then


             root
             root:tag("tr")
                :tag("tr")
                :tag("td")
                    :tag("td")
                    :attr("colspan","2")
                        :attr("colspan","2")
                    :wikitext(args["توضیح تصویر"])
                        :addClass("infobox-caption")
                        :wikitext(args["توضیح تصویر"])


         end
         end
     end
     end


     --------------------------------------------------------------------------
     --------------------------------------------------------------------------
     -- Rows
     -- Rows DEBUG MODE
     --------------------------------------------------------------------------
     --------------------------------------------------------------------------
        for i = 1, #layout do


        local field = data.fields[layout[i]]
    for i = 1, #layout do


         if field then
         local key = layout[i]
        local field = data.fields[key]


             local value
        if not field then
             log("Missing field: " .. tostring(key))
        else
            log("Checking field: " .. key)


             ------------------------------------------------------------------
             local value = nil
            -- Default value
            ------------------------------------------------------------------


            if field.default then
             if field.arg then
                value = field.default
            end
 
            ------------------------------------------------------------------
            -- Argument value
            ------------------------------------------------------------------
 
             if field.arg and args[field.arg] and args[field.arg] ~= "" then
                 value = args[field.arg]
                 value = args[field.arg]
             end
             end
            ------------------------------------------------------------------
            -- Render row
            ------------------------------------------------------------------


             if value and value ~= "" then
             if value and value ~= "" then


                 local row = root:tag("tr")
                 log("FOUND VALUE: " .. key .. " = " .. value)
 
                row
                    :tag("th")
                        :addClass("infobox-label")
                        :wikitext(field.label)
 
                if field.arg == "وبگاه" then


                    row
                local tr = root:tag("tr")
                        :tag("td")
                            :addClass("infobox-data")
                            :css("direction","ltr")
                            :css("text-align","left")
                            :wikitext(value)


                 else
                 tr:tag("th"):wikitext(field.label)


                    row
                tr:tag("td"):wikitext(value)
                        :tag("td")
                            :addClass("infobox-data")
                            :wikitext(value)
 
                end


            else
                log("EMPTY: " .. key .. " (arg=" .. tostring(field.arg) .. ")")
             end
             end
         end
         end
    end
    --------------------------------------------------------------------------
    -- Categories
    --------------------------------------------------------------------------
    if args["رده"] and args["رده"] ~= "" then
        root:wikitext(args["رده"])
     end
     end


خط ۱۵۴: خط ۱۱۵:
     local args = {}
     local args = {}


     local parent = frame:getParent()
     local parent = frame:getParent() or frame


     if parent then
     for k, v in pairs(parent.args or {}) do
        for k, v in pairs(parent.args) do
        if v and v ~= "" then
            if v and v ~= "" then
            args[k] = mw.text.trim(v)
                args[k] = mw.text.trim(v)
            end
         end
         end
     end
     end


     for k, v in pairs(frame.args) do
     for k, v in pairs(frame.args or {}) do
         if v and v ~= "" then
         if v and v ~= "" then
             args[k] = mw.text.trim(v)
             args[k] = mw.text.trim(v)

نسخهٔ ‏۳ ژوئیهٔ ۲۰۲۶، ساعت ۱۵:۵۲

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

local p = {}

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

--------------------------------------------------------------------------------
-- DEBUG TOGGLE
--------------------------------------------------------------------------------
local DEBUG = true

local function log(t)
    if DEBUG then
        mw.logObject(t)
    end
end

--------------------------------------------------------------------------------
-- Render
--------------------------------------------------------------------------------

local function render(args)

    log(args)

    local layoutName = args["نوع"] or "city"
    local layout = data.layouts[layoutName]

    if not layout then
        layout = data.layouts.city
        log("Fallback to city layout")
    else
        log("Layout: " .. layoutName)
    end

    local root = mw.html.create("table")
        :addClass("infobox alborz-infobox")

    --------------------------------------------------------------------------
    -- Title
    --------------------------------------------------------------------------

    local title = args["نام"] or mw.title.getCurrentTitle().text

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

    --------------------------------------------------------------------------
    -- Image
    --------------------------------------------------------------------------

    if args["تصویر"] and args["تصویر"] ~= "" then

        root:tag("tr")
            :tag("td")
                :attr("colspan","2")
                :wikitext("[[پرونده:" .. args["تصویر"] .. "|250px]]")

        if args["توضیح تصویر"] and args["توضیح تصویر"] ~= "" then

            root:tag("tr")
                :tag("td")
                    :attr("colspan","2")
                    :wikitext(args["توضیح تصویر"])

        end
    end

    --------------------------------------------------------------------------
    -- Rows DEBUG MODE
    --------------------------------------------------------------------------

    for i = 1, #layout do

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

        if not field then
            log("Missing field: " .. tostring(key))
        else
            log("Checking field: " .. key)

            local value = nil

            if field.arg then
                value = args[field.arg]
            end

            if value and value ~= "" then

                log("FOUND VALUE: " .. key .. " = " .. value)

                local tr = root:tag("tr")

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

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

            else
                log("EMPTY: " .. key .. " (arg=" .. tostring(field.arg) .. ")")
            end
        end
    end

    return tostring(root)

end

--------------------------------------------------------------------------------
-- Main
--------------------------------------------------------------------------------

function p.main(frame)

    local args = {}

    local parent = frame:getParent() or frame

    for k, v in pairs(parent.args or {}) do
        if v and v ~= "" then
            args[k] = mw.text.trim(v)
        end
    end

    for k, v in pairs(frame.args or {}) do
        if v and v ~= "" then
            args[k] = mw.text.trim(v)
        end
    end

    return render(args)

end

return p