پودمان:AlborzOrganization: تفاوت میان نسخهها
ظاهر
صفحهای تازه حاوی «-------------------------------------------------------------------------------- -- Module:AlborzOrganization -- Wiki Alborz Organization Information System -- Core Engine -- Version 1.0 -------------------------------------------------------------------------------- local p = {} -------------------------------------------------------------------------------- -- LOAD DATA --------------------------------------------------------------...» ایجاد کرد |
جزبدون خلاصۀ ویرایش |
||
| خط ۳: | خط ۳: | ||
-- Wiki Alborz Organization Information System | -- Wiki Alborz Organization Information System | ||
-- Core Engine | -- Core Engine | ||
-- Version 1. | -- Version 1.1 | ||
-------------------------------------------------------------------------------- | -------------------------------------------------------------------------------- | ||
| خط ۲۵: | خط ۲۵: | ||
if type(value) == "string" then | if type(value) == "string" then | ||
value = mw.text.trim(value) | value = mw.text.trim(value) | ||
| خط ۳۰: | خط ۳۱: | ||
return nil | return nil | ||
end | end | ||
end | end | ||
| خط ۳۵: | خط ۳۷: | ||
end | end | ||
-------------------------------------------------------------------------------- | -------------------------------------------------------------------------------- | ||
| خط ۴۹: | خط ۵۲: | ||
source = frame | source = frame | ||
end | end | ||
for k,v in pairs(source.args) do | for k,v in pairs(source.args) do | ||
| خط ۵۶: | خط ۶۰: | ||
if value then | if value then | ||
-- تبدیل نامهای فارسی و جایگزینها | |||
if data.lookup[key] then | |||
key = data.lookup[key] | |||
end | |||
args[key] = value | args[key] = value | ||
end | end | ||
end | end | ||
return args | return args | ||
end | end | ||
-------------------------------------------------------------------------------- | -------------------------------------------------------------------------------- | ||
| خط ۸۳: | خط ۹۶: | ||
end | end | ||
-------------------------------------------------------------------------------- | -------------------------------------------------------------------------------- | ||
| خط ۹۲: | خط ۱۰۶: | ||
local result = {} | local result = {} | ||
table.insert(result,'<table class="organization-infobox">') | |||
table.insert(result, | |||
'<table class="organization-infobox">' | |||
) | |||
------------------------------------------------------------ | ------------------------------------------------------------ | ||
| خط ۹۸: | خط ۱۱۶: | ||
------------------------------------------------------------ | ------------------------------------------------------------ | ||
local title = args.name or mw.title.getCurrentTitle().text | local title = | ||
args.name | |||
or args.fullname | |||
or mw.title.getCurrentTitle().text | |||
table.insert(result, | table.insert(result, | ||
| خط ۱۰۸: | خط ۱۳۰: | ||
) | ) | ||
------------------------------------------------------------ | ------------------------------------------------------------ | ||
-- IMAGE | -- IMAGE / LOGO | ||
------------------------------------------------------------ | ------------------------------------------------------------ | ||
local image = args.image or args.logo | |||
if image then | |||
table.insert(result, | table.insert(result, | ||
'<tr><td colspan="2" class="organization-infobox-image">' .. | '<tr><td colspan="2" class="organization-infobox-image">' .. | ||
'[[File:' . | '[[File:' .. image .. '|250px]]' | ||
) | ) | ||
if args.caption then | if args.caption then | ||
| خط ۱۳۴: | خط ۱۶۲: | ||
end | end | ||
table.insert(result,'</td></tr>') | |||
table.insert(result, | |||
'</td></tr>' | |||
) | |||
end | end | ||
------------------------------------------------------------ | ------------------------------------------------------------ | ||
| خط ۱۴۳: | خط ۱۷۹: | ||
for _,group in ipairs(data.groups) do | for _,group in ipairs(data.groups) do | ||
local fields = {} | local fields = {} | ||
for _,field in ipairs(group.fields) do | for _,field in ipairs(group.fields) do | ||
addField( | addField( | ||
| خط ۱۵۳: | خط ۱۹۲: | ||
args[field[2]] | args[field[2]] | ||
) | ) | ||
end | end | ||
if #fields > 0 then | if #fields > 0 then | ||
table.insert(result, | table.insert(result, | ||
| خط ۱۶۶: | خط ۲۱۰: | ||
) | ) | ||
for _,item in ipairs(fields) do | for _,item in ipairs(fields) do | ||
table.insert(result, | table.insert(result, | ||
'<tr>' .. | '<tr>' .. | ||
'<th class="organization-infobox-label">' .. | '<th class="organization-infobox-label">' .. | ||
item.label .. | item.label .. | ||
'</th>' .. | '</th>' .. | ||
'<td class="organization-infobox-value">' .. | '<td class="organization-infobox-value">' .. | ||
item.value .. | item.value .. | ||
'</td>' .. | '</td>' .. | ||
'</tr>' | '</tr>' | ||
) | ) | ||
end | end | ||
end | end | ||
end | end | ||
table.insert(result,'</table>') | |||
table.insert(result, | |||
'</table>' | |||
) | |||
return table.concat(result,"\n") | return table.concat(result,"\n") | ||
end | end | ||
-------------------------------------------------------------------------------- | -------------------------------------------------------------------------------- | ||
| خط ۲۰۳: | خط ۲۶۷: | ||
end | end | ||
function p.infobox(frame) | function p.infobox(frame) | ||
| خط ۲۰۹: | خط ۲۷۴: | ||
end | end | ||
return p | return p | ||
نسخهٔ کنونی تا ۵ اوت ۲۰۲۶، ساعت ۱۷:۱۱
توضیحات این پودمان میتواند در پودمان: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