Difference between revisions of "Module:Cite Talmud"

From blackwiki
Jump to navigation Jump to search
test>Daask
(Fix string append for Lua)
test>Daask
(Continue porting features of Template:Cite Talmud)
Line 2: Line 2:
 
local talmud = {}
 
local talmud = {}
  
function talmud.generate_citation(frame) -- This section is the core of the module. 'Name2' is a name of your choice. The same name needs to be referred to when the module is used.
+
talmud.jb_key = {b = "Babylonian", j = "Jerusalem"}
-- The next five lines are mostly for convenience only and can be used as is for your module. The output conditions start on line 20.
+
 
local pf = frame:getParent().args -- This line allows template parameters to be used in this code easily. The equal sign is used to define variables. 'pf' can be replaced with a word of your choice.
+
function talmud.generate_citation(...) -- frame
-- local f = frame.args -- This line allows parameters from {{#invoke:}} to be used easily. 'f' can be replaced with a word of your choice.
+
local template_args = frame:getParent().args
jb      = pf[1] or 'b' -- b for Babylonian Talmud or y for Jerusalem Talmud. Babylonian is default.
+
-- local invoke_args = frame.args -- parameters from {{#invoke:}}
     tractate = pf[2]
+
jb      = template_args[1]
     chapter  = pf[3] -- Chapter name or number (optional)
+
if not(jb) or string.find(jb, '^%s*$') then jb = 'b' end
     daf      = pf[4] -- These are page or folio numbers as described at Talmud#Slavuta Talmud 1795 and Vilna Talmud 1835. Ranges are accepted, eg. 2b-4a
+
jb = '<abbr title="' .. talmud.jb_key[jb] .. '">' .. jb .. '.</abbr>'
str = "Talmud, " .. jb .. ". " .. tractate .. " " .. daf
+
     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 = "[[Talmud]], " .. jb .. ". " .. tractate .. " " .. daf .. url
 
return str
 
return str
 
end
 
end
  
 
return talmud
 
return talmud

Revision as of 14:13, 15 May 2019

Implements {{Cite Talmud}}


-- For unit tests, see [[Module:Bananas/testcases]]
local talmud = {}

talmud.jb_key = {b = "Babylonian", j = "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
	jb = '<abbr title="' .. talmud.jb_key[jb] .. '">' .. jb .. '.</abbr>'
    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 = "[[Talmud]], " .. jb .. ". " .. tractate .. " " .. daf .. url
	return str
end

return talmud