Difference between revisions of "Module:Transclusion count/sandbox"

From blackwiki
Jump to navigation Jump to search
blackwiki>Ahecht
(add debugging ability)
blackwiki>Ahecht
(Allow passing a default value to be used if the lookup fails.)
Line 2: Line 2:
  
 
function p.main(frame)
 
function p.main(frame)
local template = frame.args[1] or mw.title.getCurrentTitle().text
+
local template = frame.args[2] or mw.title.getCurrentTitle().text
local index = mw.ustring.sub(template,1,1)
+
local index = mw.ustring.upper(mw.ustring.sub(template,1,1))
 
local data = mw.loadData('Module:Transclusion_count/data/' .. (mw.ustring.find(index, "%a") and index or "other"))
 
local data = mw.loadData('Module:Transclusion_count/data/' .. (mw.ustring.find(index, "%a") and index or "other"))
return data[template]
+
return data[template] or frame.args[1] or nil
 
end
 
end
  
 
return p
 
return p

Revision as of 04:37, 10 August 2019

Documentation for this module may be created at Module:Transclusion count/sandbox/doc

local p = {}

function p.main(frame)
	local template = frame.args[2] or mw.title.getCurrentTitle().text
	local index = mw.ustring.upper(mw.ustring.sub(template,1,1))
	local data = mw.loadData('Module:Transclusion_count/data/' .. (mw.ustring.find(index, "%a") and index or "other"))
	return data[template] or frame.args[1] or nil
end

return p