Module:ReportTOC: Difference between revisions
Appearance
Created page with "-- 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'] or '' local subtitle = frame.args['ch' .. chNum .. 'subtitle'] or '' local url = frame.args['ch' .. chNum .. 'url'] or '' if title == '' then return '' end local subtitleHtml = '' if subtitle ~= '' then subtitleHtml = '<span cla..." |
No edit summary |
||
| Line 1: | Line 1: | ||
-- Module:ReportTOC | -- Module:ReportTOC | ||
local p = {} | local p = {} | ||
function p.renderChapter(frame, chNum) | function p.renderChapter(frame, chNum) | ||
local title = frame.args['ch' .. chNum .. 'title'] or '' | local title = frame.args['ch' .. chNum .. 'title'] | ||
if not title or title == '' then | |||
return '' | |||
end | |||
local subtitle = frame.args['ch' .. chNum .. 'subtitle'] or '' | local subtitle = frame.args['ch' .. chNum .. 'subtitle'] or '' | ||
local url = frame.args['ch' .. chNum .. 'url'] or '' | local url = frame.args['ch' .. chNum .. 'url'] or '' | ||
local subtitleHtml = '' | local subtitleHtml = '' | ||
| Line 19: | Line 17: | ||
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>' | 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 | end | ||
function p.main(frame) | function p.main(frame) | ||
local html = '<onlyinclude><div class="rtoc-box"> | local html = '<onlyinclude><div class="rtoc-box"><div class="rtoc-header">Contents</div>' | ||
-- Front Matter | -- Front Matter | ||
| Line 71: | Line 26: | ||
-- SPM | -- SPM | ||
html = html .. | local spmTitle = frame.args['spmtitle'] | ||
if spmTitle and spmTitle ~= '' then | |||
local spmSubtitle = frame.args['spmsubtitle'] or '' | |||
local spmUrl = frame.args['spmurl'] or '' | |||
local spmSubtitleHtml = '' | |||
if spmSubtitle ~= '' then | |||
spmSubtitleHtml = '<span class="rtoc-entry-subtitle">' .. spmSubtitle .. '</span>' | |||
end | |||
html = html .. '<div class="s-spm"><div class="rtoc-section-title">SPM</div><div class="rtoc-entry"><div class="rtoc-entry-text"><span class="rtoc-entry-title">' .. spmTitle .. '</span>' .. spmSubtitleHtml .. '</div><span class="rtoc-read">[[' .. spmUrl .. '|Read]]</span></div></div>' | |||
end | |||
-- TS | -- TS | ||
html = html .. | local tsTitle = frame.args['tstitle'] | ||
if tsTitle and tsTitle ~= '' then | |||
local tsSubtitle = frame.args['tssubtitle'] or '' | |||
local tsUrl = frame.args['tsurl'] or '' | |||
local tsSubtitleHtml = '' | |||
if tsSubtitle ~= '' then | |||
tsSubtitleHtml = '<span class="rtoc-entry-subtitle">' .. tsSubtitle .. '</span>' | |||
end | |||
html = html .. '<div class="s-ts"><div class="rtoc-section-title">TS</div><div class="rtoc-entry"><div class="rtoc-entry-text"><span class="rtoc-entry-title">' .. tsTitle .. '</span>' .. tsSubtitleHtml .. '</div><span class="rtoc-read">[[' .. tsUrl .. '|Read]]</span></div></div>' | |||
end | |||
-- Chapters | -- Chapters | ||
local chapters = '' | |||
for i = 1, 25 do | |||
chapters = chapters .. p.renderChapter(frame, i) | |||
end | |||
if chapters ~= '' then | |||
html = html .. '<div class="s-ch"><div class="rtoc-section-title">Chapters</div>' .. chapters .. '</div>' | |||
end | |||
-- Annexes | -- Annexes | ||
Revision as of 11:51, 20 May 2026
Documentation for this module may be created at Module:ReportTOC/doc
-- Module:ReportTOC
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.main(frame)
local html = '<onlyinclude><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
local spmTitle = frame.args['spmtitle']
if spmTitle and spmTitle ~= '' then
local spmSubtitle = frame.args['spmsubtitle'] or ''
local spmUrl = frame.args['spmurl'] or ''
local spmSubtitleHtml = ''
if spmSubtitle ~= '' then
spmSubtitleHtml = '<span class="rtoc-entry-subtitle">' .. spmSubtitle .. '</span>'
end
html = html .. '<div class="s-spm"><div class="rtoc-section-title">SPM</div><div class="rtoc-entry"><div class="rtoc-entry-text"><span class="rtoc-entry-title">' .. spmTitle .. '</span>' .. spmSubtitleHtml .. '</div><span class="rtoc-read">[[' .. spmUrl .. '|Read]]</span></div></div>'
end
-- TS
local tsTitle = frame.args['tstitle']
if tsTitle and tsTitle ~= '' then
local tsSubtitle = frame.args['tssubtitle'] or ''
local tsUrl = frame.args['tsurl'] or ''
local tsSubtitleHtml = ''
if tsSubtitle ~= '' then
tsSubtitleHtml = '<span class="rtoc-entry-subtitle">' .. tsSubtitle .. '</span>'
end
html = html .. '<div class="s-ts"><div class="rtoc-section-title">TS</div><div class="rtoc-entry"><div class="rtoc-entry-text"><span class="rtoc-entry-title">' .. tsTitle .. '</span>' .. tsSubtitleHtml .. '</div><span class="rtoc-read">[[' .. tsUrl .. '|Read]]</span></div></div>'
end
-- Chapters
local chapters = ''
for i = 1, 25 do
chapters = chapters .. p.renderChapter(frame, i)
end
if chapters ~= '' then
html = html .. '<div class="s-ch"><div class="rtoc-section-title">Chapters</div>' .. chapters .. '</div>'
end
-- 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></onlyinclude>'
return html
end
return p