Module:LuaLink: Difference between revisions
From Polcompball Wiki
Jump to navigationJump to search
Content added Content deleted
(Created page with "local utils = {} local function emptyCheck(value) if value == nil then return false elseif value == "" then return false elseif value == {} then return false else return true end end local function parseIcons(params, link) local left, right, i = "", "", 1 while emptyCheck(params["icon" .. i]) do local icon = "[[File:" .. params["icon" .. i] .. "|link=" .. link .. "]]" if i % 2 == 0 then...") |
No edit summary |
||
Line 49: | Line 49: | ||
function utils.user(frame) |
function utils.user(frame) |
||
local |
local parentArgs = frame:getParent().args |
||
local name = parentArgs[1] |
|||
local users = mw.loadData("Module:LuaLink/users") |
local users = mw.loadData("Module:LuaLink/users") |
||
Line 56: | Line 57: | ||
local page, disp |
local page, disp |
||
if emptyCheck( |
if emptyCheck(parentArgs[2]) then |
||
page = |
page = parentArgs[2] |
||
else |
else |
||
page = "User:" .. name |
page = "User:" .. name |
||
end |
end |
||
if emptyCheck( |
if emptyCheck(parentArgs[3]) then |
||
disp = |
disp = parentArgs[3] |
||
elseif emptyCheck( |
elseif emptyCheck(parentArgs[2]) then |
||
disp = page |
disp = page |
||
elseif emptyCheck(params["nick"]) then |
elseif emptyCheck(params["nick"]) then |
||
Line 79: | Line 80: | ||
function utils.category(frame) |
function utils.category(frame) |
||
local |
local parentArgs = frame:getParent().args |
||
local name = parentArgs[1] |
|||
local cats = mw.loadData("Module:LuaLink/categories") |
local cats = mw.loadData("Module:LuaLink/categories") |
||
Line 86: | Line 88: | ||
local disp, page = nil, ":Category:" .. name |
local disp, page = nil, ":Category:" .. name |
||
if emptyCheck( |
if emptyCheck(parentArgs[2]) then |
||
disp = |
disp = parentArgs[2] |
||
elseif emptyCheck(params["nick"]) then |
elseif emptyCheck(params["nick"]) then |
||
disp = params["nick"] |
disp = params["nick"] |
||
Line 101: | Line 103: | ||
function utils.ideology(frame) |
function utils.ideology(frame) |
||
local |
local parentArgs = frame:getParent().args |
||
local name = parentArgs[1] |
|||
local ideo = mw.loadData("Module:LuaLink/ideologies") |
local ideo = mw.loadData("Module:LuaLink/ideologies") |
||
Line 108: | Line 111: | ||
local disp |
local disp |
||
if emptyCheck( |
if emptyCheck(parentArgs[2]) then |
||
disp = |
disp = parentArgs[2] |
||
elseif emptyCheck(params["nick"]) then |
elseif emptyCheck(params["nick"]) then |
||
disp = params["nick"] |
disp = params["nick"] |
Revision as of 20:18, 18 March 2023
The LuaLink module contains several functions to create user/ideology/category links that do not require the creation of a dedicated template.
user
category
ideology
local utils = {}
local function emptyCheck(value)
if value == nil then
return false
elseif value == "" then
return false
elseif value == {} then
return false
else
return true
end
end
local function parseIcons(params, link)
local left, right, i = "", "", 1
while emptyCheck(params["icon" .. i]) do
local icon = "[[File:" .. params["icon" .. i] .. "|link=" .. link .. "]]"
if i % 2 == 0 then
right = icon .. right
else
left = left .. icon
end
i = i + 1
end
return {left, right}
end
local function createElement(name, params, page, disp)
local color, style = "#000", ""
if emptyCheck(params["color"]) then
color = params["color"]
end
if emptyCheck(params["style"]) then
style = params["style"]
end
style = "color: " .. color .. "; " .. style
local icons = parseIcons(params, page)
local coreLink = "[[" .. page .. '|<span style="' .. style .. '"> ' .. disp .. "</span>]]"
return "'''" .. icons[1] .. coreLink .. icons[2] .. "'''"
end
function utils.user(frame)
local parentArgs = frame:getParent().args
local name = parentArgs[1]
local users = mw.loadData("Module:LuaLink/users")
local params = users[name]
if emptyCheck(params) then
local page, disp
if emptyCheck(parentArgs[2]) then
page = parentArgs[2]
else
page = "User:" .. name
end
if emptyCheck(parentArgs[3]) then
disp = parentArgs[3]
elseif emptyCheck(parentArgs[2]) then
disp = page
elseif emptyCheck(params["nick"]) then
disp = params["nick"]
else
disp = name
end
return createElement(name, params, page, disp)
else
return "Invalid user"
end
end
function utils.category(frame)
local parentArgs = frame:getParent().args
local name = parentArgs[1]
local cats = mw.loadData("Module:LuaLink/categories")
local params = cats[name]
if emptyCheck(params) then
local disp, page = nil, ":Category:" .. name
if emptyCheck(parentArgs[2]) then
disp = parentArgs[2]
elseif emptyCheck(params["nick"]) then
disp = params["nick"]
else
disp = name
end
return createElement(name, params, page, disp)
else
return "Invalid category"
end
end
function utils.ideology(frame)
local parentArgs = frame:getParent().args
local name = parentArgs[1]
local ideo = mw.loadData("Module:LuaLink/ideologies")
local params = ideo[name]
if emptyCheck(params) then
local disp
if emptyCheck(parentArgs[2]) then
disp = parentArgs[2]
elseif emptyCheck(params["nick"]) then
disp = params["nick"]
else
disp = name
end
return createElement(name, params, name, disp)
else
return "Invalid ideology"
end
end
return utils