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

Нет описания правки
Нет описания правки
 
(не показано 11 промежуточных версий этого же участника)
Строка 70: Строка 70:
     local parts = {}
     local parts = {}


     -- типы (cardTag)
     -- id сущности
    if entityId and entityId ~= "" then
        parts[#parts + 1] = "id=" .. mw.text.encode(entityId)
    end
 
    -- типы
     if merged.tags and #merged.tags > 0 then
     if merged.tags and #merged.tags > 0 then
         table.sort(merged.tags)
         table.sort(merged.tags)
Строка 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
Строка 288: Строка 310:
     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
    -- support component_store.json: when the searched id is present as a key there,
    -- create component/*/store templates (and prototype/*/store for prototype_store.json)
    local compStoreEntry = componentStoreDefs[id]
    if type(compStoreEntry) == "table" then
        for compName, members in pairs(compStoreEntry) do
            -- mark the component as found so we also process its regular template if exists
            foundComponents[compName] = true
        end
    end
    -- if the id references other names (comma separated), include their defs too
     for name in string.gmatch(id, "[^,]+") do
     for name in string.gmatch(id, "[^,]+") do
         local n = trim(name)
         local n = trim(name)
Строка 450: Строка 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