Module:TestApp

local App = {} App.__index = App

function App.new(args) local obj = setmetatable({}, App) obj.m_characters = false obj.m_creatures = false obj.m_droids = false obj.m_events = false obj.m_locations = false obj.m_organizations = false obj.m_species = false obj.m_vehicles = false obj.m_technology = false obj.m_miscellanea = false obj.args = args if (args.characters or args.dramatis_personae or args.other_characters or args.c_characters or args.l_characters) then obj.m_characters = true end if (args.creatures or args.c_creatures or args.l_creatures) then obj.m_creatures = true end if (args.droids or args.c_droids or args.l_droids) then obj.m_droids = true end if (args.events or args.c_events or args.l_events) then obj.m_events = true end if (args.locations or args.c_locations or args.l_locations) then obj.m_locations = true end if (args.organizations or args.c_organizations or args.l_organizations) then obj.m_organizations = true end if (args.species or args.c_species or args.l_species) then obj.m_species = true end if (args.vehicles or args.c_vehicles or args.l_vehicles) then obj.m_vehicles = true end if (args.technology or args.c_technology or args.l_technology) then obj.m_technology = true end if (args.miscellanea or args.c_miscellanea or args.l_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_creatures, '#app_creatures', 'Creatures')) row1:node(makeCell(self.m_droids, '#app_droids', 'Droids')) row1:node(makeCell(self.m_events, '#app_events', 'Events')) row1:node(makeCell(self.m_locations, '#app_locations', 'Locations')) row2:node(makeCell(self.m_organizations, '#app_organizations', 'Organizations and titles')) row2:node(makeCell(self.m_species, '#app_species', 'Sentient species')) row2:node(makeCell(self.m_vehicles, '#app_vehicles', 'Vehicles and vessels')) row2:node(makeCell(self.m_technology, '#app_technology', 'Weapons and technology')) 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%') local function makeCharSection(main, dp, oc, c, l)		local app = {} local header = mw.html.create('p') header :attr('name', 'app_characters') :attr('id', 'app_characters') :css('font-weight', 'bold') :css('font-size', 'larger') :wikitext('Characters') app[#app + 1] = tostring(header) if main then if c or l then local warning1 = mw.html.create('p') warning1 :css('color', '#900') :wikitext("Warning: This template is being incorrectly used. You may not use the  field if you use   or  . Please [ edit this page] and correct the template's usage.") app[#app + 1] = tostring(warning1) end if dp or oc then local warning2 = mw.html.create('p') warning2 :css('color', '#900') :wikitext("Warning: This template is being incorrectly used. You may not use the  field if you use   or  . Please [ edit this page] and correct the template's usage.") app[#app + 1] = tostring(warning2) end char = mw.html.create('table') char :addClass('appearances') :tag('tr') :tag('td') :wikitext(' ' .. main) :done :done app[#app + 1] = tostring(char) else if dp or oc then if dp then dp_header = mw.html.create('p') dp_header :attr('name', 'app_dramatis_personae') :attr('id', 'app_dramatis_personae') :css('font-weight', 'bold') :wikitext('Dramatis personae') app[#app + 1] = tostring(dp_header) dp_char = mw.html.create('table') dp_char :addClass('appearances') :tag('tr') :tag('td') :wikitext(' ' .. tostring(dp)) :done :done app[#app + 1] = tostring(dp_char) end if oc then oc_header = mw.html.create('p') oc_header :attr('name', 'app_other_characters') :attr('id', 'app_other_characters') :css('font-weight', 'bold') :wikitext('Other characters') app[#app + 1] = tostring(oc_header) oc_char = mw.html.create('table') oc_char :addClass('appearances') :tag('tr') :tag('td') :wikitext(' ' .. tostring(oc)) :done :done app[#app + 1] = tostring(oc_char) end else if c then c_header = mw.html.create('p') c_header :attr('name', 'app_canon_characters') :attr('id', 'app_canon_characters') :css('font-weight', 'bold') :wikitext('Canon characters') app[#app + 1] = tostring(c_header) c_char = mw.html.create('table') c_char :addClass('appearances') :tag('tr') :tag('td') :wikitext(' ' .. c)								:done :done app[#app + 1] = tostring(c_char) end if l then l_header = mw.html.create('p') l_header :attr('name', 'app_legends_characters') :attr('id', 'app_legends_characters') :css('font-weight', 'bold') :wikitext('Legends characters') app[#app + 1] = tostring(l_header) l_char = mw.html.create('table') l_char :addClass('appearances') :tag('tr') :tag('td') :wikitext(' ' .. l)								:done :done app[#app + 1] = tostring(l_char) end end end return table.concat(app) end local function makeSection(id, title, lc_title, main, c, l)		local app = {} local header = mw.html.create('p') header :attr('name', string.format('app_%s', id)) :attr('id', string.format('app_%s', id)) :css('font-weight', 'bold') :css('font-size', 'larger') :wikitext(title) app[#app + 1] = tostring(header) if main then if c or l then warning = mw.html.create('p') warning :css('color', '#900') :wikitext(string.format("Warning: This template is being incorrectly used. You may not use the  field if you use   or  . Please [ edit this page] and correct the template's usage.", id, id, id)) app[#app + 1] = tostring(warning) end block = mw.html.create('table') block :addClass('appearances') :tag('tr') :tag('td') :wikitext(' ' .. main) :done :done app[#app + 1] = tostring(block) else if c then c_header = mw.html.create('p') c_header :attr('name', string.format('app_canon_%s', id)) :attr('id', string.format('app_canon_%s', id)) :css('font-weight', 'bold') :wikitext(string.format('Canon %s', lc_title)) app[#app + 1] = tostring(c_header) c_block = mw.html.create('table') c_block :addClass('appearances') :tag('tr') :tag('td') :wikitext(' ' .. c)							:done :done app[#app + 1] = tostring(c_block) end if l then l_header = mw.html.create('p') l_header :attr('name', string.format('app_legends_%s', id)) :attr('id', string.format('app_legends_%s', id)) :css('font-weight', 'bold') :wikitext(string.format('Legends %s', lc_title)) app[#app + 1] = tostring(l_header) l_block = mw.html.create('table') l_block :addClass('appearances') :tag('tr') :tag('td') :wikitext(' ' .. l)							:done :done app[#app + 1] = tostring(l_block) end end return table.concat(app) end if self.m_characters then tab:node(makeCharSection(self.args.characters, self.args.dramatis_personae, self.args.other_characters, self.args.c_characters, self.args.l_characters)) end if self.m_creatures then tab:node(makeSection('creatures', 'Creatures', 'creatures', self.args.creatures, self.args.c_creatures, self.args.l_creatures)) end if self.m_droids then tab:node(makeSection('droids', 'Droid models', 'droid models', self.args.droids, self.args.c_droids, self.args.l_droids)) end if self.m_events then tab:node(makeSection('events', 'Events', 'events', self.args.events, self.args.c_events, self.args.l_events)) end if self.m_locations then tab:node(makeSection('locations', 'Locations', 'locations', self.args.locations, self.args.c_locations, self.args.l_locations)) end if self.m_organizations then tab:node(makeSection('organizations', 'Organizations and titles', 'organizations and titles', self.args.organizations, self.args.c_organizations, self.args.l_organizations)) end if self.m_species then tab:node(makeSection('species', 'Sentient species', 'sentient species', self.args.species, self.args.c_species, self.args.l_species)) end if self.m_vehicles then tab:node(makeSection('vehicles', 'Vehicles and vessels', 'vehicles and vessels', self.args.vehicles, self.args.c_vehicles, self.args.l_vehicles)) end if self.m_technology then tab:node(makeSection('technology', 'Weapons and technology', 'weapons and technology', self.args.technology, self.args.c_technology, self.args.l_technology)) end if self.m_miscellanea then tab:node(makeSection('miscellanea', 'Miscellanea', 'miscellanea', self.args.miscellanea, self.args.c_miscellanea, self.args.l_miscellanea)) end return tostring(root) end function App:tostring local comp = {} comp[#comp + 1] = self:renderTOC comp[#comp + 1] = self:renderAppearances comp = table.concat(comp) local root = mw.html.create('div') root :attr('class', 'hidable start-hidden') :css('text-align', 'center') :wikitext(comp)

return tostring(root) end

local p = {} function p._main(args) local function getAppResult local appObj = App.new(args) return appObj:tostring 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 p