Module:Demo

From MINR.ORG WIKI
Revision as of 04:12, 8 January 2015 by Codehydro (talk)

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

local p = {}

function p.get(frame, arg, passArgs)
	frame = frame:getParent() or frame
	orphan = frame:newChild{}
	--Allows parameters to be added (see example at Module:RoundN/doc and Module:RoundN/testcases/2)
	if frame.args.passArgs or passArgs then
		orphan.args = mw.clone(frame.args)
		--Set arg to something else if you want to pass your source code to the child for some reason.
		orphan[arg or 1] = nil
	end
	orphan.getParent = function() return nil end
	return {
		source = mw.text.nowiki(mw.text.decode(mw.text.unstripNoWiki(frame.args[arg or 1] or ''))),
		output = orphan:preprocess(mw.text.unstripNoWiki(frame.args[arg or 1] or '')),
		frame = frame
	}
end

function p.main(frame)
	local show = p.get(frame)
	local br = ''
	for k = 1, (show.frame.args.br or 1) do
		br = br .. '<br>'
	end
	if show[show.frame.args.result_arg] then
		return show[show.frame.args.result_arg]
	end
	return string.format('<pre%s>%s</pre>%s%s', show.frame.args.style and string.format(" style='%s'", show.frame.args.style) or '', show.source, br, show.output)
end

return p