پرش به محتوا

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

از ویکی البرز
جزبدون خلاصۀ ویرایش
برچسب: برگردانده‌شده
جزبدون خلاصۀ ویرایش
برچسب‌ها: واگردانی دستی برگردانده‌شده
خط ۲: خط ۲:
-- Module:AlborzSports
-- Module:AlborzSports
-- Wiki Alborz Sports Information System
-- Wiki Alborz Sports Information System
-- Version 3..0
-- Core Engine
-- Version 2..1
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------


خط ۱۴: خط ۱۵:


--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- CONFIGURATION
-- LOAD DEPENDENCIES
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------


local INFOBOX_CLASS = data.meta.class or "infobox sport-infobox"
local infobox = require("Module:Infobox")


local DEFAULT_IMAGE_WIDTH =
--------------------------------------------------------------------------------
    data.defaults.image_width or
-- CONFIG
    data.meta.imageWidth or
--------------------------------------------------------------------------------
    "250px"
 
local DEFAULT_IMAGE_WIDTH = data.meta.imageWidth or "250px"




--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- HELPERS
-- UTILITY FUNCTIONS
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------


local function clean(value)
local function clean(value)


     if not value then
     if value == nil then
         return nil
         return nil
     end
     end


     value = mw.text.trim(value)
     if type(value) == "string" then
 
        value = mw.text.trim(value)
 
        if value == "" then
            return nil
        end


    if value == "" then
        return nil
     end
     end


خط ۴۷: خط ۵۳:


--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- ARGUMENT NORMALIZATION
-- GET ARGUMENTS
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------


local function normalizeArgs(frame)
local function getArgs(frame)


     local args = {}
     local args = {}


     for key, value in pairs(frame.args) do
     for k,v in pairs(frame.args) do


         local cleanKey = mw.text.trim(tostring(key))
         local key = mw.text.trim(k)


         local cleanValue = clean(value)
         local value = clean(v)


         if cleanValue then
         if value then


            local field =
             args[key] = value
                data.lookup[cleanKey] or
                cleanKey
 
             args[field] = cleanValue


         end
         end
خط ۷۸: خط ۸۰:


--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- ENTITY DETECTION
-- NORMALIZE INPUT
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------


local function detectEntity(args)
local function normalize(args)


     local entity = args.entity_type
     local result = {}


    for key,value in pairs(args) do


    if entity then
        local field = data.lookup[key] or key


         if data.entities[entity] then
         result[field] = value
            return entity
        end


     end
     end


    return result


    local typeValue = args.type
end




    if typeValue then
--------------------------------------------------------------------------------
-- ENTITY DETECTION
--------------------------------------------------------------------------------


        for key, value in pairs(data.lookup) do
local function getEntity(args)


            if key == typeValue then
    local entity = args.entity_type


                if data.entities[value] then
    if not entity then
                    return value
        entity = data.defaults.entity_type
                end
    end
 
            end
 
        end


    if data.entities[entity] then
        return entity
     end
     end


 
     return "player"
     return data.defaults.entity_type or "player"


end
end
خط ۱۲۱: خط ۱۲۲:


--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- GET ENTITY DATA
-- TITLE
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------


local function getEntity(entityType)
local function getTitle(entity,args)


     if data.entities[entityType] then
     if args.name then
 
         return args.name
         return data.entities[entityType]
    end


    if data.entities[entity] then
        return data.entities[entity].title
     end
     end


    return data.meta.title


    return data.entities.player
end
--------------------------------------------------------------------------------
-- IMAGE HANDLING
--------------------------------------------------------------------------------


end
local function buildImage(args)


    if not args.image then
        return nil
    end


--------------------------------------------------------------------------------
    local width = args.image_width or DEFAULT_IMAGE_WIDTH
-- FIELD VALUE
--------------------------------------------------------------------------------


local function getValue(args, field)
    local caption = args.caption or ""


     local value = args[field]
     local image = {


        type = "image",


    if value then
        image = args.image,


         return value
         size = width,


    end
        caption = caption


    }


     return nil
     return image


end
end
خط ۱۶۰: خط ۱۷۰:


--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- FIELD LABEL
-- FIELD BUILDER
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------


local function getLabel(field)
local function buildFields(layouts,args)
 
    local fields = {}


     if data.fieldDefinitions[field] then
     for _,layout in ipairs(layouts) do


         return data.fieldDefinitions[field].label
         local label = layout[1]


    end
        local key = layout[2]
 
        local value = args[key]
 
        value = clean(value)
 
        if value then


            table.insert(fields,{


    return field
                label = label,


end
                value = value
--------------------------------------------------------------------------------
-- TITLE RENDERER
--------------------------------------------------------------------------------


local function renderTitle(box, entityType, args)
            })


    local title =
         end
         args.name or
        data.entities[entityType].title or
        data.meta.title


    end


     box
     return fields
        :tag("th")
        :attr("colspan", "2")
        :addClass("infobox-title")
        :wikitext(title)


end
end
خط ۱۹۷: خط ۲۰۷:


--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- IMAGE RENDERER
-- GROUP BUILDER
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------


local function renderImage(box, args)
local function buildGroups(entity,args)


     local image = args.image
     local groups = {}


    local entityData = data.entities[entity]


     if not image then
     if not entityData then
         return
         return groups
     end
     end




     local width =
     for _,layoutName in ipairs(entityData.layouts) do
        args.image_width or
 
        DEFAULT_IMAGE_WIDTH


        local layout = data.layouts[layoutName]


    local imageHtml =


         mw.getCurrentFrame():extensionTag(
         if layout then
             "imagemap",
 
            ""
 
        )
            local fields = buildFields(layout,args)
 
 
             if #fields > 0 then
 
 
                table.insert(groups,{


                    name = layoutName,


    local file =
                    fields = fields


        mw.html.create("div")
                })
        :addClass("infobox-image")




    file
             end
        :wikitext(
             string.format(
                "[[پرونده:%s|%s]]",
                image,
                width
            )
        )




    if args.caption then
        end


        file
            :tag("div")
            :addClass("infobox-caption")
            :wikitext(args.caption)


     end
     end




     box
     return groups
        :tag("tr")
        :tag("td")
        :attr("colspan", "2")
        :node(file)


end
end
خط ۲۵۹: خط ۲۶۰:


--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- SECTION HEADER RENDERER
-- INFOBOX BUILDER
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------


local function renderSectionHeader(box, layout)
local function buildInfobox(entity,args)


    local title =
        data.layoutTitles[layout]


    local box = {}


    if not title then
        return
    end


    box.title = getTitle(entity,args)


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


end
    local image = buildImage(args)




--------------------------------------------------------------------------------
    if image then
-- FIELD RENDERER
--------------------------------------------------------------------------------


local function renderField(box, field, value)
        box.image = image


    if not value then
        return
     end
     end




    local label =
        getLabel(field)
    local row =
        box
            :tag("tr")


    box.groups = buildGroups(entity,args)


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




     row
     return box
        :tag("td")
        :wikitext(value)


end
end
خط ۳۱۷: خط ۲۹۳:


--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- SPECIAL FIELD RENDERER
-- RENDER TEXT
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------


local function renderSpecialField(box, field, value)
local function renderValue(value)




     if field == "website" then
     if type(value) == "table" then


        return table.concat(value,"، ")


        value =
    end
            string.format(
                "[%s %s]",
                value,
                "وبگاه"
            )




     elseif field == "instagram" then
     return tostring(value)


end
--------------------------------------------------------------------------------
-- RENDER INFOBOX
--------------------------------------------------------------------------------


        value =
local function renderInfobox(box)
            string.format(
                "[%s اینستاگرام]",
                value
            )


    local result = {}


     elseif field == "telegram" then
     table.insert(result, '<table class="infobox sport-infobox">')




        value =
            string.format(
                "[%s تلگرام]",
                value
            )


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


     elseif field == "coordinates" then
     if box.title then


        table.insert(result,


        value =
            '<tr class="infobox-title">' ..
             string.format(
             '<th colspan="2">' ..
                "{{مختصات|%s}}",
            box.title ..
                value
             '</th></tr>'
             )


        )


     end
     end




    renderField(
        box,
        field,
        value
    )


end
    ------------------------------------------------------------
--------------------------------------------------------------------------------
    -- IMAGE
-- LAYOUT PROCESSOR
    ------------------------------------------------------------
--------------------------------------------------------------------------------
 
    if box.image then
 
 
        local image = box.image
 
 
        local file = image.image
 


local function renderLayout(box, args, layout)
        local size = image.size or DEFAULT_IMAGE_WIDTH




    local fields =
        local caption = image.caption or ""
        data.layouts[layout]




    if not fields then
         table.insert(result,
         return
    end


            '<tr>' ..
            '<td colspan="2" class="infobox-image">' ..


    local hasValue = false
            '[[File:' ..
            file ..
            '|' ..
            size ..
            ']]'




    for _, field in ipairs(fields) do
        )




         local value =
         if caption ~= "" then
            getValue(
 
                args,
                field
            )


            table.insert(result,


        if value then
                '<br /><small>' ..
                caption ..
                '</small>'


             hasValue = true
             )


            break


         end
         end


    end


        table.insert(result,


    if not hasValue then
            '</td></tr>'
 
        )


        return


     end
     end




    renderSectionHeader(
        box,
        layout
    )


    ------------------------------------------------------------
    -- GROUPS
    ------------------------------------------------------------


     for _, field in ipairs(fields) do
     for _,group in ipairs(box.groups) do




        local value =
            getValue(
                args,
                field
            )


        table.insert(result,


        if value then


            '<tr class="infobox-header">' ..


             renderSpecialField(
             '<th colspan="2">' ..
                box,
                field,
                value
            )


            group.name ..


        end
            '</th></tr>'


    end


        )


end




--------------------------------------------------------------------------------
        for _,field in ipairs(group.fields) do
-- ENTITY RENDERER
--------------------------------------------------------------------------------


local function renderEntity(box, args, entityType)


            table.insert(result,


    local entity =
        getEntity(entityType)


                '<tr>' ..


    if not entity then
                '<th>' ..
                field.label ..
                '</th>' ..


        return
                '<td>' ..
                renderValue(field.value) ..
                '</td>' ..


    end
                '</tr>'




    for _, layout in ipairs(entity.layouts) do
            )




         renderLayout(
         end
            box,
            args,
            layout
        )




خط ۴۸۶: خط ۴۵۲:




end


    ------------------------------------------------------------
    -- CLOSE
    ------------------------------------------------------------


--------------------------------------------------------------------------------
    table.insert(result,
-- INFOBOX BUILDER
--------------------------------------------------------------------------------


local function buildInfobox(args)
        '</table>'


    )


    local entityType =
        detectEntity(args)


    return table.concat(result,"\n")


    local box =
        mw.html.create("table")


end


    box
        :addClass(
            INFOBOX_CLASS
        )




    renderTitle(
--------------------------------------------------------------------------------
        box,
-- PUBLIC FUNCTION
        entityType,
--------------------------------------------------------------------------------
        args
 
    )
function p.main(frame)




     renderImage(
     local args = getArgs(frame)
        box,
        args
    )




     renderEntity(
     args = normalize(args)
        box,
        args,
        entityType
    )




    return tostring(box)


end
    local entity = getEntity(args)




--------------------------------------------------------------------------------
-- MAIN FUNCTION
--------------------------------------------------------------------------------


function p.main(frame)
    local box = buildInfobox(entity,args)




    local args =
        normalizeArgs(
            frame:getParent()
        )


    return renderInfobox(box)


    return buildInfobox(
        args
    )


end
end




--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- INVOKE SUPPORT
-- TEMPLATE ENTRY
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------


خط ۵۶۵: خط ۵۱۰:
end
end
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- TEMPLESTYLE SUPPORT
-- DEBUG FUNCTION
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------


local function addStyles()
function p.test(frame)
 
    local args = getArgs(frame)
 
    args = normalize(args)
 
 
    local entity = getEntity(args)
 
 
    local entityData = data.entities[entity]
 
 
    if not entityData then
 
        return "Entity not found"
 
    end


    local frame =
        mw.getCurrentFrame()


    local result = {}


    return frame:extensionTag(
        "templatestyles",
        "",
        {
            src = "Module:AlborzSports/styles.css"
        }
    )


end


    table.insert(result,


--------------------------------------------------------------------------------
        "Entity: " .. entity
-- FINAL WRAPPER
--------------------------------------------------------------------------------


local function finalize(html)
    )


    return


        addStyles()


        .. html
    table.insert(result,


end
        "Title: " .. entityData.title


    )


--------------------------------------------------------------------------------
-- PUBLIC RENDER FUNCTION
--------------------------------------------------------------------------------


function p.render(frame)


    table.insert(result,


    local args =
         "Layouts: " ..
         normalizeArgs(
            frame:getParent()
        )


        table.concat(entityData.layouts,", ")


     local output =
     )
        buildInfobox(
            args
        )




     return finalize(output)
     return table.concat(result,"\n")


end
end




--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- TEMPLATE ENTRY
-- GET ENTITY LIST
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------


function p.invoke(frame)
function p.entities()


     return p.render(frame)
     local result = {}


end


    for key,value in pairs(data.entities) do
        table.insert(result,
            key .. " : " .. value.title
        )


--------------------------------------------------------------------------------
-- TEST SUPPORT
--------------------------------------------------------------------------------


function p.test(frame)
    end


    local args = {


        name = "نمونه ورزشکار",
    return table.concat(result,"\n")


        entity_type = "player",
end


        nationality = "ایرانی",


        sport = "فوتبال",


        discipline = "فوتبال",
--------------------------------------------------------------------------------
-- GET VERSION
--------------------------------------------------------------------------------


        position = "مهاجم",
function p.version()


        current_club = "باشگاه نمونه",
    return


         birth_date = "۱۳۷۰",
         data.version.name ..


         residence = "کرج"
         " v" ..


    }
        data.version.major ..


        "." ..


    return buildInfobox(args)
        data.version.minor


end
end




--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- RETURN MODULE
-- EXPORT
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------


return p
return p

نسخهٔ ‏۴ اوت ۲۰۲۶، ساعت ۱۲:۰۵

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

--------------------------------------------------------------------------------
-- Module:AlborzSports
-- Wiki Alborz Sports Information System
-- Core Engine
-- Version 2..1
--------------------------------------------------------------------------------

local p = {}

--------------------------------------------------------------------------------
-- LOAD DATA
--------------------------------------------------------------------------------

local data = mw.loadData("Module:AlborzSports/Data")

--------------------------------------------------------------------------------
-- LOAD DEPENDENCIES
--------------------------------------------------------------------------------

local infobox = require("Module:Infobox")

--------------------------------------------------------------------------------
-- CONFIG
--------------------------------------------------------------------------------

local DEFAULT_IMAGE_WIDTH = data.meta.imageWidth or "250px"


--------------------------------------------------------------------------------
-- UTILITY FUNCTIONS
--------------------------------------------------------------------------------

local function clean(value)

    if value == nil then
        return nil
    end

    if type(value) == "string" then

        value = mw.text.trim(value)

        if value == "" then
            return nil
        end

    end

    return value

end


--------------------------------------------------------------------------------
-- GET ARGUMENTS
--------------------------------------------------------------------------------

local function getArgs(frame)

    local args = {}

    for k,v in pairs(frame.args) do

        local key = mw.text.trim(k)

        local value = clean(v)

        if value then

            args[key] = value

        end

    end

    return args

end


--------------------------------------------------------------------------------
-- NORMALIZE INPUT
--------------------------------------------------------------------------------

local function normalize(args)

    local result = {}

    for key,value in pairs(args) do

        local field = data.lookup[key] or key

        result[field] = value

    end

    return result

end


--------------------------------------------------------------------------------
-- ENTITY DETECTION
--------------------------------------------------------------------------------

local function getEntity(args)

    local entity = args.entity_type

    if not entity then
        entity = data.defaults.entity_type
    end

    if data.entities[entity] then
        return entity
    end

    return "player"

end


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

local function getTitle(entity,args)

    if args.name then
        return args.name
    end

    if data.entities[entity] then
        return data.entities[entity].title
    end

    return data.meta.title

end
--------------------------------------------------------------------------------
-- IMAGE HANDLING
--------------------------------------------------------------------------------

local function buildImage(args)

    if not args.image then
        return nil
    end

    local width = args.image_width or DEFAULT_IMAGE_WIDTH

    local caption = args.caption or ""

    local image = {

        type = "image",

        image = args.image,

        size = width,

        caption = caption

    }

    return image

end


--------------------------------------------------------------------------------
-- FIELD BUILDER
--------------------------------------------------------------------------------

local function buildFields(layouts,args)

    local fields = {}

    for _,layout in ipairs(layouts) do

        local label = layout[1]

        local key = layout[2]

        local value = args[key]

        value = clean(value)

        if value then

            table.insert(fields,{

                label = label,

                value = value

            })

        end

    end

    return fields

end


--------------------------------------------------------------------------------
-- GROUP BUILDER
--------------------------------------------------------------------------------

local function buildGroups(entity,args)

    local groups = {}

    local entityData = data.entities[entity]

    if not entityData then
        return groups
    end


    for _,layoutName in ipairs(entityData.layouts) do


        local layout = data.layouts[layoutName]


        if layout then


            local fields = buildFields(layout,args)


            if #fields > 0 then


                table.insert(groups,{

                    name = layoutName,

                    fields = fields

                })


            end


        end


    end


    return groups

end


--------------------------------------------------------------------------------
-- INFOBOX BUILDER
--------------------------------------------------------------------------------

local function buildInfobox(entity,args)


    local box = {}


    box.title = getTitle(entity,args)


    local image = buildImage(args)


    if image then

        box.image = image

    end



    box.groups = buildGroups(entity,args)



    return box

end


--------------------------------------------------------------------------------
-- RENDER TEXT
--------------------------------------------------------------------------------

local function renderValue(value)


    if type(value) == "table" then

        return table.concat(value,"، ")

    end


    return tostring(value)

end
--------------------------------------------------------------------------------
-- RENDER INFOBOX
--------------------------------------------------------------------------------

local function renderInfobox(box)

    local result = {}

    table.insert(result, '<table class="infobox sport-infobox">')



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

    if box.title then

        table.insert(result,

            '<tr class="infobox-title">' ..
            '<th colspan="2">' ..
            box.title ..
            '</th></tr>'

        )

    end



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

    if box.image then


        local image = box.image


        local file = image.image


        local size = image.size or DEFAULT_IMAGE_WIDTH


        local caption = image.caption or ""


        table.insert(result,

            '<tr>' ..
            '<td colspan="2" class="infobox-image">' ..

            '[[File:' ..
            file ..
            '|' ..
            size ..
            ']]'


        )


        if caption ~= "" then


            table.insert(result,

                '<br /><small>' ..
                caption ..
                '</small>'

            )


        end


        table.insert(result,

            '</td></tr>'

        )


    end



    ------------------------------------------------------------
    -- GROUPS
    ------------------------------------------------------------

    for _,group in ipairs(box.groups) do



        table.insert(result,


            '<tr class="infobox-header">' ..

            '<th colspan="2">' ..

            group.name ..

            '</th></tr>'


        )



        for _,field in ipairs(group.fields) do


            table.insert(result,


                '<tr>' ..

                '<th>' ..
                field.label ..
                '</th>' ..

                '<td>' ..
                renderValue(field.value) ..
                '</td>' ..

                '</tr>'


            )


        end


    end



    ------------------------------------------------------------
    -- CLOSE
    ------------------------------------------------------------

    table.insert(result,

        '</table>'

    )


    return table.concat(result,"\n")


end



--------------------------------------------------------------------------------
-- PUBLIC FUNCTION
--------------------------------------------------------------------------------

function p.main(frame)


    local args = getArgs(frame)


    args = normalize(args)



    local entity = getEntity(args)



    local box = buildInfobox(entity,args)



    return renderInfobox(box)


end



--------------------------------------------------------------------------------
-- TEMPLATE ENTRY
--------------------------------------------------------------------------------

function p.infobox(frame)

    return p.main(frame)

end
--------------------------------------------------------------------------------
-- DEBUG FUNCTION
--------------------------------------------------------------------------------

function p.test(frame)

    local args = getArgs(frame)

    args = normalize(args)


    local entity = getEntity(args)


    local entityData = data.entities[entity]


    if not entityData then

        return "Entity not found"

    end


    local result = {}



    table.insert(result,

        "Entity: " .. entity

    )



    table.insert(result,

        "Title: " .. entityData.title

    )



    table.insert(result,

        "Layouts: " ..

        table.concat(entityData.layouts,", ")

    )


    return table.concat(result,"\n")

end



--------------------------------------------------------------------------------
-- GET ENTITY LIST
--------------------------------------------------------------------------------

function p.entities()

    local result = {}


    for key,value in pairs(data.entities) do


        table.insert(result,

            key .. " : " .. value.title

        )


    end


    return table.concat(result,"\n")

end



--------------------------------------------------------------------------------
-- GET VERSION
--------------------------------------------------------------------------------

function p.version()

    return

        data.version.name ..

        " v" ..

        data.version.major ..

        "." ..

        data.version.minor

end



--------------------------------------------------------------------------------
-- EXPORT
--------------------------------------------------------------------------------

return p