모듈:Small scan link

모듈 설명문서[만들기]
-- Implements [[틀:작은 스캔 링크]]
require('strict')

local p = {} --p stands for package

local getArgs = require('Module:Arguments').getArgs

-- simple function to make a link to a give index page
local function index_link(index, display)
	return "[[" .. "색인:" .. index .. "|" .. display .. "]]"	
end

-- get the n'th link in the args, including name if given
local function get_link(args, n)
	local display = n
	local argname = '이름' .. n
	if args[argname] ~= nil then
		display = args[argname]
	end

	return index_link(args[n], display)
end

--[=[
Return a formatted small scan link
Args:
   1,2,3....        : The index pages to link to
   name1, name2, ...: Display text for corresponding index page
]=]
function p._small_scan_link(args)
	local s = ''

	if args[1] == nil then
		error("At least an Index page is required", 0) 	
	end
	
	if args[2] == nil then
		-- single argument

		local target = args[1]
		local link_text = ""
		-- use the provided name if there is one
		if args['이름1'] ~= nil then
			link_text = args['이름1']
		else
			-- name based on existance of target
			if mw.title.new("색인:" .. target).exists then
				link_text = "전사 작업 문서"
			else
				link_text = "전사 작업 시작"
			end
		end
		s = index_link(target, link_text)
	else
		-- multiple positional args

		local i = 1
		s = "권별 전사 작업 문서: "
		-- iterate positional parameters
		while args[i] ~= nil do
			s = s .. get_link(args, i)
			i = i + 1
			
			if args[i] ~= nil then
				s = s .. ", "
			end
		end
	end

	return "<span class=\"scanlink\" style=\"font-size: 83%;\">(" .. s .. ")</span>"
end

function p.small_scan_link(frame)
	local args = getArgs(frame)
	return p._small_scan_link(args)
end

return p