Module:Side box/AHSW

local Box = {} local SB = require('Module:Side box') local HF = require('Module:HF') local L = require('Module:List') local Icon = require('Module:Icon').main local getArgs = require('Module:Arguments').getArgs

local function makeInvokeFunc(funcName) return function (frame) local args = getArgs(frame) return Box[funcName](args) end end

local function collapsiblediv( content, label ) local labeltext = label or '' local outerDiv = mw.html.create( 'div' ) :attr('data-expandtext','+'):attr('data-collapsetext','-') :addClass('toccolours mw-collapsible mw-collapsed') :tag('div'):addClass('metadata-section-label'):wikitext(labeltext):done :tag('div'):addClass('mw-collapsible-content mhlist hwrap'):wikitext(content):allDone return tostring(outerDiv) end

-- Implements Box.witch = makeInvokeFunc('_witch') -- Implements Box.voodoo = makeInvokeFunc('_voodoo') -- Implements Box.guests = makeInvokeFunc('_gueststars') -- Implements Box.music = makeInvokeFunc('_music') -- Implements plaintext syntax for Music,. Unfinished. -- Despite it being called "concise", it's just a horrible syntax for the end result. _music is much easier. Box.music_concise = makeInvokeFunc('_music_concise')

function Box._witch( args ) local powerslist = HF.explode( ";", args[1] or '' ) local boxargs = { text = "Witch Magic", image = '', class = 'hlist hwrap plainlinks infobox', style = 'text-align: center' }	boxargs.below = L.makeList('horizontal',powerslist) local box = SB._main(boxargs) return box end

function Box._voodoo( args ) local powerslist = HF.explode( ";", args[1] or '' ) local boxargs = { text = "Voodoo Magic", image = '', class = 'hlist hwrap plainlinks infobox', style = 'text-align: center' }	boxargs.below = L.makeList('horizontal',powerslist) local box = SB._main(boxargs) return box end

function Box._gueststars( args ) local boxargs = { text = "Guest Cast", image = '', class = 'hwrap infobox' }	local boxcontents = {} if not HF.isempty( args['special'] ) then table.insert( boxcontents, 	 	collapsiblediv( L.makeList('unbulleted', HF.explode( ";", args['special'] ) ), "Special Guest Stars" )) end if not HF.isempty( args['supporting'] ) then table.insert( boxcontents, 	 	collapsiblediv( L.makeList('unbulleted',  HF.explode( ";", args['supporting'] ) ), "Supporting Cast" )) end if not HF.isempty( args[1] ) then table.insert( boxcontents, 	 	collapsiblediv( L.makeList('unbulleted',  HF.explode( ";", args[1] ) ), "Guest Roles" )) end boxargs.below = table.concat(boxcontents) return SB._main(boxargs) end

function Box._music( args ) local songlist = { } local boxargs = { text = "Music", image = '', class = 'mw-collapsible hwrap plainlinks infobox', style = 'text-align: center' }	local T = mw.html.create('table'):addClass('sortable hwrap') :css('margin','auto'):css('width','100%') :tag('tr') :tag('th'):attr('width','50%'):wikitext('Performer'):done :tag('th'):attr('width','50%'):wikitext('Song'):done :done local tree = HF.parseIndexedFields( args ) for i,entry in ipairs( tree.fields ) do		local song = entry['song'] if not HF.isempty(entry['spotify']) then song = song .. ' ' .. Icon{ common = 'spotify', link='http://open.spotify.com/track/'..entry['spotify']} end if not HF.isempty(entry['youtube']) then song = song .. ' ' .. Icon{ common = 'youtube', link='http://www.youtube.com/watch?v='..entry['youtube']} end if not HF.isempty(entry['notes']) then song = song .. ' ' end T:tag('tr'):tag('td'):wikitext(entry['performer']):done:tag('td'):wikitext(song):done:done end T:allDone boxargs.below = tostring(T) return SB._main(boxargs) end

-- Despite it being called "concise", it's just a horrible syntax for the end result. _music is much easier. function Box._music_concise( args ) local songlist = { } local boxargs = { text = "Music", image = '', class = 'mw-collapsible hwrap plainlinks infobox', style = 'text-align: center' }	local T = mw.html.create('table'):addClass('sortable') :css('margin','auto'):css('width','100%') :tag('tr') :tag('th'):attr('width','50%'):wikitext('Performer'):done :tag('th'):attr('width','50%'):wikitext('Song'):done :done -- Plaintext separator mode for i,a in ipairs( args ) do	 if a:find('¡') then for i,v in ipairs( HF.explode('¡',v) ) do table.insert( songlist, v ) end else table.insert( songlist, a ) end end for i,v in ipairs(songlist) do	 local song = HF.explode('¦',v) local performer = table.remove(song,1) local songname = table.remove(song,1) -- Disregard scene= or theme= -- pattern regex spotify= -- pattern regex youtube= T:tag('tr') :tag('td'):wikitext(performer):done :tag('td'):wikitext(songname):done :done end -- Plaintext separator mode

T:allDone boxargs.below = tostring(T) return SB._main(boxargs) end

return Box