FANDOM


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 {{Character/Magic}}
Box.witch = makeInvokeFunc('_witch')
-- Implements {{Character/Voodoo}}
Box.voodoo = makeInvokeFunc('_voodoo')
-- Implements {{Episode/Guests}}
Box.guests = makeInvokeFunc('_gueststars')
-- Implements {{Episode/Music}}
Box.music = makeInvokeFunc('_music')
-- Implements plaintext syntax for Music, {{Episode/Music/concise}}. 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 = "'''[[:Category:Witches#Magics|Witch Magic]]'''",
		image = '[[File:AHSW-Coven-Full.png|40px|link=]]',
		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 = "'''[[:Category:Voodoo#Powers|Voodoo Magic]]'''",
		image = '[[File:AHSW-Coven-Full.png|40px|link=]]',
		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 = '[[File:Map symbol theatre 02.svg|40px|link=]]',
		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 = '[[File:BlueNote.svg|left|50px|link=]]',
		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 .. '<ref>'..entry['notes']..'</ref>' 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 = '[[File:BlueNote.svg|left|50px|link=]]',
		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

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.