پودمان:AlborzSports: تفاوت میان نسخهها
ظاهر
جزبدون خلاصۀ ویرایش |
جزبدون خلاصۀ ویرایش |
||
| خط ۴۲: | خط ۴۲: | ||
return value | return value | ||
end | end | ||
| خط ۶۰: | خط ۶۱: | ||
end | end | ||
for | for key, value in pairs(source.args) do | ||
local cleanKey = | |||
mw.text.trim(tostring(key)) | |||
local cleanValue = | |||
clean(value) | |||
if cleanKey ~= "" and cleanValue then | |||
args[cleanKey] = cleanValue | |||
end | end | ||
| خط ۷۳: | خط ۷۸: | ||
return args | return args | ||
end | end | ||
| خط ۹۳: | خط ۹۹: | ||
return result | return result | ||
end | end | ||
-------------------------------------------------------------------------------- | |||
-- ENTITY ALIASES | |||
-------------------------------------------------------------------------------- | |||
local entityAliases = { | |||
-- People | |||
player = "player", | |||
athlete = "player", | |||
["بازیکن"] = "player", | |||
["ورزشکار"] = "player", | |||
coach = "coach", | |||
["مربی"] = "coach", | |||
referee = "referee", | |||
["داور"] = "referee", | |||
manager = "manager", | |||
["مدیر ورزشی"] = "manager", | |||
-- Clubs | |||
club = "club", | |||
sports_club = "club", | |||
sport_club = "club", | |||
["باشگاه"] = "club", | |||
["باشگاه ورزشی"] = "club", | |||
-- Academy | |||
academy = "academy", | |||
["آکادمی"] = "academy", | |||
["آکادمی ورزشی"] = "academy", | |||
-- Facilities | |||
stadium = "stadium", | |||
["ورزشگاه"] = "stadium", | |||
gym = "gym", | |||
gymnasium = "gym", | |||
["سالن"] = "gym", | |||
["سالن ورزشی"] = "gym", | |||
pool = "pool", | |||
swimming_pool = "pool", | |||
["استخر"] = "pool", | |||
zurkhaneh = "zurkhaneh", | |||
["زورخانه"] = "zurkhaneh", | |||
sports_school = "sports_school", | |||
["مدرسه ورزشی"] = "sports_school", | |||
sports_complex = "sports_complex", | |||
["مجموعه ورزشی"] = "sports_complex", | |||
facility = "facility", | |||
["مجموعه"] = "facility", | |||
-- Organization / Board | |||
board = "board", | |||
sports_board = "board", | |||
["هیئت"] = "board", | |||
["هیئت ورزشی"] = "board", | |||
-- Competition | |||
competition = "competition", | |||
["مسابقه"] = "competition", | |||
["مسابقات"] = "competition" | |||
} | |||
-------------------------------------------------------------------------------- | -------------------------------------------------------------------------------- | ||
| خط ۱۰۳: | خط ۱۸۹: | ||
local entity = | local entity = | ||
clean(args.entity_type) | clean(args.entity_type) | ||
---------------------------------------------------------------- | |||
-- DEFAULT ENTITY | |||
---------------------------------------------------------------- | |||
if not entity then | if not entity then | ||
| خط ۱۱۰: | خط ۲۰۰: | ||
end | end | ||
---------------------------------------------------------------- | |||
-- NORMALIZE ENTITY | |||
---------------------------------------------------------------- | |||
entity = | |||
entityAliases[entity] | |||
or entity | |||
---------------------------------------------------------------- | |||
-- VALID ENTITY | |||
---------------------------------------------------------------- | |||
if data.entities[entity] then | if data.entities[entity] then | ||
return entity | return entity | ||
end | |||
---------------------------------------------------------------- | |||
-- SAFE FALLBACK | |||
---------------------------------------------------------------- | |||
local defaultEntity = | |||
data.defaults.entity_type or "player" | |||
defaultEntity = | |||
entityAliases[defaultEntity] | |||
or defaultEntity | |||
if data.entities[defaultEntity] then | |||
return defaultEntity | |||
end | end | ||
return "player" | return "player" | ||
end | end | ||
| خط ۱۲۸: | خط ۲۵۰: | ||
end | end | ||
local entityData = | |||
return | data.entities[entity] | ||
if entityData and entityData.title then | |||
return entityData.title | |||
end | end | ||
return data.meta.title | return data.meta.title | ||
end | end | ||
| خط ۱۵۰: | خط ۲۷۸: | ||
local caption = | local caption = | ||
args.caption or "" | args.caption | ||
or "" | |||
return { | return { | ||
| خط ۱۶۳: | خط ۲۹۲: | ||
} | } | ||
end | end | ||
| خط ۱۶۹: | خط ۲۹۹: | ||
-------------------------------------------------------------------------------- | -------------------------------------------------------------------------------- | ||
local function buildFields( | local function buildFields(layout, args) | ||
local fields = {} | local fields = {} | ||
for _, | for _, item in ipairs(layout) do | ||
local label = | local label = | ||
item[1] | |||
local key = | local key = | ||
item[2] | |||
local value = | local value = | ||
| خط ۱۸۸: | خط ۳۲۰: | ||
if value then | if value then | ||
table.insert(fields, { | table.insert( | ||
fields, | |||
{ | |||
label = label, | |||
value = value | |||
} | |||
) | |||
end | end | ||
| خط ۲۰۱: | خط ۳۳۶: | ||
return fields | return fields | ||
end | end | ||
| خط ۲۱۸: | خط ۳۵۴: | ||
end | end | ||
for _, layoutName in ipairs(entityData.layouts) do | ---------------------------------------------------------------- | ||
-- USE ONLY ENTITY-SPECIFIC LAYOUTS | |||
-- | |||
-- IMPORTANT: | |||
-- "base" is NOT automatically added. | |||
-- It is displayed only when explicitly included | |||
-- in the entity's layouts. | |||
---------------------------------------------------------------- | |||
for _, layoutName in ipairs(entityData.layouts or {}) do | |||
local layout = | local layout = | ||
| خط ۲۲۶: | خط ۳۷۱: | ||
local fields = | local fields = | ||
buildFields(layout, args) | buildFields( | ||
layout, | |||
args | |||
) | |||
---------------------------------------------------------------- | |||
-- DO NOT DISPLAY EMPTY GROUPS | |||
---------------------------------------------------------------- | |||
if #fields > 0 then | if #fields > 0 then | ||
table.insert(groups, { | local title = | ||
data.layoutTitles[layoutName] | |||
or layoutName | |||
table.insert( | |||
groups, | |||
{ | |||
name = title, | |||
fields = fields | |||
} | |||
) | |||
end | end | ||
| خط ۲۴۷: | خط ۴۰۴: | ||
return groups | return groups | ||
end | end | ||
| خط ۲۹۱: | خط ۴۴۹: | ||
} | } | ||
content = clean(content) | content = | ||
clean(content) | |||
if not content then | if not content then | ||
| خط ۲۹۸: | خط ۴۵۷: | ||
return content | return content | ||
end | end | ||
| خط ۳۱۳: | خط ۴۷۳: | ||
box.title = | box.title = | ||
getTitle(entity, args) | getTitle( | ||
entity, | |||
args | |||
) | |||
---------------------------------------------------------------- | ---------------------------------------------------------------- | ||
| خط ۳۳۱: | خط ۴۹۴: | ||
box.groups = | box.groups = | ||
buildGroups(entity, args) | buildGroups( | ||
entity, | |||
args | |||
) | |||
---------------------------------------------------------------- | ---------------------------------------------------------------- | ||
| خط ۳۴۱: | خط ۵۰۷: | ||
return box | return box | ||
end | end | ||
| خط ۳۵۹: | خط ۵۲۶: | ||
return tostring(value) | return tostring(value) | ||
end | |||
-------------------------------------------------------------------------------- | |||
-- ESCAPE HTML | |||
-------------------------------------------------------------------------------- | |||
local function escape(value) | |||
if value == nil then | |||
return "" | |||
end | |||
return mw.text.nowiki( | |||
tostring(value) | |||
) | |||
end | end | ||
| خط ۳۷۵: | خط ۵۵۹: | ||
table.insert( | table.insert( | ||
result, | result, | ||
'<table class="sport-infobox">' | '<table class="sport-infobox">' | ||
) | ) | ||
| خط ۳۸۸: | خط ۵۷۴: | ||
'<tr class="sport-infobox-title">' .. | '<tr class="sport-infobox-title">' .. | ||
'<th colspan="2">' .. | '<th colspan="2">' .. | ||
box.title .. | box.title .. | ||
'</th></tr>' | '</th></tr>' | ||
| خط ۴۲۰: | خط ۶۰۹: | ||
'<tr>' .. | '<tr>' .. | ||
'<td colspan="2" class="sport-infobox-image">' .. | '<td colspan="2" class="sport-infobox-image">' .. | ||
'[[File:' .. | '[[File:' .. | ||
file .. | file .. | ||
| خط ۴۳۵: | خط ۶۲۶: | ||
'<div class="sport-infobox-caption">' .. | '<div class="sport-infobox-caption">' .. | ||
caption .. | caption .. | ||
'</div>' | '</div>' | ||
| خط ۴۴۴: | خط ۶۳۷: | ||
table.insert( | table.insert( | ||
result, | result, | ||
'</td></tr>' | '</td></tr>' | ||
) | ) | ||
| خط ۴۵۴: | خط ۶۴۹: | ||
for _, group in ipairs(box.groups) do | for _, group in ipairs(box.groups) do | ||
---------------------------------------------------------------- | |||
-- GROUP HEADER | |||
---------------------------------------------------------------- | |||
table.insert( | table.insert( | ||
| خط ۴۵۹: | خط ۶۵۸: | ||
'<tr class="sport-infobox-header">' .. | '<tr class="sport-infobox-header">' .. | ||
'<th colspan="2">' .. | '<th colspan="2">' .. | ||
group.name .. | group.name .. | ||
'</th></tr>' | '</th></tr>' | ||
) | ) | ||
---------------------------------------------------------------- | |||
-- GROUP FIELDS | |||
---------------------------------------------------------------- | |||
for _, field in ipairs(group.fields) do | for _, field in ipairs(group.fields) do | ||
| خط ۴۷۳: | خط ۶۷۹: | ||
'<th class="sport-infobox-label">' .. | '<th class="sport-infobox-label">' .. | ||
field.label .. | field.label .. | ||
'</th>' .. | '</th>' .. | ||
'<td class="sport-infobox-value">' .. | '<td class="sport-infobox-value">' .. | ||
renderValue(field.value) .. | renderValue(field.value) .. | ||
'</td>' .. | '</td>' .. | ||
| خط ۴۹۲: | خط ۷۰۲: | ||
-- | -- | ||
-- IMPORTANT: | -- IMPORTANT: | ||
-- | -- Medals remain INSIDE the infobox table. | ||
---------------------------------------------------------------- | ---------------------------------------------------------------- | ||
| خط ۵۰۲: | خط ۷۱۱: | ||
'<tr>' .. | '<tr>' .. | ||
'<td colspan="2" class="sport-infobox-medals">' .. | '<td colspan="2" class="sport-infobox-medals">' .. | ||
box.medals .. | box.medals .. | ||
'</td>' .. | '</td>' .. | ||
'</tr>' | '</tr>' | ||
| خط ۵۱۷: | خط ۷۳۰: | ||
table.insert( | table.insert( | ||
result, | result, | ||
'</table>' | '</table>' | ||
) | ) | ||
| خط ۵۲۴: | خط ۷۳۹: | ||
"\n" | "\n" | ||
) | ) | ||
end | end | ||
| خط ۵۳۱: | خط ۷۴۷: | ||
function p.main(frame) | function p.main(frame) | ||
---------------------------------------------------------------- | |||
-- GET ARGUMENTS | |||
---------------------------------------------------------------- | |||
local args = | local args = | ||
| خط ۵۳۶: | خط ۷۵۶: | ||
---------------------------------------------------------------- | ---------------------------------------------------------------- | ||
-- NORMALIZE | -- NORMALIZE INPUT | ||
---------------------------------------------------------------- | ---------------------------------------------------------------- | ||
| خط ۵۵۰: | خط ۷۷۰: | ||
---------------------------------------------------------------- | ---------------------------------------------------------------- | ||
-- BUILD | -- BUILD INFOBOX | ||
---------------------------------------------------------------- | ---------------------------------------------------------------- | ||
| خط ۵۸۵: | خط ۸۰۵: | ||
local args = | local args = | ||
getArgs(frame) | getArgs(frame) | ||
---------------------------------------------------------------- | |||
-- NORMALIZE | |||
---------------------------------------------------------------- | |||
args = | args = | ||
normalize(args) | normalize(args) | ||
---------------------------------------------------------------- | |||
-- ENTITY | |||
---------------------------------------------------------------- | |||
local entity = | local entity = | ||
getEntity(args) | getEntity(args) | ||
---------------------------------------------------------------- | |||
-- ENTITY DATA | |||
---------------------------------------------------------------- | |||
local entityData = | local entityData = | ||
| خط ۵۹۶: | خط ۸۲۸: | ||
if not entityData then | if not entityData then | ||
return "Entity not found" | |||
return "Entity not found: " .. tostring(entity) | |||
end | end | ||
---------------------------------------------------------------- | |||
-- RESULT | |||
---------------------------------------------------------------- | |||
local result = {} | local result = {} | ||
| خط ۶۰۳: | خط ۸۴۱: | ||
table.insert( | table.insert( | ||
result, | result, | ||
"Entity: " .. entity | |||
"Entity: " .. | |||
entity | |||
) | ) | ||
table.insert( | table.insert( | ||
result, | result, | ||
"Title: " .. entityData.title | |||
"Title: " .. | |||
tostring( | |||
entityData.title | |||
) | |||
) | ) | ||
| خط ۶۱۷: | خط ۸۶۳: | ||
table.concat( | table.concat( | ||
entityData.layouts, | entityData.layouts or {}, | ||
", " | ", " | ||
) | |||
) | |||
---------------------------------------------------------------- | |||
-- DEBUG TYPE | |||
---------------------------------------------------------------- | |||
table.insert( | |||
result, | |||
"Subtype: " .. | |||
tostring( | |||
args.subtype | |||
or "NOT FOUND" | |||
) | ) | ||
| خط ۶۳۱: | خط ۸۹۳: | ||
"Coach: " .. | "Coach: " .. | ||
tostring( | tostring( | ||
args.coach | args.coach | ||
| خط ۶۴۶: | خط ۹۰۹: | ||
"Medals: " .. | "Medals: " .. | ||
tostring( | tostring( | ||
args.medaltemplates | args.medaltemplates | ||
| خط ۶۷۷: | خط ۹۴۱: | ||
key .. | key .. | ||
" : " .. | " : " .. | ||
value.title | tostring( | ||
value.title | |||
) | |||
) | ) | ||
نسخهٔ ۱۰ اوت ۲۰۲۶، ساعت ۱۱:۱۹
توضیحات این پودمان میتواند در پودمان:AlborzSports/توضیحات قرار گیرد.
--------------------------------------------------------------------------------
-- Module:AlborzSports
-- Wiki Alborz Sports Information System
-- Core Engine
-- Version 2.2
--------------------------------------------------------------------------------
local p = {}
--------------------------------------------------------------------------------
-- LOAD DATA
--------------------------------------------------------------------------------
local data = mw.loadData("Module:AlborzSports/Data")
--------------------------------------------------------------------------------
-- CONFIG
--------------------------------------------------------------------------------
local DEFAULT_IMAGE_WIDTH =
data.meta.imageWidth or "280px"
--------------------------------------------------------------------------------
-- UTILITY FUNCTIONS
--------------------------------------------------------------------------------
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
local parent = frame:getParent()
if parent and next(parent.args) then
source = parent
end
for key, value in pairs(source.args) do
local cleanKey =
mw.text.trim(tostring(key))
local cleanValue =
clean(value)
if cleanKey ~= "" and cleanValue then
args[cleanKey] = cleanValue
end
end
return args
end
--------------------------------------------------------------------------------
-- NORMALIZE INPUT
--------------------------------------------------------------------------------
local function normalize(args)
local result = {}
for key, value in pairs(args) do
local field =
data.lookup[key] or key
result[field] = value
end
return result
end
--------------------------------------------------------------------------------
-- ENTITY ALIASES
--------------------------------------------------------------------------------
local entityAliases = {
-- People
player = "player",
athlete = "player",
["بازیکن"] = "player",
["ورزشکار"] = "player",
coach = "coach",
["مربی"] = "coach",
referee = "referee",
["داور"] = "referee",
manager = "manager",
["مدیر ورزشی"] = "manager",
-- Clubs
club = "club",
sports_club = "club",
sport_club = "club",
["باشگاه"] = "club",
["باشگاه ورزشی"] = "club",
-- Academy
academy = "academy",
["آکادمی"] = "academy",
["آکادمی ورزشی"] = "academy",
-- Facilities
stadium = "stadium",
["ورزشگاه"] = "stadium",
gym = "gym",
gymnasium = "gym",
["سالن"] = "gym",
["سالن ورزشی"] = "gym",
pool = "pool",
swimming_pool = "pool",
["استخر"] = "pool",
zurkhaneh = "zurkhaneh",
["زورخانه"] = "zurkhaneh",
sports_school = "sports_school",
["مدرسه ورزشی"] = "sports_school",
sports_complex = "sports_complex",
["مجموعه ورزشی"] = "sports_complex",
facility = "facility",
["مجموعه"] = "facility",
-- Organization / Board
board = "board",
sports_board = "board",
["هیئت"] = "board",
["هیئت ورزشی"] = "board",
-- Competition
competition = "competition",
["مسابقه"] = "competition",
["مسابقات"] = "competition"
}
--------------------------------------------------------------------------------
-- ENTITY DETECTION
--------------------------------------------------------------------------------
local function getEntity(args)
local entity =
clean(args.entity_type)
----------------------------------------------------------------
-- DEFAULT ENTITY
----------------------------------------------------------------
if not entity then
entity =
data.defaults.entity_type
end
----------------------------------------------------------------
-- NORMALIZE ENTITY
----------------------------------------------------------------
entity =
entityAliases[entity]
or entity
----------------------------------------------------------------
-- VALID ENTITY
----------------------------------------------------------------
if data.entities[entity] then
return entity
end
----------------------------------------------------------------
-- SAFE FALLBACK
----------------------------------------------------------------
local defaultEntity =
data.defaults.entity_type or "player"
defaultEntity =
entityAliases[defaultEntity]
or defaultEntity
if data.entities[defaultEntity] then
return defaultEntity
end
return "player"
end
--------------------------------------------------------------------------------
-- TITLE
--------------------------------------------------------------------------------
local function getTitle(entity, args)
if args.name then
return args.name
end
local entityData =
data.entities[entity]
if entityData and entityData.title then
return entityData.title
end
return data.meta.title
end
--------------------------------------------------------------------------------
-- IMAGE HANDLING
--------------------------------------------------------------------------------
local function buildImage(args)
if not args.image then
return nil
end
local width =
args.image_width
or DEFAULT_IMAGE_WIDTH
local caption =
args.caption
or ""
return {
type = "image",
image = args.image,
size = width,
caption = caption
}
end
--------------------------------------------------------------------------------
-- FIELD BUILDER
--------------------------------------------------------------------------------
local function buildFields(layout, args)
local fields = {}
for _, item in ipairs(layout) do
local label =
item[1]
local key =
item[2]
local value =
clean(args[key])
----------------------------------------------------------------
-- ONLY ADD EXISTING VALUES
----------------------------------------------------------------
if value then
table.insert(
fields,
{
label = label,
value = value
}
)
end
end
return fields
end
--------------------------------------------------------------------------------
-- GROUP BUILDER
--------------------------------------------------------------------------------
local function buildGroups(entity, args)
local groups = {}
local entityData =
data.entities[entity]
if not entityData then
return groups
end
----------------------------------------------------------------
-- USE ONLY ENTITY-SPECIFIC LAYOUTS
--
-- IMPORTANT:
-- "base" is NOT automatically added.
-- It is displayed only when explicitly included
-- in the entity's layouts.
----------------------------------------------------------------
for _, layoutName in ipairs(entityData.layouts or {}) do
local layout =
data.layouts[layoutName]
if layout then
local fields =
buildFields(
layout,
args
)
----------------------------------------------------------------
-- DO NOT DISPLAY EMPTY GROUPS
----------------------------------------------------------------
if #fields > 0 then
local title =
data.layoutTitles[layoutName]
or layoutName
table.insert(
groups,
{
name = title,
fields = fields
}
)
end
end
end
return groups
end
--------------------------------------------------------------------------------
-- MEDAL BUILDER
--------------------------------------------------------------------------------
local function buildMedals(args)
local medals =
clean(args.medaltemplates)
if not medals then
medals =
clean(args.medals)
end
if not medals then
return nil
end
local frame =
mw.getCurrentFrame()
local content =
frame:expandTemplate{
title = "Infobox medal templates",
args = {
medals = medals,
title =
args.medaltemplates_title
or "",
expand = "yes"
}
}
content =
clean(content)
if not content then
return nil
end
return content
end
--------------------------------------------------------------------------------
-- INFOBOX BUILDER
--------------------------------------------------------------------------------
local function buildInfobox(entity, args)
local box = {}
----------------------------------------------------------------
-- TITLE
----------------------------------------------------------------
box.title =
getTitle(
entity,
args
)
----------------------------------------------------------------
-- IMAGE
----------------------------------------------------------------
local image =
buildImage(args)
if image then
box.image = image
end
----------------------------------------------------------------
-- GROUPS
----------------------------------------------------------------
box.groups =
buildGroups(
entity,
args
)
----------------------------------------------------------------
-- MEDALS
----------------------------------------------------------------
box.medals =
buildMedals(args)
return box
end
--------------------------------------------------------------------------------
-- RENDER VALUE
--------------------------------------------------------------------------------
local function renderValue(value)
if type(value) == "table" then
return table.concat(
value,
"، "
)
end
return tostring(value)
end
--------------------------------------------------------------------------------
-- ESCAPE HTML
--------------------------------------------------------------------------------
local function escape(value)
if value == nil then
return ""
end
return mw.text.nowiki(
tostring(value)
)
end
--------------------------------------------------------------------------------
-- RENDER INFOBOX
--------------------------------------------------------------------------------
local function renderInfobox(box)
local result = {}
----------------------------------------------------------------
-- OPEN TABLE
----------------------------------------------------------------
table.insert(
result,
'<table class="sport-infobox">'
)
----------------------------------------------------------------
-- TITLE
----------------------------------------------------------------
if box.title then
table.insert(
result,
'<tr class="sport-infobox-title">' ..
'<th colspan="2">' ..
box.title ..
'</th></tr>'
)
end
----------------------------------------------------------------
-- IMAGE
----------------------------------------------------------------
if box.image then
local image =
box.image
local file =
image.image
local size =
image.size
or DEFAULT_IMAGE_WIDTH
local caption =
image.caption
or ""
table.insert(
result,
'<tr>' ..
'<td colspan="2" class="sport-infobox-image">' ..
'[[File:' ..
file ..
'|' ..
size ..
']]'
)
if caption ~= "" then
table.insert(
result,
'<div class="sport-infobox-caption">' ..
caption ..
'</div>'
)
end
table.insert(
result,
'</td></tr>'
)
end
----------------------------------------------------------------
-- GROUPS
----------------------------------------------------------------
for _, group in ipairs(box.groups) do
----------------------------------------------------------------
-- GROUP HEADER
----------------------------------------------------------------
table.insert(
result,
'<tr class="sport-infobox-header">' ..
'<th colspan="2">' ..
group.name ..
'</th></tr>'
)
----------------------------------------------------------------
-- GROUP FIELDS
----------------------------------------------------------------
for _, field in ipairs(group.fields) do
table.insert(
result,
'<tr>' ..
'<th class="sport-infobox-label">' ..
field.label ..
'</th>' ..
'<td class="sport-infobox-value">' ..
renderValue(field.value) ..
'</td>' ..
'</tr>'
)
end
end
----------------------------------------------------------------
-- MEDALS
--
-- IMPORTANT:
-- Medals remain INSIDE the infobox table.
----------------------------------------------------------------
if box.medals then
table.insert(
result,
'<tr>' ..
'<td colspan="2" class="sport-infobox-medals">' ..
box.medals ..
'</td>' ..
'</tr>'
)
end
----------------------------------------------------------------
-- CLOSE TABLE
----------------------------------------------------------------
table.insert(
result,
'</table>'
)
return table.concat(
result,
"\n"
)
end
--------------------------------------------------------------------------------
-- PUBLIC FUNCTION
--------------------------------------------------------------------------------
function p.main(frame)
----------------------------------------------------------------
-- GET ARGUMENTS
----------------------------------------------------------------
local args =
getArgs(frame)
----------------------------------------------------------------
-- NORMALIZE INPUT
----------------------------------------------------------------
args =
normalize(args)
----------------------------------------------------------------
-- ENTITY
----------------------------------------------------------------
local entity =
getEntity(args)
----------------------------------------------------------------
-- BUILD INFOBOX
----------------------------------------------------------------
local box =
buildInfobox(
entity,
args
)
----------------------------------------------------------------
-- RENDER
----------------------------------------------------------------
return renderInfobox(box)
end
--------------------------------------------------------------------------------
-- TEMPLATE ENTRY
--------------------------------------------------------------------------------
function p.infobox(frame)
return p.main(frame)
end
--------------------------------------------------------------------------------
-- DEBUG FUNCTION
--------------------------------------------------------------------------------
function p.test(frame)
local args =
getArgs(frame)
----------------------------------------------------------------
-- NORMALIZE
----------------------------------------------------------------
args =
normalize(args)
----------------------------------------------------------------
-- ENTITY
----------------------------------------------------------------
local entity =
getEntity(args)
----------------------------------------------------------------
-- ENTITY DATA
----------------------------------------------------------------
local entityData =
data.entities[entity]
if not entityData then
return "Entity not found: " .. tostring(entity)
end
----------------------------------------------------------------
-- RESULT
----------------------------------------------------------------
local result = {}
table.insert(
result,
"Entity: " ..
entity
)
table.insert(
result,
"Title: " ..
tostring(
entityData.title
)
)
table.insert(
result,
"Layouts: " ..
table.concat(
entityData.layouts or {},
", "
)
)
----------------------------------------------------------------
-- DEBUG TYPE
----------------------------------------------------------------
table.insert(
result,
"Subtype: " ..
tostring(
args.subtype
or "NOT FOUND"
)
)
----------------------------------------------------------------
-- DEBUG COACH
----------------------------------------------------------------
table.insert(
result,
"Coach: " ..
tostring(
args.coach
or "NOT FOUND"
)
)
----------------------------------------------------------------
-- DEBUG MEDALS
----------------------------------------------------------------
table.insert(
result,
"Medals: " ..
tostring(
args.medaltemplates
or args.medals
or "NOT FOUND"
)
)
return table.concat(
result,
"\n"
)
end
--------------------------------------------------------------------------------
-- GET ENTITY LIST
--------------------------------------------------------------------------------
function p.entities()
local result = {}
for key, value in pairs(data.entities) do
table.insert(
result,
key ..
" : " ..
tostring(
value.title
)
)
end
table.sort(result)
return table.concat(
result,
"\n"
)
end
--------------------------------------------------------------------------------
-- GET VERSION
--------------------------------------------------------------------------------
function p.version()
return
data.version.name ..
" v" ..
data.version.major ..
"." ..
data.version.minor
end
--------------------------------------------------------------------------------
-- EXPORT
--------------------------------------------------------------------------------
return p