Module:Cite and Module:Cite/sandbox: Difference between pages

(Difference between pages)
Jump to navigation Jump to search
Page 1
Page 2
imported>Ahecht
simplify
 
imported>Ahecht
expand unknown templates that exist
 
Line 1: Line 1:
require ('strict');
require ('strict');


local cfg = mw.loadData ('Module:Cite/config');
local cfg = mw.loadData ('Module:Cite/config/sandbox');




Line 48: Line 48:
]]
]]


local function cite (frame, template)
local function cite (frame, template_name)
local template = template_name:lower(); -- lowercase for table indexes
 
local args_t = require ('Module:Arguments').getArgs (frame, {frameOnly=true});
local args_t = require ('Module:Arguments').getArgs (frame, {frameOnly=true});
local known_t = cfg.known_templates_t[template] -- boolean true if using [[Module:Citation/CS1]]


template = template:lower(); -- lowercase for table indexes
if not known_t then -- do we recognize this template name?
local title = mw.title.new("Cite "..template_name, 10)
if not cfg.known_templates_t[template] then -- do we recognize this template name?
if title.content then -- does it exist? (using content because exists is expensive)
return frame:expandTemplate{title=title.text, args=args_t} -- use the template directly
end
return make_error_msg (frame, substitute (cfg.settings_t.unknown_name, {template})); -- nope; abandon with error message
return make_error_msg (frame, substitute (cfg.settings_t.unknown_name, {template})); -- nope; abandon with error message
elseif type(known_t) == 'table' then
return require(known_t[1])[known_t[2]](frame) -- call alternative module
end
end