Module:ReportTOC
Appearance
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