Jump to content

Module:ReportTOC: Difference between revisions

From ClimateKG
No edit summary
No edit summary
 
Line 64: Line 64:


function p.main(frame)
function p.main(frame)
     local html = '<onlyinclude><div class="rtoc-box">' ..
     local html = '<div class="rtoc-box">' ..
                 '<div class="rtoc-header">Contents</div>'
                 '<div class="rtoc-header">Contents</div>'
      
      
Line 82: Line 82:
     html = html .. '<div class="s-an"><div class="rtoc-section-title">Annexes</div><div class="rtoc-oos">Content in this section is out of scope</div></div>'
     html = html .. '<div class="s-an"><div class="rtoc-section-title">Annexes</div><div class="rtoc-oos">Content in this section is out of scope</div></div>'
      
      
     html = html .. '</div></onlyinclude>'
     html = html .. '</div>'
      
      
     return html
     return html

Latest revision as of 11:56, 20 May 2026

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

-- Module:ReportTOC
-- Handles rendering of report table of contents with chapters loop

local p = {}

function p.renderChapter(frame, chNum)
    local title = frame.args['ch' .. chNum .. 'title']
    if not title or title == '' then
        return ''
    end
    
    local subtitle = frame.args['ch' .. chNum .. 'subtitle'] or ''
    local url = frame.args['ch' .. chNum .. 'url'] or ''
    
    local subtitleHtml = ''
    if subtitle ~= '' then
        subtitleHtml = '<span class="rtoc-entry-subtitle">' .. subtitle .. '</span>'
    end
    
    return '<div class="rtoc-entry"><div class="rtoc-entry-text"><span class="rtoc-entry-title">' .. title .. '</span>' .. subtitleHtml .. '</div><span class="rtoc-read">[[' .. url .. '|Read]]</span></div>'
end

function p.renderSection(frame, sectionKey, sectionLabel, maxChapters)
    -- For SPM and TS, single entries
    if sectionKey == 'spm' or sectionKey == 'ts' then
        local title = frame.args[sectionKey .. 'title']
        if not title or title == '' then
            return ''
        end
        
        local subtitle = frame.args[sectionKey .. 'subtitle'] or ''
        local url = frame.args[sectionKey .. 'url'] or ''
        
        local subtitleHtml = ''
        if subtitle ~= '' then
            subtitleHtml = '<span class="rtoc-entry-subtitle">' .. subtitle .. '</span>'
        end
        
        return '<div class="s-' .. sectionKey .. '">' ..
               '<div class="rtoc-section-title">' .. sectionLabel .. '</div>' ..
               '<div class="rtoc-entry"><div class="rtoc-entry-text"><span class="rtoc-entry-title">' .. title .. '</span>' .. subtitleHtml .. '</div><span class="rtoc-read">[[' .. url .. '|Read]]</span></div>' ..
               '</div>'
    end
    
    -- For chapters, loop through all
    if sectionKey == 'ch' then
        local chapters = ''
        for i = 1, maxChapters do
            chapters = chapters .. p.renderChapter(frame, i)
        end
        
        if chapters == '' then
            return ''
        end
        
        return '<div class="s-ch">' ..
               '<div class="rtoc-section-title">' .. sectionLabel .. '</div>' ..
               chapters ..
               '</div>'
    end
    
    return ''
end

function p.main(frame)
    local html = '<div class="rtoc-box">' ..
                 '<div class="rtoc-header">Contents</div>'
    
    -- Front Matter
    html = html .. '<div class="s-fm"><div class="rtoc-section-title">Front Matter</div><div class="rtoc-oos">Content in this section is out of scope</div></div>'
    
    -- SPM
    html = html .. p.renderSection(frame, 'spm', 'SPM', 0)
    
    -- TS
    html = html .. p.renderSection(frame, 'ts', 'TS', 0)
    
    -- Chapters (up to 25)
    html = html .. p.renderSection(frame, 'ch', 'Chapters', 25)
    
    -- Annexes
    html = html .. '<div class="s-an"><div class="rtoc-section-title">Annexes</div><div class="rtoc-oos">Content in this section is out of scope</div></div>'
    
    html = html .. '</div>'
    
    return html
end

return p