Call of Duty Wiki
Advertisement
Call of Duty Wiki

Dokumentacja dla tego modułu może zostać utworzona pod nazwą Moduł:Navbox/opis

--
-- Moduł zapewnia funkcjonalność dynamicznego tworzenia kolejnych list
-- w szablonie Szablon:Navbox w oparciu o listy punktowane.
--
-- Moduł przygotowany na potrzeby polskiej Call of Duty Wiki
--
-- @author  MGRINZ
--

local navboxRow = '<tr><th class="navbox-group">%s</th><td class="navbox-list">%s</td></tr>'
local navboxRowNoGroup = '<tr><td class="navbox-list" colspan="2">%s</td></tr>'
local linkSeparator = ' · '
local BR = '<br />'
local HR = '----'
 
function parseList(listContent)
	local items = {}
	local result = ""
 
	listContent = listContent .. "\n"
	for line in listContent:gmatch("(.-)\n") do
		line = line:gsub("^%s*", ""):gsub("%s+$", "")
 
		if line:sub(1, 1) == '*' then
			line = line:gsub("^%*%s*", "")
			items[#items + 1] = line
			if line:sub(-1) == "(" then
				result = result .. table.concat(items, linkSeparator)
				items = {}
			end
		else
			result = result .. table.concat(items, linkSeparator)
			items = {}
			if line:sub(1, 1) == "" then
				-- do nothing / skip line
			elseif line:sub(1, 4) == HR then
				result = result .. "\n" .. line
			else
				if result:sub(-#HR):sub(1, #HR) ~= HR and result:sub(-#BR):sub(1, #BR) ~= BR then
					result = result .. BR
				end
				result = result .. line .. BR
			end
		end
	end
 
	result = result .. table.concat(items, linkSeparator)
 
	if result:sub(1, #BR) == BR then
		result = result:sub(#BR + 1)
	end
 
	return result
end
 
return {
	Groups = function(frame)
		local listsCount = frame:getParent().args["lists"] or 30
		local navboxGroupContent
		local navboxListContent
 
		local result = {}
 
		for i = 1, listsCount do
			navboxGroupContent = frame:getParent().args["group" .. i]
			navboxListContent = frame:getParent().args["list" .. i]
			if navboxListContent ~= nil then
				if navboxGroupContent ~= nil then
					result[#result + 1] = string.format(navboxRow, navboxGroupContent, parseList(navboxListContent))
				else
					result[#result + 1] = string.format(navboxRowNoGroup, parseList(navboxListContent))
				end
			end
		end
		return table.concat(result, "\n")
	end
}
Advertisement