17 214
contributi
(Added new functions *** sovrascritto il testo esistente ***) |
|||
local w = require('Modulo:Wikilib')
local c = mw.loadData('Modulo:Colore/data')
--[[
vendorMappings.gradient = {
moz = {
['to right'] = 'left'
},
webkit = {
['to right'] = 'left'
}
}
-- All linear gradient function names
local linearGradientsFunctions = {
'-moz-linear-gradient',
'-webkit-linear-gradient',
'linear-gradient'
}
-- Holds all kinds of wikicode input processing
local processInput = {}
--[[
Returns a list of color hexes from
a table of couples: first one is the
color name, second one the shade
(defaulting to normal)
--]]
processInput.parseCouples = function(args)
local name = table.remove(args, 1)
local shade = table.remove(args, 1)
shade = (shade == '' or shade == nil)
and 'normale'
or shade
if #args == 0 then
return c[name][shade]
end
return c[name][shade], processInput.parseCouples(args)
end
--[[
requested color hexes.
Can take an arbitrary number of
arguments,
organized in couples: first the color
name, then the shade (if the shade
is empty
If the first argument isn't a known
color, all arguments are assumed to
be hexes.
For two-color cases, there are special
rules: empty color name or shade default
to their counterpart of the first color.
--]]
processInput.gradient = function(args)
local p = w.trimAll(args,
-- Colore/data indexing fails, assuming hexes
if not c[p[1]] then
return unpack(p
end
-- Two-color case special rules
if #p < 5 then
p = w.emptyStringToNil(p, string.lower)
name = p[
local to = {
name = p[3] or from.name,
shade = p[4] or from.shade
}
return c[from.name][from.shade], c[to.name][to.shade]
end
-- Standard behavior
return processInput.parseCouples(args)
end
-- Generates styles for linear gradients
styles.gradient.linear = function(conf,
-- Grouping variadic and adding # to hexes
local colors = table.map({...}, function(hex)
return hex:find('#') and hex or '#' .. hex
end)
-- Accumulator table
local css = {'background-size: 100%'}
for _, funct in pairs(linearGradientsFunctions) do
-- Cloning due to later table.insert
local gradientArgs = mw.clone(colors)
if conf then
local prefix = funct:match('^%-(%a+)%-')
local conf = prefix
and vendorMappings.gradient[prefix][conf]
or conf
table.insert(gradientArgs, 1, conf)
end
gradientArgs = table.concat(gradientArgs, ', ')
table.insert(css, table.concat{'background-image: ',
funct, '(', gradientArgs , ')'})
end
return table.concat(css, '; ') .. ';'
end
-- Generates horizontal linear gradients styles
css.horizGradLua = function(
return styles.gradient.linear('to right',
processInput.gradient(
end
css.horiz_grad_lua = css.horizGradLua
-- Generates vertical linear gradients styles
css.vertGradLua = function(...)
return styles.gradient.linear(nil,
processInput.gradient({...}))
end
css.vert_grad_lua = css.vertGradLua
--[[
--]]
css['vert-grad'] = function(frame)
return styles.gradient.linear(
processInput.gradient(mw.clone(frame.args)))
end
|
contributi