Module:Documentation

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

--Load Modules loadLib(_G)

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

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

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

function Doc:exists(title) return mw.title.new(title).exists end

function Doc:parseLinkEntry(t2, isMain) t2[1] = string.parseDualArg(t2[1]) local val local title = string.makeTitle(t2[2] or '', 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:exists(self.sandbox) and self:linksToList(self.links.sandbox) or self:parseLinkEntry(self.createSandbox, true),						}, self:linksToList(self.links.tools, true)), sep)					) :done :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('Module Links: ', 'b'), 						self:linksToList(self.links.moduleLinks, true)					) :done :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.titleExists = self:exists(self.title) self.titleObj = mw.title.new(self.title) self.sandbox = table.concat{ self.title, '/sandbox' } self.doc = table.concat{ self.title, '/doc' } self.talk = self.titleObj.talkPageTitle.fullText 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 = {} 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" }}, }	}	self.links.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"; } }			}, 		},	}	self.links.tools = { { { 'Special:PrefixIndex/', self.title, '/' }, 'View subpages', 'View the subpages of this Module' }, { { 'Special:WhatLinksHere/', self.title, }, 'View links', 'View what links here to this Module' }, }	self.links.talk = { {			main={ self.talk, 'Talk' }, prepend={ self.talk, '+', 'Add a new section to the module\'s talk page', query={ action="edit", section="new" }}, { self.talk, 'edit', 'Edit the module\'s talk page', query={ action="edit" }}, { self.talk, 'latest diff', 'View the latest edit\'s diff on the module\'s talk page', query={ diff="cur" }}, { self.talk, 'hist', 'View the history on the module\'s talk page', query={ action="history" }}, },		{		},	}	self.links.moduleLinks = { { alt=self:linksToList(self.links.talk[1]) }, { self.title, 'Latest Diff', 'View the latest edit\'s diff on the module', query={ diff="cur" }}, { { 'Special:Log/', self.title }, 'Page Logs', 'View the logs for this page', }, }	return self:buildMainBox end

--Create Class Doc = table.makeClass(Doc, nil, nil, { ignore=true })

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

--Finish Module/Exports return Doc