پودمان:AlborzHealthcare: تفاوت میان نسخهها
ظاهر
جزبدون خلاصۀ ویرایش |
جزبدون خلاصۀ ویرایش |
||
| خط ۴۸: | خط ۴۸: | ||
local args = {} | local args = {} | ||
local source = | -- پارامترها مستقیم از الگو دریافت میشوند | ||
local source = frame | |||
نسخهٔ کنونی تا ۴ اوت ۲۰۲۶، ساعت ۱۳:۴۲
توضیحات این پودمان میتواند در پودمان:AlborzHealthcare/توضیحات قرار گیرد.
--------------------------------------------------------------------------------
-- Module:AlborzHealthcare
-- Wiki Alborz Healthcare Information System
-- Core Engine
-- Version 1.1
--------------------------------------------------------------------------------
local p = {}
--------------------------------------------------------------------------------
-- LOAD DATA
--------------------------------------------------------------------------------
local data = mw.loadData("Module:AlborzHealthcare/Data")
--------------------------------------------------------------------------------
-- CLEAN
--------------------------------------------------------------------------------
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 = {}
-- پارامترها مستقیم از الگو دریافت میشوند
local source = frame
for k,v in pairs(source.args) do
local key = mw.text.trim(k)
local value = clean(v)
if value then
args[key] = value
end
end
return args
end
--------------------------------------------------------------------------------
-- ADD FIELD
--------------------------------------------------------------------------------
local function addField(result,label,value)
value = clean(value)
if value then
table.insert(result,{
label = label,
value = value
})
end
end
--------------------------------------------------------------------------------
-- BUILD INFOBOX
--------------------------------------------------------------------------------
local function build(args)
local result = {}
table.insert(result,
'<table class="healthcare-infobox">'
)
------------------------------------------------------------
-- TITLE
------------------------------------------------------------
local title =
args.name or mw.title.getCurrentTitle().text
table.insert(result,
'<tr class="healthcare-infobox-title">' ..
'<th colspan="2">' ..
title ..
'</th></tr>'
)
------------------------------------------------------------
-- IMAGE
------------------------------------------------------------
if args.image then
table.insert(result,
'<tr>' ..
'<td colspan="2" class="healthcare-infobox-image">' ..
'[[File:' ..
args.image ..
'|250px]]'
)
if args.caption then
table.insert(result,
'<div class="healthcare-infobox-caption">' ..
args.caption ..
'</div>'
)
end
table.insert(result,
'</td></tr>'
)
end
------------------------------------------------------------
-- GROUPS
------------------------------------------------------------
for _,group in ipairs(data.groups) do
local fields = {}
for _,field in ipairs(group.fields) do
addField(
fields,
field[1],
args[field[2]]
)
end
if #fields > 0 then
table.insert(result,
'<tr class="healthcare-infobox-header">' ..
'<th colspan="2">' ..
group.title ..
'</th></tr>'
)
for _,item in ipairs(fields) do
table.insert(result,
'<tr>' ..
'<th class="healthcare-infobox-label">' ..
item.label ..
'</th>' ..
'<td class="healthcare-infobox-value">' ..
item.value ..
'</td>' ..
'</tr>'
)
end
end
end
------------------------------------------------------------
-- CLOSE
------------------------------------------------------------
table.insert(result,
'</table>'
)
return table.concat(result,"\n")
end
--------------------------------------------------------------------------------
-- PUBLIC FUNCTIONS
--------------------------------------------------------------------------------
function p.main(frame)
local args = getArgs(frame)
return build(args)
end
function p.infobox(frame)
return p.main(frame)
end
--------------------------------------------------------------------------------
-- EXPORT
--------------------------------------------------------------------------------
return p