Module:Documentation: Difference between revisions

Jump to navigation Jump to search
m 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..."
Tag: Replaced
mNo edit summary
 
Line 1: Line 1:
-- Module:Documentation
local p = {}
local p = {}


Line 6: Line 5:
     local docTitle = mw.title.new(currentTitle.prefixedText .. '/doc')
     local docTitle = mw.title.new(currentTitle.prefixedText .. '/doc')
      
      
    -- 创建主容器
     local container = mw.html.create('div')
     local container = mw.html.create('div')
         :addClass('template-documentation')
         :addClass('template-documentation')


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


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


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


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


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


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