پرش به محتوا

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

از ویکی البرز
صفحه‌ای تازه حاوی «local p = {} --================================================== -- Module:InfoboxPerson -- Part 1 -- Core utilities --================================================== local html = mw.html ---------------------------------------------------- -- NORMALIZE ---------------------------------------------------- local function normalize(value) if value == nil then return nil end value = tostring(value) value = mw.text.trim(v...» ایجاد کرد
 
جز جایگزینی صفحه با 'local core = require("Module:InfoboxPerson/Core") local p = {} function p.main(frame) return core.main(frame) end return p'
برچسب: جایگزین شد
 
(۲ نسخهٔ میانیِ ایجادشده توسط همین کاربر نشان داده نشد)
خط ۱: خط ۱:
local core = require("Module:InfoboxPerson/Core")
local p = {}
local p = {}
--==================================================
-- Module:InfoboxPerson
-- Part 1
-- Core utilities
--==================================================
local html = mw.html
----------------------------------------------------
-- NORMALIZE
----------------------------------------------------
local function normalize(value)
if value == nil then
return nil
end
value = tostring(value)
value = mw.text.trim(value)
if value == "" then
return nil
end
-- حذف نیم‌فاصله و کاراکترهای نامرئی
value = mw.ustring.gsub(
value,
"[\u200C\u200D\uFEFF]",
""
)
return value
end
----------------------------------------------------
-- ARGUMENT COLLECTION
----------------------------------------------------
local function collectArgs(frame)
local args = {}
local function read(tbl)
if not tbl then
return
end
for key, value in pairs(tbl) do
local k = normalize(key)
local v = normalize(value)
if k and v then
args[k] = v
end
end
end
local parent = frame:getParent()
if parent then
read(parent.args)
end
read(frame.args)
return args
end
----------------------------------------------------
-- ARG ALIASES
----------------------------------------------------
local aliases = {
name = {
"نام",
"نام بازیکن",
"name",
"playername"
},
image = {
"تصویر",
"پرونده",
"image"
},
caption = {
"توضیح تصویر",
"زیرنویس",
"caption"
},
fullname = {
"نام کامل",
"نام اصلی",
"full_name",
"fullname"
},
birth_date = {
"زادروز",
"تاریخ تولد",
"birth_date"
},
birth_place = {
"زادگاه",
"محل تولد",
"birth_place"
},
death_date = {
"درگذشته",
"تاریخ درگذشت",
"death_date"
},
nationality = {
"ملیت",
"nationality"
},
height = {
"قد",
"height"
},
weight = {
"وزن",
"weight"
},
sport = {
"ورزش",
"sport"
},
club = {
"باشگاه",
"club"
},
team = {
"تیم",
"تیم ملی",
"team"
},
coach = {
"مربی",
"سرمربی",
"coach"
}
}
--==================================================
-- RESOLVE ALIASES
--==================================================
local function resolveArgs(args)
local result = {}
for key, list in pairs(aliases) do
for i = 1, #list do
local value = args[list[i]]
if value then
result[key] = value
break
end
end
end
return result
end
----------------------------------------------------
-- VALUE CHECK
----------------------------------------------------
local function hasValue(value)
return normalize(value) ~= nil
end
----------------------------------------------------
-- CREATE INFOBOX
----------------------------------------------------
local function createBox()
local box = html.create("table")
box
:addClass("infobox")
:addClass("person-infobox")
return box
end
----------------------------------------------------
-- ADD TITLE
----------------------------------------------------
local function addTitle(box, args)
local title = args.name
if not title then
title = mw.title.getCurrentTitle().text
end
local row = box:tag("tr")
row
:tag("th")
:attr("colspan", "2")
:css({
["background-color"] = "#2C5F9E",
color = "#FFFFFF",
["text-align"] = "center",
["font-size"] = "120%",
padding = "8px"
})
:wikitext(title)
end
----------------------------------------------------
-- ADD IMAGE
----------------------------------------------------
local function addImage(box, args)
if not hasValue(args.image) then
return
end
local row = box:tag("tr")
row
:tag("td")
:attr("colspan", "2")
:css({
["text-align"] = "center",
padding = "5px"
})
:wikitext(
"[[File:"
.. args.image
.. "|250px]]"
)
if hasValue(args.caption) then
local caption = box:tag("tr")
caption
:tag("td")
:attr("colspan", "2")
:css({
["text-align"] = "center",
["font-size"] = "90%"
})
:wikitext(args.caption)
end
end
----------------------------------------------------
-- ADD HEADER
----------------------------------------------------
local function addHeader(box, text)
local row = box:tag("tr")
row
:tag("th")
:attr("colspan", "2")
:css({
["background-color"] = "#2C5F9E",
color = "#FFFFFF",
["text-align"] = "center"
})
:wikitext(text)
end
----------------------------------------------------
-- ADD ROW
----------------------------------------------------
local function addRow(box, label, value)
if not hasValue(value) then
return false
end
local row = box:tag("tr")
row
:tag("th")
:wikitext(label)
row
:tag("td")
:wikitext(value)
return true
end
--==================================================
-- PERSONAL SECTION
--==================================================
local function addPersonal(box, args)
local hasData = false
if hasValue(args.fullname)
or hasValue(args.birth_date)
or hasValue(args.birth_place)
or hasValue(args.death_date)
or hasValue(args.nationality)
or hasValue(args.height)
or hasValue(args.weight) then
hasData = true
end
if not hasData then
return
end
addHeader(
box,
"اطلاعات شخصی"
)
addRow(
box,
"نام کامل",
args.fullname
)
addRow(
box,
"زاده",
args.birth_date
)
addRow(
box,
"زادگاه",
args.birth_place
)
addRow(
box,
"درگذشته",
args.death_date
)
addRow(
box,
"ملیت",
args.nationality
)
addRow(
box,
"قد",
args.height
)
addRow(
box,
"وزن",
args.weight
)
end
--==================================================
-- SPORT SECTION
--==================================================
local function addSport(box, args)
local hasData = false
if hasValue(args.sport)
or hasValue(args.club)
or hasValue(args.team)
or hasValue(args.coach) then
hasData = true
end
if not hasData then
return
end
addHeader(
box,
"اطلاعات ورزشی"
)
addRow(
box,
"ورزش",
args.sport
)
addRow(
box,
"باشگاه",
args.club
)
addRow(
box,
"تیم",
args.team
)
addRow(
box,
"مربی",
args.coach
)
end
--==================================================
-- RENDER
--==================================================
local function render(args)
local box = createBox()
addTitle(
box,
args
)
addImage(
box,
args
)
addPersonal(
box,
args
)
addSport(
box,
args
)
return tostring(box)
end
--==================================================
-- ENTRY POINT
--==================================================


function p.main(frame)
function p.main(frame)
 
return core.main(frame)
 
local rawArgs = collectArgs(frame)
 
 
 
local args = resolveArgs(rawArgs)
 
 
 
return render(args)
 
 
end
end


return p
return p

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

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

local core = require("Module:InfoboxPerson/Core")

local p = {}

function p.main(frame)
	return core.main(frame)
end

return p