Module:Documentation

--Load loader function local loadLib = require('Module:LoadLib')

--Load Modules loadLib(_G)

--Begin Exports local p = {} local Doc = {} local nowiki = mw.text.nowiki local lb, rb = nowiki('['), nowiki(']') local sep = ' &bull; '

function Doc:linksToList(t) local ret = {} local t2 = {}

for i, v in ipairs(t) do		table.push(ret, self:parseLinkEntry(v, t.main)) end ret = table.concat(ret, sep) if t.main then ret = table.concat{ self:parseLinkEntry(t.main, true), ' (', ret, ') ' } end return ret end

function Doc:parseLinkEntry(t2, isMain) local val local title = string.makeTitle(t2[2], t2[3], { disableAbbr=true }) if t2.query then val = string.fullUrl(t2[1], t2.query or {}, title) else val = string.makeLink(t2[1], title) end return isMain and (t2.alt or val) or table.concat{ lb, val, rb } end

function Doc:buildMainBox self.html :css{ ['font-family']='Arial !important'; }		:tag('div') :addClass('color1') :css{ ['padding'] = '2px'; ['border'] = '1.3px solid black'; ['margin'] = '4px'; ['box-shadow'] = '0 0 2px black'; ['border-bottom'] = 'none'; ['margin-bottom'] = 0; }			:tag('span') :css{ ['float'] = 'right'; ['font'] = 'italic small arial'; }				:wikitext('(', string.makeLink('#module-code', string.makeTitle('jump to code', "Jump to the code of this module", { disableAbbr=true })), ')')			:done :tag('span') :css{ float="left"; }				:wikitext(string.makeImage('Template Info Icon.svg', { link='', size=60 })) :done :tag('span') :css{ ['font'] = 'bold x-large arial'; ['margin-left'] = '7px'; ['text-align'] = 'center'; }				:wikitext(self.type, ' Documentation') :done :tag('span') :css{ ['margin-left']='7px'; }				:wikitext(self:linksToList(self.titleExists and self.links.pageTools[1] or self.links.pageTools[2])) :done :tag('hr') :addClass('page-header__separator') :css{ ['background-color'] = '#daa9ad'; ['border'] = 0; ['height'] = '1px'; ['margin-bottom'] = '3px'; ['margin-top'] = 0; ['width'] = '100%'; }			:done :tag('div') :tag('p') :css{ margin=0; }					:wikitext(						string.wrapTag('Page Tools: ', 'b'), 						table.concat(table.merge({							self.titleExists and self:linksToList(self.links.sandbox) or self:parseLinkEntry(self.createSandbox, true)						}, self.links.tools), sep2)					) :done :done :done local mt = { __tostring = function return tostring(self.html) end, __concat = function(a, b)			if a == self.html then return tostring(a)..b			else return tostring(b)..a			end end }	return setmetatable({ self.html }, mt) end

function Doc:constructor(title, _type) checkType(true, 1, title, 'string', true) checkType(true, 2, _type, 'string', true) self.title = title or 'Sandbox' self.type = string.ucfirst(_type or 'Module') self.title = table.concat{ self.type, ':', (self.title:gsub(table.concat{ '^', self.type, ':?' }, '')) } self.doc = table.concat{ self.title, '/doc' } self.titleExists = mw.title.new(self.title).exists self.sandbox = table.concat{ self.title, '/sandbox' } self.html = mw.html.create('div') local createDocQuery = { action='edit', redlink=1, minor=1, useeditor="source", preload='Template:LuaDocumentation/preload', editintro='Template:LuaDocumentation/editintro', summary=table.format{ "Creating Module Documenation for \"%s\"", self.doc }; }	self.createSandbox = { self.sandbox, string.makeTitle('Create Sandbox', 'Create the sandbox subpage for this module', { disableAbbr=true }), query = { action="edit", redlink=1, minor=1, useeditor="source", preload="Template:LuaDocumentation/preload", editintro="Template:LuaDocumentation/editintro", summary=table.format{ "Creating Sandbox Module for \"%s\"", self.doc }; }	}	self.links = { pageTools = { {				{ self.doc, 'view', 'View the Documentation subpage for this module', }, { self.doc, 'edit', 'Edit the Documentation subpage for this module', query={ action='edit' }}, { self.doc, 'latest diff', 'View the diff on the latest Edit to the Documentation subpage for this module', query={ diff='cur' }}, { self.doc, 'hist', 'View the history of this module\'s documentation subpage', query={ action='history' }}, { self.title, 'purge', 'Purge this page', query={ action="purge" }}, },			{				{ self.doc, 'create', 'Create the Documentation for this module', query=createDocQuery }, { self.title, 'purge', 'Purge this page', query={ action="purge" }}, }		},		sandbox = { main={ self.sandbox, 'Sandbox' }, { self.sandbox, 'edit', 'Edit the sandbox module', query={ action="edit" }}, { self.sandbox, 'latest diff', 'View the latest edit\'s diff on the sandbox module', query={ diff="cur" }}, { self.sandbox, 'hist', 'View the history on the sandbox module', query={ action="history" }}, alt=string.wrapHtml{ "reset", " ", attrs={ title="Reset the sandbox module to match the main module", id="re-mirror-sandbox", style={ cursor="pointer"; } }			},		},	}	return self:buildMainBox end

function Doc.main(frame) local args = getArgs(frame) return Doc:constructor(table.unpack(args)) end

Doc.main = { 'static', Doc.main }

--Finish Module/Exports return table.makeClass(Doc, nil, nil, { ignore=true })