Module:TestApp

local App = {} App.__index = App

function App.new(args) local obj = setmetatable({}, App) obj.m_characters = false obj.m_locations = false obj.m_media = false obj.m_miscellanea = false obj.args = args if (args.characters) then obj.m_characters = true end if (args.locations) then obj.m_locations = true end if (args.media) then obj.m_media = true end if (args.miscellanea) then obj.m_miscellanea = true end return obj end

function App:renderTOC local title = "By type " local button = mw.html.create('span') button :addClass('hidable-button') title = title .. tostring(button) local root = mw.html.create('table') root :attr('id', 'appearancesTOC') :css('padding', '5px') :css('border', '1px solid #AAAAAA') :css('-moz-border-radius', '6px') :css('margin', '0 auto 4px auto') local row1 = root:tag('tr') local row2 = root:tag('tr') local function makeCell(val, id, label) local cell = mw.html.create('td') if val then cell :css('padding', '0 1em') :wikitext( .. label .. ) else cell :css('padding', '0 1em') :css('color', 'gray') :css('font-style', 'italic') :wikitext(label) end return cell end row1:node(makeCell(self.m_characters, '#app_characters', 'Characters')) row1:node(makeCell(self.m_locations, '#app_locations', 'Locations')) row2:node(makeCell(self.m_media, '#app_media', 'Media')) row2:node(makeCell(self.m_miscellanea, '#app_miscellanea', 'Miscellanea')) return title .. tostring(root) end

function App:renderAppearances local root = mw.html.create('div') root :addClass('hidable-content') :css('clear', 'both') :css('text-align', 'left') local tab = root:tag('table') tab :attr('id', 'appearancesSection') :css('width', '100%') x = false local function subTable(text) if x then text = '' .. text .. '' else text = '' .. text x = true end local cell = mw.html.create('table') cell :addClass('appearances') :tag('tr') :tag('td') :wikitext(text) :done :done return cell end local function makeCharSection(main, dp, oc, c, l)		local s = mw.html.create('tr') local section = s:tag('td') section:tag('p') :attr('name', 'app_characters') :attr('id', 'app_characters') :css('font-weight', 'bold') :css('font-size', 'larger') :wikitext('Characters') if self.m_characters then tab:node(makeSection('characters', 'Characters', 'characters', self.args.characters, self.args.characters, self.args.characters)) end if self.m_locations then tab:node(makeSection('locations', 'Locations', 'locations', self.args.locations, self.args.locations, self.args.locations)) end if self.m_media then tab:node(makeSection('media', 'Media', 'media', self.args.media, self.args.media, self.args.media)) end if self.m_miscellanea then tab:node(makeSection('miscellanea', 'Miscellanea', 'miscellanea', self.args.miscellanea, self.args.miscellanea, self.args.miscellanea)) end return tostring(root) end function App:__tostring local comp = {} comp[#comp + 1] = self:renderTOC comp[#comp + 1] = self:renderAppearances local box = table.concat(comp) local root = mw.html.create('div') root :attr('class', 'hidable start-hidden') :css('text-align', 'center') :wikitext(box)

return tostring(root) end

local p = {} function p._main(args) local function getAppResult local appObj = App.new(args) return tostring(appObj) end result = getAppResult return result end

function p.main(frame) local args = {} for k, v in pairs(frame:getParent.args) do		k = k:gsub("[- ]", "_") v = v:match('^%s*(.-)%s*$') if v ~= '' then args[k] = v		end end return p._main(args) end

return end