Module:Su

From Zoophilia Wiki
Revision as of 05:55, 17 June 2014 by meta>Mr. Stradivarius (create replacement for Template:Su)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

Documentation for this module may be created at Module:Su/doc

-- This module implements {{su}}.

local p = {}

function p.main(frame)
	-- Use arguments from the parent frame only, and remove any blank arguments.
	-- We don't need to trim whitespace from any arguments, as this module only
	-- uses named arguments, and whitespace is trimmed from them automatically. 
	local origArgs = frame:getParent().args
	local args = {}
	for k, v in pairs(origArgs) do
		if v ~= '' then
			args[k] = v
		end
	end
	return p.luaMain(args)
end

function p.luaMain(args)
	local span = mw.html.create('span')

	-- Set the styles
	span:css{
		['display']        = 'inline-block',
		['margin-bottom']  = '-0.3em',
		['vertical-align'] = args.b and '-0.4em' or '0.8em',
		['line-height']    = '1.2em',
	}
	if args.w == 'f' then
		span:css{
			['font-family'] = 'monospace,courier',
			['font-size']   = '85%'
		}
	else
		span:css('font-size', args.w and args.w or '85%')
	end
	if args.a == 'r' then
		span:css('text-align', 'right')
	elseif args.a == 'c' then
		span:css('text-align', 'center')
	else
		span:css('text-align', 'left')
	end

	-- Add the wikitext
	span
		:wikitext(args.p)
		:tag('br', {selfClosing = true}):done()
		:wikitext(args.b)
	
	return tostring(span)
end

return p