Misplaced Pages

Module:Singles: Difference between revisions

Article snapshot taken from[REDACTED] with creative commons attribution-sharealike license. Give it a read and then ask your questions in the chat. We can research this topic together.
Browse history interactively← Previous editNext edit →Content deleted Content added
Revision as of 09:47, 10 May 2017 view sourceJc86035 (talk | contribs)Extended confirmed users, Template editors34,237 edits {{Infobox}}, lowercase parameters per MOS:INFOBOX← Previous edit Revision as of 18:18, 10 May 2017 view source Frietjes (talk | contribs)Autopatrolled, Extended confirmed users, Template editors1,002,365 edits left align listsNext edit →
Line 27: Line 27:
out = out .. '</span>' out = out .. '</span>'
end end
if out ~= '' then
return '<div style="text-align:left">' .. out .. '\n</div>'
end
return out return out
end end

Revision as of 18:18, 10 May 2017

Module documentation[view] [edit] [history] [purge]

This module implements the {{Singles}} template. Please see the template page for usage instructions.

The above documentation is transcluded from Module:Singles/doc. (edit | history)
Editors can experiment in this module's sandbox (edit | diff) and testcases (create) pages.
Subpages of this module.

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 .. '(%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, 'ingle ?')
	for _, num in ipairs(nums) do
		out = out .. '\n# <span class="item"><span class="fn">"' .. (args or args or args) .. '"</span>'
		local date = args or args or args
		if date then
			out = out .. '<br />Released: ' .. date
		end
		out = out .. '</span>'
	end
	
	if out ~= '' then
		return '<div style="text-align:left">' .. out .. '\n</div>'
	end
	
	return out
end

return p
Module:Singles: Difference between revisions Add topic