-- Modules we needlocal getArgs = require('Module:Arguments').getArgslocal warn = require('Module:Warning')
-- Configurationlocal cfg = mw.loadData('Module:Folger Shakespeare/config');local _plays = mw.loadData('Module:Folger Shakespeare/plays');
-- Turn plays table inside out so we can look up by alias toolocal plays = for _, play in pairs(_plays) do for _, key in pairs(play.keys) do plays[key] = endend
-- This module's function lookup table, used by the calling contextlocal p =
function p.sfd(args) local play = plays[args[1]] local act = tonumber(args[2]) local scene = tonumber(args[3]) local line = args[4]
-- Check the play argument if play
"" then warn("No play argument provided, or the play provided was not recognised.") return end
-- Check the act argument if act
"" then warn("No act argument provided, or the act given was not numerical.") return end
-- Check the scene argument if scene
"" then warn("No scene argument provided, or the scene given was not numerical.") return end
-- Check the line argument if line
"" then warn("No line argument provided.") return end
local display_line = line if mw.ustring.match(line, '^%s*%d+[-–]%d+%s*$') then line = mw.ustring.match(line, '^%s*(%d+)[-–]%d+%s*$') elseif mw.ustring.match(line, '^%s*%d+%s*$') then line = mw.ustring.match(line, '^%s*(%d+)%s*$') else warn(("Could not coerce %s into a valid line specification."):format(line)) return end
local location = mw.ustring.format('line-%d.%d.%d', act, scene, line) local url = mw.ustring.format(cfg.url_pattern, play.folgerid, act, scene, location)
local id = play.title .. act .. '_' .. scene .. '_' .. display_line local name = 'FOOTNOTE' .. id
local location_link = mw.ustring.format(cfg.location_format, url, act, scene, display_line) local cite = mw.ustring.format("%s, %s", play.title, location_link)
local result = mw.getCurrentFrame:extensionTag return resultend
function p.supported_plays(frame) local t = mw.html.create('table') :addClass('wikitable') :addClass('sortable') t:tag('tr') :tag('th'):wikitext('Play') :tag('th'):wikitext('Aliases') for _, play in ipairs(_plays) do local playlink = mw.ustring.format("%s", play.wikilink, play.title) local row = t:tag('tr') row:tag('td'):wikitext(playlink) local aliasList = frame:expandTemplate row:tag('td'):wikitext(aliasList) end return tend
function p.main(frame) local args = getArgs(frame) return p.sfd(args)end
return p