OneShot Wiki
m (Hm)
m (23 revisions: Importing templates, modules and categories from Undertale Wiki)
 
(18 intermediate revisions by the same user not shown)
Line 1: Line 1:
  +
-- Module for various loops used in various templates on the wiki
  +
-- Author: KockaAdmiralac
  +
-- <nowiki>
 
local p = {};
 
local p = {};
  +
  +
function template_args()
  +
return mw.getCurrentFrame():getParent().args
  +
end
   
 
function p.translation(frame)
 
function p.translation(frame)
local args = mw.getCurrentFrame():getParent().args
+
local args = template_args()
 
local ret = ''
 
local ret = ''
for i, v in pairs(args) do
+
for i, v in ipairs(args) do
 
ret = ret .. '{{Translation/element|' .. v .. '}}&nbsp;•&nbsp;'
 
ret = ret .. '{{Translation/element|' .. v .. '}}&nbsp;•&nbsp;'
 
end
 
end
 
return frame:preprocess(ret .. '{{Translation/element}}')
 
return frame:preprocess(ret .. '{{Translation/element}}')
  +
end
  +
  +
function p.dots(frame)
  +
local args = template_args()
  +
local ret = ''
  +
for i, v in ipairs(args) do
  +
ret = ret .. v .. '&nbsp;•&nbsp;'
  +
end
  +
ret = string.gsub(ret, '&nbsp;•&nbsp;$', '')
  +
return ret
  +
end
  +
  +
function p.loop(frame)
  +
local args = template_args()
  +
local cols = frame.args[1]
  +
local template = frame.args[2]
  +
local ret = ''
  +
local data = {}
  +
local del = 0
  +
if frame.args[3] then
  +
del = tonumber(frame.args[3])
  +
end
  +
for i, v in ipairs(args) do
  +
local ind = i - del
  +
local index = math.ceil(ind / cols)
  +
if ind > 0 then
  +
if not(data[index]) then
  +
data[index] = {}
  +
end
  +
data[index][((ind - 1) % cols) + 1] = v
  +
end
  +
end
  +
for i, v in ipairs(data) do
  +
ret = ret .. '{' .. '{' .. template .. '/element|'
  +
for i2, v2 in ipairs(v) do
  +
ret = ret .. mw.text.trim(v2) .. '|'
  +
end
  +
ret = ret .. '}}'
  +
end
  +
return frame:preprocess(ret)
 
end
 
end
   
 
return p
 
return p
  +
-- </nowiki>

Latest revision as of 16:54, 2 July 2017

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

-- Module for various loops used in various templates on the wiki
-- Author: KockaAdmiralac
-- <nowiki>
local p = {};

function template_args()
    return mw.getCurrentFrame():getParent().args
end

function p.translation(frame)
    local args = template_args()
    local ret = ''
    for i, v in ipairs(args) do
        ret = ret .. '{{Translation/element|' .. v .. '}}&nbsp;•&nbsp;'
    end
    return frame:preprocess(ret .. '{{Translation/element}}')
end

function p.dots(frame)
    local args = template_args()
    local ret = ''
    for i, v in ipairs(args) do
        ret = ret .. v .. '&nbsp;•&nbsp;'
    end
    ret = string.gsub(ret, '&nbsp;•&nbsp;$', '')
    return ret
end

function p.loop(frame)
    local args = template_args()
    local cols = frame.args[1]
    local template = frame.args[2]
    local ret = ''
    local data = {}
    local del = 0
    if frame.args[3] then
        del = tonumber(frame.args[3])
    end
    for i, v in ipairs(args) do
        local ind = i - del
        local index = math.ceil(ind / cols)
        if ind > 0 then
            if not(data[index]) then
                data[index] = {}
            end
            data[index][((ind - 1) % cols) + 1] = v
        end
    end
    for i, v in ipairs(data) do
        ret = ret .. '{' .. '{' .. template .. '/element|'
        for i2, v2 in ipairs(v) do
            ret = ret .. mw.text.trim(v2) .. '|'
        end
        ret = ret .. '}}'
    end
    return frame:preprocess(ret)
end

return p
-- </nowiki>