Jump to content

Module:Singles: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
Restore default line-height
{{Infobox}}, lowercase parameters per MOS:INFOBOX
Line 17: Line 17:
function p.main(frame)
function p.main(frame)
local args = require('Module:Arguments').getArgs(frame, {wrappers = 'Template:Singles'})
local args = require('Module:Arguments').getArgs(frame, {wrappers = 'Template:Singles'})
local out = [=[<tr>
local out = ''
local nums = getArgNums(args, '[Ss]ingle ?')
<th style="text-align:center; background:]=] .. frame:expandTemplate{title = 'Infobox album/color', args = {args.Type}} .. [=[;" colspan="3">[[Single (music)|Singles]] from '']=] .. (args.Name or mw.title.getCurrentTitle().prefixedText) .. [=[''</th>
</tr>
<tr style="text-align:left; vertical-align:top;">
<td colspan="3">]=]
local nums = getArgNums(args, '[Ss]ingle ')
for _, num in ipairs(nums) do
for _, num in ipairs(nums) do
out = out .. '\n# <span class="item"><span class="fn">"' .. (args['Single ' .. num] or args['single ' .. num]) .. '"</span>'
out = out .. '\n# <span class="item"><span class="fn">"' .. (args['single' .. num] or args['single ' .. num] or args['Single ' .. num]) .. '"</span>'
local date = args['Single ' .. num .. ' date'] or args['single ' .. num .. ' date']
local date = args['single' .. num .. 'date'] or args['single ' .. num .. ' date'] or args['Single ' .. num .. ' date']
if date then
if date then
out = out .. '<br />Released: ' .. date
out = out .. '<br />Released: ' .. date
Line 31: Line 27:
out = out .. '</span>'
out = out .. '</span>'
end
end
out = out .. [=[</td>
</tr>]=]
return out
return out
end
end

Revision as of 09:47, 10 May 2017

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 = 'Template:Singles'})
	local out = ''
	local nums = getArgNums(args, '[Ss]ingle ?')
	for _, num in ipairs(nums) do
		out = out .. '\n# <span class="item"><span class="fn">"' .. (args['single' .. num] or args['single ' .. num] or args['Single ' .. num]) .. '"</span>'
		local date = args['single' .. num .. 'date'] or args['single ' .. num .. ' date'] or args['Single ' .. num .. ' date']
		if date then
			out = out .. '<br />Released: ' .. date
		end
		out = out .. '</span>'
	end
	return out
end

return p