Moduuli:InsiderCite

Jedipediasta, vapaasta Tähtien sota-tietosanakirjasta tänään, 24. huhtikuuta 2024
Siirry navigaatioonSiirry hakuun

Tämän moduulin ohjeistuksen voi tehdä sivulle Moduuli:InsiderCite/ohje

-- This module implements [[Template:InsiderCite]].
 
local p = {}
 
function p._main(args)
	-- Define defaults
	local image = 'SWInsider.png'
	local invert = true
	local publication = 'Star Wars Insider'
	local defaultIssue = '{{{1}}}'
 
	-- Find optional values, and override defaults if necessary
	local size, page, display, issue, extra
	size = 'x12px'
	if args[1]
		and (
			args[1]:find('^Special%s')
			or args[1]:find('^Best%s') 
			or args[1]:find('^Digital%s')
		)
	then
		if args[2] then
			page = args[2]
			display = args[3] or args[2]
		end
		issue = args[1] or defaultIssue
	elseif args.issue1 then
		if args[1] then
			page = args[1]
			display = args[2] or args[1]
		end
		issue = args.issue1
		local issue2 = args.issue2 or '{{{issue2}}}'
		extra = string.format(
			'–[[%s %s|%s]]',
			publication, issue2, issue2
		)
	elseif tonumber(args[1]) and tonumber(args[1]) <= 22 then
		image = 'LFCMlogo.jpg'
		invert = false
		publication = 'The Lucasfilm Fan Club Magazine'
		size = 'x16px'
		if args[2] then
			page = args[2]
			display = args[3] or args[2]
		end
		issue = args[1] or defaultIssue
	else
		if args[2] then
			page = args[2]
			display = args[3] or args[2]
		end
		issue = args[1] or defaultIssue
	end
 
	-- Make the file link
	local fileLink = string.format(
		'[[Tiedosto:%s%s|text-top|link=Star Wars Insider]]',
		image,
		size and '|' .. size or ''
	)
 
	-- Make the story link
	local storyLink
	if page and display then
		storyLink = string.format("”[[%s|%s]]”&mdash;", page, display)
	else
		storyLink = ''
	end
 
	-- Make the issue link
	local issueLink = string.format(
		"[[%s %s|''%s'' %s]]",
		publication, issue, publication, issue
	)
 
	-- Make the final output.
	extra = extra or ''
	if invert then
		return '<span class="invert-images">' .. fileLink .. '</span> ' .. storyLink .. issueLink .. extra
	else
		return fileLink .. ' ' .. storyLink .. issueLink .. extra
	end
end
 
function p.main(frame)
	local args = {}
	for k, v in pairs(frame:getParent().args) do
		v = v:match('^%s*(.-)%s*$') -- trim whitespace
		if v ~= '' then
			args[k] = v
		end
	end
	return p._main(args)
end
 
return p