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

мНет описания правки
мНет описания правки
Строка 135: Строка 135:
                 if not switchKeyToTemplates[sw][key] then
                 if not switchKeyToTemplates[sw][key] then
                     switchKeyToTemplates[sw][key] = {}
                     switchKeyToTemplates[sw][key] = {}
                    switchKeySources[sw][key] = {}
                     table.insert(switchKeyOrder[sw], key)
                     table.insert(switchKeyOrder[sw], key)
                 end
                 end
Строка 144: Строка 143:
                 end
                 end
                 local tplStr = makeTplCall(tplPath, sw, key, id, extra)
                 local tplStr = makeTplCall(tplPath, sw, key, id, extra)
                 table.insert(switchKeyToTemplates[sw][key], tplStr)
                 local priority = 1
                table.insert(switchKeySources[sw][key],
                if parsed and parsed.priority ~= nil then
                     { kind = kind, name = name, pathName = pathName, tplPath = tplPath })
                    if type(parsed.priority) == "number" then
                        priority = parsed.priority
                    else
                        local pnum = tonumber(parsed.priority)
                        if pnum then priority = pnum end
                    end
                end
                local entry = {
                    tpl = tplStr,
                     source = { kind = kind, name = name, pathName = pathName, tplPath = tplPath },
                    priority = priority,
                    idx = #switchKeyToTemplates[sw][key] + 1
                }
                table.insert(switchKeyToTemplates[sw][key], entry)
             end
             end
         end
         end
Строка 160: Строка 172:
         local cfg = switchConfigs[sw] or {}
         local cfg = switchConfigs[sw] or {}
         for _, key in ipairs(switchKeyOrder[sw]) do
         for _, key in ipairs(switchKeyOrder[sw]) do
             local tplCalls = switchKeyToTemplates[sw][key] or {}
             local entries = switchKeyToTemplates[sw][key] or {}
             local sources = switchKeySources[sw][key] or {}
            local tplCalls = {}
             local sources = {}
            if #entries > 0 then
                table.sort(entries, function(a, b)
                    if a.priority == b.priority then return a.idx < b.idx end
                    return a.priority > b.priority
                end)
                for _, e in ipairs(entries) do
                    table.insert(tplCalls, e.tpl)
                    table.insert(sources, e.source)
                end
            end
             if cfg.wrapper then
             if cfg.wrapper then
                 local outStr = cfg.wrapper(key, tplCalls, sources)
                 local outStr = cfg.wrapper(key, tplCalls, sources)