Module:R:Mindat

From Wiktionary, the free dictionary
Jump to navigation Jump to search

This module needs documentation.
Please document this module by describing its purpose and usage on the documentation page.

local export = {}

local function initial_capital(x)
	return x:gsub("^%l", string.upper)
end

local function space_to_underscore(x)
	return x:gsub(" ", "_")
end

function export.index(frame)
	-- Data module causes a Lua memory error just for this template.
	local title = mw.title.getCurrentTitle().text
	if title == "gold" then
		return nil
	end
	
	local args, mensa = frame:getParent().args, mw.loadData("Module:R:Mindat/data")
	local w = args[1] or title
	local wU = args[1] or initial_capital(title)
	local glossary = args['glossary']
	
	local function link_main(w, wU)
		return mensa[wU] and "[https://www.mindat.org/min-".. (mensa[wU] or "") .. ".html " .. w .."]" or ""
	end
	
	local function link_glossary(w,wU)
		return "[https://www.mindat.org/glossary/" .. space_to_underscore(wU) .. " " .. w.."]"
	end
	
	return glossary and link_glossary(w,wU) or link_main(w,wU)
end		
		
return export