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; ' local pagename = mw.title.getCurrentTitle.fullText

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), ' ', 			#t ~= 0 and '(' or , 			ret, 			#t ~= 0 and ')' or , ' ',		}	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-top'] = '1.3px solid black'; ['border-left'] = '1.3px solid black'; ['border-right'] = '1.3px solid black'; ['border-bottom'] = 'none'; ['margin'] = '4px 4px 0 4px'; ['box-shadow'] = '0 0 2px black'; }			: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') :attr{ id="header" } :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.docObj.exists 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 :tag('div') :css{ ['background-color'] = 'rgba(120,120,120,0.05)'; ['box-shadow'] = '0 0 2px black'; ['border-bottom'] = 'none'; ['border-top'] = 'none'; ['padding'] = '0.5em'; ['margin'] = '0 4px 0 4px'; ['border-right'] = '1.3px solid black'; ['border-left'] = '1.3px solid black'; }			:wikitext(				self.docObj.exists and					self.docObj:getContent				or					table.concat{ 						string.wrapHtml{							'The documentation for this module does not exist. Please create it if you are familiar with this module. ',							' ', {								class="error"							},						},						string.wrapTag({ '(', string.fullUrl(self.doc, self.createDocQuery, 'create'), ')', }, 'strong'),					}			) :tag('span') :css{ display="none" } :wikitext(, self.doc, ) :done :done :tag('div') :addClass('color1') :css{ ['padding'] = '2px'; ['border-left'] = '1.3px solid black'; ['border-right'] = '1.3px solid black'; ['border-bottom'] = '1.3px solid black'; ['border-top'] = 'none'; ['margin'] = '0 4px 4px 4px'; ['box-shadow'] = '0 0 2px black'; }			:tag('span') :css{ ['font-size']='20px'; ['margin']='5px'; }				:wikitext('(', string.makeLink('Module:Documentation', 'How does this work?'), ')') :done :tag('span') :css{ ['margin-left']='27%'; }				:wikitext(string.wrapTag('Other Tools: ', 'b')) :wikitext(					self:exists(self.testcases) 						and self:linksToList(self.links.testcases[1]) 						or self:parseLinkEntry(self.links.testcases[2], true)				) :done :tag('span') :css{ float='right'; ['font-style']='italic'; }				:wikitext('(', string.makeLink('#header', 'back to top'), ')') :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.sandbox = table.concat{ self.title, '/sandbox' } self.testcases = table.concat{ self.title, '/testcases' } self.doc = table.concat{ self.title, '/doc' } self.titleObj = mw.title.new(self.title) self.titleExists = self.titleObj.exists self.talkObj = self.titleObj.talkPageTitle self.sandboxObj = mw.title.new(self.sandbox) self.testcasesObj = mw.title.new(self.testcases) self.docObj = mw.title.new(self.doc) self.talk = self.titleObj.talkPageTitle.fullText self.html = mw.html.create('div') self.createDocQuery = { action='edit', redlink=1, minor=1, useeditor="source", preload='Template:LuaDocumentation/preload/doc', editintro='Template:LuaDocumentation/editintro/doc', 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=self.title, 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=self.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" }}, },		{			main={ self.talk, 'Create talk', 'Create the talk page for this module', query={ action='edit', redlink=1, minor=1, useeditor="source", preload='Template:LuaDocumentation/preload/talk', editintro='Template:LuaDocumentation/editintro/talk', summary=table.format{ 'Creating talk page for module \"%s\"', self.title }, }			},		},	}	self.links.moduleLinks = { { alt=self:linksToList(self.links.talk[self.talkObj.exists and 1 or 2]) }, { 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', }, }	self.links.testcases = { {			 main={ self.testcases, 'Testcases', 'View the testcases subpage for this module' }, { self.testcases, 'edit', 'Edit the testcases subpage for this module' }, { self.testcases, 'latest diff', 'Edit the testcases subpage for this module' }, self.testcasesObj.talkPageTitle.exists and { self.testcasesObj.talkPageTitle.fullText, 'run', 'Run the testcases subpage for this module' } or { self.testcasesObj.talkPageTitle.fullText, 'create', 'Create the testcases results subpage for this module', query={ action='edit', redlink=1, minor=1, useeditor="source", preload='Template:LuaDocumentation/preload/testcasesResults', editintro='Template:LuaDocumentation/editintro/testcasestestcasesResults', summary=table.format{ 'Creating testcases results page for module \"%s\"', self.title }, },				},		},		{ 			self.testcases, 'Create testcases', 'Create the testcases subpage for this module', query={ action='edit', redlink=1, minor=1, useeditor="source", preload='Template:LuaDocumentation/preload/testcases', editintro='Template:LuaDocumentation/editintro/testcases', summary=table.format{ 'Creating testcases subpage for module \"%s\"', self.title }, }		}	}	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