پرش به محتوا

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

از ویکی البرز
جزبدون خلاصۀ ویرایش
جزبدون خلاصۀ ویرایش
خط ۲: خط ۲:
-- Module:AlborzSports
-- Module:AlborzSports
-- Wiki Alborz Sports Information System
-- Wiki Alborz Sports Information System
-- Version 3.0
-- Core Engine
-- Version 2..1
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------


خط ۱۲: خط ۱۳:


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


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


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


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


local DEFAULT_IMAGE_WIDTH =
local DEFAULT_IMAGE_WIDTH = data.meta.imageWidth or "250px"
    data.defaults.image_width
    or 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


    if type(value) == "string" then


    value =
        value = mw.text.trim(value)
        mw.text.trim(
            tostring(value)
        )


        if value == "" then
            return nil
        end


    if value == "" then
        return nil
     end
     end


     return value
     return value
خط ۵۷: خط ۵۳:


--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- ARGUMENT SOURCE
-- GET ARGUMENTS
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------


local function getArgsFrame(frame)
local function getArgs(frame)
 
    local args = {}
 
    for k,v in pairs(frame.args) do
 
        local key = mw.text.trim(k)


    local parent =
        local value = clean(v)
        frame:getParent()


        if value then


    if parent
            args[key] = value
    and next(parent.args) then


         return parent
         end


     end
     end


 
     return args
     return frame


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


--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- NORMALIZE ARGUMENTS
-- NORMALIZE INPUT
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------


local function normalizeArgs(frame)
local function normalize(args)


     frame =
     local result = {}
        getArgsFrame(frame)


    for key,value in pairs(args) do


    local args = {}
        local field = data.lookup[key] or key


        result[field] = value


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


    return result


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




        local cleanValue =
--------------------------------------------------------------------------------
            clean(value)
-- ENTITY DETECTION
--------------------------------------------------------------------------------


local function getEntity(args)


        if cleanValue then
    local entity = args.entity_type


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


            local field =
    if data.entities[entity] then
                data.lookup[cleanKey]
        return entity
                or cleanKey
    end


    return "player"


            args[field] =
end
                cleanValue




        end
--------------------------------------------------------------------------------
-- TITLE
--------------------------------------------------------------------------------
 
local function getTitle(entity,args)


    if args.name then
        return args.name
     end
     end


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


     return args
     return data.meta.title


end
end
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- ENTITY DETECTION
-- IMAGE HANDLING
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------


local function detectEntity(args)
local function buildImage(args)
 
 
    if args.entity_type
    and data.entities[args.entity_type] then
 
        return args.entity_type


    if not args.image then
        return nil
     end
     end


    local width = args.image_width or DEFAULT_IMAGE_WIDTH


     return
     local caption = args.caption or ""
        data.defaults.entity_type
        or "player"


end
    local image = {


        type = "image",


--------------------------------------------------------------------------------
        image = args.image,
-- GET ENTITY
--------------------------------------------------------------------------------


local function getEntity(entityType)
        size = width,


        caption = caption


     if data.entities[entityType] then
     }
 
        return data.entities[entityType]


    end
     return image
 
 
     return
        data.entities.player


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


--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- GET VALUE
-- FIELD BUILDER
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------


local function getValue(args, field)
local function buildFields(layouts,args)


     local value =
     local fields = {}
        args[field]


    for _,layout in ipairs(layouts) do


    if value then
        local label = layout[1]


         return value
         local key = layout[2]


    end
        local value = args[key]


        value = clean(value)


    return nil
        if value then


end
            table.insert(fields,{


                label = label,


--------------------------------------------------------------------------------
                value = value
-- LABEL
--------------------------------------------------------------------------------


local function getLabel(field)
            })


 
         end
    if data.fieldDefinitions
    and data.fieldDefinitions[field]
    and data.fieldDefinitions[field].label then
 
 
         return
            data.fieldDefinitions[field].label


     end
     end


 
     return fields
     return field


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


--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- TITLE
-- GROUP BUILDER
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------


local function renderTitle(box, entityType, args)
local function buildGroups(entity,args)


    local groups = {}


     local entity =
     local entityData = data.entities[entity]
         getEntity(entityType)
 
    if not entityData then
         return groups
    end




     local title =
     for _,layoutName in ipairs(entityData.layouts) do
        args.name
        or entity.title
        or data.meta.title




        local layout = data.layouts[layoutName]


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


        if layout then


end


            local fields = buildFields(layout,args)


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


local function renderImage(box,args)
            if #fields > 0 then




    if not args.image then
          table.insert(groups,{


        return
          name = data.layoutTitles[layoutName] or layoutName,


    end
          fields = fields


              })


    local width =
            end
        args.image_width
        or DEFAULT_IMAGE_WIDTH




        end


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


    end




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


end


    if args.caption then


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


        image
local function buildInfobox(entity,args)
            :tag("div")
            :addClass("infobox-caption")
            :wikitext(args.caption)




     end
     local box = {}




    box.title = getTitle(entity,args)


    box
        :tag("tr")
        :tag("td")
        :attr("colspan","2")
        :node(image)


    local image = buildImage(args)


end


    if image then


--------------------------------------------------------------------------------
        box.image = image
-- SECTION HEADER
--------------------------------------------------------------------------------


local function renderSectionHeader(box,layout)
    end




    local title =
        layout


    box.groups = buildGroups(entity,args)




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


    return box


end
end
خط ۳۲۶: خط ۲۹۲:


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


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




     local row =
     if type(value) == "table" then
        box
        :tag("tr")


        return table.concat(value,"، ")


 
     end
     row
        :tag("th")
        :wikitext(
            getLabel(field)
        )
 




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


end
end
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- SPECIAL FIELDS
-- RENDER INFOBOX
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------


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


    local result = {}


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




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


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


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


        table.insert(result,


        value =
            '<tr class="infobox-title">' ..
             string.format(
             '<th colspan="2">' ..
                "[%s اینستاگرام]",
            box.title ..
                value
             '</th></tr>'
             )


        )


     elseif field == "telegram" then
     end
 
 
        value =
            string.format(
                "[%s تلگرام]",
                value
            )




    end


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


    if box.image then


    renderField(
        box,
        field,
        value
    )


end
        local image = box.image
--------------------------------------------------------------------------------
-- LAYOUT PROCESSOR
--------------------------------------------------------------------------------


local function renderLayout(box,args,layout)


        local file = image.image


    local fields =
        data.layouts[layout]


        local size = image.size or DEFAULT_IMAGE_WIDTH


    if not fields then


         return
         local caption = image.caption or ""


    end


        table.insert(result,


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


    local rows = {}
            '[[File:' ..
            file ..
            '|' ..
            size ..
            ']]'




        )


    for _, item in ipairs(fields) do


        if caption ~= "" then


        local label =
            item[1]


            table.insert(result,


        local field =
                '<br /><small>' ..
            item[2]
                caption ..
                '</small>'


        local value =
            getValue(
                args,
                field
             )
             )




         if value then
         end




            table.insert(
        table.insert(result,
                rows,
                {
                    label = label,
                    field = field,
                    value = value
                }
            )


            '</td></tr>'


         end
         )




خط ۴۶۳: خط ۳۹۹:




     if #rows == 0 then
     ------------------------------------------------------------
    -- GROUPS
    ------------------------------------------------------------
 
    for _,group in ipairs(box.groups) do


        return


    end


        table.insert(result,




    renderSectionHeader(
            '<tr class="infobox-header">' ..
        box,
        layout
    )


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


            group.name ..


    for _, row in ipairs(rows) do
            '</th></tr>'




        renderSpecialField(
            box,
            row.field,
            row.value
         )
         )




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




end
            table.insert(result,




                '<tr>' ..


--------------------------------------------------------------------------------
                '<th>' ..
-- ENTITY RENDERER
                field.label ..
--------------------------------------------------------------------------------
                '</th>' ..


local function renderEntity(box,args,entityType)
                '<td>' ..
                renderValue(field.value) ..
                '</td>' ..


                '</tr>'


    local entity =
        getEntity(entityType)


            )




    if not entity then
        end


        return


     end
     end
خط ۵۱۵: خط ۴۵۲:




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


    table.insert(result,


         renderLayout(
         '</table>'
            box,
 
            args,
    )
            layout
        )




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




خط ۵۳۳: خط ۴۷۱:


--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- INFOBOX BUILDER
-- PUBLIC FUNCTION
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------


local function buildInfobox(args)
function p.main(frame)




     local entityType =
     local args = getArgs(frame)
        detectEntity(args)




    args = normalize(args)


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




    local entity = getEntity(args)


    box
        :addClass(
            INFOBOX_CLASS
        )




    local box = buildInfobox(entity,args)


    renderTitle(
        box,
        entityType,
        args
    )




    return renderInfobox(box)


    renderImage(
        box,
        args
    )


end




    renderEntity(
        box,
        args,
        entityType
    )


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


function p.infobox(frame)


     return
     return p.main(frame)
        tostring(box)
 


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


function p.test(frame)


    local args = getArgs(frame)


--------------------------------------------------------------------------------
    args = normalize(args)
-- MAIN
--------------------------------------------------------------------------------


function p.main(frame)


    local entity = getEntity(args)


    local args =
        normalizeArgs(frame)


    local entityData = data.entities[entity]




     return
     if not entityData then
        buildInfobox(args)


        return "Entity not found"


end
    end




    local result = {}


--------------------------------------------------------------------------------
-- INVOKE
--------------------------------------------------------------------------------


function p.invoke(frame)


    table.insert(result,


    return
         "Entity: " .. entity
         p.main(frame)


 
    )
end






--------------------------------------------------------------------------------
    table.insert(result,
-- RENDER
--------------------------------------------------------------------------------


function p.render(frame)
        "Title: " .. entityData.title


    )


    return
        p.main(frame)




end
    table.insert(result,


        "Layouts: " ..


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


--------------------------------------------------------------------------------
    )
-- TEST
--------------------------------------------------------------------------------


function p.test(frame)


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


    local args = {
end




        name =
            "علیرضا جهانبخش",


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


        entity_type =
function p.entities()
            "player",


    local result = {}


        nationality =
            "ایرانی",


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


        country =
            "ایران",


        table.insert(result,


        sport =
             key .. " : " .. value.title
             "فوتبال",


        )


        discipline =
            "فوتبال",


    end


        position =
            "هافبک",


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


        current_club =
end
            "هیرنفین",




        birth_date =
            "۱۱ مرداد ۱۳۷۲",


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


        birth_place =
function p.version()
            "جیرنده"


    return


    }
        data.version.name ..


        " v" ..


        data.version.major ..


    return
         "." ..
         buildInfobox(args)


        data.version.minor


end
end

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

توضیحات این پودمان می‌تواند در پودمان: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 = data.layoutTitles[layoutName] or 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