You can edit almost every page by Creating an account and confirming your email.

Module:Sandbox/BrandonXLF/2

From EverybodyWiki Bios & Wiki

Documentation for this module may be created at Module:Sandbox/BrandonXLF/2/doc

-- Table of functions
local p = {}
local errorMsg = require('Module:Error').error

-- Arguments
local a = mw.getCurrentFrame().args
local pA = mw.getCurrentFrame():getParent().args

-- Variables containing HTML attributes
local hList = 'style="margin:0;padding:0;display:inline-block;list-style:none;"'
local hItem = 'style="margin:0;padding:0 0.25em 0 0;display:inline-block;"'
local pList = 'style="line-height:inherit;list-style:none none;margin:0;"'
local pItem = 'style="margin-bottom:0;"'

--[[ 
core() function
Parameters:
	list
	parameter prefix
	seperator
	prefix
	postfix/sufi
	last seperator
	list HTMl tag
	list HTML attributes
	item HTML attributes
]]--

local function core (args, para, sep, pre, post, lastSep, lTag, lAttr, iAttr)
	if not args then return '' end -- Return nothing if no list
	
	local out, list, count, key = '', {}, 0, 1
	para, sep, pre, post = para or '', sep or '', pre or '', post or ''

	if args[para..'0'] then return errorMsg({'Error: incorect parameter '..para..'0, use '..para..'1 or '..para}) end -- Don't use para0
	if args[para] and args[para..'1'] then return errorMsg({'Error: do not use both '..para..' and '..para..'1'}) end -- Don't use para and para1

	for k,v in pairs(args) do
		local k = tostring(k):match(para..'(%d+)')
		if k then
			list[tonumber(k)] = tostring(v)
			count = count + 1
		end
	end
	
	if args[para] then
		list[1] = args[para]
		count = count + 1
	end
	
	while count ~= 0 do
		local v = list[key]
		if v then
			v = pre..v:gsub('$i', tostring(key))..post..sep -- Create list item
			out = out..(lTag and '<li'..(iAttr and ' '..iAttr or '')..'>'..v..'</li>' or v) -- Add list item tag if needed
			count = count - 1
		end
		key = key + 1
	end
	
	if out == '' then return ''	end -- Return nothing if no output
	
	out = out:reverse() -- Reverse out
	sep = sep:reverse() -- Reverse seperator
	out = out:gsub(sep,'',1) -- Remove final seperator
	if lastSep then
		lastSep = lastSep:reverse() -- Reverse last seperator
		out = out:gsub(sep,lastSep,1) -- Replace final seperator with last seperator
	end
	out = out:reverse() -- Unreverse out
	
	return (lTag and '<'..lTag..(lAttr and ' '..lAttr or '')..'>'..out..'</'..lTag..'>' or out) -- Return output
end

--[[
Invokable functions
Use $value to retrive value from arguments
]]--

p.main			= function() return core (pA,a[1],a[2],a[3],a[4],a[5]) end
p.ordered		= function() return core (pA,a[1],'',a[2],a[3],nil,'ol') end
p.bulleted		= function() return core (pA,a[1],'',a[2],a[3],nil,'ul') end 
p.unbulleted	= function() return core (pA,a[1],'',a[2],a[3],nil,'ul',pList,pItem) end
p.horizontal	= function() return core (pA,a[1],' · ',a[2],a[3],nil,'ul',hList,hItem) end
p.comma 		= function() return core (pA,a[1],', ',a[2],a[3],nil,'ul',hList,hItem) end 
p['and']		= function() return core (pA,a[1],', ',a[2],a[3],' and ') end
p['or'] 		= function() return core (pA,a[1],', ',a[2],a[3],' or ') end 

--[[
p.example() function
Takes parent parameters 
FUNC is used to give function to call
CODE is used to give child parameters
TEXT is used to return the child code
]]--

function p.example (frame)
	local call = '{{#invoke:'..frame:getTitle():gsub('Module:','')..'|'..mw.text.unstripNoWiki(a.CODE)..'}}'
	if a.TEXT then
		return '<nowiki>'..call..'</nowiki>'
	else
		return frame:preprocess(call)
	end
end

-- Return function table

return p