Jump to content

Module:Singles

Permanently protected module
From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Callanecc (talk | contribs) at 02:00, 31 January 2014 (Protected Module:Singles: Highly visible template: Used in Template:Singles ([Edit=Allow only template editors and admins] (indefinite) [Move=Allow only template editors and admins] (indefinite))). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

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 = frame:getParent().args
	local out = [=[<tr style="text-align:center;">
  <th style="background:{{Template:Infobox album/color|]=] .. (args.Type or '') .. [=[}};" colspan="3">[[Single (music)|Singles]] from '']=] .. (args.Name or '{{{Name}}}') .. [=[''</th>
</tr>
<tr style="text-align:left; vertical-align:top; line-height:11px;">
  <td colspan="3">]=]
	local nums = getArgNums(args, '[Ss]ingle ')
	for x,num in pairs(nums) do
		out = out .. '\n# <span class="item"><span class="fn">"' .. (args['Single ' .. num] or args['single ' .. num]) .. '"</span>'
		local date = args['Single ' .. num .. ' date'] or args['single ' .. num .. ' date']
		if date then
			out = out .. '<br />Released: ' .. date
		end
		out = out .. '</span>'
	end
	out = out .. [=[</td>
</tr>]=]
	return out
end

return p