Module:Citation

From Otherkin Wiki

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

local p = {}

function p.build_author_username(author, username, interviewer)
	if not author and not username then
		return false;
	end
	
	local text = ""
	
	if author and username then
		text = author .. " (" .. username .. ")"
	elseif author then
		text = author
	elseif username then
		text = username
	end
	
	if interviewer then text = text .. ", interviewed by " .. interviewer end
		
	return text
	
end
	
function p.build_title_url(title, url)
	if not title and not url then	
		return "No title specified"
	end
	
	if title and url then
		return "\"[" .. url .. " " .. title .. "]\""
	elseif title then
		return "\"" .. title .. "\""								
	elseif url then
		return url
	end
	
end

function p.build_comment_on(title, url)												-- formats the 'comment on' bit depending on if a url, title or both are provided
	if not title and not url then	
		return false;															-- if comment fields aren't filled, no need to continue
	end
	
	local prefix = "Comment on "
	
	if title and url then														-- there are probably less redundant ways to form the text than this but it gets the job done
		return prefix .. "\"[" .. url .. " " .. title .. "]\"</i>"
	elseif title then
		return prefix .. "\"" .. title .. "\"</i>"								
	elseif url then
		return prefix .. url .. "</i>"
	end
	
end

function p.main(frame)
	local args = frame:getParent().args
	
	local author = p.build_author_username(args.author, args.username, args.interviewer)
	local title = p.build_title_url(args.title, args.url)
	local comment_on = p.build_comment_on(args.comment_on, args.comment_url)
	
	local text = ""
	
	if author then text = text .. author .. ". " end
	if args.date then text = text .. "(" .. args.date .. ") " end
	text = text .. title .. " "
	if comment_on then text = text .. comment_on .. ". " end
	if args.work then text = text .. "<i>" .. args.work .. "</i>. " end
	if args.timestamp then text = text .. "at " .. args.timestamp .. ". " end
	if args.pages then text = text .. "pg. " .. args.pages .. ". " end
	if args.publisher then text = text .. args.publisher .. ". " end
	if args.archiveurl then text = text .. "<small>([" .. args.archiveurl .. " Archived] version)</small>" end
	
	return text
end

return p