Module:Sandbox/Andrybak/sandbox

From English Wikipedia @ Freddythechick
local getArgs = require('Module:Arguments').getArgs
local yesno = require('Module:Yesno')
local Date = require('Module:Date')._Date

-- TODO use TemplateStyles

p = {}

local function wikiError(message)
	local ret = mw.html.create('div')
		:addClass('error')
		:wikitext(message)
	return tostring(ret)
end

-- replace all newlines in the string with break tags
-- slideshow only supports single line captions
local function replaceNewlines(s)
	return mw.ustring.gsub(s, '%c', 'XXXX')
end

-- Extract value named "paramName" from a subpage of [[Template:POTD]]
local function getPotdPart(frame, potdSubpage, paramName)
	return frame:expandTemplate{
		title = potdSubpage,
		args = { paramName }
	}
end

-- bottom half of [[Template:Portal POTD]] for a POTD subpage
local function getPotdText(frame, potdDate, moreHtml)
	local potdText = getPotdPart(frame, "POTD/" .. potdDate, "portal layout/text")
	mw.log(potdText)
	local debugText = "<br/>BEFORE: " .. potdText
	potdText = replaceNewlines(potdText)
	debugText = debugText .. "<br/>AFTER: " .. potdText
	mw.log(potdText)
	mw.log("---------------------------")
	if moreHtml
	then
		potdText = potdText .. moreHtml .. debugText
	end
	return potdText
end


function main(frame)
	local root = getPotdText(frame, "2013-10-18", "xyzzy") 
	return frame:preprocess(root)
end

p.main = main

return p