Module:Lorem ipsum: Difference between revisions
Appearance
NeonWabbit (talk | contribs) Created page with "local yn = require("Module:Yesno") return { main = function(frame) local args = require("Module:Arguments").getArgs(frame) local data = args["data"] and mw.loadData(args["data"]) or mw.loadData("Module:Lorem_ipsum/data") local paragraphs = {} for k,v in ipairs(data) do table.insert(paragraphs, v) end local out = '' local link = yn(args["link"]) or yn(args[4]) or false local join = yn(args["join"]) or false local joinprefixsuffix = yn(args["joinprefi..." Tags: Mobile edit Mobile web edit Advanced mobile edit |
NeonWabbit (talk | contribs) No edit summary |
||
| Line 1: | Line 1: | ||
local yn = require("Module:Yesno") | local yn = require("Module:Yesno") | ||
local p = {} | |||
function p._main(args) | |||
local paragraphs = {} | |||
local outTbl = setmetatable({}, {__call = function (t, v) t[#t+1] = v end}) | |||
local link = yn(args["link"]) or yn(args[4]) or false | |||
local join = yn(args["join"]) or false | |||
local joinprefixsuffix = yn(args["joinprefixsuffix"]) or false | |||
local cat = yn(args["cat"]) or true | |||
local count = tonumber(args[1]) or 1 | |||
local i = tonumber(args["start"]) or 1 | |||
local data = mw.loadData(args["data"] or "Module:Lorem_ipsum/data") | |||
local maxLen = tonumber(args["max len"]) | |||
for k,v in ipairs(data) do | |||
table.insert(paragraphs, v) | |||
end | |||
if join and (not joinprefixsuffix) then | |||
outTbl(args["prefix"] or args[2] or "") | |||
end | |||
while i > 0 and i <= count do | |||
if (not join) or joinprefixsuffix then | |||
outTbl(args["prefix"] or args[2] or "\n") | |||
end | end | ||
mw.log(count, i, data) | |||
outTbl(mw.ustring.format(paragraphs[math.mod(i - 1, #paragraphs) + 1], (link and "link" or ""))) | |||
if not join then | |||
outTbl((args["suffix"] or args[3] or "") .. "\n") | |||
else | |||
if joinprefixsuffix then | |||
outTbl(args["suffix"] or args[3] or "") | |||
if join | |||
if | |||
end | end | ||
outTbl(i == count and "" or " ") | |||
end | end | ||
if join and (not joinprefixsuffix) then | link = false | ||
i = i + 1 | |||
end | |||
if join and (not joinprefixsuffix) then | |||
outTbl(args["suffix"] or args[3] or "") | |||
end | |||
if cat and mw.title.getCurrentTitle().namespace == 0 and not mw.isSubsting() then | |||
outTbl("[[Category:Wikipedia articles containing placeholders]]") | |||
end | end | ||
local outStr = mw.getCurrentFrame():preprocess(table.concat(outTbl)) | |||
return maxLen and mw.ustring.sub(outStr, 1, maxLen) or outStr | |||
end | |||
function p.main(frame) | |||
local args = require("Module:Arguments").getArgs(frame) | |||
return p._main(args, false) | |||
end | |||
function p.oneParagraph(frame) | |||
local args = require("Module:Arguments").getArgs(frame) | |||
args["join"] = true | |||
args["start"] = tonumber(args[1]) or 1 | |||
return p._main(args) | |||
end | |||
return p | |||
Latest revision as of 02:50, 2 July 2026
For actual documentation, view the corresponding Wikipedia pages.
local yn = require("Module:Yesno")
local p = {}
function p._main(args)
local paragraphs = {}
local outTbl = setmetatable({}, {__call = function (t, v) t[#t+1] = v end})
local link = yn(args["link"]) or yn(args[4]) or false
local join = yn(args["join"]) or false
local joinprefixsuffix = yn(args["joinprefixsuffix"]) or false
local cat = yn(args["cat"]) or true
local count = tonumber(args[1]) or 1
local i = tonumber(args["start"]) or 1
local data = mw.loadData(args["data"] or "Module:Lorem_ipsum/data")
local maxLen = tonumber(args["max len"])
for k,v in ipairs(data) do
table.insert(paragraphs, v)
end
if join and (not joinprefixsuffix) then
outTbl(args["prefix"] or args[2] or "")
end
while i > 0 and i <= count do
if (not join) or joinprefixsuffix then
outTbl(args["prefix"] or args[2] or "\n")
end
mw.log(count, i, data)
outTbl(mw.ustring.format(paragraphs[math.mod(i - 1, #paragraphs) + 1], (link and "link" or "")))
if not join then
outTbl((args["suffix"] or args[3] or "") .. "\n")
else
if joinprefixsuffix then
outTbl(args["suffix"] or args[3] or "")
end
outTbl(i == count and "" or " ")
end
link = false
i = i + 1
end
if join and (not joinprefixsuffix) then
outTbl(args["suffix"] or args[3] or "")
end
if cat and mw.title.getCurrentTitle().namespace == 0 and not mw.isSubsting() then
outTbl("[[Category:Wikipedia articles containing placeholders]]")
end
local outStr = mw.getCurrentFrame():preprocess(table.concat(outTbl))
return maxLen and mw.ustring.sub(outStr, 1, maxLen) or outStr
end
function p.main(frame)
local args = require("Module:Arguments").getArgs(frame)
return p._main(args, false)
end
function p.oneParagraph(frame)
local args = require("Module:Arguments").getArgs(frame)
args["join"] = true
args["start"] = tonumber(args[1]) or 1
return p._main(args)
end
return p