Module:Side box

From Wikimedia Commons, the free media repository
Jump to navigation Jump to search
Lua
CodeDiscussionEditHistoryLinksLink count Subpages:DocumentationTestsResultsSandboxLive code All modules

Documentation for this module may be created at Module:Side box/doc

Code

-- This module implements {{side box}}.

local yesno = require('Module:Yesno')

local p = {}

function p.main(frame)
	local origArgs = frame:getParent().args
	local args = {}
	for k, v in pairs(origArgs) do
		v = v:match('%s*(.-)%s*$')
		if v ~= '' then
			args[k] = v
		end
	end

	return p.renderSidebox(args)
end

function p.renderSidebox(data)
	-- Renders the sidebox HTML.
	-- Element root
	local root = mw.html.create('table')
	root:addClass('messagebox')
	root:addClass('noresize')
	if yesno(data.metadata) ~= false then
		-- For compatibility with MediaWiki:Common.css and the many user styles that opt-in to it,
		-- this element must a table, not a div.
		root:addClass('metadata')
	end
	root:addClass(data.class)
	root:css{clear = 'right', float = 'right', width = '238px'}
	if data.style then
		root:cssText(data.style)
	end

	-- The body row
	local bodyRow = root:newline():tag('tr'):newline()
	local textCell = bodyRow:newline():tag('td')
	textCell:addClass('plainlist')
	if data.textstyle then
		textCell:cssText(data.textstyle)
	end
	textCell:wikitext(data.text)

	root:newline()

	return tostring(root)
end

return p