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

мНет описания правки
мНет описания правки
Строка 119: Строка 119:
     local id = args[1] or ""
     local id = args[1] or ""
     if id == "" then return "" end
     if id == "" then return "" end
    local function parseListArg(str)
        local res = {}
        if not str or str == "" then return res end
        for item in string.gmatch(str, "[^,]+") do
            local s = trim(item)
            if s ~= "" then
                local a, b = s:match("^([^_]+)_(.+)$")
                if a and b then
                    res[a] = res[a] or {}
                    res[a][b] = true
                end
            end
        end
        return res
    end
    local blacklist = parseListArg(args.blacklist or "")
    local whitelist = parseListArg(args.whitelist or "")


     local componentDefs = load_module_data("component.json")
     local componentDefs = load_module_data("component.json")
Строка 161: Строка 178:
             local keys = parsed[sw] or {}
             local keys = parsed[sw] or {}
             for _, key in ipairs(keys) do
             for _, key in ipairs(keys) do
                 if not switchKeyToTemplates[sw][key] then
                local skip = false
                     switchKeyToTemplates[sw][key] = {}
                 if next(whitelist) ~= nil then
                    table.insert(switchKeyOrder[sw], key)
                    if not (whitelist[sw] and whitelist[sw][key]) then skip = true end
                else
                     if blacklist[sw] and blacklist[sw][key] then skip = true end
                 end
                 end
                 local extra = ""
                 if not skip then
                if ok and dp and dp.flattenField then
                    if not switchKeyToTemplates[sw][key] then
                    local dataPage = tplPath .. ".json"
                        switchKeyToTemplates[sw][key] = {}
                    extra = dp.flattenField({ args = { id, dataPage } })
                        table.insert(switchKeyOrder[sw], key)
                end
                    end
                local tplStr = makeTplCall(tplPath, sw, key, id, extra)
                    local extra = ""
                local priority = 1
                    if ok and dp and dp.flattenField then
                if parsed and parsed.priority ~= nil then
                        local dataPage = tplPath .. ".json"
                    if type(parsed.priority) == "number" then
                        extra = dp.flattenField({ args = { id, dataPage } })
                        priority = parsed.priority
                    end
                    else
                    local tplStr = makeTplCall(tplPath, sw, key, id, extra)
                        local pnum = tonumber(parsed.priority)
                    local priority = 1
                        if pnum then priority = pnum end
                    if parsed and parsed.priority ~= nil then
                        if type(parsed.priority) == "number" then
                            priority = parsed.priority
                        else
                            local pnum = tonumber(parsed.priority)
                            if pnum then priority = pnum end
                        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
                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