Module:Documentation

From Sandbox Wiki
Revision as of 21:56, 15 May 2026 by Sandbox (talk | contribs) (Replaced content with "-- Module:Documentation local p = {} function p.main(frame) local currentTitle = mw.title.getCurrentTitle() local docTitle = mw.title.new(currentTitle.prefixedText .. '/doc') -- 创建主容器 local container = mw.html.create('div') :addClass('template-documentation') -- 创建头部区域 local header = container:tag('div') :addClass('template-documentation-header') -- 标题及图标 (使用 FontAwesome) head...")
Jump to navigation Jump to search

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

-- Module:Documentation
local p = {}

function p.main(frame)
    local currentTitle = mw.title.getCurrentTitle()
    local docTitle = mw.title.new(currentTitle.prefixedText .. '/doc')
    
    -- 创建主容器
    local container = mw.html.create('div')
        :addClass('template-documentation')

    -- 创建头部区域
    local header = container:tag('div')
        :addClass('template-documentation-header')

    -- 标题及图标 (使用 FontAwesome)
    header:tag('div')
        :addClass('template-documentation-title')
        :wikitext('<i class="fas fa-book-open"></i> 模板文档')

    -- 操作链接及图标
    local links = header:tag('div')
        :addClass('template-documentation-links')

    if docTitle.exists then
        -- 如果文档存在,显示查看、编辑、历史
        links:wikitext(string.format(
            '[ <i class="fas fa-eye"></i> [[%s|查看]] ] ' ..
            '[ <i class="fas fa-edit"></i> [%s 编辑] ] ' ..
            '[ <i class="fas fa-history"></i> [%s 历史] ] ' ..
            '[ <i class="fas fa-sync-alt"></i> [%s 刷新] ]',
            docTitle.prefixedText,
            docTitle:fullUrl('action=edit'),
            docTitle:fullUrl('action=history'),
            currentTitle:fullUrl('action=purge')
        ))
    else
        -- 如果文档不存在,显示创建链接
        links:wikitext(string.format(
            '[ <i class="fas fa-plus-circle" style="color:#d33;"></i> [%s 创建文档] ]',
            docTitle:fullUrl('action=edit&redlink=1')
        ))
    end

    -- 创建内容区域
    local content = container:tag('div')
        :addClass('template-documentation-content')

    if docTitle.exists then
        -- 嵌入包含 /doc 页面的内容
        content:wikitext(frame:expandTemplate{ title = docTitle.prefixedText })
    else
        content:wikitext('<i class="fas fa-exclamation-circle" style="color:#d33;"></i> 该模板暂无文档。请点击上方链接创建。')
    end

    return tostring(container)
end

return p