Module:Sandbox: Difference between revisions

From Fanon Wiki
mNo edit summary
mNo edit summary
 
(18 intermediate revisions by 2 users not shown)
Line 1: Line 1:
local p = {}
--Hey, this is a sandbox for Lua!
--Be careful :O


function p.main(frame)
local f = {}
local c1, c2, title
 
c1 = mw.text.trim(frame.args["color"]) or "#ff8100"
function f.main(frame)
c2 = mw.text.trim(frame.args["text"]) or "#000"
local description
title = frame.args["title"]
if frame.args["description"]=="" or frame.args["description"]==nil then description="No description provided [[Category:Files lacking description]]" else description=frame.args["description"] end
    local items = frame.args[1]
local type = mw.ustring.lower(frame.args["type"] or "")
    if items ~= nil then
local source
        items = mw.text.split(items, "\n")
if frame.args["source"]=="" or frame.args["description"]==nil then source="No source specified [[Category:Files lacking a source]]" else source=frame.args["source"] end
    else
local result = {}
        items = {}
local t = {}
    end
t = {
    local result = {}
    ['art'] = "Official artwork [[Category:Official artwork]]",
    table.insert(result, ' <div class="infobox" style="border-color: '.. c1 ..'"><div class="p-1 fs-2 mb-3 br-4 text-center" style="background:'.. c1 ..'; color: '.. c2 ..'; grid-column: span 4">'.. title ..'</div> ')
    --removing other types for testing purposes
    local i = 1
}
    local x = 1
    local y = 2
type = t[type] or "No type specified. [[Category:Files without a type specified]]"
    local item = {}
    local parents = {}
local license = mw.title.getCurrentTitle():getContent()
    local resultItems = ""
if license:find('%{%{License%-') then license = "" else license = "[[Category:Files without licenses]]" end
    local resultSection = ""
    local resultForm = ""
local panel = '<div class="panel" style="--panel-color: #c5c5c5"><div class="mb-2 panel-title">File information</div><table class="table-responsive"><tr><th class="p-2" style="background: #ff4242; color: #fff; border-radius: .5rem 0 0 0">Description</th><td class="p-2">'.. description ..'</td></tr><tr><th class="p-2" style="background: #4292ff; color: #fff">Type</th><td class="p-2" style="background: rgba(0,0,0,.12)">'.. type ..'</td></tr><tr><th class="p-2" style="background: #f5ff42; border-radius: 0 0 0 .5rem">Source/author</th><td class="p-2">'.. source ..'</td></tr></table></div>'.. license ..''
    while items[i] do
        item = mw.text.split(items[i], "/")
if mw.title.getCurrentTitle().namespace ~= 6 then panel = "Hey! The module does not spawn here because it's intended to be used on File pages only." end
        if item[2] and mw.text.trim(item[1]) ~= "" and mw.text.trim(item[2]) ~= "" then
            x = 1
table.insert(result, panel)
            resultItems = ""
return table.concat(result, "")
            while parents[x] do
                resultItems = resultItems .. parents[x]
                x = x + 1
            end
            y = 2
            resultSection = mw.text.trim(item[1])
            resultForm = mw.text.trim(item[2] or "N/A")
            resultExt = mw.text.trim(item[3] or "split")
           
            table.insert(result, '<div class="p-1 infobox-head infobox-'.. resultExt ..'" style="background:'.. c1 ..'; color:'.. c2 ..'">'.. resultSection ..'</div><div class="p-1 infobox-cell infobox-'.. resultExt ..'">'.. resultForm ..'</div>')
           
        end
        i = i + 1
    end
    table.insert(result, "</div>")
    return table.concat(result, "")
end
end


return p
return f

Latest revision as of 18:28, 11 November 2023

A sandbox for testing lua modules. Since this is a module, it uses actual programming code instead of wiki formatting.


--Hey, this is a sandbox for Lua!
--Be careful :O

local f = {}

function f.main(frame)
	local description
	if frame.args["description"]=="" or frame.args["description"]==nil then description="No description provided [[Category:Files lacking description]]" else description=frame.args["description"] end
	local type = mw.ustring.lower(frame.args["type"] or "")
	local source 
	if frame.args["source"]=="" or frame.args["description"]==nil then source="No source specified [[Category:Files lacking a source]]" else source=frame.args["source"] end
	local result = {}
	local t = {}
	t = {
	    ['art'] = "Official artwork [[Category:Official artwork]]",
	    --removing other types for testing purposes
	 }
	 
	type = t[type] or "No type specified. [[Category:Files without a type specified]]"
	
	local license = mw.title.getCurrentTitle():getContent()
	if license:find('%{%{License%-') then license = "" else license = "[[Category:Files without licenses]]" end
	
	local panel = '<div class="panel" style="--panel-color: #c5c5c5"><div class="mb-2 panel-title">File information</div><table class="table-responsive"><tr><th class="p-2" style="background: #ff4242; color: #fff; border-radius: .5rem 0 0 0">Description</th><td class="p-2">'.. description ..'</td></tr><tr><th class="p-2" style="background: #4292ff; color: #fff">Type</th><td class="p-2" style="background: rgba(0,0,0,.12)">'.. type ..'</td></tr><tr><th class="p-2" style="background: #f5ff42; border-radius: 0 0 0 .5rem">Source/author</th><td class="p-2">'.. source ..'</td></tr></table></div>'.. license ..''
	
	if mw.title.getCurrentTitle().namespace ~= 6 then panel = "Hey! The module does not spawn here because it's intended to be used on File pages only." end
	
	table.insert(result, panel)
	return table.concat(result, "")
end

return f