local export =
local data = mw.loadData("Module:Legislationuk/data")
-- TODO: Use .local function roman(num)end
-- Constructor for an Act object.local function makeAct(text) local Act = local links = -- Parse the pseudo-template used for each Act and extract the parameters. text = text:gsub("^.-$", "") -- Wikilinks need to be temporarily substituted to prevent middle pipes from disrupting the parse. local u, i = mw.ustring.char, 1 for link in text:gmatch("%[%[(.-)%]%]") do links[i] = "" .. link .. "" text = text:gsub("%[%[" .. link .. "%]%]", u(0xE000+i)) end --Extract the arguments. local args = mw.text.split(text, "|") --Re-substitute any links. local cp = mw.ustring.codepoint for i, arg in ipairs(args) do args[i] = mw.ustring.gsub(arg, "[" .. u(0xE000) .. "-" .. u(0xF000) .. "]", function(cap1) return links[cp(cap1)-0xE000] end) end -- Parse each argument to extract the key and value. Any numbered arguments preceded by a named argument in the wikitext will need to have their keys adjusted downwards. for i, arg in ipairs(args) do local name = arg:match("^(.-)=") or i local val = arg:gsub("^" .. name .. "=", "") or arg while type(name)
nil do name = name - 1 end Act._args[name] = val end function Act:getArgs return self._args end -- Give the (English) short title as a link (which may be given explicitly in the wikitext, so as to support piped links). -- FIXME: This will break if a user tries to link only part of the title. Do we want to allow that? function Act:shortTitle if self:getArgs[1]:match("^%[%[.*%]%]$") then return self:getArgs[1] else return "" end end function Act:cyShortTitle return self:getArgs.cyshort end function Act:longTitle return self:getArgs[5] end function Act:cyLongTitle return self:getArgs.cylong end -- Gives the legislation type, which may be contextually adjusted based on an optional parameter (e.g. for URLs). function Act:type(context) if context
"y" or false end function Act:isMaintained return self:getArgs.maintained
"welsh" then return "https://archives.library.wales/index.php/" .. self:getArgs.url else leg_type = "public" and "PU" or "PB" local session = "" if self:date < os.time then for _, t in ipairs(data) do if legDate >= t.sDate.date and legDate <= t.eDate.date then session = t.archive end end end local num = self:type
"govUK" then return "" elseif context
function export.main(frame) local html = mw.html local args = frame:getParent.args[1] and frame:getParent.args or frame.args local Act -- Iterate over the pseudo-templates to generate the HTML row for each Act. for i, arg in ipairs(args) do if arg:match("