Module:Lua install/sandbox

-- Creates documentation for using or loading lua modules local docs = {} local getArgs = require("Dev:Arguments").getArgs local i18n = require("Dev:Lua install/i18n/sandbox") local html = mw.html local contentLanguage = mw.getContentLanguage:getCode

-- Entry point function docs.main(frame) local args = getArgs(frame) local source = args.source local uselang = args.uselang return docs.createDocs( source, uselang) end

--Creates docs --@parameters --source (string) : custom code to use module --uselang (string): localization for the module text stored in /i18n subpage function docs.createDocs(source, uselang) contentLanguage = uselang or contentLanguage local moduleName = tostring(mw.title.getCurrentTitle.subpageText or "") local nodeInstructions = mw.html.create("div") local messages, message_type, message_lang local messages = { "header", "install", "moduleuse", "loadingmodules", "creatingtemplate", "articleuse" }   for key, value in ipairs(i18n) do        message = mw.text.split(key, key) message_type = message[3] message_lang = message[4] createInstructions(instruction,code,heading, lang) end

local nodeOtherInstructions = mw.html.create("div") nodeInstructions :node(nodeDefaultInstructions) nodeOtherInstructions:node(nodeMetaDoc1) :node(nodeTemplatetInstructions) :node(nodeMetaDoc2) if source then local nodeOtherDocs = createInstructions("Other instructions",source, "Other information") nodeOtherInstructions:node(nodeOtherDocs, nodeOtherDocs) end local fullInstructions = tostring(nodeHeader) .. tostring(createCollapse(nodeInstructions,nodeOtherInstructions)) return fullInstructions end -- creates a simple header (makes it easier to understand code and style differently) function createHeader(text) local header = html.create("h2") return tostring(header:wikitext(text)) end -- Creates instructions along with the code and heading function createInstructions(instruction,code,heading, lang) local createTag = mw.html.create local nodeContainer = createTag("div") local nodeHeader = createTag("h3") local nodeCode = createTag("div") local nodeInstruction = createTag("div") local styles = { clear = "both", margin= "1em auto", ["border-left"]= "10px solid #228b22", ["border-right"]= "10px solid #228b22", ["border-radius"] ="10px", ["background-color"] = "rgb(242, 242, 242)" }   for style,attribute in pairs(styles) do        nodeContainer:css(style,attribute) end local moduleName = tostring(mw.title.getCurrentTitle.subpageText or "") instruction = instruction:gsub("$1","Module:" .. moduleName) instruction = instruction:gsub("$2","Template:".. moduleName) code = code:gsub("$3",moduleName) nodeHeader:css("text-align","center") nodeHeader:wikitext(heading) nodeInstruction:wikitext(instruction) nodeCode:wikitext(preprocess( [[ "))   nodeContainer:node(nodeHeader)    nodeContainer:node(nodeInstruction)    nodeContainer:node(nodeCode)    return nodeContainer end

function createCollapse(displayed, collapsed) local collapsedDiv = mw.html.create("div") collapsedDiv:addClass("mw-collapsible mw-collapsed") :wikitext(tostring(displayed)) collapsedDiv:tag("div") :addClass("mw-collapsible-content") :wikitext(tostring(collapsed)) return collapsedDiv end -- useful for debugging and testing in console. function preprocess(text) if mw.getCurrentFrame then return mw.getCurrentFrame:preprocess(text) end return text end return docs