Module:Sandbox/Andrybak and Module:Sandbox/Andrybak/sandbox: Difference between pages
Appearance
(Difference between pages)
Content deleted Content added
testNilExpandTemplate: fix |
test |
||
Line 1: | Line 1: | ||
local getArgs = require('Module:Arguments').getArgs |
local getArgs = require('Module:Arguments').getArgs |
||
local yesno = require('Module:Yesno') |
|||
local Date = require('Module:Date')._Date |
|||
-- TODO use TemplateStyles |
|||
p = {} |
p = {} |
||
local function wikiError(message) |
|||
local |
local ret = mw.html.create('div') |
||
:addClass('error') |
|||
local images = {} |
|||
:wikitext(message) |
|||
for t = 0, 512, 1 |
|||
return tostring(ret) |
|||
do |
|||
local d = os.date("%Y-%m-%d", start + t * 24 * 60 * 60) |
|||
local image = frame:expandTemplate{ |
|||
title = "POTD/" .. d, |
|||
args = { "image" } |
|||
} |
|||
table.insert(images, image) |
|||
⚫ | |||
⚫ | |||
end |
end |
||
-- replace all newlines in the string with break tags |
|||
p.asciiToSevenSegmentDisplayUnicode = function(frame) |
|||
-- slideshow only supports single line captions |
|||
local args = getArgs(frame) |
|||
local function replaceNewlines(s) |
|||
local s = args[1] |
|||
return mw.ustring.gsub(s, '%c', 'XXXX') |
|||
local map = { |
|||
['0'] = "🯰", |
|||
['1'] = "🯱", |
|||
['2'] = "🯲", |
|||
['3'] = "🯳", |
|||
['4'] = "🯴", |
|||
['5'] = "🯵", |
|||
['6'] = "🯶", |
|||
['7'] = "🯷", |
|||
['8'] = "🯸", |
|||
['9'] = "🯹" |
|||
} |
|||
local result = string.gsub(s, "%d", |
|||
⚫ | |||
local replacement = map[digit] |
|||
return replacement or digit |
|||
⚫ | |||
) |
|||
⚫ | |||
end |
end |
||
-- Extract value named "paramName" from a subpage of [[Template:POTD]] |
|||
p.testNilExpandTemplate = function(frame) |
|||
local function getPotdPart(frame, potdSubpage, paramName) |
|||
args = { |
|||
[1] = nil, |
|||
[2] = '', |
|||
[3] = "foobar" |
|||
} |
|||
return frame:expandTemplate{ |
return frame:expandTemplate{ |
||
title = |
title = potdSubpage, |
||
args = |
args = { paramName } |
||
} |
} |
||
end |
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 |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
local root = getPotdText(frame, "2013-10-18", "xyzzy") |
|||
⚫ | |||
end |
|||
p.main = main |
|||
return p |
return p |