Module:Cite: Difference between revisions

Content deleted Content added
No edit summary
simplify
 
(4 intermediate revisions by 2 users not shown)
Line 22:
]]
 
local function make_error_msg (frame, msg, nocat)
local module_name = frame:getTitle(); -- get the module name for prefix and help-link label
local namespace = mw.title.getCurrentTitle().namespace; -- used for categorization
 
local category_link = ((0 == namespace) and not nocat) and substitute ('[[Category:$1]]', {cfg.settings_t.err_category}) or '';
return substitute ('<span style="color:#d33">Error: &#x7B;{[[$1|#invoke:$2]]}}: $3 ([[:$4|$5]])</span>$6',
{
Line 34:
cfg.settings_t.help_text_link, -- help wikilink to text at help page
cfg.settings_t.help, -- help wikilink display text
category_link -- link to error category (for main namespace errors only)
})
end
Line 44:
post-expand include size limit.
 
{{#invoke:cite|cite|book|title=Title}}
 
]]
 
local function cite (frame, template)
local args_t = require ('Module:Arguments').getArgs (frame, {frameOnly=true});
 
if not args_t[1] then -- this is the template name; we must have a template name
local template = args_t[1]template:lower(); -- lowercase for table indexes
return make_error_msg (frame, cfg.error_messages_t.missing); -- 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 cfg.known_templates_t[template] then -- do we recognize this template name?
return make_error_msg (frame, substitute (cfg.error_messages_tsettings_t.unknownunknown_name, {template})); -- nope; abandon with error message
end
 
local config_t = {['CitationClass'] = cfg.citation_classes_t[template] or template}; -- set CitationClass value
return require ('Module:Citation/CS1/sandbox')._citation (nil, args_t, config_t); -- TODO:go switchrender tothe live modulecitation
end
 
Line 69 ⟶ 65:
]]
 
return setmetatable({}, {__index = -- returns an empty TABLE whose metatable has the __index set so that, for any given KEY, it returns
return {
function(_, template) -- this anonymous function called as function(TABLE, KEY)
cite = cite,
return function (frame) return cite (frame, template) end; -- which in turn returns a function that calls cite() with the KEY name
}
end
})