Difference between revisions 21306550 and 21306551 on frwiktionary

local export = {}

-- The main entry point.
-- This is the only function that can be invoked from a template.
function export.show(frame)
	if mw.title.getCurrentTitle().nsText == "Template" then
		return "(This template/module should be used for pages in the Category: namespace.)"
	elseif mw.title.getCurrentTitle().nsText ~= "Category" then
		error("This template/module can only be used for pages in the Category: namespace.")
	end
	
	local args = frame.args
	local template = args["template"]
	
	if not template then
		error("The \"template\" parameter was not specified.")
	end
	
	-- Get all the parameters and the label data
	local info = {}
	info.code = args["code"]; if info.code == "" then info.code = nil end
	info.label = args["label"]; if info.label == "" then info.label = nil end
	info.sc = args["sc"]; if info.sc == "" then info.sc = nil end
	info.template = template
	
	-- Does the category have the correct name?
	local errormessage = check_name(info)
	
	if errormessage then
		return errormessage
	end
	
	-- Generate the displayed information
	local display = {}
	table.insert(display, show_breadcrumbs(info))
	table.insert(display, show_description(info))
	table.insert(display, show_subcategory_list(info))
	table.insert(display, show_TOC(info))
	
	return show_categories(info) .. table.concat(display, "\n\n") .. "<br clear=\"all\"/>"
end

-- Retrieves an item of information
function get_item(info, item)
	return mw.getCurrentFrame():expandTemplate{title = info.template .. "/CONFIG", args = {item, code = info.code or "", label = info.label or "", sc = info.sc or ""}}
end

(contracted; show full)			return mw.getCurrentFrame():expandTemplate{title = TOC_template.text, args = {}}
		end
	end
	
	return nil
end

return export