Modulis:Singles

Vikipēdijas lapa
Jump to navigation Jump to search
Dokumentācijas ikona Moduļa dokumentācija[izveidot]
--SinglsX
--SinglsX datums
local p = {}

-- Ripped from Module:Infobox. TODO: Make a utility module that can do this kind of thing
local 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 {1, 2, 5}.
    local nums = {}
    for k, v in pairs(args) do
        local num = tostring(k):match('^' .. prefix .. '([1-9]%d*)$')
        if num then table.insert(nums, tonumber(num)) end
    end
    table.sort(nums)
    return nums
end

function p.main(frame)
	local args = require('Module:Arguments').getArgs(frame, {wrappers = 'Veidne:Singli'})
	local out = [=[<tr style="text-align:center;">
  <th style="background:]=] .. frame:expandTemplate{title = 'Albuma infokaste/krāsa', args = {args.Type}} .. [=[;" colspan="3">]=] .. (args.Singli_nos or args.Nosaukums or mw.title.getCurrentTitle().prefixedText) .. [=[ singli</th>
</tr>
<tr style="text-align:left; vertical-align:top; line-height:11px;">
  <td colspan="3">]=]
	local nums = getArgNums(args, '[Ss]ingl[es]%s?')
	for _, num in ipairs(nums) do
		out = out .. '\n# <span class="item"><span class="fn">' .. (args['Single ' .. num] or args['Singls' .. num]) .. '</span>'
		local datums = (args['Singls' .. num .. ' datums'] or args['Single ' .. num .. ' date'])
		if datums then
			out = out .. '<br />Izdots: ' .. datums
		end
		out = out .. '</span>'
	end
	out = out .. [=[</td>
</tr>]=]
	return out
end

return p