local p =
function p.notification(frame) local args = frame:getParent.args local argNums = getArgNums(args, "title") local out = "" local multipleInHeader = false for index, num in ipairs(argNums) do num = tostring(num) local ending = "" local argsForOutput = if index
#argNums - 1 or not isOffsetItemSameHeader(args, argNums, index, 2) then -- it's the penultimate in the header; set the ending to " and " ending = frame:expandTemplate .. frame:expandTemplate .. frame:expandTemplate else -- it's not the last or penultimate in the header; -- set the ending to ", " ending = frame:expandTemplate .. frame:expandTemplate end else argsForOutput["type"] = args["type" .. num] argsForOutput["header"] = args["header" .. num] if multipleInHeader then -- if there've been multiple in the header, queue this -- as the last one, so it'll include the multiple end -- with the header name and type multipleInHeader = false argsForOutput["multipleEnd"] = true end if index ~= #argNums then -- this isn't the last in the list, but it's clearly the -- last in the header; start the next header with an -- "and" to separate the headers ending = frame:expandTemplate .. frame:expandTemplate .. frame:expandTemplate end end argsForOutput["multipleInHeader"] = multipleInHeader out = out .. frame:expandTemplate .. ending end return outend
function getArgNums(args, prefix) -- Returns a table containing the numbers of the arguments that exist -- for the specified prefix. For example, if the prefix was 'data', and -- 'data1', 'data2', and 'data5' exist, it would return . -- This function is adapted from, and is released under -- the Creative Commons Attribution-Share-Alike License 3.0. -- https://creativecommons.org/licenses/by-sa/3.0/ local nums = for k, v in pairs(args) do local num = tostring(k):match('^' .. prefix .. '([0-9]%d*)$') if num then table.insert(nums, tonumber(num)) end end table.sort(nums) return numsend
-- isOffsetItemSameHeader takes the args, the argument numbers gathered,-- the current index, and a given offset, and checks whether the item at that-- offset is from the same type and the same header.function isOffsetItemSameHeader(args, argNums, index, offset) return args["type" .. argNums[index + offset]]
args["header" .. argNums[index]]end
return p