Jump to content

Module:Smyth

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Erutuon (talk | contribs) at 03:51, 4 October 2016 (debug, allow multiple separators). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

export = {}

data = {
	["Smyth"] = {
		["path"] = "1999.04.0007",
		["parts"] = { "part", "chapter", "section", "smythp" }
	}
}

local function url(resourceCode, part, code)
	code = mw.uri.encode(code, PATH)
	return "http://www.perseus.tufts.edu/hopper/text?doc=Perseus:text:" .. path .. ":" .. part .. "=" .. code
end

function Smyth(section, part)
	if not part then
		part = "smythp"
	end
	SmythData = data.Smyth
	path = SmythData.path
	return url(path, part, section)
end

function export.SmythSection(frame)
	local output = ""
	local sections = frame.args[1]
	local section, separators = {}, {}
	local part = frame.args[2]
	if sections then
		n = 1
		for separator, number in string.gmatch(sections, "([^%d]*)(%d+)") do
			section[n] = number
			if separator == "" or separator == nil then
				separators[n] = ""
			else
				separators[n] = separator
			end
			if section[n] == nil or section[n] == "" then
				n = false
			end
			n = n + 1
		end
	else
		error("SmythSection wants input in the first parameter")
	end
	for i = 1, #section do
		output = output .. separators[i] .. "[" .. Smyth(section[i]) .. " " .. section[i] .. "]"
	end
	return output
end

return export