Difference between revisions of "Module:Demo"

From MINR.ORG WIKI
m
(allow other wrapper modules to use results)
Line 1: Line 1:
 
local p = {}
 
local p = {}
 +
 +
function p.get(frame)
 +
frame = frame:getParent() or frame
 +
return {source = mw.text.nowiki(mw.text.unstripNoWiki(frame.args[1] or '')), output = frame:preprocess(mw.text.unstripNoWiki(frame.args[1] or '')), frame = frame}
 +
end
  
 
function p.main(frame)
 
function p.main(frame)
frame = frame:getParent() or frame
+
local show = p.get(frame)
local code = mw.text.nowiki(mw.text.unstripNoWiki(frame.args[1] or ''))
 
local template = frame:preprocess(mw.text.unstripNoWiki(frame.args[1] or ''))
 
 
local br = ''
 
local br = ''
for k = 1, (frame.args.br or 1) do
+
for k = 1, (show.frame.args.br or 1) do
 
br = br .. '<br>'
 
br = br .. '<br>'
 
end
 
end
return string.format('<pre%s>%s</pre>%s%s', frame.args.style and string.format(" style='%s'", frame.args.style) or '', code, br, template)
+
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
 
end
  
 
return p
 
return p

Revision as of 20:36, 31 December 2014

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

local p = {}

function p.get(frame)
	frame = frame:getParent() or frame
	return {source = mw.text.nowiki(mw.text.unstripNoWiki(frame.args[1] or '')), output = frame:preprocess(mw.text.unstripNoWiki(frame.args[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
	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