Die Seite wurde neu angelegt: „local argutils = require("Module:Arguments") local M = {} local function build_image(args) local figure = mw.html.create("figure") figure:addClass("infobox__image") if args.image then figure:wikitext(args.image) end if args.caption then local caption = mw.html.create("figcaption") caption:addClass("infobox__image-caption") caption:wikitext(args.caption) figure:node(caption) end return figure end local function build_main_section…“
 
KKeine Bearbeitungszusammenfassung
Zeile 96: Zeile 96:


local function build(args)
local function build(args)
local wrapper = mw.html.create("aside")
local wrapper = mw.html.create("div")
wrapper:attr("role", "aside")
wrapper:addClass("infobox")
wrapper:addClass("infobox")

Version vom 17. September 2024, 21:14 Uhr

Die Dokumentation für dieses Modul kann unter Modul:Infobox/Doku erstellt werden

local argutils = require("Module:Arguments")

local M = {}

local function build_image(args)
	local figure = mw.html.create("figure")
	figure:addClass("infobox__image")
	
	if args.image then
		figure:wikitext(args.image)	
	end
	
	if args.caption then
		local caption = mw.html.create("figcaption")
		caption:addClass("infobox__image-caption")
		caption:wikitext(args.caption)
		figure:node(caption)
	end
	
	return figure
end

local function build_main_section(args)
	local section = mw.html.create("div")
	section:addClass("infobox__section")
	
	if args.header ~= nil then
		local header = mw.html.create("h1")
		header:addClass("infobox__header")
		header:wikitext(args.header)
		section:node(header)
	end
	
	if args.subheader ~= nil then
		local subheader = mw.html.create("h2")
		subheader:addClass("infobox__header")
		subheader:wikitext(args.subheader)
		section:node(subheader)
	end
	
	if args.images ~= nil then
		for _, image_args in ipairs(args.images) do
			section:node(build_image(image_args))
		end
	end
	
	return section
end

local function build_section_entry(args)
	if type(args) == "string" then
		local div = mw.html.create("div")
		div:addClass("infobox__section-entry")
		div:wikitext(args)
		return div
	else
		local dl = mw.html.create("dl")
		dl:addClass("infobox__section-entry")
		
		if args.label ~= nil then
			local dt = mw.html.create("dt")
			dt:addClass("infobox__section-entry-label")
			dt:wikitext(args.label)
			dl:node(dt)
		end
		if args.text ~= nil then
			local dd = mw.html.create("dd")
			dd:addClass("infobox__section-entry-text")
			dd:wikitext(args.text)
			dl:node(dd)
		end
		
		return dl
	end
end

local function build_section(args)
	local section = mw.html.create("div")
	section:addClass("infobox__section")
	
	if args.header ~= nil then
		local header = mw.html.create("h2")
		header:addClass("infobox__header")
		header:wikitext(args.header)
		section:node(header)
	end
	
	if args.entries ~= nil then
		for _, entry_args in ipairs(args.entries) do
			section:node(build_section_entry(entry_args))
		end
	end
	
	return section
end

local function build(args)
	local wrapper = mw.html.create("div")
	wrapper:attr("role", "aside")
	wrapper:addClass("infobox")
	
	wrapper:node(build_main_section(args))
	if args.sections ~= nil then
		for _, section_args in ipairs(args.sections) do
			wrapper:node(build_section(section_args))	
		end
	end
	
	return wrapper
end

function M.render(frame)
	local parentFrame = frame:getParent() or {}
	local flat_args = parentFrame.args or {}
	local args = argutils.parse_deep(flat_args)
	return tostring(build(args))
end

return M