Jump to content

Module:Good article topics: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
add default value for the topic variable
avoid the need for any string matching if no topic argument specified
Line 4: Line 4:


function p.main(frame)
function p.main(frame)
local topic = frame:getParent().args[1] or ''
local topic = frame:getParent().args[1]
if not topic then
return ''
end
topic = topic:match('^%s*(.-)%s*$') -- Trim whitespace
topic = topic:match('^%s*(.-)%s*$') -- Trim whitespace
local ret
local ret

Revision as of 07:57, 19 February 2014

-- This module implements {{GA/Topic}}.

local p = {}

function p.main(frame)
	local topic = frame:getParent().args[1]
	if not topic then
		return ''
	end
	topic = topic:match('^%s*(.-)%s*$') -- Trim whitespace
	local ret
	if topic ~= '' then
		ret = p._main(topic)
	end
	ret = ret or ''
	return ret
end

function p._main(topic)
	topic = topic:lower()
	local data = mw.loadData('Module:Good article topics/data')
	return data[topic]
end

return p