Модуль:Сущность: различия между версиями
Pok (обсуждение | вклад) мНет описания правки |
Pok (обсуждение | вклад) Нет описания правки |
||
| Строка 67: | Строка 67: | ||
end | end | ||
local function buildCardCall(merged) | local function buildCardCall(merged, entityId) | ||
if | local parts = {} | ||
table.sort(merged.sections) | |||
-- id сущности | |||
if entityId and entityId ~= "" then | |||
parts[#parts + 1] = "id=" .. mw.text.encode(entityId) | |||
end | |||
-- типы (cardTag) | |||
if merged.tags and #merged.tags > 0 then | |||
table.sort(merged.tags) | |||
parts[#parts + 1] = "тип=" .. table.concat(merged.tags, ", ") | |||
end | |||
-- секции карточки | |||
if merged.sections and #merged.sections > 0 then | |||
table.sort(merged.sections) | |||
parts[#parts + 1] = "sections=" .. table.concat(merged.sections, ", ") | |||
for _, section in ipairs(merged.sections) do | |||
local labels = merged.labelLists[section] | |||
if labels and #labels > 0 then | |||
local enc = {} | |||
for i = 1, #labels do | |||
enc[i] = mw.text.encode(labels[i]) | |||
end | |||
parts[#parts + 1] = mw.text.encode(section) .. "=" .. table.concat(enc, ", ") | |||
end | |||
end | |||
end | |||
-- содержимое полей | |||
for compositeKey, originalLabel in pairs(merged.labelOverrides or {}) do | |||
if originalLabel and originalLabel ~= "" then | |||
parts[#parts + 1] = mw.text.encode(compositeKey .. "_label") .. "=" .. mw.text.encode(originalLabel) | |||
end | end | ||
end | end | ||
for | for compositeKey, content in pairs(merged.contentByKey or {}) do | ||
if content and content ~= "" then | if content and content ~= "" then | ||
parts[#parts + 1] = mw.text.encode( | parts[#parts + 1] = mw.text.encode(compositeKey) .. "=" .. mw.text.encode(content) | ||
end | end | ||
end | end | ||
if #parts == 0 then | |||
return "" | |||
end | |||
return "{{карточка/сущность|" .. table.concat(parts, "|") .. "}}" | return "{{карточка/сущность|" .. table.concat(parts, "|") .. "}}" | ||
end | end | ||
local function cardWrapper(frame, keyOrder, keyToTemplates, keySources) | local function cardWrapper(frame, keyOrder, keyToTemplates, keySources, entityId) | ||
local merged = { sections = {}, sectionsMap = {}, labelLists = {}, | local merged = { | ||
sections = {}, | |||
sectionsMap = {}, | |||
labelLists = {}, | |||
labelSets = {}, | |||
labelOverrides = {}, | |||
contentByKey = {}, | |||
tags = {}, | |||
tagSet = {} | |||
} | |||
for _, section in ipairs(keyOrder or {}) do | for _, section in ipairs(keyOrder or {}) do | ||
local entries = keyToTemplates[section] or {} | local entries = keyToTemplates[section] or {} | ||
| Строка 102: | Строка 142: | ||
table.insert(merged.sections, section) | table.insert(merged.sections, section) | ||
end | end | ||
local cur = merged.labelLists[section] or {} | local compositeKey = tostring(section) .. "-" .. tostring(label) | ||
merged.labelOverrides[compositeKey] = label | |||
merged. | merged.contentByKey[compositeKey] = content | ||
merged.labelSets[section] = merged.labelSets[section] or {} | |||
if not merged.labelSets[section][compositeKey] then | |||
merged.labelSets[section][compositeKey] = true | |||
local cur = merged.labelLists[section] or {} | |||
table.insert(cur, compositeKey) | |||
merged.labelLists[section] = cur | |||
end | |||
end | |||
if e.cardTag and e.cardTag ~= "" then | |||
if not merged.tagSet[e.cardTag] then | |||
merged.tagSet[e.cardTag] = true | |||
table.insert(merged.tags, e.cardTag) | |||
end | |||
end | end | ||
end | end | ||
end | end | ||
end | end | ||
return buildCardCall(merged) | return buildCardCall(merged, entityId) | ||
end | end | ||
| Строка 156: | Строка 210: | ||
end | end | ||
local function renderBlocks(frame, switchesTbl, configs, keyOrder, keyToTemplates, keySources, noHeaders) | local function renderBlocks(frame, switchesTbl, configs, keyOrder, keyToTemplates, keySources, noHeaders, entityId) | ||
local outLocal = {} | local outLocal = {} | ||
for _, sw in ipairs(switchesTbl) do | for _, sw in ipairs(switchesTbl) do | ||
local cfg = configs[sw] or {} | local cfg = configs[sw] or {} | ||
if cfg.fullCard and sw == "card" then | if cfg.fullCard and sw == "card" then | ||
local outStr = cfg.wrapper(frame, keyOrder[sw], keyToTemplates[sw], keySources[sw]) | local outStr = cfg.wrapper(frame, keyOrder[sw], keyToTemplates[sw], keySources[sw], entityId) | ||
if outStr and outStr ~= "" then table.insert(outLocal, outStr) end | if outStr and outStr ~= "" then table.insert(outLocal, outStr) end | ||
else | else | ||
| Строка 296: | Строка 350: | ||
tplLabel = tplLabelStr, | tplLabel = tplLabelStr, | ||
tplContent = tplContentStr, | tplContent = tplContentStr, | ||
cardTag = parsed.cardTag, | |||
source = { kind = kind, name = name, pathName = pathName, tplPath = tplPath }, | source = { kind = kind, name = name, pathName = pathName, tplPath = tplPath }, | ||
priority = priority, | priority = priority, | ||
| Строка 322: | Строка 377: | ||
for _, e in ipairs(errors) do table.insert(out, e) end | for _, e in ipairs(errors) do table.insert(out, e) end | ||
local blocks = renderBlocks(frame, switches, switchConfigs, switchKeyOrder, switchKeyToTemplates, switchKeySources, | local blocks = renderBlocks(frame, switches, switchConfigs, switchKeyOrder, switchKeyToTemplates, switchKeySources, | ||
hasWhitelist) | hasWhitelist, id) | ||
for _, b in ipairs(blocks) do table.insert(out, b) end | for _, b in ipairs(blocks) do table.insert(out, b) end | ||
| Строка 377: | Строка 432: | ||
local out = {} | local out = {} | ||
local blocks = renderBlocks(frame, switches, switchConfigs, switchKeyOrder, switchKeyToTemplates, switchKeySources, | local blocks = renderBlocks(frame, switches, switchConfigs, switchKeyOrder, switchKeyToTemplates, switchKeySources, | ||
hasWhitelist) | hasWhitelist, "") | ||
for _, b in ipairs(blocks) do table.insert(out, b) end | for _, b in ipairs(blocks) do table.insert(out, b) end | ||