Module:文档

来自植物大战僵尸百科
跳转到导航 跳转到搜索
{{🛈}}模組文檔[查看] [編輯] [歷史] [清除缓存]此文档嵌入自Module:文档/文档

本模組用於{{文檔}},用法見其文檔。

模组内容

doc

本模組的返回值。

doc.main(frame)
從框架對象frame接收參數並傳遞至doc._main,返回其結果。
doc._main(args)
接收參數表args並返回說明文檔結果。
local doc = {}
local ts = require('Module:参数').loadData('Module:文档/参数')
local getArgs = require('Dev:Arguments').getArgs

function doc.main(frame)
    local args = getArgs(frame, { wrappers = { "Template:文档" } })
    return doc._main(args)
end

function doc._main(args)
    local title = mw.title.getCurrentTitle()
    local namespace = ''
    if title:inNamespace('Template') then
        namespace = ts:msg('模板')
    end
    if title:inNamespace('Module') then
        namespace = ts:msg('模組')
    end
    local documentation = mw.html.create('div'):addClass('documentation')
    local header = documentation:tag('div'):addClass('documentation-header')
        :tag('span'):node('{{🛈}}'):done()
        :tag('span'):node(ts:msg('文檔', namespace)):done()
    local links = header:tag('span'):addClass('documentation-editlinks')
    local inner = ts:parameter('內容', args)
    local docName = args[1] or ts:msg('文檔頁面', title.text)
    local docTitle = mw.title.new(docName, 'Template')
    local docExists = docTitle.exists
    if inner then
        links :node('[')
            :node(mw.text.tag('span', { title = ts:msg('內聯編輯') },
                string.format('[%s %s]', title:fullUrl({ action = 'edit' }), ts:msg('編'))))
            :node(']')
    elseif docExists then
        links :node('[')
            :node(mw.text.tag('span', { title = ts:msg('查看') },
                string.format('[[%s|%s]]', docTitle.fullText, ts:msg('閱'))))
            :node('] [')
            :node(mw.text.tag('span', { title = ts:msg('編輯') },
                string.format('[[Special:EditPage/%s|%s]]', docTitle.fullText, ts:msg('編'))))
            :node('] [')
            :node(mw.text.tag('span', { title = ts:msg('歷史') },
                string.format('[[Special:PageHistory/%s|%s]]', docTitle.fullText, ts:msg('史'))))
            :node('] [')
            :node(mw.text.tag('span', { title = ts:msg('清除') },
                string.format('[[Special:Purge/%s|%s]]', title.fullText, ts:msg('清'))))
            :node(']')
    else
        links :node('[')
            :node(mw.text.tag('span', { title = ts:msg('建立') },
                string.format('[[Special:EditPage/%s|%s]]', docTitle.fullText, ts:msg('建'))))
            :node(']')
    end
    local source = header:tag('span'):addClass('documentation-source')
    if inner then
        source:node(ts:msg('內聯文檔'))
    elseif docExists then
        source:node(ts:msg('嵌入', docTitle.fullText))
    else
        source:node(ts:msg('尚未建立'))
    end
    local content = documentation:tag('div'):addClass('documentation-content'):newline()
    if inner then
        content:node(inner)
    elseif docExists then
        content:node(mw.getCurrentFrame():expandTemplate { title = docTitle.fullText })
    end
    return documentation
end

return doc