Module:PHLawAmend/list

From Wikisource
Jump to navigation Jump to search
local p = {}
abbrsModule = require( "Module:PHLawAmend/abbrs" )
abbrs = abbrsModule.main

function p.list( frame )
	--Check if theres a president abbr
	if string.find(frame.args[3], "%(%a+%)") then
		local presStart, presEnd = string.find(frame.args[3], "%(%a+%)")
		local pres = abbrsModule.presidents[string.sub(frame.args[3], presStart+1, presEnd-1)][1]
		cat = abbrs[frame.args[1]][2]..pres..'/' .. frame.args[2] .. '/' .. frame.args[3]
	else 
		cat = abbrs[frame.args[1]][2]..'/' .. frame.args[2] .. '/' .. frame.args[3]
	end
	
	
	a = frame:callParserFunction("#ifexist", "Category:"..cat, frame:preprocess(
		"<DynamicPageList>"..
		"\ncategory="..cat..
		"\nmode=none"..
		"\nordermethod=sortkey"..
		"\nnamespace=main"..
		"</DynamicPageList>"
	), '')
	
    return a
end

function p.statusText( frame )
	repeal = frame:callParserFunction("#ifexist", "Category:"..abbrs[frame.args[1]][2]..'/repeal/' .. frame.args[2], "true", "false")
	amend = frame:callParserFunction("#ifexist", "Category:"..abbrs[frame.args[1]][2]..'/amend/' .. frame.args[2], "true", "false")
	
	if (repeal == "true" and amend == "true") then return "Amended and repealed (whole or part)" 
	elseif (repeal == "true" and amend == "false") then return "Repealed (whole or part)" 
	elseif (repeal == "false" and amend == "true") then return "Amended"
	else return "In force" end
end

function p.statusStyle( frame )
	repeal = frame:callParserFunction("#ifexist", "Category:"..abbrs[frame.args[1]][2]..'/repeal/' .. frame.args[2], "true", "false")
	amend = frame:callParserFunction("#ifexist", "Category:"..abbrs[frame.args[1]][2]..'/amend/' .. frame.args[2], "true", "false")
	
	if (repeal == "true" and amend == "true") then return "background-color: #FFFFCC;"
	elseif (repeal == "true" and amend == "false") then return "background-color: #ed9a9a;" 
	elseif (repeal == "false" and amend == "true") then return "background-color: #AAF0D1;"
	else return "background-color: #8dd6a0;" end
end
return p