Module:Infobox
From Portals of Phereon Wiki
Documentation for this module may be created at Module:Infobox/doc
local p = {};
local cargo = mw.ext.cargo;
local utils = require( "Module:Utils" );
function p.infobox(frame)
local args = frame.args["args"] or "";
args = utils.toTable(args,'=',';','');
local theme = frame.args["theme"] or "default";
local theme_source = frame.args["theme-source"];
local itype = frame.args["type"];
local accent_color_source = frame.args["accent-color-source"];
local accent_color_default = frame.args["accent-color-default"];
local accent_color_text_source = frame.args["accent-color-text-source"];
local accent_color_text_default = frame.args["accent-color-text-default"];
local style = "";
local layout = frame.args["layout"] or "default";
local name = frame.args["name"];
local infobox = mw.html.create("aside"):addClass("portable-infobox noexcerpt pi-background"):addClass("pi-layout-"..layout);
if (theme_source == nil) then infobox:addClass("pi-theme-"..theme); else infobox:addClass("pi-theme-"..args[theme_source]); end
if (itype ~= nil) then infobox:addClass("pi-type-"..itype); end
if (accent_color_source ~= nil) then style = "background-color:"..args[accent_color_source]..";";
elseif (accent_color_default ~= nil) then style = "background-color:"..accent_color_default..";"; end
if (accent_color_text_source ~= nil) then style = style .. "color:"..args[accent_color_text_source]..";";
elseif (accent_color_text_default ~= nil) then style = style .. "color:"..accent_color_text_default..";"; end
if (style ~= "") then infobox:attr("style",style); end
if (name ~= nil) then infobox:attr("data-item-name",name); end
for i = 1, 100, 1 do
if (frame.args[i] == nil) then break end
local elem = utils.toTable(frame.args[i],'=',';','');
if (elem["type"] == "title") then
infobox:node(title(elem,args)):done();
end
end
return tostring(infobox);
end
function title(elem,args)
local source = elem["source"];
local default = elem["default"];
local title = mw.html.create("h2"):addClass("pi-item pi-item-spacing pi-title pi-secondary-background");
if (source ~= nil and args[source] ~= nil) then
title:wikitext(args[source]);
elseif (default ~= nil) then
title:wikitext(default);
end
return title;
end
--=p.infobox(mw.getCurrentFrame():newChild{title="whatever",args={["args"]="Name=test",["type"]="wtf","type=title;default={{{PAGENAME}}};source=Name"}})
return p