Модуль:Сущность: различия между версиями

Нет описания правки
Нет описания правки
 
(не показано 10 промежуточных версий этого же участника)
Строка 69: Строка 69:
local function buildCardCall(merged, entityId)
local function buildCardCall(merged, entityId)
     local parts = {}
     local parts = {}
    -- id сущности
    if entityId and entityId ~= "" then
        parts[#parts + 1] = "id=" .. mw.text.encode(entityId)
    end


     -- типы  
     -- типы  
Строка 106: Строка 111:
             parts[#parts + 1] = mw.text.encode(compositeKey) .. "=" .. content
             parts[#parts + 1] = mw.text.encode(compositeKey) .. "=" .. content
         end
         end
    end
    -- id сущности
    if entityId and entityId ~= "" and #parts > 0 then
        table.insert(parts, 1, "id=" .. mw.text.encode(entityId))
     end
     end


Строка 120: Строка 120:
end
end


local function cardWrapper(frame, keyOrder, keyToTemplates, keySources, entityId)
local function cardWrapper(frame, keyOrder, keyToTemplates, keySources, entityId, noHeaders)
     local merged = {
     local merged = {
         sections = {},
         sections = {},
Строка 168: Строка 168:
                         merged.labelLists[section] = cur
                         merged.labelLists[section] = cur
                     end
                     end
                end
                    if e.cardTag and e.cardTag ~= "" then
                if e.cardTag and e.cardTag ~= "" then
                        if not merged.tagSet[e.cardTag] then
                    if not merged.tagSet[e.cardTag] then
                            merged.tagSet[e.cardTag] = true
                        merged.tagSet[e.cardTag] = true
                            table.insert(merged.tags, e.cardTag)
                        table.insert(merged.tags, e.cardTag)
                        end
                     end
                     end
                 end
                 end
Строка 178: Строка 178:
         end
         end
     end
     end
    if noHeaders then
        local hasLabel = false
        for _, v in pairs(merged.labelOverrides or {}) do
            if v and v ~= "" then hasLabel = true break end
        end
        if not hasLabel then
            for _, lst in pairs(merged.labelLists or {}) do
                if #lst > 0 then hasLabel = true break end
            end
        end
        local hasContent = false
        for _, v in pairs(merged.contentByKey or {}) do
            if v and v ~= "" then hasContent = true break end
        end
        if not hasLabel and not hasContent then
            return ""
        end
    end
     return buildCardCall(merged, entityId)
     return buildCardCall(merged, entityId)
end
end
Строка 229: Строка 251:
         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], entityId)
             local outStr = cfg.wrapper(frame, keyOrder[sw], keyToTemplates[sw], keySources[sw], entityId, noHeaders)
             if outStr and outStr ~= "" then table.insert(outLocal, outStr) end
             if outStr and outStr ~= "" then table.insert(outLocal, outStr) end
         else
         else
Строка 284: Строка 306:
             if type(v) == "string" then
             if type(v) == "string" then
                 foundComponents[v] = true
                 foundComponents[v] = true
            end
        end
    end
    local protoEntry = prototypeStoreDefs[id]
    if type(protoEntry) == "table" then
        for protoName, _ in pairs(protoEntry) do
            if type(protoName) == "string" then
                foundPrototypes[protoName] = true
             end
             end
         end
         end
Строка 439: Строка 452:
     for _, b in ipairs(blocks) do table.insert(out, b) end
     for _, b in ipairs(blocks) do table.insert(out, b) end


     return frame:preprocess(table.concat(out, "\n"))
     return frame:preprocess(table.concat(out, "\n") .. "[[Категория:Сущности]]")
end
end