پودمان:AlborzOrganization
توضیحات این پودمان میتواند در پودمان:AlborzOrganization/توضیحات قرار گیرد.
--------------------------------------------------------------------------------
-- Module:AlborzOrganization
-- Wiki Alborz Organization Information System
-- Core Engine
-- Version 1.1
--------------------------------------------------------------------------------
local p = {}
--------------------------------------------------------------------------------
-- LOAD DATA
--------------------------------------------------------------------------------
local data = mw.loadData("Module:AlborzOrganization/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:getParent()
if not source or not next(source.args) then
source = frame
end
for k,v in pairs(source.args) do
local key = mw.text.trim(k)
local value = clean(v)
if value then
-- تبدیل نامهای فارسی و جایگزینها
if data.lookup[key] then
key = data.lookup[key]
end
args[key] = value
end
end
return args
end
--------------------------------------------------------------------------------
-- ADD FIELD
--------------------------------------------------------------------------------
local function addField(fields,label,value)
value = clean(value)
if value then
table.insert(fields,{
label = label,
value = value
})
end
end
--------------------------------------------------------------------------------
-- BUILD INFOBOX
--------------------------------------------------------------------------------
local function build(args)
local result = {}
table.insert(result,
'<table class="organization-infobox">'
)
------------------------------------------------------------
-- TITLE
------------------------------------------------------------
local title =
args.name
or args.fullname
or mw.title.getCurrentTitle().text
table.insert(result,
'<tr class="organization-infobox-title">' ..
'<th colspan="2">' ..
title ..
'</th></tr>'
)
------------------------------------------------------------
-- IMAGE / LOGO
------------------------------------------------------------
local image = args.image or args.logo
if image then
table.insert(result,
'<tr><td colspan="2" class="organization-infobox-image">' ..
'[[File:' .. image .. '|250px]]'
)
if args.caption then
table.insert(result,
'<div class="organization-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="organization-infobox-header">' ..
'<th colspan="2">' ..
group.title ..
'</th></tr>'
)
for _,item in ipairs(fields) do
table.insert(result,
'<tr>' ..
'<th class="organization-infobox-label">' ..
item.label ..
'</th>' ..
'<td class="organization-infobox-value">' ..
item.value ..
'</td>' ..
'</tr>'
)
end
end
end
table.insert(result,
'</table>'
)
return table.concat(result,"\n")
end
--------------------------------------------------------------------------------
-- PUBLIC
--------------------------------------------------------------------------------
function p.main(frame)
return build(getArgs(frame))
end
function p.infobox(frame)
return p.main(frame)
end
return p