See Template:TOR
local libraryUtil = require('libraryUtil')
local checkType = libraryUtil.checkType
local mArguments -- initialized lazily
local data = mw.loadJsonData('Module:TOR/data.json')
local p = {}
---Get citation
--- @param frame table - template arguments
--- @return string
function p.main(frame)
mArguments = require('Module:Arguments')
return p._main(mArguments.getArgs(frame), frame)
end
--- @param args table - template arguments
--- @param frame table - data
--- @return string
function p._main(args, frame)
checkType('_main', 1, args, 'table')
checkType('_main', 2, frame, 'table')
local key = mw.text.trim(args[1] or "")
if key == "" then
return ""
end
local book = data.citations[key]
if not book then
return "<span class='error'>Unknown citation key: " .. key .. "</span>"
end
local citeArgs = {
author = book.author or "",
title = book.title or "",
date = book.date or "",
publisher = book.publisher or "",
chapter = args.chapter or args[3] or "",
page = args.page or args[2] or "",
pages = args.pages or ""
}
return frame:expandTemplate{ title = 'cite book', args = citeArgs }
end
return p