User:Arcorann/TOCgen/Module

From Wikisource
Jump to navigation Jump to search
-- This is an module to implement "TOCgen", a TOC template inspired by TOCStyle, ppoem and esWS's Módulo:ICP
require('strict')

local p = {} --p stands for package

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

local altparams = {

}

local presets = {
	['3'] = {
		['class'] = minimal
	}
}

local rowmodels = {
	['CD.P'] = {
		-- put something here
	}
}

function p.generate_row(rowargs)
	-- pass
end

function p.generate_chapter_link(prefix,suffix,disp)
	return "[[" .. prefix .. "/" .. suffix .. "|" .. disp .. "]]"
end

function p.generate_page_link_raw(rawpagenum,label)
	return "[[Page:{{#titleparts:{{PAGENAME}}|1|1}}/" .. rawpagenum .. "|" .. label .. "]]"
end

function p.generate_page_link_offset(pagenum,offset)
	return p.generate_page_link_raw(pagenum + offset,pagenum)
end

function p._TOCgen(args)
	local params = {}

	-- handle start and end
	local open = args['start'] == "open" or not args['start']
	local close = args['end'] == "close" or not args['end']
	
	local isPageNs = mw.title.getCurrentTitle():inNamespace(104)
	
	-- in Page namespace, we always open a fresh environment and close it at the end
	if isPageNs then
		open = true
		close = true
	end
	
	if args['preset'] ~= nil then
		local preset = args['preset']
		for k,v in presets[preset]
			params[k] = v
	end
	
	
	
	
	-- https://www.mediawiki.org/wiki/Extension:Scribunto/Lua_reference_manual#mw.html.create
	local ret_html = mw.html.create()
	
	
end

function p.TOCgen(frame)
	local args = getArgs(frame)
	-- handle argument aliases here
	for k,v in pairs(altparams) do
		if args[k] and not args[v] then
			args[v] = args[k]
		end
	end
	return p._TOCgen(args)
end


return p