Module:Demo: Difference between revisions

From Zoophilia Wiki
Jump to navigationJump to search
meta>Codehydro
m prevent arg from spilling into frame
meta>Codehydro
better way to isolate args
Line 3: Line 3:
function p.get(frame, arg)
function p.get(frame, arg)
frame = frame:getParent() or frame
frame = frame:getParent() or frame
        local nowiki = frame.args[arg or 1]
orphan = frame:newChild{}
frame.args[arg or 1] = nil
orphan.getParent = function() return nil end
local result = {
        return {
source = mw.text.nowiki(mw.text.decode(mw.text.unstripNoWiki(nowiki or ''))),
source = mw.text.nowiki(mw.text.decode(mw.text.unstripNoWiki(frame.args[arg or 1] or ''))),
output = frame:preprocess(mw.text.unstripNoWiki(nowiki or ''))
output = orphan:preprocess(mw.text.unstripNoWiki(frame.args[arg or 1] or '')),
frame = frame
}
}
frame.args[arg or 1] = nowiki
result.frame = frame
return result
end
end



Revision as of 20:18, 7 January 2015

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

local p = {}

function p.get(frame, arg)
	frame = frame:getParent() or frame
	orphan = frame:newChild{}
	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