Jump to content

Module:Sandbox/Andrybak

From Wikipedia, the free encyclopedia
local getArgs = require('Module:Arguments').getArgs

p = {}

p.list = function(frame)
	local start = 1609455600
	local images = {}
	for t = 0, 512, 1
	do
		local d = os.date("%Y-%m-%d", start + t * 24 * 60 * 60)
		local image = frame:expandTemplate{
			title = "POTD/" .. d,
			args = { "image" }
		}
		table.insert(images, image)
	end
	return frame:preprocess(table.concat(images, "<br />"))
end

p.asciiToSevenSegmentDisplayUnicode = function(frame)
	local args = getArgs(frame)
	local s = args[1]
	local map = {
		['0'] = "🯰",
		['1'] = "🯱",
		['2'] = "🯲",
		['3'] = "🯳",
		['4'] = "🯴",
		['5'] = "🯵",
		['6'] = "🯶",
		['7'] = "🯷",
		['8'] = "🯸",
		['9'] = "🯹"
	}
	local result = string.gsub(s, "%d",
		function(digit)
			local replacement = map[digit]
			return replacement or digit
		end
	)
	return result
end

p.testNilExpandTemplate = function(frame)
	args = {
		[1] = nil,
		[2] = '',
		[3] = "foobar"
	}
	return frame:expandTemplate{
		title = 'X5',
		args = args
	}
end

return p