Module:Sandbox

From blackwiki
Revision as of 12:47, 3 April 2017 by blackwiki>Where was I last night?
Jump to navigation Jump to search

Scribunto Testing Area

This is not an actual Lua module. It exists to provide a convenient pseudo-namespace for code testing, hopefully preventing the main Module: namespace from becoming littered with experiments, as Lua modules cannot exist as subpages in the User: namespace.

Please name your experimental modules in the following format to help keep things tidy:

Module:Sandbox/Your User Name/Module name

You can use Special:PrefixIndex/Module:Sandbox to list modules in this area.



require('Module:No globals')
local getArgs = require('Module:Arguments').getArgs
local p = {}

local infoboxImage = require('Module:InfoboxImage').InfoboxImage
local lc = require('Module:WikitextLC').selective

function p.main(frame)
	local args = getArgs(frame)
	return p._main(args)
end

function p._main(args)
	-- Main module code goes here.
	local variety = {'', '-hans', '-hant', '-cn', '-hk', '-mo', '-sg', '-tw'}
	local varietyHans = {'-hans', '-cn', '-sg'}
	local varietyHant = {'-hant', '-hk', '-mo', '-tw'}
	local hansIndicator, hantIndicator = false, false
	
	for i, v in ipairs(varietyHans) do
		if args['image' .. v] then
			hansIndicator = true
			break
		end
	end

	for i, v in ipairs(varietyHant) do
		if args['image' .. v] then
			hantIndicator = true
			break
		end
	end

	if hansIndicator and hansIndicator then
		local content = {}
		for i, v in ipairs(variety) do
			local parameter = 'image' .. v
			local value = args[patameter]
			if value then
				content[parameter] = infoboxImage{args = {image = value, sizedefault = 'frameless', upright = '1.15'}}
			end
		end
		return lc(content)
	end
	
	return infoboxImage{args = {image = args.image, sizedefault = 'frameless', upright = '1.15'}}
	
end

return p