Module:Documentation

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

-- <nowiki>
local p = {}

function p.docs(frame)
    local title = mw.title.getCurrentTitle()
    local docTitle = title.fullText .. '/doc'
    -- THIS IS EXPENSIVE
    local docs = mw.title.new(docTitle)
    local html = mw.html.create('div'):addClass('template-documentation')
    -- Links
    local editLink =  tostring(docs:fullUrl({ action = 'edit' }))
    local historyLink = tostring(docs:fullUrl({ action = 'history' }))
    local purgeLink = tostring(title:fullUrl({ action = 'purge' }))
    if docs.exists then
        html:tag('div')
                :addClass('template-documentation__header')
                :tag('div')
                    :addClass('template-documentation__title')
                    :wikitext('[[/doc|Template documentation]]')
                :done()
                :tag('div')
                    :addClass('template-documentation__buttons')
                    :wikitext(
                        '[[' .. editLink .. ' edit] • [' .. historyLink ..
                        ' history] • [' .. purgeLink .. ' purge]]'
                    )
                :done()
            :done()
            :tag('div')
                :addClass('template-documentation__contents')
                :wikitext(docs:getContent())
            :done()
    else
        html:tag('div')
            :addClass('template-documentation__error')
            :wikitext(
                'This template has no documentation! Click [' .. editLink ..
                ' here] to create it or [' .. purgeLink ..
                ' here] to purge the current page after the documentation has been created'
            )
            :done()
    end
    return tostring(html:done())
end

function p.page(frame)
    local args = frame:getParent().args
end

return p