Module:Lorem ipsum: Difference between revisions
(do not add category when substing the module) |
m (1 revision imported: Initial setup) |
||
(No difference)
|
Latest revision as of 19:15, 31 August 2024
This module is rated as alpha. It is ready for third party input, and may be used on a few pages to see if problems arise, but should be watched. Suggestions for new features or changes in their input and output mechanisms are welcome. |
Implements {{Lorem ipsum }}, {{Lorem ipsum span }}, and {{Dolorem ipsum }}.
Parameters:
- "data": Data page containing a list of paragraphs to use for generating filler text. Defaults to Module:Lorem ipsum/data.
Usage
{{#invoke:Lorem ipsum|function_name}}
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 cat = yn(args["cat"]) or true
local count = tonumber(args[1] or 1)
local i = 1
if join then
out = out .. (args["prefix"] or args[2] or "")
end
while i <= count do
if not join then
out = out .. (args["prefix"] or args[2] or "\n")
end
out = out .. mw.ustring.format(paragraphs[math.mod(i - 1, #paragraphs) + 1], (link and "link" or ""))
if not join then
out = out .. (args["suffix"] or args[3] or "") .. "\n"
else
out = out .. (i == count and "" or " ")
end
link = false
i = i + 1
end
if join then
out = out .. (args["suffix"] or args[3] or "")
end
if cat and mw.title.getCurrentTitle().namespace == 0 and not mw.isSubsting() then
out = out .. "[[Category:Wikipedia articles containing placeholders]]"
end
return frame:preprocess(out)
end,
oneParagraph = 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 i = tonumber(args[1] or 1)
local link = yn(args["link"])
local paragraph = paragraphs[math.mod(i - 1, #paragraphs) + 1]
local maxLen = tonumber(args["max len"] or mw.ustring.len(paragraph))
local out = ""
if cat and mw.title.getCurrentTitle().namespace == 0 and not mw.isSubsting() then
out = out .. "[[Category:Wikipedia articles containing placeholders]]"
end
out = out .. mw.ustring.format(mw.ustring.sub(paragraph, 1, maxLen), (link and "link" or ""))
return frame:preprocess(out)
end
}