require('strict')  
local p = {}
local data = {}
local templateArgs = {} -- contains arguments passed to cite web
local target = {} -- short cut to target table, e.g. fishbase, cof, etc  
local function firstToUpper(str)
return (str:gsub("^%l", string.upper))
end
-- define citation template and custom parameters for various sources  
--####################### Default functions ##########################
data.default = {}
-- currently being tested on Avibase, but Fossilworks, Tropicos, FNA and a few others are candidates
data.default.id = function (id, source)
local title = id
local url = source.customArgs['baseURL'] .. (source.customArgs['searchStr'] or "") .. id
return title, url
end
data.default.error = function
return "Minimal requirement is two of id, url and title parameters"
end
data.default.search = function (search, source)
local title = "Search for " .. search
local url = source.customArgs['baseURL'] .. source.customArgs['searchString'] .. search .. source.customArgs['searchSuffix']
return title, url
end  
--[[ handling for ID only (unused, original concept)
p.genericIdCitation = function(, title, url)  
if not templateArgs['id'] then return "no id parameter detected" end  
templateArgs['url']= target.CustomArgs['baseURL'] .. target.CustomArgs['searchStr'] .. templateArgs['id']  
return p.citeWeb(, title, url)
end]]
--####################### FISH #####################################
--======================== Fishbase =================================
data.fishbase = {
citationArgs = {
['editor1-last']="Froese", ['editor1-first']="Rainer", ['editor1-link']="Rainer Froese",
['editor2-last']="Pauly", ['editor2-first']="Daniel",
--['last-author-amp'] ="yes",
['website'] = "Fishbase",
--['publisher'] = ""
},
customArgs = { exclude= "order, family,genus, species, subspecies, 1, 2, 3, 4",
baseURL = "http://www.fishbase.org/",
defaultTitle = "Search FishBase"
},
}
data.fishbase.species = function(genus, species, subspecies)  
local title = genus .. " " .. species
local url = data.fishbase.customArgs['baseURL']
.. "summary/SpeciesSummary.php?genusname=" .. genus .. "&speciesname=" .. species
if subspecies then
url = url .. "+" .. subspecies
title = title .. " " .. subspecies
end
title = "*" .. title .. "*"
return title, url
end
data.fishbase.genus = function(genus)
local title = "Species in genus *" .. firstToUpper(genus) .. "*"
local url = data.fishbase.customArgs['baseURL'] .. "identification/SpeciesList.php?genus=" .. genus
return title, url
end
data.fishbase.order = function(order)
local title = "Order " .. firstToUpper(order)
local url = data.fishbase.customArgs['baseURL'] .. "Summary/OrdersSummary.php?order=" .. order
return title, url
end
data.fishbase.family = function(family)
local title = "Family " .. firstToUpper(family)
local url = data.fishbase.customArgs['baseURL'] .. "Summary/FamilySummary.php?family=" .. family
return title, url
end
data.fishbase.error = function
return "No recognised taxon options: order, family, genus, species, subspecies."
end
data.fishbase.custom = function
--TODO decide what to do with default date
local version = "April 2006 version" -- Should we have a default (probably not)
if templateArgs['month'] then version = templateArgs['month'] end
if templateArgs['year'] then version = templateArgs['year'] .. " version" end
if templateArgs['month'] then version = templateArgs['month'] .. " " .. version end
templateArgs['version'] = version
end
--================================ Catalog of Fishes ================================================
data.cof = {
citationArgs = {
--baseURL = "http://researcharchive.calacademy.org/research/ichthyology/catalog/fishcatget.asp?",
['editor1-last']="Eschmeyer", ['editor1-first']="William N.", ['editor1-link']="William N. Eschmeyer",
['editor2-last']="Fricke", ['editor2-first']="Ron",
['editor3-last']="van der Laan", ['editor3-first']="Richard",
['name-list-style'] ="amp",
['website'] = "Catalog of Fishes",
['publisher'] = "California Academy of Sciences"
},
customArgs = { exclude= "family,genus,species,genid,spid,id,list,1,2,3",
baseURL = "http://researcharchive.calacademy.org/research/ichthyology/catalog/fishcatget.asp?",
defaultTitle = "CAS - Eschmeyer's Catalog of Fishes"
}
}
data.cof.species = function(genus, species, subspecies)
local taxon = genus .. " " .. species
local url = data.cof.customArgs['baseURL'] .. 'tbl=species&genus=' .. genus .. '&species=' .. species
local title = "Species related to " .. "*" .. firstToUpper(taxon) .. "*" -- .. "" species synonyms"
return title, url
end
data.cof.genus = function(genus)
local url = data.cof.customArgs['baseURL'] .. 'tbl=species&genus=' .. genus
local title = "Species in the genus *" .. firstToUpper(genus) .. "*"
return title, url
end
-- note the family works with subfamilies using &family=SUBFAMILY
data.cof.family = function(family)
local list = templateArgs['list'] or "genus"
local url = data.cof.customArgs['baseURL'] .. 'tbl=' .. list .. '&family=' .. family
local title = "Species"
if list == "genus" then title = "Genera" end
title = title .. ' in the family ' .. firstToUpper(family)
return title, url
end
data.cof.genid = function(genid)
local searchStr = "genid" .. '=' .. genid
local title = searchStr
local url = data.cof.customArgs['baseURL'] .. searchStr
return title, url
end
data.cof.spid = function(spid)
local searchStr = "spid" .. '=' .. spid
local title = searchStr
local url = data.cof.customArgs['baseURL'] .. searchStr
return title, url
end
data.cof.error = function
return "Error. No recognised option set by template (need one of family, genus, species (also requires genus), spid, or genid"
end
--======================Fishes of the World 5===============================
data.fotw5 = {
citeTemplate = "Cite book",
citationArgs = {
--['website'] = "[[]]",
first1 = "Joseph S.", last1 = "Nelson",
first2="Terry C.", last2="Grande",
first3="Mark V. H.", last3="Wilson",
--work = "Fishes of the World (work)",
title = "Fishes of the World", edition="5th", year = 2016,
publisher ="John Wiley and Sons", location="Hoboken",
isbn = "978-1-118-34233-6", doi="10.1002/9781119174844" ,
},
customArgs = {exclude="gb-page,q,dq,1",
baseURL = "https://onlinelibrary.wiley.com/doi/book/10.1002/9781119174844", -- online library
defaultTitle = "Fishes of the World",
altTitle = "Fishes of the World", -- wikilinked for when using chapter/section title
altURL = "https://sites.google.com/site/fotw5th/", -- classification
},
GoogleBooks = { baseURL = "https://books.google.co.uk/books?id=",
id = "E-MLDAAAQBAJ",
defaultPage = "&pg=PP1"
}
}
data.fotw5.default2 = function(targs)
local title = data.fotw5.citationArgs['work']
local url = data.fotw5.customArgs['baseURL']
local chapterParams = { title = title,
['chapter-url']= data.fotw5.customArgs['googleBooks']
}
--return title, url, chapterParams
end  
data.BentonVP4 = {
citeTemplate = "Cite book",
citationArgs = {
first1 = "Michael J.", last1 = "Benton",
title = "Vertebrate Palaeontology", edition="4th", year = 2014,
publisher ="John Wiley & Sons",
isbn = "978-1-118-40764-6",
},
customArgs = {exclude="gb-page,q,dq,1",
--baseURL = "",
defaultTitle = "Vertebrate Palaeontology",
altTitle = "Vertebrate Palaeontology" -- wikilinked for when using chapter/section title
},
GoogleBooks = { baseURL = "https://books.google.co.uk/books?id=",
id = "qak-BAAAQBAJ",
defaultPage = "&pg=PP1",
}
}  
--====================TODO FishWisePro==================================================
data.fishwisepro = {
citationArgs = {
['website'] = "FishWisePro",  
},
customArgs = {exclude="family,genus,species,1",
baseURL = ""
}
}  
-- #################### AMPHIBIA and REPTILES ###############################
-- ================= Amphibian Species of the World (ASW6)