imported>TheGhostOfInky No edit summary |
imported>TheGhostOfInky No edit summary |
||
(32 intermediate revisions by 2 users not shown) | |||
Line 15: | Line 15: | ||
local arg2 = frame.args[2] or frame:getParent().args[2] | local arg2 = frame.args[2] or frame:getParent().args[2] | ||
local x = tonumber(arg2) | local x = tonumber(arg2) | ||
for i= | local elm2 = elm | ||
for i=2,x do | |||
elm2 = elm2 .. elm | |||
end | end | ||
return | return elm2 | ||
end | end | ||
function utils.gradient(frame) | |||
local count1 = 2 | |||
local count2 = 2 | |||
local tab1 = frame.args[2] | |||
local tab2 = frame:getParent().args[2] | |||
local direction = frame.args[1] or frame:getParent().args[2] | |||
local arglist | |||
local argcount | |||
local range | |||
while tab1 ~= nil do | |||
tab1 = frame.args[count1] | |||
count1 = count1 + 1 | |||
end | |||
while tab2 ~= nil do | |||
tab2 = frame:getParent().args[count2] | |||
count2 = count2 + 1 | |||
end | |||
if count1 >= count2 then | |||
arglist = frame.args | |||
argcount = count1 - 2 | |||
else | |||
arglist = frame:getParent().args | |||
argcount = count2 - 2 | |||
end | |||
range = arglist[2] .. ", " | |||
for i=2,(argcount-1) do | |||
local x = string.format("%.1f",100 * ((i-1)/(argcount-1))).. "% " | |||
range = range .. arglist[i] .. " ".. x .. ", " | |||
range = range .. arglist[i + 1] .. " " .. x .. ", " | |||
end | |||
range = range .. arglist[argcount] .. " 100%" | |||
return "linear-gradient(to "..direction..", ".. range ..") no-repeat" | |||
end | |||
function utils.parentGradient(frame) | |||
local count = 1 | |||
local args = frame:getParent().args | |||
local direction = args["direction"] | |||
local param = args[1] | |||
while param ~= nil do | |||
count = count + 1 | |||
param = args[count] | |||
end | |||
local range = args[1] .. ", " | |||
for i=1,(count-2) do | |||
local x = string.format("%.1f",100 * ((i)/(count-1))).. "% " | |||
range = range .. args[i] .. " ".. x .. ", " | |||
range = range .. args[i + 1] .. " " .. x .. ", " | |||
end | |||
range = range .. args[count-1] .. " 100%" | |||
return "linear-gradient(to "..direction..", ".. range ..") no-repeat" | |||
end | |||
function utils.shadow(frame) | |||
local color = frame.args[1] or frame:getParent().args[1] or "#000" | |||
local x = {1,-1,-1,1,0,1,0,-1} | |||
local y = {1,1,-1,-1,-1,0,1,0} | |||
local tab = {} | |||
for i=1,8 do | |||
tab[i] = tostring(x[i]) .. "px " .. tostring(y[i]) .. "px " .. color | |||
end | |||
return table.concat(tab,",") | |||
end | |||
return utils | return utils |
Latest revision as of 16:37, 1 March 2023
Module:Repeat contains several utilities to avoid having to repeat code in multiple templates, these are:
big
This utility adds one or several <big> tags around an element to increase its size. Its syntax only takes 2 arguments, the first is the text you want to increase the size of and the 2nd is the number of big tags to add.
Example usage:
This text is going to be big
{{#invoke:Repeat|big|This text is going to be big|5}}
This text not so much
{{#invoke:Repeat|big|This text not so much|1}}
same
This utility simply repeats a given segment of wikitext the provided times, it takes 2 arguments, the first is the text to repeat and the second is the number of times to do so
Example usage:
Hello Hello Hello Hello Hello
{{#invoke:Repeat|same|Hello |5}}
Goodbye Goodbye Goodbye Goodbye Goodbye Goodbye Goodbye Goodbye Goodbye Goodbye Goodbye Goodbye Goodbye Goodbye Goodbye Goodbye Goodbye Goodbye Goodbye Goodbye
{{#invoke:Repeat|same|Goodbye |20}}
gradient
This utility creates a linear gradient with hard cutoffs, it takes 3 or more arguments, the first is the direction towards which the gradient should be and the following arguments are the colors of the gradient.
Example usage:
<div style="background: {{#invoke:Repeat|gradient|right|#E50000|#FF8D00|#FFEE00|#008121|#004CFF|#760188}}; width:500px;height:50px;"></div>
<div style="background: {{#invoke:Repeat|gradient|bottom left|#018E71|#21CFAB|#9AE9C3|#FFFFFF|#7CAFE4|#4F47CC|#3C1379}}; width:500px;height:50px;"></div>
parentGradient
Similar functionality to Gradient but always grabs arguments from the parent template, ("direction" and unlabled elements are grabbed)
Example usage:
<!-- Some template --> <span style="background: {{#invoke:Repeat|parentGradient}}>{{{Text}}}</span> <!-- Template usage --> {{Some Template | text = sample text | direction = right | #0ff | #f00 }}
shadow
This utility creates a text shadow of a specific color all around the text, it takes a single argument, the color of the shadow
Example usage:
<div style="text-shadow:{{#invoke:Repeat|shadow|#F00}}">Hello, Red World!</div>
<div style="text-shadow:{{#invoke:Repeat|shadow|#7851a9}}">Hello, Royal Purple!</div>
local utils = {}
function utils.big(frame)
local elm = frame.args[1] or frame:getParent().args[1]
local arg2 = frame.args[2] or frame:getParent().args[2]
local x = tonumber(arg2)
for i=1,x do
elm = "<big>" .. elm .. "</big>"
end
return elm
end
function utils.same(frame)
local elm = frame.args[1] or frame:getParent().args[1]
local arg2 = frame.args[2] or frame:getParent().args[2]
local x = tonumber(arg2)
local elm2 = elm
for i=2,x do
elm2 = elm2 .. elm
end
return elm2
end
function utils.gradient(frame)
local count1 = 2
local count2 = 2
local tab1 = frame.args[2]
local tab2 = frame:getParent().args[2]
local direction = frame.args[1] or frame:getParent().args[2]
local arglist
local argcount
local range
while tab1 ~= nil do
tab1 = frame.args[count1]
count1 = count1 + 1
end
while tab2 ~= nil do
tab2 = frame:getParent().args[count2]
count2 = count2 + 1
end
if count1 >= count2 then
arglist = frame.args
argcount = count1 - 2
else
arglist = frame:getParent().args
argcount = count2 - 2
end
range = arglist[2] .. ", "
for i=2,(argcount-1) do
local x = string.format("%.1f",100 * ((i-1)/(argcount-1))).. "% "
range = range .. arglist[i] .. " ".. x .. ", "
range = range .. arglist[i + 1] .. " " .. x .. ", "
end
range = range .. arglist[argcount] .. " 100%"
return "linear-gradient(to "..direction..", ".. range ..") no-repeat"
end
function utils.parentGradient(frame)
local count = 1
local args = frame:getParent().args
local direction = args["direction"]
local param = args[1]
while param ~= nil do
count = count + 1
param = args[count]
end
local range = args[1] .. ", "
for i=1,(count-2) do
local x = string.format("%.1f",100 * ((i)/(count-1))).. "% "
range = range .. args[i] .. " ".. x .. ", "
range = range .. args[i + 1] .. " " .. x .. ", "
end
range = range .. args[count-1] .. " 100%"
return "linear-gradient(to "..direction..", ".. range ..") no-repeat"
end
function utils.shadow(frame)
local color = frame.args[1] or frame:getParent().args[1] or "#000"
local x = {1,-1,-1,1,0,1,0,-1}
local y = {1,1,-1,-1,-1,0,1,0}
local tab = {}
for i=1,8 do
tab[i] = tostring(x[i]) .. "px " .. tostring(y[i]) .. "px " .. color
end
return table.concat(tab,",")
end
return utils