Module:Sandbox/trappist the monk/cite
Module documentation[] [purge]
require ('strict');
--[[--------------------------< K N O W N _ T E M P L A T E S _ T >-------------------------------------------
list of all known cs1|2 templates by their canonical names
key is lowercase canonical template name
]]
local known_templates_t = {
['arxiv'] = true,
['av media'] = true,
['av media notes'] = true,
['biorxiv'] = true,
['book'] = true,
['citation'] = true,
['citeseerx'] = true,
['conference'] = true,
['document'] = true,
['encyclopedia'] = true,
['episode'] = true,
['interview'] = true,
['journal'] = true,
['magazine'] = true,
['mailing list'] = true,
['map'] = true,
['medrxiv'] = true,
['news'] = true,
['newsgroup'] = true,
['podcast'] = true,
['press release'] = true,
['report'] = true,
['serial'] = true,
['sign'] = true,
['speech'] = true,
['SSRN'] = true,
['tech report'] = true,
['thesis'] = true,
['web'] = true,
}
--[[--------------------------< C I T A T I O N _ C L A S S E S _ T >-----------------------------------------
|CitationClass= in the cs1|2 templates gets the lowercase template name except for these
key is lowercase canonical template name
]]
local citation_classes_t = { --
['av media'] = 'audio-visual',
['av media notes'] = 'AV-media-notes',
['encyclopedia'] = 'encyclopaedia',
['mailing list'] = 'mailinglist',
['press release'] = 'pressrelease',
['tech report'] = 'techreport',
}
--[[--------------------------< C I T E >---------------------------------------------------------------------
test to prove that Module:Citation/CS1/sandbox can be called from another Module
{{#invoke:Sandbox/trappist the monk/cite|cite|book|title=Title}}
TODO: needs better error handling
]]
local function cite (frame)
local args_t = require ('Module:Arguments').getArgs (frame);
if not args_t[1] then -- this is the template name; we must have a template name
return error ('missing template name as first positional parameter'); -- no template name; abandon with error message
end
local template = args_t[1]:lower(); -- lowercase for table indexes
args_t[1] = nil; -- unset, no longer needed (and would break the cs1|2 template)
if not known_templates_t[template] then -- do we recognize this template name?
return error ('unknown template name: ' .. template); -- nope; abandon with error message
end
local config_t = {['CitationClass'] = citation_classes_t[template] or template};
return require ('Module:Citation/CS1/sandbox')._citation (nil, args_t, config_t);
end
--[[--------------------------< E X P O R T S >---------------------------------------------------------------
]]
return {
cite = cite,
}