Module:Smyth: Difference between revisions

Content deleted Content added
m fix naming problem
Misc code cleanup, remove functions and variables used only once
 
(9 intermediate revisions by 2 users not shown)
Line 1:
local export = {}
 
local function Smyth(section, part)
data = {
["Smyth"] = {
["path"] = "1999.04.0007"
}
}
 
local find, match, gmatch = mw.ustring.find, mw.ustring.match, mw.ustring.gmatch
 
local function makeURL(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
local Part, url
if section == "" or section == nil then
Line 40 ⟶ 25:
end
end
code section = mw.uri.encode(codesection, "PATH")
url = makeURL(path, part, section)
return url = "http://www.perseus.tufts.edu/hopper/text?doc=Perseus:text:" 1999.04. path .. "0007:" .. part .. "=" .. codesection
end
return { url = url, Part = Part }
Line 48 ⟶ 34:
local sectionParameter = frame.args[1]
local output, sign = "", ""
local sections, postscripts, separators = {}, {}, {}
local part = frame.args[2]
if sectionParameter then
n = 1
if mw.ustring.find(sectionParameter, "[^%d%s]") then
for number, postscript, separator in mw.ustring.gmatch(sectionParameter, "(%d*+ ?%au?)(%.?[%l%d]?)(%p?[^%d]*)") do
if sections[n], == "" andpostscripts[n], separators[n] == ""number, postscript, thenseparator
if number == "" or number == nil then
if sections[n] == "" or sections[n] == nil then
else
sections[n] = number
end
if separator == "" or separator == nil then
separators[n] = ""
else
separators[n] = separator
end
if sections[n] == "" and separators[n] == "" then
break
end
Line 70 ⟶ 47:
end
else
sections[1], separators[1] = mw.ustring.match(sectionParameter, "(%d*+)"), ""
end
else
error("SmythSection wants input in the first parameter")
end
if #sections == nil or #sections == "" then
error("No numbers in the text provided to SmythSection")
elseif sections[2] == "" or sections[2] == nil then
sign = "§"
else
Line 83 ⟶ 60:
end
for i = 1, #sections do
if sections[i] == "" or sections[i] == nil then -- Does gmatch return nil or an empty string when it finds no match?
break
else
if not postscripts[i] then postscripts[i] = "" end
local sectionPath = string.gsub(sections[i], "%.%d", "")
if not separators[i] then separators[i] = "" end
output = output .. "[" .. Smyth(sectionPathsections[i]).url .. " "
if i == 1 then
output = output .. " "sign .. sign" "
end
output = output .. " "sections[i] .. sectionspostscripts[i] .. "]" .. separators[i]
end
end
Line 99 ⟶ 77:
function export.SmythPart(frame)
local sectionParameter = frame.args[1]
local section = mw.ustring.match(sectionParameter, "(%d+)")
return Smyth(section).Part
end