Module:Ca

From 100% Orange Juice Wiki
Jump to: navigation, search

Documentation for this module may be created at Module:Ca/doc

local p = {}
p.main = function(f)
	local args = f:getParent().args
	local linkText = args[2] or args[1]
	local outputMode = args[3] or "text"
	if args[1] == nil then return '' end
	local tags = {}
	if string.find(args[1], '&') ~= nil then
		if string.find(args[1], '%(') ~= nil then
			local split = mw.text.split(args[1],' %(')
			if string.find(split[2],'&') then
				--format: Tomomo (Casual & Sweet Eater)
				local disambig = mw.text.split(string.gsub(split[2],'%)',''),' & ')
				tags[1] = mw.text.trim(split[1] .. ' (' .. disambig[1] .. ')')
				tags[2] = mw.text.trim(split[1] .. ' (' .. disambig[2] .. ')')
			else
				--format: Sora & Sham (Cuties)
				tags[1] = string.gsub(args[1], '[ &%(%)]', '_')
			end
		else
			--format: Tomato & Mimyuu
			tags = mw.text.split(args[1],' & ')
		end
	else 
		tags[1] = string.gsub(args[1], '[ %(%)]', '_')
	end
	local tagOutput = tags[1] .. '"'
	if table.maxn(tags)>1 then
		tagOutput = 'multiple" data-tt-tags=\'['
		for i,v in ipairs(tags) do
			tagOutput = tagOutput .. '"'..v..'"'
			if i < table.maxn(tags) then
				tagOutput = tagOutput .. ', '
			end
		end
		tagOutput = tagOutput .. "]'"
	end
	local output
	if outputMode == "image" then
		output = '<span class="character-icon" data-card2="'.. args[1]..'" style="white-space:pre;"><span title="'.. args[1]..'"><span class="ajaxttlink -'..tagOutput
		output = output ..'>[[File:'.. args[1] ..'.png|alt=|'.. args[2] ..'|link='.. args[1]..']]</span></span></span>'
		
	else
		output = '<span class="character-icon" data-card2="'.. args[1]..'" style="white-space:pre;">[['.. args[1] ..'|<span class="ajaxttlink -'..tagOutput
		output = output .. '>'..linkText..'</span>]]</span>'
	end
		
	return output
end
return p