Модуль:Песочница/D6194c-1cc/MedInfobox
Перейти к навигации
Перейти к поиску
Примеры[править код]
|
|
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
local p = {}
local formatter = require('Модуль:Песочница/D6194c-1cc/WDFormatV2')
local f = formatter.f
local wikidata = require('Модуль:WDCommon')
local source = require('Модуль:Песочница/D6194c-1cc/WDMedCondition')
local function formatImage(source, processedData, result)
result.wikitext = '[[File:' .. result.text .. '|274x400px]]'
result.text = ''
end
local function formatIncubationPeriod(source, processedData, result)
local text
if source.minIncubationPeriod and source.maxIncubationPeriod then
if source.minIncubationPeriod.unitEntity and source.minIncubationPeriod.unitEntity == source.maxIncubationPeriod.unitEntity then
text = source.minIncubationPeriod.value .. '—' .. source.maxIncubationPeriod.value
text = text .. ' ' .. wikidata.unit(source.minIncubationPeriod.unitEntity)
end
end
result.wikitext = text
result.text = text
end
local titleTag = {
name = 'th',
classes = { 'infobox-above' },
attr = { colspan = 2 },
}
local fullRowTag = {
name = 'td',
attr = { colspan = 2 },
}
local imageCaptionTag = {
name = 'td',
attr = { colspan = 2 },
classes = { 'media-caption' },
}
local nameTag = {
name = 'th',
}
local valueTag = {
name = 'td',
}
local rowTag = {
name = 'tr',
}
local MedInfoboxProfile = {
tag = {
name = 'table',
classes = { 'infobox' },
},
groups = {
{
tag = rowTag,
groups = {
{
tag = titleTag,
field = 'name'
},
},
},
{
tag = rowTag,
groups = {
{
tag = fullRowTag,
field = 'image',
format = { formatImage },
},
},
},
{
tag = rowTag,
groups = {
{
tag = imageCaptionTag,
field = 'imageDescription',
},
},
},
{
tag = rowTag,
groups = {
{
tag = nameTag,
depends = 'conditionType',
value = 'Тип',
},
{
tag = valueTag,
field = 'conditionType',
format = { f.wikilink },
capitalize = true,
},
},
},
{
tag = rowTag,
groups = {
{
tag = nameTag,
depends = 'location',
entity = 'P927',
},
{
tag = valueTag,
field = 'location',
format = { f.wikilink },
capitalize = true,
},
},
},
{
tag = rowTag,
groups = {
{
tag = nameTag,
depends = 'afflicts',
entity = 'P689',
},
{
tag = valueTag,
field = 'afflicts',
format = { f.wikilink },
capitalize = true,
},
},
},
{
tag = rowTag,
groups = {
{
tag = nameTag,
depends = 'symptoms',
entity = 'Q169872',
value = 'Симптомы',
},
{
tag = valueTag,
field = 'symptoms',
format = { f.wikilink },
capitalize = true,
},
},
},
{
tag = rowTag,
groups = {
{
tag = nameTag,
depends = 'transmission',
entity = 'P1060',
value = 'Передача',
},
{
tag = valueTag,
field = 'transmission',
format = { f.wikilink },
capitalize = true,
},
},
},
{
tag = rowTag,
groups = {
{
tag = nameTag,
depends = 'cause',
entity = 'P828',
value = 'Причиной является',
},
{
tag = valueTag,
field = 'cause',
format = { f.wikilink },
capitalize = true,
},
},
},
{
tag = rowTag,
groups = {
{
tag = nameTag,
depends = 'notCause',
entity = 'P9353',
value = 'Причиной не является',
},
{
tag = valueTag,
field = 'notCause',
format = { f.wikilink },
capitalize = true,
},
},
},
{
tag = rowTag,
groups = {
{
tag = nameTag,
depends = { 'minIncubationPeriod', 'maxIncubationPeriod' },
value = 'Инкубационный период',
},
{
tag = valueTag,
depends = 'maxIncubationPeriod',
field = 'minIncubationPeriod',
format = { formatIncubationPeriod },
capitalize = true,
},
},
},
{
tag = rowTag,
groups = {
{
tag = nameTag,
depends = 'naturalHostSpecies',
value = 'Естественные носители',
},
{
tag = valueTag,
field = 'naturalHostSpecies',
format = { f.wikilink },
capitalize = true,
},
},
},
{
tag = rowTag,
groups = {
{
tag = nameTag,
depends = 'specialities',
entity = 'Q930752',
value = 'Медицинские специальности',
},
{
tag = valueTag,
field = 'specialities',
format = { f.wikilink },
capitalize = true,
},
},
},
},
}
local function strToArray(str)
if not str then
return nil
elseif type(str) == 'table' then
if next(str) == nil then
return nil
end
return str
end
local array = {}
for item in str:gmatch('[^,;]+') do
table.insert(array, { value=item })
end
return array
end
local function valueToTable(value)
if not value then
return nil
end
return { value = value }
end
local function valueAndEntityToTable(str, entity)
local t = {}
if str then
t.value = str
end
if entity then
t.entity = entity
end
if next(t) == nil then
return nil
end
return t
end
function p.gen(frame)
local args = frame.args
local s = source.fetch({
name = valueAndEntityToTable(args.name, args.nameEntity),
specialities = strToArray(args.specialities),
})
return formatter.format(MedInfoboxProfile, s)
end
return p