Jump to content

Module:User:IPOfAFlower/readThat

From Wikipedia, the free encyclopedia
local p = {}

local data = mw.loadJsonData("User:IPOfAFlower/read.json")
local config = mw.loadJsonData("User:IPOfAFlower/scripts/readIt.config.json")

function p.main(frame) 
	local root = mw.html.create("div")
	local headers = {}
	
	for name, status in pairs(data) do
		if headers[status['type']] == nil then 
			root:tag("h3"):wikitext(config[status['type']]["display"])
			headers[status['type']] = root:tag("ul")			                              
		end
		
		local li = headers[status['type']]:tag("li")
		if config[status['type']]['needsAgree'] then 
			local template;
			if status["agreed"] then 
				template = "{{agree}}:"
			else
				template = "{{Disagree}}"
            end
			li:wikitext(frame:preprocess(template)) 
		end

		li:wikitext(" [["..name.."]]")
        
        if config[status['type']]['showDate'] then
		  li:wikitext(" - read at " .. status['date'])
        end
		li:done()
	end

	return root
end

return p