Difference between revisions of "Module:Cite Talmud"
Jump to navigation
Jump to search
test>Daask (Fix Jerusalem Talmud abbr) |
test>Daask (Rearrange to consolidate output at end of function) |
||
| Line 8: | Line 8: | ||
jb = template_args[1] | jb = template_args[1] | ||
if not(jb) or string.find(jb, '^%s*$') then jb = 'b' end | if not(jb) or string.find(jb, '^%s*$') then jb = 'b' end | ||
| − | if talmud.jb_key[jb] then | + | if not talmud.jb_key[jb] then |
| − | + | str = frame:expandTemplate{ title = 'error', args = { 'First argument must be either b for Babylonian Talmud or y for Jerusalem Talmud. (Given "' .. jb .. '")' } } | |
| − | |||
| − | |||
end | end | ||
tractate = template_args[2] | tractate = template_args[2] | ||
| Line 20: | Line 18: | ||
url = "https://www.sefaria.org/" .. string.gsub(tractate, ' ', '_') .. '.' .. string.gsub(daf or '2a', ' ', '_') | url = "https://www.sefaria.org/" .. string.gsub(tractate, ' ', '_') .. '.' .. string.gsub(daf or '2a', ' ', '_') | ||
end | end | ||
| − | + | -- str is only set if there has been an error. | |
| + | if not str then | ||
| + | str = '[[Talmud]], <abbr title="' .. talmud.jb_key[jb] .. '">' .. jb .. '.</abbr> ' | ||
| + | str = str .. tractate .. " " .. daf .. url | ||
| + | end | ||
return str | return str | ||
end | end | ||
return talmud | return talmud | ||
Revision as of 14:46, 15 May 2019
Implements {{Cite Talmud}}
local talmud = {}
talmud.jb_key = {b = "Babylonian", y = "Jerusalem"}
function talmud.generate_citation(frame)
local template_args = frame:getParent().args
-- local invoke_args = frame.args -- parameters from {{#invoke:}}
jb = template_args[1]
if not(jb) or string.find(jb, '^%s*$') then jb = 'b' end
if not talmud.jb_key[jb] then
str = frame:expandTemplate{ title = 'error', args = { 'First argument must be either b for Babylonian Talmud or y for Jerusalem Talmud. (Given "' .. jb .. '")' } }
end
tractate = template_args[2]
chapter = template_args[3] -- Chapter name or number (optional)
daf = template_args[4] -- These are page or folio numbers as described at Talmud#Slavuta Talmud 1795 and Vilna Talmud 1835. Ranges are accepted, eg. 2b-4a
url = template_args['url']
if not url then
url = "https://www.sefaria.org/" .. string.gsub(tractate, ' ', '_') .. '.' .. string.gsub(daf or '2a', ' ', '_')
end
-- str is only set if there has been an error.
if not str then
str = '[[Talmud]], <abbr title="' .. talmud.jb_key[jb] .. '">' .. jb .. '.</abbr> '
str = str .. tractate .. " " .. daf .. url
end
return str
end
return talmud