Module:Object usage

local export = {}

-- if not empty
local function ine(val)
	if val == "" then
		return nil
	end
	return val
end

local function parse_form(args, i, default)
	local m_form_data = mw.loadData('Module:form of/data')

	local output = {}
	while args[i] do
		local tag = args[i]
		if m_form_data.shortcuts[tag] then
			tag = m_form_data.shortcuts[tag]
		end
		table.insert(output, tag)
		i = i + 1
	end

	return (#output > 0) and table.concat(output, " ") or default
end

function export.show_bare(frame)
	local pargs = frame:getParent().args
	
	local lang = pargs[1]
	local means = pargs["means"]
	
	if mw.title.getCurrentTitle().nsText == "Template" then
		lang = "und"
		means = "meaning"
	end
	
	lang = lang and require("Module:languages").getByCode(lang) or require("Module:languages").err(lang, 1)
	
	return "[+" .. parse_form(pargs, 2, "object") .. (means and (" = " .. means) or "") .. "]"
end

function export.show_prep(frame)
	local pargs = frame:getParent().args
	
	local lang = pargs[1]
	local means = pargs["means"]
	local term = ine(pargs[2])
	local alt = ine(pargs["alt"])
	local senseid = ine(pargs["senseid"])
	
	if mw.title.getCurrentTitle().nsText == "Template" then
		lang = "und"
		means = "meaning"
		term = "preposition"
	end
	
	lang = lang and require('Module:languages').getByCode(lang) or require('Module:languages').err(lang, 1)

	return "[+ <span>" ..
		require('Module:links').full_link({lang = lang, term = term, alt = alt, id = senseid, tr = "-"}, "term") ..
		" <span>(" .. parse_form(pargs, 3, "object") .. ")</span></span>" .. (means and (" = " .. means) or "") .. "]"
end

function export.show_postp(frame)
	local pargs = frame:getParent().args
	
	local lang = pargs[1]
	local means = pargs["means"] or nil
	local term = ine(pargs[2])
	local alt = ine(pargs["alt"])
	local senseid = ine(pargs["senseid"])
	
	if mw.title.getCurrentTitle().nsText == "Template" then
		lang = "und"
		means = "meaning"
		term = "postposition"
	end
	
	lang = lang and require('Module:languages').getByCode(lang) or require('Module:languages').err(lang, 1)

	return "[+ <span><span>(" .. parse_form(pargs, 3, "object") .. ")</span> " ..
		require('Module:links').full_link({lang = lang, term = term, alt = alt, id = senseid, tr = "-"}, "term") ..
		"</span>" .. (means and (" = " .. means) or "") .. "]"
end

return export