پودمان:AlborzInfoBox: تفاوت میان نسخهها
ظاهر
جزبدون خلاصۀ ویرایش |
جزبدون خلاصۀ ویرایش برچسب: برگرداندهشده |
||
| خط ۱: | خط ۱: | ||
local p = {} | local p = {} | ||
local data = mw.loadData('Module:AlborzInfoBox/Data/Geography') | local data = mw.loadData('Module:AlborzInfoBox/Data/Geography') | ||
| خط ۱۴: | خط ۱۳: | ||
s = mw.text.trim(s) | s = mw.text.trim(s) | ||
s = mw.ustring.gsub(s, "[\u200C\u200D]", "") | s = mw.ustring.gsub(s, "[\u200C\u200D]", "") | ||
return s | return s | ||
| خط ۲۰: | خط ۱۸: | ||
------------------------------------------------------- | ------------------------------------------------------- | ||
-- ARG | -- 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 function getArgs(frame) | ||
local args = {} | local args = {} | ||
local function add(tbl) | local function add(tbl) | ||
if not tbl then return end | |||
if not tbl then | |||
return | |||
end | |||
for k, v in pairs(tbl) do | for k, v in pairs(tbl) do | ||
if v and v ~= "" then | if v and v ~= "" then | ||
args[norm(k)] = mw.text.trim(v) | |||
end | end | ||
end | end | ||
end | end | ||
| خط ۴۱: | خط ۸۴: | ||
local parent = frame:getParent() | local parent = frame:getParent() | ||
if parent then | if parent then | ||
add(parent.args) | add(parent.args) | ||
| خط ۴۶: | خط ۹۰: | ||
return args | return args | ||
end | end | ||
------------------------------------------------------- | ------------------------------------------------------- | ||
-- | -- ADD ROW | ||
------------------------------------------------------- | ------------------------------------------------------- | ||
local function | 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 | end | ||
------------------------------------------------------- | ------------------------------------------------------- | ||
-- BADGE | -- BADGE | ||
------------------------------------------------------- | ------------------------------------------------------- | ||
local badgeMap = { | local badgeMap = { | ||
city = "شهر", | city = "شهر", | ||
village = "روستا", | village = "روستا", | ||
| خط ۱۰۳: | خط ۱۲۵: | ||
mountain = "کوه", | mountain = "کوه", | ||
cave = "غار", | |||
river = "رودخانه", | river = "رودخانه", | ||
waterfall = "آبشار", | waterfall = "آبشار", | ||
park = "پارک", | park = "پارک", | ||
historic = "بنای تاریخی" | historic = "بنای تاریخی" | ||
} | } | ||
local function addBadge(root, rawType) | local function addBadge(root, rawType) | ||
if not rawType or rawType == "" then | if not rawType or rawType == "" then | ||
return | return | ||
end | end | ||
local label = badgeMap[rawType] or rawType | local label = badgeMap[rawType] or rawType | ||
root:tag("tr") | root:tag("tr") | ||
:tag("td") | :tag("td") | ||
:attr("colspan", "2") | :attr("colspan","2") | ||
: | :addClass("infobox-badge") | ||
:tag("span") | :tag("span") | ||
: | :addClass("infobox-badge-label") | ||
:wikitext(label) | :wikitext(label) | ||
end | end | ||
| خط ۱۴۰: | خط ۱۵۶: | ||
------------------------------------------------------- | ------------------------------------------------------- | ||
local function addImage(root, args) | local function addImage(root,args) | ||
local image = | |||
local image = | |||
args[norm("تصویر")] | |||
or args[norm("پرونده")] | |||
or args.image | |||
if not image then | if not image then | ||
return | return | ||
end | end | ||
root:tag("tr") | root:tag("tr") | ||
:tag("td") | :tag("td") | ||
:attr("colspan", "2") | :attr("colspan","2") | ||
: | :addClass("infobox-image") | ||
:wikitext("[[پرونده:" .. image .. "|250px]]") | :wikitext("[[پرونده:" .. image .. "|250px]]") | ||
end | end | ||
| خط ۱۶۰: | خط ۱۷۹: | ||
------------------------------------------------------- | ------------------------------------------------------- | ||
local function addCaption(root, args) | local function addCaption(root,args) | ||
local caption = | local caption = | ||
args[norm("توضیح تصویر")] | |||
or args[norm("عنوان تصویر")] | |||
or args[norm("زیرنویس")] | |||
if not caption then | if not caption then | ||
| خط ۱۷۳: | خط ۱۹۲: | ||
root:tag("tr") | root:tag("tr") | ||
:tag("td") | :tag("td") | ||
:attr("colspan", "2") | :attr("colspan","2") | ||
: | :addClass("infobox-caption") | ||
:wikitext(caption) | |||
:wikitext | |||
end | end | ||
------------------------------------------------------- | ------------------------------------------------------- | ||
-- | -- TABLE | ||
------------------------------------------------------- | ------------------------------------------------------- | ||
local function | 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) | |||
tr:tag("th") | 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 | end | ||
------------------------------------------------------- | ------------------------------------------------------- | ||
| خط ۲۰۲: | خط ۲۳۵: | ||
local function addRows(root, args, layout) | local function addRows(root, args, layout) | ||
local field = data.fields[ | for i = 1, #layout do | ||
local field = data.fields[layout[i]] | |||
if field then | if field then | ||
local value = | local value = getArg(args, field) | ||
if (not value or value == "") and field.default then | if (not value or value == "") and field.default then | ||
| خط ۲۲۰: | خط ۲۵۳: | ||
end | end | ||
end | end | ||
end | end | ||
| خط ۲۲۹: | خط ۲۶۴: | ||
local function render(args) | local function render(args) | ||
local rawType = | local rawType = args[norm("نوع")] or "city" | ||
local layout = data.layouts[rawType] or data.layouts.city | |||
local layout = | |||
data.layouts[rawType] | |||
or data.layouts.city | |||
local root = newTable(rawType) | local root = newTable(rawType) | ||
addTitle(root, args) | addTitle(root, args) | ||
addBadge(root, rawType) | addBadge(root, rawType) | ||
addImage(root, args) | addImage(root, args) | ||
addCaption(root, args) | addCaption(root, args) | ||
addRows(root, args, layout) | addRows(root, args, layout) | ||
return tostring(root) | return tostring(root) | ||
end | end | ||
| خط ۲۴۸: | خط ۲۹۱: | ||
function p.main(frame) | function p.main(frame) | ||
local args = getArgs(frame) | |||
return render(args) | |||
end | end | ||
return p | return p | ||
نسخهٔ ۴ ژوئیهٔ ۲۰۲۶، ساعت ۰۷:۲۹
توضیحات این پودمان میتواند در پودمان: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