Module:Codename/doc

local CnDoc = {} local data = mw.loadData('Module:Codename')

local function createHeadCell(text, rowspan, colspan) local cell = mw.html.create('th'):css{ ['text-align'] = 'center', ['border'] = '1px solid var(--secondary-color)' }:wikitext(text) if (rowspan or 1) ~= 1 then cell:attr('rowspan', rowspan) end if (colspan or 1) ~= 1 then cell:attr('colspan', colspan) end return cell end

local function generateHead(elem) elem :tag('tr') :node(createHeadCell('Codename', 3)) :node(createHeadCell('Association', 1, 6)) :done :tag('tr') :node(createHeadCell('Title', 2)) :node(createHeadCell('Link', 2)) :node(createHeadCell('Icon', 2)) :node(createHeadCell('Manual', 1, 2)) :node(createHeadCell('Guides', 2)) :done :tag('tr') :node(createHeadCell('U/C')) :node(createHeadCell('PAL')) end

local function generateBody(elem) local na = ' &mdash; ' for codename, fields in pairs(data) do       local row = mw.html.create('tr')

-- Codename row:tag('td'):tag('code'):wikitext(codename) -- Title row:tag('td'):wikitext(fields['title'] or na) -- Link if fields['link'] then row:tag('td'):wikitext(..fields['link']..) else row:tag('td'):wikitext(na) end -- Icon if fields['icon'] then row:tag('td'):wikitext('File:'..fields['icon']..'') else row:tag('td'):wikitext(na) end -- Manuals if fields['manual'] then row:tag('td'):wikitext(fields['manual']['NTSC-U/C'] or na) row:tag('td'):wikitext(fields['manual']['PAL'] or na) else row:tag('td'):wikitext(na):done:tag('td'):wikitext(na) end -- Guides if fields['guide'] then if type(fields['guide']) == 'string' then row:tag('td'):wikitext(fields['guide']) elseif type(fields['guide']) == 'table' then local guide_list = mw.html.create('ul'):css{ ['list-style-position'] = 'inside', ['margin-left'] = 0 }               for _, guide in pairs(fields['guide']) do                    guide_list:tag('li'):wikitext(guide) end row:tag('td'):node(guide_list) end else row:tag('td'):wikitext(na) end

elem:node(row) end end

function CnDoc.main local wrapper = mw.html.create('table'):addClass('article-table'):css('width', '100%') generateHead(wrapper) generateBody(wrapper) return wrapper end

return CnDoc