Jump to content
Toggle menu
  • 1 articles
  • 7 files
  • 3 users
  • 102 edits
Shroudforge
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

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

require('strict')

local p = {}

local libraryUtil = require('libraryUtil')
local checkType = libraryUtil.checkType
local checkTypeForNamedArg = libraryUtil.checkTypeForNamedArg

--- @class DetailsData
--- @field summary DetailsSummaryData The summary of the details.
--- @field details DetailsDetailsData The details of the details.

--- @class DetailsSummaryData
--- @field content string The content of the summary.
--- @field class string|nil An additional HTML class for the summary. Optional.

--- @class DetailsDetailsData
--- @field content string The content of the details.
--- @field class string|nil An additional HTML class for the details. Optional.
--- @field open boolean|nil Whether the details are open by default. Defaults to true.

--- Get the wikitext for the details element
---
--- @param data DetailsData
--- @param frame mw.frame|nil The frame object to use. Defaults to the current frame.
--- @return string
function p.getWikitext(data, frame)
	frame = frame or mw.getCurrentFrame()

	checkType('Module:Details.getWikitext', 1, data, 'table')
	checkTypeForNamedArg('Module:Details.getWikitext', 'summary', data.summary, 'table')
	checkTypeForNamedArg('Module:Details.getWikitext', 'details', data.details, 'table')
	checkType('Module:Details.getWikitext', 2, frame, 'table')

	local summary = frame:extensionTag({
		name = 'summary',
		content = data.summary.content,
		args = {
			class = data.summary.class,
		},
	})
	local details = frame:extensionTag({
		name = 'details',
		content = summary .. data.details.content,
		args = {
			class = data.details.class,
			-- Boolean does not work with Extension:Details, has to be 'yes' or 'no'
			open = data.details.open ~= false and 'yes' or 'no',
		},
	})
	return details
end

return p
Last modified
Copyright